Defining antlr rule for identifiers with one chara

2019-09-20 06:26发布

问题:

i like to define a very simple rule, which should represent identifiers. This works quite well for identifiers which are longer than one characters, but for identifiers with exactly one character I get a MismatchedTokenException(64!=45). This is the rule:

ID : ('a'..'z' | 'A'..'Z')+ ;

What is wrong with that?

Thanks!

回答1:

You're absolutely right, the rule on its own is fine, but I figured out that a lot in ANTLR depends on the order of rules. I had another rule before, which did already match the ID rule. Finally it makes sense, because the Lexer cannot decide which rule to take.

Thanks!



标签: antlr