[antlr-interest] Matching braces in grammar
Johannes Luber
jaluber at gmx.de
Mon May 21 06:43:57 PDT 2007
Jukkis wrote:
>> Basically you need to replace STRING_LITERAL with something
>> like that:
>>
>> beanshell_statement
>> : "$" LCURLY! block+ RCURLY!
>> ;
>>
>> block
>> : text
>> | LCURLY text RCURLY
>> ;
>>
>> Best regards,
>> Johannes Luber
>
> Hello again, and thank you for your quick response Johannes! However, I feel this solves only part of the problem -- because BeanShell code can have any number of nested curly-brace delimited blocks. Obviously, we cannot just write
>
> block
> : block
> | LCURLY block RCURLY
> ;
>
> since this would lead to an infinite recursion rule, the kind which is not allowed in ANTLR. Also, for the same reason, we cannot refer to the 'block' rule from any rule whose ancestor 'block' is, if I have understood correctly.
How about?
beanshell_statement
: '$' LCURLY! block+ RCURLY!
;
block
: TEXT
| LCURLY block RCURLY
;
TEXT
: ('A'..'Z'|'a'..'z')+
;
Best regards,
Johannes Luber
More information about the antlr-interest
mailing list