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: [email protected] 
[mailto:[email protected]] On Behalf Of Dariusz Dwornikowski
Sent: Saturday, June 25, 2011 5:30 AM
To: [email protected]
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


List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/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.

Reply via email to