Thank you for your explanation. And your solution works great, too.

Christian

Am 03.11.2011 21:31, schrieb Jim Idle:
> You don't want that anyway as your nodes will not have token start and
> stop information and you might need that.
>
> method_declaration
>      : method_header method_body
>      ;
>
> method_body
>       : (
>                 ';'!  
>       | '{'!   statement_list?   '}'!
>        )
>               -> ^(METHOD_BODY statement_list?)
>      ;
>
> method_header
>       :  attributes ID etc
>
>               ->^(METHOD_HEADER attributes ID )
>       ;
>
>
> Jim
>
>> -----Original Message-----
>> From: [email protected] [mailto:antlr-interest-
>> [email protected]] On Behalf Of Christian
>> Sent: Thursday, November 03, 2011 1:01 PM
>> To: [email protected]
>> Subject: [antlr-interest] Check if rule returns empty result
>>
>> Hi at all,
>>
>> I have the following rules:
>>
>> method_declaration
>>     : method_header method_body  -> ^(METHOD_HEADER method_header)
>> ^(METHOD_BODY method_body)
>>     ;
>>
>> method_body:
>>     ';'!
>>     | '{'!   statement_list?   '}'!;
>>     ;
>>
>> Of course, method_body is executed because it has no question mark.
>> However, introducing rewrite rules and operators cause a problem. By
>> using ^(METHOD_BODY method_body), method_body must return a non-empty
>> value. However, statement_list? is optional and thus may not match at
>> all. In this case, method_body returns nothing anymore and I get an
>> RewriteEmpty exception.
>>
>> How can I solve this problem by only changing rewrite rules?
>>
>> Regards,
>> Christian
>>
>> 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
>


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