From b7fe9f37154b77529abb83e6518b81824318c7d1 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Thu, 18 Sep 2014 09:26:36 -0400 Subject: [PATCH] grammar: enable single parentheses-less arguments in one-line annotations ~~~ fun foo is some_annot "hello" ~~~ Signed-off-by: Jean Privat --- src/parser/nit.sablecc3xx | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/parser/nit.sablecc3xx b/src/parser/nit.sablecc3xx index 9d22a62..2dc8600 100644 --- a/src/parser/nit.sablecc3xx +++ b/src/parser/nit.sablecc3xx @@ -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]} ; -- 1.7.9.5