grammar Soroban

rule formula
  '=' space? logical <Formula> / string / number / boolean
end
rule logical
  and ( space? 'or' space? and )*
end
rule and
  truthval ( space? 'and' space? truthval )*
end
rule truthval
  comparison / '(' space? logical space? ')' / boolean
end
rule boolean
  'true' / 'false' / 'TRUE' / 'FALSE'
end
rule comparison
  expression ( space? comparator space? expression )*
end
rule comparator
  '=' <Equal> / '<>' <NotEqual> / '>=' / '<=' / '>' / '<'
end
rule expression
  multiplicative ( space? additive_operator space? multiplicative )*
end
rule additive_operator
  '+' / '-'
end
rule multiplicative
  value ( space? multiplicative_operator space? value )*
end
rule multiplicative_operator
  '^' <Pow> / '*' / '/'
end
rule value
  ( function / '(' space? expression space? ')' / range / number / boolean / identifier / string / '-' value )
end
rule function
  [a-zA-Z]+ '(' space? arguments? space? ')' <Function>
end
rule arguments
  logical ( space? ',' space? logical )*
end
rule number
  float / integer
end
rule float
  [0-9]* '.' [0-9]+
end
rule integer
  [0-9]+
end
rule identifier
  [a-zA-Z] [a-zA-Z0-9]* <Identifier>
end
rule label
  [A-Za-z]+ [1-9] [0-9]* <Label> / '$' [A-Za-z]+ '$' [1-9] [0-9]* <Label>
end
rule string
  '"' ('\"' / !'"' .)* '"' / "'" [^']* "'"
end
rule range
  label ':' label <Range>
end
rule space
  [\s]+
end

end