2
votes

I have a short ANTLR grammar:

query : word (WS word)+;
word : simpleword | compoundword;
compoundword : simpleword (NONWORD+ simpleword)+ | NONWORD+ simpleword (NONWORD+ simpleword)* NONWORD*;
simpleword : SIMPLEWORD;

SIMPLEWORD: [0-9a-zA-Z]+;
NONWORD: [-_];
WS  : (' ' | '\r' | '\n');

But the generated parser fails to parse string "abc-def qwe qaz" with message "mismatched input '-' expecting WS".

Any tips how to fix this? Why doesn't the "abc-def" match compoundword production (first alternative)?

1

1 Answers

1
votes

Actually the problem was outside the code posted in the question - I had a few other productions, but I was under the impression that they should not affect my parser if they are not reachable from my topmost production. They did.