123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- {
- const {tc, term} = options;
- }
- term
- = maybeFactor:maybe_factor remainingAdds:remaining_adds {
- return tc.tokenTerm(maybeFactor, remainingAdds);
- }
- remaining_adds = add_sub*
- add_sub
- = operator:add_sub_operator rhs:maybe_factor {
- return tc.tokenOperation(operator, rhs);
- }
- maybe_factor
- = spaces term:(factor / primary) spaces {
- return term;
- }
- factor
- = primary:primary remaining:remaining_muls {
- return tc.tokenFactor(primary, remaining);
- }
- remaining_muls = mul_div+
- mul_div
- = operator:mul_div_operator rhs:primary {
- return tc.tokenOperation(operator, rhs);
- }
- add_sub_operator
- = spaces operator:(plus / minus) spaces {
- return operator;
- }
- mul_div_operator
- = spaces operator:(multiply / divide) spaces {
- return operator;
- }
- primary
- = spaces primary:(parens / numeric_value / function_value / field_value) spaces {
- return primary;
- }
- parens
- = open_paren term:term closed_paren {
- return term;
- }
- plus
- = "+" {
- return "plus";
- }
- minus
- = "-" {
- return "minus";
- }
- multiply
- = "*" {
- return "multiply";
- }
- divide
- = [/÷] {
- return "divide";
- }
- function_value "function"
- = function_name open_paren spaces function_args? spaces closed_paren {
- return tc.tokenFunction(text(), location());
- }
- numeric_value "number"
- = [+-]?[0-9]+ ("." [0-9]*)? {
- return text();
- }
- field_value "field"
- = [a-zA-Z_\.]+ {
- return tc.tokenField(text(), location());
- }
- function_args
- = aggregate_param (spaces comma spaces aggregate_param)*
- aggregate_param
- = quoted_aggregate_param / raw_aggregate_param
- raw_aggregate_param
- = param:[^()\t\n, \"]+
- quoted_aggregate_param
- = '"' param:('\\"' / [^\t\n\"])* '"'
- function_name = [a-zA-Z_0-9]+
- comma = ","
- open_paren = "("
- closed_paren = ")"
- spaces = " "*
|