Why is the error listener is not called for invalid token in my antlr4 grammar?

62 Views Asked by At

the start of my top level grammar is:

INT2: INT INT;
INT4 :  INT INT INT INT;
DATE: (INT | INT2) SEP (INT | INT2) SEP (INT2 | INT4);
fromdate: DATE;
todate: DATE;
interval: DATES (fromdate DASH todate);

luah: (interval SEMICOLON remainingpart;

When I feed it the string:

Dates:4/1/2024-4/1/2025 fghyhj

it does not generate the error on fghyhj, but token generation stops at a correct place:

Token: 'DATES', Text: 'Dates:', Line: '1', Column: '0'
Token: 'DATE', Text: '4/1/2024', Line: '1', Column: '6'
Token: 'DASH', Text: '-', Line: '1', Column: '14'
Token: 'DATE', Text: '4/1/2025', Line: '1', Column: '15'
Token: 'SPACES', Text: ' ', Line: '1', Column: '23'

If I feed just an invalid string, like “asdfsdfsedf”, the error handler catches the error: mismatched input 'asdfsdfsedf' expecting {DATES etc.

I don't understand why fghyhj does not generates the error. Thanks!

0

There are 0 best solutions below