[antlr-interest] ANTLR problem with .+ in tree grammar
Dariusz Dwornikowski
dariusz.dwornikowski at cs.put.poznan.pl
Sat Jun 25 03:29:56 PDT 2011
Hi,
I've got such a problem. I am experimenting with the ANTLR in order to
implement some kind of language later. The example below.
Grammar file (interesting part):
...
tokens{
BODY;
}
componentStatement
: 'component'^ IDENT '{'! body '}'! ';'!
;
body
: .+ -> BODY
;
...
tree gramar file:
...
component
: ^('component' name=IDENT body=BODY) {comp.add(new
Component($name.text, $body.text));}
;
..
What i want is to catch such a situation (for experiment purposes only):
component Foo {
anything goes here 123 :)
};
Now, I know rewrite in my example rewrites .+ to BODY it is ok. When I
change the grammar to
body
: .+ -> BODY
;
and tree grammar to:
component
: ^('component' name=IDENT body=(.+)) {comp.add(new
Component($name.text, $body.text));}
;
the generates Walker generates it wrong:
comp.add(new Component((name!=null?name.getText():null), b.text)); it
should have been b.getText()
How can I change files in order to catch what I want?
PS: ANTLR is great:) And Greetings to everybody :)
--
Pozdrawiam,
-----------------------------------------------------------------------------
Dariusz Dwornikowski,
Institute of Computing Science, Poznań University of Technology
www.cs.put.poznan.pl/ddwornikowski/
room 421 WE | tel. +48 61 665 21 24 | mobile: +48 533 890 600
-----------------------------------------------------------------------------
More information about the antlr-interest
mailing list