From 35e638e77e647c89784c775f77f2057b66370b65 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Mon, 14 Jul 2014 10:25:12 -0400 Subject: [PATCH] grammer: accept redef and visibility in front of annotation ~~~ var foo is public bar fun baz is # doc redef private foobar end ~~~ Signed-off-by: Jean Privat --- src/parser/nit.sablecc3xx | 26 +++++++++++++++++--------- src/parser/parser_nodes.nit | 9 +++++++++ 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/parser/nit.sablecc3xx b/src/parser/nit.sablecc3xx index 41de805..52516c7 100644 --- a/src/parser/nit.sablecc3xx +++ b/src/parser/nit.sablecc3xx @@ -603,9 +603,9 @@ annotations_o~nopar {-> annotations?} ; one_annotation~nopar {-> annotation} - = {alone} atid annotations_o~nopar {-> New annotation(atid, Null, [], Null, annotations_o~nopar.annotations)} + = {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} atid opar no at_args [n2]:no cpar annotations_o~nopar {-> New annotation(atid, opar, [at_args.at_arg], cpar, annotations_o~nopar.annotations)} +!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)} ; many_annotations {-> annotations} @@ -616,13 +616,21 @@ annotation_list {-> annotation*} = {many} one_annotation annotations_tail* {-> [one_annotation.annotation, annotations_tail.annotation] } ; -line_annotations~forclass {-> annotations} - = line_annotation~forclass+ {-> New annotations(Null, Null, [line_annotation~forclass.annotation], Null) } +line_annotations {-> annotations} + = line_annotation+ {-> New annotations(Null, Null, [line_annotation.annotation], Null) } ; -line_annotation~forclass {-> annotation} - = [doc]:no atid~forclass annotations? n1 {-> New annotation(atid~forclass.atid, Null, [], Null, annotations)} - | {args} [doc]:no atid~forclass opar no at_args cpar annotations? n1 {-> New annotation(atid~forclass.atid, opar, [at_args.at_arg], cpar, annotations)} - | {nopar} [doc]:no atid~forclass at_args_nopar n1 {-> New annotation(atid~forclass.atid, Null, [at_args_nopar.at_arg], Null, Null)} +line_annotation {-> annotation} + = [doc]:no redef visibility atid annotations? n1 {-> New annotation(doc.doc, redef.kwredef, visibility, atid.atid, Null, [], Null, annotations)} + | {args} [doc]:no redef visibility atid opar no at_args cpar annotations? n1 {-> New annotation(doc.doc, redef.kwredef, visibility, atid.atid, opar, [at_args.at_arg], cpar, annotations)} + | {nopar} [doc]:no redef visibility atid at_args_nopar n1 {-> New annotation(doc.doc, redef.kwredef, visibility, atid.atid, Null, [at_args_nopar.at_arg], Null, Null)} + ; +line_annotations_forclass {-> annotations} + = line_annotation_forclass+ {-> New annotations(Null, Null, [line_annotation_forclass.annotation], Null) } + ; +line_annotation_forclass {-> annotation} + = [doc]:no atid_forclass annotations? n1 {-> New annotation(doc.doc, Null, Null, atid_forclass.atid, Null, [], Null, annotations)} + | {args} [doc]:no atid_forclass opar no at_args cpar annotations? n1 {-> New annotation(doc.doc, Null, Null, atid_forclass.atid, opar, [at_args.at_arg], cpar, annotations)} + | {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} @@ -901,7 +909,7 @@ doc = comment+; annotations = at? opar? [items]:annotation* cpar?; -annotation = atid opar? [args]:at_arg* cpar? annotations?; +annotation = doc? kwredef? visibility? atid opar? [args]:at_arg* cpar? annotations?; at_arg = {type} type diff --git a/src/parser/parser_nodes.nit b/src/parser/parser_nodes.nit index 435a809..8a6bf20 100644 --- a/src/parser/parser_nodes.nit +++ b/src/parser/parser_nodes.nit @@ -2408,6 +2408,15 @@ class AAnnotations end class AAnnotation super Prod + var _n_doc: nullable ADoc = null + fun n_doc: nullable ADoc do return _n_doc + fun n_doc=(n_doc: nullable ADoc) do _n_doc = n_doc + var _n_kwredef: nullable TKwredef = null + fun n_kwredef: nullable TKwredef do return _n_kwredef + fun n_kwredef=(n_kwredef: nullable TKwredef) do _n_kwredef = n_kwredef + var _n_visibility: nullable AVisibility + fun n_visibility: nullable AVisibility do return _n_visibility + fun n_visibility=(n_visibility: nullable AVisibility) do _n_visibility = n_visibility var _n_atid: AAtid fun n_atid: AAtid do return _n_atid fun n_atid=(n_atid: AAtid) do _n_atid = n_atid -- 1.7.9.5