I have the following grammar:
@top Program { expression }
@skip { space }
expression { Identifier | Number | brackets<Op> | FunctionCall }
Plus { expression !plus ArithOp<"+"> expression }
And { expression !and LogicOp<"and"> expression }
Op {
Plus |
And
}
FunctionCall { Not }
Not { fn<"not"> "(" expression ")" }
fn<term> { @specialize[@name={term}]<Identifier, term> }
brackets<expression> { "(" expression ")" | expression }
@tokens {
space { @whitespace+ }
identifierChar { @asciiLetter }
word { identifierChar (identifierChar | @digit)* }
Identifier { word }
Number { @digit+ }
ArithOp<term> { term }
LogicOp<term> { term }
}
which handles all the cases such as (1+1)
or not(foo+bar)
or foo + 1
. But LogicOp parses 1and1
or fooandbar
as a valid expression - it should not be allowed - any whitespace should be required before and after that LogicOp eg 1 and 1
or foo and bar
. I tried to introduce requiredSpace token, but it can’t be compiled because it overlaps with @skip { space }. Is this somehow possible? Thank you