From: Jean Privat Date: Thu, 18 Dec 2014 20:01:43 +0000 (-0500) Subject: parser_nodes: promote `get_annotation` and `AAnnotation::name` from `annotation` X-Git-Tag: v0.7~13^2~4 X-Git-Url: http://nitlanguage.org parser_nodes: promote `get_annotation` and `AAnnotation::name` from `annotation` Signed-off-by: Jean Privat --- diff --git a/src/annotation.nit b/src/annotation.nit index f5d2447..19653a3 100644 --- a/src/annotation.nit +++ b/src/annotation.nit @@ -34,29 +34,9 @@ redef class Prod end return res.first end - - # Return all its annotations of a given name in the order of their declaration - # Retun an empty array if no such an annotation. - fun get_annotations(name: String): Array[AAnnotation] - do - var res = new Array[AAnnotation] - var nas = n_annotations - if nas == null then return res - for na in nas.n_items do - if na.name != name then continue - res.add(na) - end - return res - end end redef class AAnnotation - # The name of the annotation - fun name: String - do - return n_atid.n_id.text - end - # Get the single argument of `self` as a `String`. # Raise error and return null on any inconsistency. fun arg_as_string(modelbuilder: ModelBuilder): nullable String diff --git a/src/parser/parser_nodes.nit b/src/parser/parser_nodes.nit index a7f8071..1cc8a31 100644 --- a/src/parser/parser_nodes.nit +++ b/src/parser/parser_nodes.nit @@ -269,6 +269,20 @@ abstract class Prod # All the annotations attached directly to the node var n_annotations: nullable AAnnotations = null is writable + # Return all its annotations of a given name in the order of their declaration + # Retun an empty array if no such an annotation. + fun get_annotations(name: String): Array[AAnnotation] + do + var res = new Array[AAnnotation] + var nas = n_annotations + if nas == null then return res + for na in nas.n_items do + if na.name != name then continue + res.add(na) + end + return res + end + redef fun replace_with(n: ANode) do super @@ -2038,6 +2052,12 @@ class AAnnotation var n_opar: nullable TOpar = null is writable var n_args = new ANodes[AExpr](self) var n_cpar: nullable TCpar = null is writable + + # The name of the annotation + fun name: String + do + return n_atid.n_id.text + end end # An annotation name