[antlr-interest] ANTLR problem with .+ in tree grammar
Sam Harwell
sharwell at pixelminegames.com
Sat Jun 25 09:55:34 PDT 2011
I use the following rule for that:
genericBlock
: '{'
(genericBlock | ~('{'|'}'))*
'}'
;
Since the curly braces are inside the genericBlock rule, you'll have to modify your componentStatement rule:
componentStatement
: 'component'^ IDENT genericBlock ';'!
;
Sam
-----Original Message-----
From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Dariusz Dwornikowski
Sent: Saturday, June 25, 2011 5:30 AM
To: antlr-interest at antlr.org
Subject: [antlr-interest] ANTLR problem with .+ in tree grammar
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
-----------------------------------------------------------------------------
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
More information about the antlr-interest
mailing list