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:
[EMAIL PROTECTED],0:1=u'a1',<4>,1:0] | [EMAIL PROTECTED],3:5=u'aa2',<4>,1:3] |
[EMAIL PROTECTED],7:9=u'aa3',<4>,1:7] | [EMAIL PROTECTED],11:12=u'b1',<4>,1:11]
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})
;
SYM
: ('a'..'z')+ ('0'..'9')*
;
--------------------------------------------------
Foo.stg:
group Foo;
printfoo(symbols) ::= << <symbols; separator=" | "> >>
--------------------------------------------------
Foo.py:
import sys
import antlr3
import stringtemplate3
from FooParser import FooParser
from FooLexer import FooLexer
inputFileName = sys.argv[1]
templateFileName = sys.argv[2]
templates = stringtemplate3.StringTemplateGroup(
file=open(templateFileName, 'r'), lexer='angle-bracket'
)
input = antlr3.ANTLRFileStream(inputFileName)
lexer = FooLexer(input)
tokens = antlr3.TokenRewriteStream(lexer)
parser = FooParser(tokens)
parser.templateLib = templates
parser.prog()
print tokens.toString()
----------------------------------------------------
Best Regards,
Sharath MS
List: http://www.antlr.org:8080/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org:8080/mailman/options/antlr-interest/your-email-address
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---