I use the following Java-code to instantiate a parser generated with ANTLR.
package foo;
public class Test1 {
public static void main(String[] args) throws RecognitionException {
CharStream stream = new ANTLRStringStream("foo ");
BugLexer lexer = new BugLexer(stream);
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
BugParser parser = new BugParser(tokenStream);
parser.specification();
}
}
My grammar:
grammar Bug;
options {
language = Java;
}
@header {
package foo;
}
@lexer::header {
package foo;
}
specification :
'foo' EOF
;
WS
: (' ' | '\t' | '\n' | '\r')+ {$channel = HIDDEN;}
;
SCOLON
: (~ ';')+
;
And the error I get:
line 1:0 mismatched input 'foo ' expecting 'foo'
I would expect the space in the input to be ignored, but its not.. The antlr interpreter in eclipse says its fine so I suppose my Java code is wrong somehow, but I just don't see it...
Note: If I remove the rule for SCOLON then theres not bug for the input.