@@ -100,10 +100,7 @@ module.exports = grammar({
100100 $ . extend_artifact ,
101101 ) ,
102102 ) ,
103- seq (
104- kw ( 'annotate' ) ,
105- $ . annotate_artifact ,
106- ) ,
103+ $ . annotate_artifact ,
107104 ) ,
108105 ) ,
109106
@@ -827,7 +824,7 @@ module.exports = grammar({
827824
828825 extend_context_or_service : $ => seq (
829826 field ( 'kind' , choice ( kw ( 'context' ) , kw ( 'service' ) ) ) ,
830- def_path_name ( $ ) ,
827+ ref_definition ( $ ) ,
831828 optional ( kw ( 'with' ) ) ,
832829 repeat ( $ . annotation ) ,
833830 choice (
@@ -838,7 +835,7 @@ module.exports = grammar({
838835
839836 extend_structure : $ => seq (
840837 choice ( kw ( 'type' ) , kw ( 'aspect' ) , kw ( 'entity' ) ) ,
841- def_path_name ( $ ) ,
838+ ref_definition ( $ ) ,
842839 choice (
843840 seq (
844841 kw ( 'with' ) ,
@@ -857,7 +854,7 @@ module.exports = grammar({
857854
858855 extend_projection : $ => seq (
859856 kw ( 'projection' ) ,
860- def_path_name ( $ ) ,
857+ ref_definition ( $ ) ,
861858 optional_kw ( 'with' ) ,
862859 repeat ( $ . annotation ) ,
863860 choice (
@@ -877,8 +874,7 @@ module.exports = grammar({
877874 ) ,
878875
879876 extend_artifact : $ => seq (
880- def_path_name ( $ ) ,
881- field ( 'element' , optional ( seq ( ':' , $ . simple_path ) ) ) ,
877+ ref_definition_with_optional_element ( $ ) ,
882878 choice (
883879 seq (
884880 repeat ( $ . annotation ) ,
@@ -1176,12 +1172,18 @@ module.exports = grammar({
11761172 ) ,
11771173
11781174 annotate_artifact : $ => seq (
1179- $ . simple_path ,
1180- optional ( seq ( ':' , $ . simple_path ) ) ,
1175+ kw ( 'annotate' ) ,
1176+ ref_definition_with_optional_element ( $ ) ,
11811177 optional_kw ( 'with' ) ,
11821178 repeat ( $ . annotation ) ,
11831179 choice (
1184- seq ( '{' , repeat ( $ . annotate_element ) , '}' , optional ( $ . annotate_action ) , optional ( ';' ) ) ,
1180+ seq (
1181+ '{' ,
1182+ repeat ( $ . annotate_element ) ,
1183+ '}' ,
1184+ optional ( $ . annotate_action ) ,
1185+ optional ( ';' ) ,
1186+ ) ,
11851187 seq ( $ . annotate_action , optional ( ';' ) ) ,
11861188 seq (
11871189 '(' ,
@@ -1435,6 +1437,34 @@ function def_path_name($) {
14351437 return field ( 'name' , alias ( $ . simple_path , $ . name ) ) ;
14361438}
14371439
1440+ /**
1441+ * Convenience function for a reference that is either a definition (`E`)
1442+ * or an element (`E:elem`).
1443+ *
1444+ * @param {object } $
1445+ * @return {SeqRule }
1446+ */
1447+ function ref_definition_with_optional_element ( $ ) {
1448+ if ( arguments . length !== 1 )
1449+ throw new InvalidArgument ( 'incorrect number of arguments' ) ;
1450+ return seq (
1451+ alias ( $ . simple_path , $ . definition_reference ) ,
1452+ optional ( seq ( ':' , alias ( $ . simple_path , $ . element_reference ) ) ) ,
1453+ ) ;
1454+ }
1455+
1456+ /**
1457+ * Convenience function for a reference that is a definition (`E`).
1458+ *
1459+ * @param {object } $
1460+ * @return {AliasRule }
1461+ */
1462+ function ref_definition ( $ ) {
1463+ if ( arguments . length !== 1 )
1464+ throw new InvalidArgument ( 'incorrect number of arguments' ) ;
1465+ return alias ( $ . simple_path , $ . definition_reference ) ;
1466+ }
1467+
14381468/**
14391469 * A list of `rule`. At least one rule must be parsed.
14401470 *
0 commit comments