From 4f502cceecf665850e6bf8bc5c7c882a361a8d36 Mon Sep 17 00:00:00 2001 From: Derval Guillaume <gderval@uliege.be> Date: Wed, 21 Dec 2022 16:21:08 +0100 Subject: [PATCH] Do not allow full expressions in generator indices --- src/gboml/ast/hyperedges.py | 2 +- src/gboml/ast/nodes.py | 2 +- src/gboml/gboml.lark | 5 +++-- src/gboml/parsing.py | 4 ++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/gboml/ast/hyperedges.py b/src/gboml/ast/hyperedges.py index df46a83..bf61a40 100644 --- a/src/gboml/ast/hyperedges.py +++ b/src/gboml/ast/hyperedges.py @@ -27,7 +27,7 @@ class HyperEdgeDefinition(HyperEdge): @dataclass class HyperEdgeGenerator(HyperEdge): name: str - indices: list["RValue"] + indices: list[str] loop: Loop import_from: Optional[Extends] = None parameters: list[Definition] = field(default_factory=list) diff --git a/src/gboml/ast/nodes.py b/src/gboml/ast/nodes.py index 0092e3a..8c7167d 100644 --- a/src/gboml/ast/nodes.py +++ b/src/gboml/ast/nodes.py @@ -33,7 +33,7 @@ class NodeDefinition(Node): @dataclass class NodeGenerator(Node): name: str - indices: list["RValue"] + indices: list[str] loop: Loop import_from: Optional[Extends] = None parameters: list[Definition] = field(default_factory=list) diff --git a/src/gboml/gboml.lark b/src/gboml/gboml.lark index a1323ab..ce07166 100644 --- a/src/gboml/gboml.lark +++ b/src/gboml/gboml.lark @@ -37,7 +37,7 @@ extends: "extends" var_or_param ["from" STRING] // NODES ?node: node_definition | node_import node_definition: _block_shortcut{_node_header, _node_content} -_node_header: "#NODE" ID olist{index} [extends] [loop] tags +_node_header: "#NODE" ID olist{index_id} [extends] [loop] tags _node_content: parameters_block program_block variables_block constraints_block objectives_block parameters_block: (_block_repeat_or_pass{_opt_param_header,definition})? @@ -57,7 +57,7 @@ variable_scope_change: ID SCOPE ";" ?hyperedge: hyperedge_definition | hyperedge_import hyperedge_definition: _block_shortcut{_hyperedge_header, _hyperedge_content} -_hyperedge_header: "#HYPEREDGE" ID olist{index} [extends] [loop] tags +_hyperedge_header: "#HYPEREDGE" ID olist{index_id} [extends] [loop] tags _hyperedge_content: parameters_block constraints_block hyperedge_import: "#HYPEREDGE" ID "=" "import" var_or_param "from" STRING hyperedge_redefs @@ -140,6 +140,7 @@ function: ID "(" separated_maybe_empty_list{generated_rvalue, ","} ")" var_or_param: separated_list{var_or_param_leaf, "."} var_or_param_leaf: (ID | TAG) olist{index} ?index: "[" rvalue "]" +?index_id: "[" ID "]" //rvalue: anything that can be assigned to a parameter ?rvalue: import | array_or_dict | expression | range | STRING diff --git a/src/gboml/parsing.py b/src/gboml/parsing.py index 8d5e301..ac9be84 100644 --- a/src/gboml/parsing.py +++ b/src/gboml/parsing.py @@ -131,7 +131,7 @@ def _lark_to_gboml(tree: Tree, filename: Optional[str] = None) -> GBOMLGraph: def program_block(self, meta: Meta, *childrens: list[Node | HyperEdge]) -> NodesAndHyperEdges: return self.NodesAndHyperEdges([x for x in childrens if isinstance(x, Node)], [x for x in childrens if isinstance(x, HyperEdge)]) - def hyperedge_definition(self, meta: Meta, name: str, indices: list[RValue], extends: Optional[Extends], + def hyperedge_definition(self, meta: Meta, name: str, indices: list[str], extends: Optional[Extends], loop: Optional[Loop], tags: set[str], param_block: list[Definition] = None, constraint_block: list[Constraint | CtrActivation] = None): constraint_block = constraint_block or [] @@ -148,7 +148,7 @@ def _lark_to_gboml(tree: Tree, filename: Optional[str] = None) -> GBOMLGraph: return HyperEdgeGenerator(name, indices, loop, extends, param_block, constraint_block, activations, tags, meta=meta) - def node_definition(self, meta: Meta, name: str, indices: list[RValue], extends: Optional[Extends], + def node_definition(self, meta: Meta, name: str, indices: list[str], extends: Optional[Extends], loop: Optional[Loop], tags: set[str], param_block: list[Definition] = None, subprogram_block: NodesAndHyperEdges = None, variable_block: list[VariableDefinition] = None, -- GitLab