[antlr-interest] Problem using string literals

S West antlr at smabber.com
Sat Oct 20 17:21:43 PDT 2007


I'm using ANTLR 3.0.1, ANTLRWorks 1.1.3 and this is my first post here.  Hi all.

I've reduced to a minimal grammar that replicates my problem:


grammar Test;

test		:	(LETTER | '-')+
		;

unrelated_rule	:	'BONGO: ' LETTER;

LETTER		:	('A'..'Z');



When I choose the main rule to be test and give the input:
ONE-TWO-THREE

The whole input is consumed by test, as expected.

When I choose the main rule to be test and give the input:
ONE-BONGO-TWO-THREE

The output window says 'line:1:9 mismatched character '-' expecting ':'

Out of the input only
ONE-WO-THREE
is consumed.

I do not understand why this is happening, the literal 'BONGO: ' is in a totally separate and 
unreferred-to parser rule.

Please could someone let know me know why this occurs, and hopefully how I can rewrite to avoid it.

Thank you kindly,
Simon.


More information about the antlr-interest mailing list