I want to match a constant, which is basically an all uppercase string.
Also, I want to match an identifier, which can contain a mix of lowercase and uppercase letters.
Start
= Constant
/ Identifier
Identifier
= h:[A-Za-z_] t:[a-zA-Z0-9_]* { return { type: 'IDENTIFIER', value: h + t.join('') } }
Constant
= h:[A-Z] t:[A-Z_0-9]* { return { type: 'CONSTANT', value: h + t.join('') } }
The problem is, when I try to match Asd
, it says: Line 1, column 2: Expected [A-Z_0-9] or end of input but "s" found.
It seems it matches the Constant rule but doesn't swap to the Identifier one even when it fails...
The problem seems to be that a constant is also a valid identifier, but I can't figure out rules to break the ambiguity, I think if Constant match fails it should just try the Identifier rule...