wc_rules/expressions/expression.lark
%import common.CNAME
%import common.WS_INLINE
%import common.NUMBER
%ignore WS_INLINE
%import common.ESCAPED_STRING
%import common.NEWLINE
COMMENT: /#.*/
%ignore COMMENT
%ignore NEWLINE
?literal.1: NUMBER -> number | "True"-> true | "False" -> false | ESCAPED_STRING -> string
?atom: literal | function_call | "(" expression ")"
variable: CNAME
attribute: CNAME
arg: (expression|boolean_expression)
kw: CNAME
kwarg: kw "=" arg
args: arg ("," arg )*
kwargs: kwarg ("," kwarg)*
function_name: CNAME
subvariable: CNAME
function_call: variable ["." subvariable] "." function_name "(" [args|kwargs] ")"
| variable ["." subvariable] "." attribute
| function_name "(" [args|kwargs] ")"
| variable
?sum: term (add_op term)*
?term: factor (mul_op factor)*
?factor: factor_op factor | atom
?factor_op: "+" -> noflip | "-" -> flipsign
?add_op: "+" -> add | "-" -> subtract
?mul_op: "*" -> multiply | "/" -> divide
?expression: sum
boolean_expression: expression bool_op expression
?bool_op: ">=" -> geq | "<=" -> leq | ">" -> ge | "<" -> le | "==" -> eq | "!=" -> ne
assignment: declared_variable "=" (expression|boolean_expression)
declared_variable: CNAME
?start: (assignment|boolean_expression)