Correct way to eliminate the ambiguities of the lexer ANTLR rule?

Please see the source code: https://gist.github.com/1684022 .

I have two signs:

ID  :   ('a'..'z' | 'A'..'Z') ('0'..'9' | 'a'..'z' | 'A'..'Z' | ' ')*;

PITCH   
    :   (('A'|'a') '#'?)
    |   (('B'|'b') '#'?) 
    |   (('C'|'c') '#'?);

Obviously, the letter "A" will be ambiguity.

Next, I define:

note    :   PITCH;
name    :   ID;
main    :   name ':' note '\n'?

Now, if I enter “A: A” as input to the parser, I always get an error message. Either the parser expects a PITCH, or an ID depending on whether the identifier or PITCH is determined:

mismatched input 'A' expecting ID

What is the correct way to allow this to work as intended?


, , , ANTLR " ". , main , name/ID, , , "A" PITCH, " " / " ", , "".

/ , ID PITCH, , dasblinkenlight?

+5
1

, :

ID  :   (('a'..'z' | 'A'..'Z') ('0'..'9' | 'a'..'z' | 'A'..'Z' | ' ')+)
    |   ('d'..'z' | 'D'..'Z');

PITCH : 'a'..'c' | 'A'..'C';

SHARP : '#';

note    :   PITCH SHARP?;

name    :   ID | PITCH;

main    :   name ':' note '\n'? EOF

, "" . "" .

+4

All Articles