79 lines
1.3 KiB
Plaintext
79 lines
1.3 KiB
Plaintext
@external propSource highlighting from "./highlight.js"
|
|
@top Program { (Expression newline)* }
|
|
|
|
@tokens {
|
|
Number { "-"? $[0-9]+ ('.' $[0-9]+)? }
|
|
Boolean { "true" | "false" }
|
|
String { '\'' !["]* '\'' }
|
|
newline { "\n" | @eof }
|
|
space { " " }
|
|
leftParen { "(" }
|
|
rightParen { ")" }
|
|
"+"[@name=operator]
|
|
"-"[@name=operator]
|
|
"*"[@name=operator]
|
|
"/"[@name=operator]
|
|
}
|
|
|
|
@external tokens tokenizer from "./tokenizers" { Identifier, Word }
|
|
@precedence {
|
|
multiplicative @left,
|
|
additive @left
|
|
}
|
|
|
|
Expression {
|
|
FunctionCall |
|
|
FunctionCallOrIdentifier |
|
|
BinOp |
|
|
ParenExpr |
|
|
Word |
|
|
String |
|
|
Number |
|
|
Boolean
|
|
}
|
|
|
|
|
|
FunctionCallOrIdentifier {
|
|
Identifier
|
|
}
|
|
|
|
FunctionCall {
|
|
Identifier (~ambig space arg)+
|
|
}
|
|
|
|
arg {
|
|
PositionalArg | NamedArg | IncompleteNamedArg
|
|
}
|
|
|
|
PositionalArg {
|
|
value
|
|
}
|
|
|
|
NamedArg {
|
|
Identifier "=" value
|
|
}
|
|
|
|
IncompleteNamedArg {
|
|
Identifier "="
|
|
}
|
|
|
|
BinOp {
|
|
operand ~ambig space !multiplicative "*" space operand |
|
|
operand ~ambig space !multiplicative "/" space operand |
|
|
operand ~ambig space !additive "+" space operand |
|
|
operand ~ambig space !additive "-" space operand
|
|
}
|
|
|
|
operand {
|
|
value | BinOp
|
|
}
|
|
|
|
|
|
ParenExpr {
|
|
leftParen Expression rightParen
|
|
}
|
|
|
|
value {
|
|
ParenExpr | Identifier | Word | String | Number | Boolean
|
|
}
|