[antlr-interest] Generator Bug: Expands $ within Comments

Thomas Brandon tbrandonau at gmail.com
Thu Aug 7 01:10:35 PDT 2008


Actually ANTLR does assume that target languages use C style comments
to allow unmatched action block and string delimiters in comments. But
this is only in ANTLR.g not in the seperate action parser. Though the
action parser does allow escaping (\$) to get around the problem here.
This means using unmatched delimiters in python single line comments
will cause problems. Multi line comments are handled by the string
handling, though an unmatched " here will cause problems. Delimiting
is not handled in ANTLR.g so there is currently no way to get around
this.
Probably a good idea to standardise and allow delimiting in both.
Possibly also keeping the current comment\string handling, with target
control, to make it easier for users.

Tom.
On Thu, Aug 7, 2008 at 5:33 PM, Benjamin Niemann <pink at odahoda.de> wrote:
> Hi Brent,
>
> this is by design. ANTLR doesn't know about the syntax of the target
> language, including how comments look like.
>
> -Ben
>
>
> On Wed, Aug 6, 2008 at 10:43 PM, Foust <javafoust at gmail.com> wrote:
>> The latest beta (from 08/03/2008) expands parser variables within comments:
>>
>>
>>
>> statement                           : ^(T_STMT expr?)
>>
>>                                                 {
>>
>>
>> System.out.println("STMT: ");// + $expr.text);
>>
>>                                                 }
>>
>>
>>
>> It wouldn't be such an issue, except there are cases (like this one) where
>> the expansion extends over multiple lines, so temporarily-commenting out a
>> portion of a line using a line comment as above causes a compilation problem
>> in the target language:
>>
>>
>>
>>    System.out.println("STMT: ");
>> //(object1!=null?(input.getTokenStream().toString(
>>
>>            input.getTreeAdaptor().getTokenStartIndex(object1.start),
>>
>>            input.getTreeAdaptor().getTokenStopIndex(object1.start))):null));
>>
>>
>>
>>
>>
>> Brent
>>
>>
>


More information about the antlr-interest mailing list