Tokens with '' causing trouble for StringTemplate
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Thursday, September 29, 2011 04:13 PM

I'm just getting started with ANTLR v3 and StringTemplate. I have a very simple DSL that allows me to indicate I/O direction using ' <-', '->', and ' <->'. I've defined these in a token block as: IN = '->'; OUT = ' <-'; INOUT = ' <->'; This works great when generating ASTs; however, when I try to use StringTemplate with any of my DSL's source containing ' <-', then I get the following exception. problem parsing template 'anonymous' line 1:1: unexpected char: ' <' at org.antlr.stringtemplate.language.AngleBracketTemplateLexer.nextToken(AngleBracketTemplateLexer.java:149) at antlr.TokenBuffer.fill(TokenBuf   More>>

I'm just getting started with ANTLR v3 and StringTemplate. I have a very simple DSL that allows me to indicate I/O direction using ' <-', '->', and ' <->'. I've defined these in a token block as:

			
IN = '->';
OUT = ' <-';
INOUT = ' <->';


This works great when generating ASTs; however, when I try to use StringTemplate with any of my DSL's source containing ' <-', then I get the following exception.

			
problem parsing template 'anonymous'
line 1:1: unexpected char: ' <'
at org.antlr.stringtemplate.language.AngleBracketTemplateLexer.nextToken(AngleBracketTemplateLexer.java:149)
at antlr.TokenBuffer.fill(TokenBuffer.java:69)
at antlr.TokenBuffer.LA(TokenBuffer.java:80)
at antlr.LLkParser.LA(LLkParser.java:52)
at org.antlr.stringtemplate.language.TemplateParser.template(TemplateParser.java:103)
at org.antlr.stringtemplate.StringTemplate.breakTemplateIntoChunks(StringTemplate.java:850)
at org.antlr.stringtemplate.StringTemplate.setTemplate(StringTemplate.java:441)
at org.antlr.stringtemplate.StringTemplate. (StringTemplate.java:308)
at com.kevlindev.simpleType.SimpleTypeJava.io(SimpleTypeJava.java:444)
at com.kevlindev.simpleType.SimpleTypeJava.property(SimpleTypeJava.java:374)
at com.kevlindev.simpleType.SimpleTypeJava.type(SimpleTypeJava.java:224)
at com.kevlindev.simpleType.SimpleTypeJava.prog(SimpleTypeJava.java:114)
at com.kevlindev.simpleType.SimpleTypeTest.parse(SimpleTypeTest.java:74)
at com.kevlindev.simpleType.SimpleTypeTest.main(SimpleTypeTest.java:31)


Based on the error, it looks like I need to somehow escape the angle brackets in my tokens. I tried escaping them in the tree-building parser, but that had no effect. If I change the tokens to use text without brackets, all is good. Any suggestions on how I can get around this issue?

Thanks,

Kevin

   <<Less

Re: Tokens with '' causing trouble for StringTemplate

Posted By:   Anonymous  
Posted On:   Thursday, September 29, 2011 04:16 PM

Note that the title should be: "Tokens with '<' causing trouble for StringTemplate". I didn't realize I needed to entitize my title :)
About | Sitemap | Contact