[antlr-interest] Translating recurring input with python target and stringtemplate

Jim Idle jimi at temporal-wave.com
Wed Oct 22 09:43:15 PDT 2008


On Wed, 2008-10-22 at 20:39 +0530, Sharath MS wrote:

> Hi,
> 
> I'm using antlr-3.1b2 with Python as my target language along with
> stringtemplate. I'm trying to translate the following text:
> 
> a1,aa2,aa3,b1
> 
> to
> 
> a1 | aa2 | aa3 | b1
> 
> basically replacing the commas with pipes.
> 
> However, the output that I'm getting is something like this:
> 
> [@0,0:1=u'a1',<4>,1:0] | [@2,3:5=u'aa2',<4>,1:3] |
> [@4,7:9=u'aa3',<4>,1:7] | [@6,11:12=u'b1',<4>,1:11]



THis looks like a text serialization of the entire token..

> 
> Seems that the list being passed to the template contains more than
> just the text. Also, I'm using the rewrite option  and a
> TokenRewriteStream as i need to add to an existing grammar. Any help
> in translating this text in this setup, would be greatly appreciated.
> Thanks!
> 
> Here is the .g, .stg and .py files for your reference:
> 
> --------------------------------------------------
> 
> Foo.g:
> 
> grammar Foo;
> options {
>   language=Python;
>   output=template;
>   rewrite = true;
> }
> 
> prog: stat+;
> 
> stat:
> p+=SYM (',' p+=SYM )*
>         -> printfoo(symbols={$p})


Try $p.text


Jim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20081022/1b5f8e3c/attachment.html 


More information about the antlr-interest mailing list