diff --git a/src/gboml/ast/__init__.py b/src/gboml/ast/__init__.py index 550739ba0eb6a3bac35ab448aeac7327fdc01765..ef2a017ba0348fb63b4e3ddce94bcab672f266d6 100644 --- a/src/gboml/ast/__init__.py +++ b/src/gboml/ast/__init__.py @@ -6,7 +6,8 @@ __all__ = [ "StdConstraint", "SOSConstraint", "Objective", "VariableDefinition", "Node", "HyperEdge", "NodeDefinition", "NodeImport", "HyperEdgeDefinition", "HyperEdgeImport", "ExpressionOp", "GBOMLGraph", "ImplicitLoop", "RValue", "RValueWithGen", "GeneratedRValue", - "Range", "MultiLoop", "DictEntry", "Dictionary", "NodeGenerator", "HyperEdgeGenerator" + "Range", "MultiLoop", "DictEntry", "Dictionary", "NodeGenerator", "HyperEdgeGenerator", + "DefinitionType" ] from gboml.ast.arrays import * diff --git a/src/gboml/ast/variables.py b/src/gboml/ast/variables.py index fd761cee0896a06e73321b35ffec912d0fba40a2..87a7927673d00683f9c0244f9129ab46b979f7c1 100644 --- a/src/gboml/ast/variables.py +++ b/src/gboml/ast/variables.py @@ -18,9 +18,14 @@ class VarType(Enum): binary = "binary" +class DefinitionType(Enum): + constant = "=" + expression = "<-" + @dataclass class Definition(GBOMLObject): name: str + type: DefinitionType value: RValue tags: list[str] = field(default_factory=list) diff --git a/src/gboml/gboml.lark b/src/gboml/gboml.lark index 9cad8648b6498b1b2db67028377d1b0468fc6077..9118012b1aebff0c4430d2ab4747ee514116078b 100644 --- a/src/gboml/gboml.lark +++ b/src/gboml/gboml.lark @@ -91,7 +91,8 @@ bool_expression_comparison: expression (COMPARISON_OPERATOR | CTR_OPERATOR) expr COMPARISON_OPERATOR: "<" | ">" | "!=" // DEFINITIONS -definition: ID "=" rvalue tags ";" +definition: ID DEF_TYPE rvalue tags ";" +DEF_TYPE: "=" | "<-" // ARRAYS array_or_dict: "{" separated_maybe_empty_list{_array_or_dict_entry, ","} "}" diff --git a/src/gboml/parsing.py b/src/gboml/parsing.py index 1612dcce28e2397f3b2ad3cdd470e886564e7283..1aa31304166b66a46a41d5369873c5090bf7eac1 100644 --- a/src/gboml/parsing.py +++ b/src/gboml/parsing.py @@ -114,6 +114,7 @@ def _lark_to_gboml(tree: Tree, filename: Optional[str] = None) -> GBOMLGraph: def COMPARISON_OPERATOR(self, token): return Operator(token.value) def STRING(self, token): return token.value[1:-1].replace('\\"', '"') def VTYPE(self, token): return VarType(token.value) + def DEF_TYPE(self, token): return DefinitionType(token.value) NodesAndHyperEdges = namedtuple("NodesAndHyperEdges", ["nodes", "hyperedges"]) diff --git a/tests/instances/ok/complex_parsing.txt b/tests/instances/ok/complex_parsing.txt index a617270feb59b665283e8ae5b382cad8cdbe7bd7..349e9999474fe97f947ddde48d97bd3aa835b04d 100644 --- a/tests/instances/ok/complex_parsing.txt +++ b/tests/instances/ok/complex_parsing.txt @@ -5,7 +5,7 @@ b = 2.2; c = 2e2; d = -1; - e = 2e-2; + e <- 2e-2; f = [0:2]; g = [0:10:2]; #NODE nodeI = import nodeA from "hello.gboml";