[antlr-interest] "new CommonToken" issued in Java target in spite of setting TokenLabelType to something else

Hardy, Stephen Stephen_Hardy at rabbit.com
Thu Aug 2 11:06:43 PDT 2007


There seems to be a bug in the Java target string template.  Even though
I set TokenLabelType = MyToken in the parser/lexer options, the lexer
template is generating code like

            MyToken DECIMAL_LITERAL1=null;
		...
            DECIMAL_LITERAL1 = new CommonToken(input,
Token.INVALID_TOKEN_TYPE, 
                 Token.DEFAULT_CHANNEL, 
                 DECIMAL_LITERAL1Start1480, getCharIndex()-1);		

(which causes a type mismatch compile error) for .g file input like

LINE_COMMAND 
	: '#' WSNONL+ 
		DECIMAL_LITERAL 
		{
			line_offset =
Integer.parseInt($DECIMAL_LITERAL.text) - tokenStartLine;
		}
		WSNONL+ 
		STRING_LITERAL 
		{
			currentFile = $STRING_LITERAL.text;
			file_changed = true;
		}
		~('\n'|'\r')* '\r'? '\n' {skip();}
    ;

The error seems to be fixable by modifying the Java.stg (string
template) file in the source, however I have not had previous success in
modifying the templates owing to my abysmal lack of understanding of
Java etc.

Can anyone tell me (preferably in words of 1 syllable or less) how to
get Antlr to actually read a modified template file?  Where do I have to
stick it to get it to be read?  Somebody mentioned putting it in the
classpath, but the classpath is not really a path but a list of jar
files.  How do I add the template files to a jar file??!!??

Regards,
SJH


More information about the antlr-interest mailing list