diff --git a/src/gboml/ast/hyperedges.py b/src/gboml/ast/hyperedges.py index df46a8392c2af9195daebed462b215734f8ca8b3..bf61a40a4ef408d9e52193fcfb6df1aea8f6d409 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 0092e3a931ea61d6a6aab8eeeca29b6de1990ca6..8c7167de4ed26d3a3a1677e881571458f408140d 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 a1323abb666d131f5b2fe0b1070a04e7794bd263..ce0716688f690ce496768354c04e86ebb42b033f 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 8d5e301562605c5153a1d852393ea34764dc0f77..ac9be844d4dea7f453442a255bd82c4601b71a36 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,