[JSR308] Others possible syntaxes for type annotations

Maxim Kizub mkizub at gmail.com
Thu May 17 15:00:29 EDT 2007


Hello.

I think, grammar changes may be specified as:

TypeArguments:
       < TypeOrAnnotArgument {, TypeOrAnnotArgument} >

TypeOrAnnotArgument :
       [TypeArgument | Annotation]

or as

TypeArguments:
       < ? [TypeArgument {, TypeArgument}] ?[; Annotations] >

I'm not familiar with this parser grammar notation, so I don't know how 
to express that annotations go after type parameters.
For JavaCC grammar would be:

TypeArguments() : {}
{
"<"
   TypeArgument() ( "," TypeArgument())* ( "," Annotation() )*
|   Annotation() ( "," Annotation() )*
">"
}

or

TypeArguments() : {}
{
"<"
   TypeArgument() ( "," TypeArgument())* [ ";" Annotations() ]
|   [ ";" ] Annotations()
">"
}

JavaCC grammar needs no lookahead, since annotations are clearly 
distinct from type parameters (because they start with @ token)

Map<Foo<Boo>, Map<String, Boo>> can be annotated as

Map<Foo<Boo, @BooAnnot>, Map<String, Boo, @MapInnerAnnot>, @MapAnnot>

or using semicolon as the separator

Map<Foo<Boo; @FooAnnot>, Map<String, Boo; @MapInnerAnnot>; @MapAnnot>

or annotating everything will be

Map<Foo<Boo<@BooAnnot>; @FooBooAnnot>, Map<String<@StringAnnot>, 
Boo<@BooAnnot>; @MapStrBooAnnot>; @MapFooBooMapStrBooAnnot>

Eugene Kuleshov wrote:
> Maxim Kizub wrote:
>> The proposition was about using uniform syntax for type parameters 
>> and annotations.
>> In this way type annotation syntax IS non-ambiguous, uniform and 
>> logical. Compare
>> 1) @A String @B string;
>> 2) @A String<@B> string;
>> The case (1) has strange reading rules, because it looks like (@A 
>> String) (@B string), but must be read as @A (String @B) string.
>> In contrast, in case (2) it's obvious, that @B belongs to type 
>> String, not to the variable.
>  Maxim, can you please provide more details for the suggested grammar 
> changes? I.e. what are you suggesting to add into the existing 
> grammar. See 
> http://docs.oracle.com/javase/specs/jls/se5.0/html/syntax.html#18.1
>
>  Example with a string type is rather limited, so I wonder how 
> generified types would look like in your proposal.
>  Say, in something like Map<Foo<Boo>, Map<String, Boo>> how would you 
> separately annotate each Map, Foo and Boo types? Maybe I am just 
> confused by use of <> and it may worth investigating use of some other 
> token? Though there is no single-char "bracket" tokens left and we'll 
> have to use some multi-char token, and that won't look pretty...
>
>  regards,
>  Eugene
>
>
>
> _______________________________________________
> JSR308 mailing list
> JSR308 at lists.csail.mit.edu
> https://lists.csail.mit.edu/mailman/listinfo/jsr308
>




More information about the JSR308 mailing list