grammar: enable single parentheses-less arguments in one-line annotations
authorJean Privat <jean@pryen.org>
Thu, 18 Sep 2014 13:26:36 +0000 (09:26 -0400)
committerJean Privat <jean@pryen.org>
Thu, 18 Sep 2014 17:04:51 +0000 (13:04 -0400)
~~~
fun foo is some_annot "hello"
~~~

Signed-off-by: Jean Privat <jean@pryen.org>

src/parser/nit.sablecc3xx

index 9d22a62..2dc8600 100644 (file)
@@ -617,7 +617,22 @@ many_annotations {-> annotations}
        ;
 
 annotation_list {-> annotation*}
-       = {many} one_annotation annotations_tail* {-> [one_annotation.annotation, annotations_tail.annotation] }
+       = {many} one_annotation_list annotations_tail* {-> [one_annotation_list.annotation, annotations_tail.annotation] }
+       ;
+
+one_annotation_list~nopar {-> annotation}
+       = {alone} redef visibility atid annotations_o~nopar {-> New annotation(Null, redef.kwredef, visibility, atid, Null, [], Null, annotations_o~nopar.annotations)}
+// !nopar to unambiguise 'new T@foo(bar)' between 'new T@(foo(bar))' and 'new (T@foo)(bar)'
+!nopar | {args} redef visibility atid opar no at_args [n2]:no cpar annotations_o~nopar {-> New annotation(Null, redef.kwredef, visibility, atid, opar, [at_args.at_arg], cpar, annotations_o~nopar.annotations)}
+!nopar | {nopar} redef visibility atid at_arg_single {-> New annotation(Null, redef.kwredef, visibility, atid, Null, [at_arg_single.at_arg], Null, Null)}
+       ;
+at_arg_single {-> at_arg}
+// FIXME: why expr_single but not expr_atom is not clear :(
+       = {expr} [expr]:expr_single_nopar {-> New at_arg.expr(expr.expr)}
+       ;
+
+annotations_tail {-> annotation}
+       = comma no one_annotation_list {-> one_annotation_list.annotation}
        ;
 
 line_annotations {-> annotations}
@@ -637,10 +652,6 @@ line_annotation_forclass {-> annotation}
        | {nopar} [doc]:no atid_forclass at_args_nopar n1 {-> New annotation(doc.doc, Null, Null, atid_forclass.atid, Null, [at_args_nopar.at_arg], Null, Null)}
        ;
 
-annotations_tail {-> annotation}
-       = comma no one_annotation {-> one_annotation.annotation}
-       ;
-
 at_args~nopar {-> at_arg* }
        = {many} at_arg~nopar at_args_tail* {-> [at_arg~nopar.at_arg, at_args_tail.at_arg]}
        ;