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

Jon Schewe jpschewe at mtu.net
Thu Mar 17 19:26:16 PST 2005


One problem with this is that if you remove the calls to newline(),
you're line numbers will be off.  This makes error reporting rather
difficult.

On Fri, 2005-03-18 at 12:24 +1100, Davin McCall wrote:
> 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
> >
> >
> >

________________________________________________________________________
Jon Schewe | http://mtu.net/~jpschewe
GPG signature at http://mtu.net/~jpschewe/gpg.sig.html
For I am convinced that neither death nor life, neither angels 
nor demons, neither the present nor the future, nor any 
powers, neither height nor depth, nor anything else in all 
creation, will be able to separate us from the love of God that 
is in Christ Jesus our Lord. - Romans 8:38-39





More information about the antlr-interest mailing list