[antlr-interest] java.g - a couple of issues

Davin McCall davmac at deakin.edu.au
Thu Mar 17 17:24:12 PST 2005


To clarify, we have changed the single line comment target "SL_COMMENT" 
as follows:

(Original)
// Single-line comments
SL_COMMENT
    :    "//"
        (~('\n'|'\r'))* ('\n'|'\r'('\n')?)
        {$setType(Token.SKIP); newline();}
    ;

(Modified)
// Single-line comments
SL_COMMENT
    :    "//"
        (~('\n'|'\r'))*
        {$setType(Token.SKIP); }
    ;

And the typeArgumentBounds target from:

typeArgumentBounds[boolean addImagNode]
    {boolean isUpperBounds = false;}
    :
        ( "extends"! {isUpperBounds=true;} | "super"! ) 
classOrInterfaceType[addImagNode]
        {
            if (isUpperBounds)
            {
                #typeArgumentBounds = 
#(#[TYPE_UPPER_BOUNDS,"TYPE_UPPER_BOUNDS"], #typeArgumentBounds);
            }
            else
            {
                #typeArgumentBounds = 
#(#[TYPE_LOWER_BOUNDS,"TYPE_LOWER_BOUNDS"], #typeArgumentBounds);
            }
        }
    ;

To:

typeArgumentBounds[boolean addImagNode]
    {boolean isUpperBounds = false;}
    :
        ( "extends"! {isUpperBounds=true;} | "super"! ) 
classOrInterfaceType[addImagNode] arraySpecOpt
        {
            if (isUpperBounds)
            {
                #typeArgumentBounds = 
#(#[TYPE_UPPER_BOUNDS,"TYPE_UPPER_BOUNDS"], #typeArgumentBounds);
            }
            else
            {
                #typeArgumentBounds = 
#(#[TYPE_LOWER_BOUNDS,"TYPE_LOWER_BOUNDS"], #typeArgumentBounds);
            }
        }
    ;


Davin


Davin McCall wrote:

> Hi,
> We're using Michael Studman's java 1.5 grammar as a base for our own 
> and have noticed the following issues. We've got fixes but I wanted to 
> both highlight the issues to the community and see if anyone else has 
> comments (especially in regards to whether the fixes are correct :-) ).
>
> 1. Single line comments without a terminating newline at the end of a 
> file cause a parse error, due to the requirement that the comment is 
> followed by a line-end.
>
> It seems to be possible to just remove that requirement (and also the 
> call to newline()) and then everything works fine (ie. the match is 
> greedy anyway).
>
> 2. Arrays aren't allowed as wildcard bounds (they should be).
>
> For instance, "? extends Thread[]" as a wildcard in some declaration 
> causes a parse error. A possible fix is to add "arraySpecOpt" in to 
> the "typeArgumentBounds" target.
>
> Davin
>
>
>



More information about the antlr-interest mailing list