Fully qualified names failing to be recognised correctly with valid grammar

27 Views Asked by At

I've got a basic ANTLR-4 grammar at the moment in my Eclipse IDE for Java, and have the following:

// Parser

importDeclaration:
    'use' name=FQN ';'
;

// Lexer and terminals

fragment LETTER: [a-zA-Z_];
fragment LETTER_OR_DIGIT: [a-zA-Z0-9_];
ID: LETTER LETTER_OR_DIGIT*;
FQN: ID ('.' ID)*;

WS: [ \t\r\n]+ -> skip ; // skip spaces, tabs, newlines
COMMENT: '/*' .*? '*/' -> channel(HIDDEN);
LINE_COMMENT: '//' ~[\r\n]* -> channel(HIDDEN);

Hopefully a short and sweet question, when I do the following:

use test;

I get:

line 1:4 mismatched input 'test' expecting FQN

And name throws a NullPointerException if I try to use it.
Except it works fine when I do:

use test.test;

This has to do with the ('.' ID)* portion, but have no idea why it's happening.

Any ideas?

Edit:

Just realised my code was wrong, had (FQN|ID) which was my bad workaround. Fixed it now.

0

There are 0 best solutions below