[antlr-interest] How does one refer to the char matching '.'?

Vaclav Barta vbar at comp.cz
Sun Jul 15 09:59:31 PDT 2007


Hi,

I'd like to have a lexer rule for string characters:

StringChar
	: .
	;

I presume that when defining it as the last rule, after quote tokens etc., 
only the "generic" characters will match, and it does seem to work, but how 
do I get at the matched character?

Perhaps not very surprisingly,

StringChar returns [ char value ]
	: . { $value = $.; }
	;

doesn't work:

    [javac] /home/vb/antlr/antmaker/src/LoaderLexer.java:395: <identifier> 
expected
    [javac]                value = $.;
    [javac]                          ^

Is there some special syntax I'm missing?

	Bye
		Vasek


More information about the antlr-interest mailing list