stebln
stebln

Reputation: 51

Defining antlr rule for identifiers with one character

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!

Upvotes: -1

Views: 1549

Answers (1)

stebln
stebln

Reputation: 51

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!

Upvotes: 5

Related Questions