I'm trying to match a duration string, like for 30 minutes
or for 2 hours
using the following rules:
durationPhrase: FOR_STR (MINUTE_DURATION | HOUR_DURATION);
MINUTE_DURATION: NONZERO_NUMBER MINUTE_STR;
HOUR_DURATION: NONZERO_NUMBER HOUR_STR;
MINUTE_STR: 'minute'('s')?;
HOUR_STR: 'hour'('s')?;
FOR_STR: 'for';
NONZERO_NUMBER: [0-9]+;
WS: (' '|[\n\t\r]) -> skip;
With the following input:
for 30 minutes
Attempting to debug/match the durationPhrase
rule, I'm presented with the error:
line 1:4 mismatched input '30' expecting {MINUTE_DURATION, HOUR_DURATION}
But I can't seem to figure out what lexer rule the '30' is matching? I was under the impression the "longest" lexer rule would win, which would be the MINUTE_DURATION
rule.
Is it instead matching NONZERO_NUMBER
first? And if so, why?