From 355d9db91f87cc207de8b0160a60be57fc0c5933 Mon Sep 17 00:00:00 2001 From: killian-scalian Date: Tue, 29 Jul 2025 09:38:25 +0200 Subject: [PATCH 01/15] first commit max operator --- grammar/Expr.g4 | 2 + src/gems/expression/__init__.py | 2 + src/gems/expression/degree.py | 9 +- src/gems/expression/equality.py | 8 + src/gems/expression/evaluate.py | 1 + src/gems/expression/expression.py | 19 + src/gems/expression/indexing.py | 4 + src/gems/expression/parsing/antlr/Expr.interp | 4 +- src/gems/expression/parsing/antlr/Expr.tokens | 12 +- .../expression/parsing/antlr/ExprLexer.interp | 5 +- .../expression/parsing/antlr/ExprLexer.py | 1254 +--------- .../expression/parsing/antlr/ExprLexer.tokens | 12 +- .../expression/parsing/antlr/ExprParser.py | 2228 ++++------------- .../expression/parsing/antlr/ExprVisitor.py | 91 +- .../expression/parsing/parse_expression.py | 4 + src/gems/expression/print.py | 6 +- src/gems/expression/visitor.py | 13 + src/gems/model/max.py | 80 + src/gems/model/port.py | 7 +- src/gems/simulation/linearize.py | 5 +- 20 files changed, 829 insertions(+), 2937 deletions(-) create mode 100644 src/gems/model/max.py diff --git a/grammar/Expr.g4 b/grammar/Expr.g4 index 73e4d0ba..a08208a8 100644 --- a/grammar/Expr.g4 +++ b/grammar/Expr.g4 @@ -33,6 +33,7 @@ expr | IDENTIFIER '[' expr ']' # timeIndex | '(' expr ')' '[' shift ']' # timeShiftExpr | '(' expr ')' '[' expr ']' # timeIndexExpr + | 'max' '(' expr (',' expr)* ')' # maxExpr ; atom @@ -74,6 +75,7 @@ fragment CHAR : [a-zA-Z_]; fragment CHAR_OR_DIGIT : (CHAR | DIGIT); NUMBER : DIGIT+ ('.' DIGIT+)?; +MAX : 'max'; TIME : 't'; IDENTIFIER : CHAR CHAR_OR_DIGIT*; COMPARISON : ( '=' | '>=' | '<=' ); diff --git a/src/gems/expression/__init__.py b/src/gems/expression/__init__.py index 3d949b6e..500a58a6 100644 --- a/src/gems/expression/__init__.py +++ b/src/gems/expression/__init__.py @@ -29,6 +29,8 @@ NegationNode, ParameterNode, VariableNode, + MaxNode, + TimeShiftNode, literal, param, sum_expressions, diff --git a/src/gems/expression/degree.py b/src/gems/expression/degree.py index d9051818..0165c885 100644 --- a/src/gems/expression/degree.py +++ b/src/gems/expression/degree.py @@ -22,6 +22,7 @@ TimeEvalNode, TimeShiftNode, TimeSumNode, + MaxNode, ) from .expression import ( @@ -98,7 +99,9 @@ def all_time_sum(self, node: AllTimeSumNode) -> int: return visit(node.operand, self) def scenario_operator(self, node: ScenarioOperatorNode) -> int: - scenario_operator_cls = getattr(gems.expression.scenario_operator, node.name) + scenario_operator_cls = getattr( + gems.expression.scenario_operator, node.name + ) # TODO: Carefully check if this formula is correct return scenario_operator_cls.degree() * visit(node.operand, self) @@ -108,6 +111,8 @@ def port_field(self, node: PortFieldNode) -> int: def port_field_aggregator(self, node: PortFieldAggregatorNode) -> int: return visit(node.operand, self) + def max_node(self, node: MaxNode) -> int: + return 0 # always constant if operands are constants def compute_degree(expression: ExpressionNode) -> int: return visit(expression, ExpressionDegreeVisitor()) @@ -124,4 +129,4 @@ def is_linear(expr: ExpressionNode) -> bool: """ True if the expression is linear with respect to variables. """ - return compute_degree(expr) <= 1 + return compute_degree(expr) <= 1 \ No newline at end of file diff --git a/src/gems/expression/equality.py b/src/gems/expression/equality.py index d5a543ff..4268a730 100644 --- a/src/gems/expression/equality.py +++ b/src/gems/expression/equality.py @@ -24,6 +24,7 @@ NegationNode, ParameterNode, VariableNode, + MaxNode ) from gems.expression.expression import ( AllTimeSumNode, @@ -111,6 +112,8 @@ def visit(self, left: ExpressionNode, right: ExpressionNode) -> bool: right, PortFieldAggregatorNode ): return self.port_field_aggregator(left, right) + if isinstance(left, MaxNode) and isinstance(right, MaxNode): + return self.max_node(left, right) raise NotImplementedError(f"Equality not implemented for {left.__class__}") def literal(self, left: LiteralNode, right: LiteralNode) -> bool: @@ -133,6 +136,11 @@ def addition(self, left: AdditionNode, right: AdditionNode) -> bool: self.visit(l, r) for l, r in zip(left_ops, right_ops) ) + def max_node(self, left: MaxNode, right: MaxNode) -> bool: + if len(left.operands) != len(right.operands): + return False + return all(self.visit(l_op, r_op) for l_op, r_op in zip(left.operands, right.operands)) + def multiplication( self, left: MultiplicationNode, right: MultiplicationNode ) -> bool: diff --git a/src/gems/expression/evaluate.py b/src/gems/expression/evaluate.py index 23c3cf4d..e98828af 100644 --- a/src/gems/expression/evaluate.py +++ b/src/gems/expression/evaluate.py @@ -25,6 +25,7 @@ TimeEvalNode, TimeShiftNode, TimeSumNode, + MaxNode, ) from .expression import ( diff --git a/src/gems/expression/expression.py b/src/gems/expression/expression.py index 44bfcfc9..12af35b2 100644 --- a/src/gems/expression/expression.py +++ b/src/gems/expression/expression.py @@ -64,6 +64,13 @@ def __rsub__(self, lhs: Any) -> "ExpressionNode": lhs = _wrap_in_node(lhs) return lhs + self + def max(self, rhs: Any) -> "ExpressionNode": + lhs = self + operands = [] + operands.extend(lhs.operands if isinstance(lhs, MaxNode) else [_wrap_in_node(lhs)]) + operands.extend(rhs.operands if isinstance(rhs, MaxNode) else [_wrap_in_node(rhs)]) + return MaxNode(operands) + def __mul__(self, rhs: Any) -> "ExpressionNode": return _apply_if_node(rhs, lambda x: MultiplicationNode(self, x)) @@ -384,6 +391,18 @@ class Comparator(enum.Enum): class ComparisonNode(BinaryOperatorNode): comparator: Comparator +@dataclass(frozen=True, eq=False) +class MaxNode(ExpressionNode): + operands: List[ExpressionNode] + def __post_init__(self): + if len(self.operands) < 2: + raise ValueError("MaxNode requires at least two operands") + if not all(isinstance(op, ExpressionNode) for op in self.operands): + raise TypeError("All operands must be instances of ExpressionNode") + from gems.model.max import _validate_max_expression + _validate_max_expression(self) + + @dataclass(frozen=True, eq=False) class AdditionNode(ExpressionNode): diff --git a/src/gems/expression/indexing.py b/src/gems/expression/indexing.py index 022aa936..ba6fa8e0 100644 --- a/src/gems/expression/indexing.py +++ b/src/gems/expression/indexing.py @@ -37,6 +37,7 @@ TimeShiftNode, TimeSumNode, VariableNode, + MaxNode ) from .visitor import ExpressionVisitor, T, visit @@ -158,6 +159,9 @@ def port_field_aggregator(self, node: PortFieldAggregatorNode) -> IndexingStruct raise ValueError( "Port fields aggregators must be resolved before computing indexing structure." ) + + def max_node(self, node: MaxNode) -> IndexingStructure: + return self._combine(node.operands) def compute_indexation( diff --git a/src/gems/expression/parsing/antlr/Expr.interp b/src/gems/expression/parsing/antlr/Expr.interp index 94f1370f..e66a200f 100644 --- a/src/gems/expression/parsing/antlr/Expr.interp +++ b/src/gems/expression/parsing/antlr/Expr.interp @@ -14,6 +14,7 @@ null '[' ']' null +'max' 't' null null @@ -35,6 +36,7 @@ null null null NUMBER +MAX TIME IDENTIFIER COMPARISON @@ -51,4 +53,4 @@ right_expr atn: -[4, 1, 18, 140, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 3, 2, 79, 8, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 5, 2, 90, 8, 2, 10, 2, 12, 2, 93, 9, 2, 1, 3, 1, 3, 3, 3, 97, 8, 3, 1, 4, 1, 4, 3, 4, 101, 8, 4, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 3, 5, 111, 8, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 5, 5, 119, 8, 5, 10, 5, 12, 5, 122, 9, 5, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 3, 6, 130, 8, 6, 1, 6, 1, 6, 1, 6, 5, 6, 135, 8, 6, 10, 6, 12, 6, 138, 9, 6, 1, 6, 0, 3, 4, 10, 12, 7, 0, 2, 4, 6, 8, 10, 12, 0, 2, 1, 0, 5, 6, 2, 0, 2, 2, 7, 7, 153, 0, 14, 1, 0, 0, 0, 2, 18, 1, 0, 0, 0, 4, 78, 1, 0, 0, 0, 6, 96, 1, 0, 0, 0, 8, 98, 1, 0, 0, 0, 10, 110, 1, 0, 0, 0, 12, 129, 1, 0, 0, 0, 14, 15, 5, 16, 0, 0, 15, 16, 5, 1, 0, 0, 16, 17, 5, 16, 0, 0, 17, 1, 1, 0, 0, 0, 18, 19, 3, 4, 2, 0, 19, 20, 5, 0, 0, 1, 20, 3, 1, 0, 0, 0, 21, 22, 6, 2, -1, 0, 22, 79, 3, 6, 3, 0, 23, 79, 3, 0, 0, 0, 24, 25, 5, 2, 0, 0, 25, 79, 3, 4, 2, 13, 26, 27, 5, 3, 0, 0, 27, 28, 3, 4, 2, 0, 28, 29, 5, 4, 0, 0, 29, 79, 1, 0, 0, 0, 30, 31, 5, 8, 0, 0, 31, 32, 5, 3, 0, 0, 32, 33, 3, 4, 2, 0, 33, 34, 5, 4, 0, 0, 34, 79, 1, 0, 0, 0, 35, 36, 5, 9, 0, 0, 36, 37, 5, 3, 0, 0, 37, 38, 3, 0, 0, 0, 38, 39, 5, 4, 0, 0, 39, 79, 1, 0, 0, 0, 40, 41, 5, 8, 0, 0, 41, 42, 5, 3, 0, 0, 42, 43, 3, 8, 4, 0, 43, 44, 5, 10, 0, 0, 44, 45, 3, 8, 4, 0, 45, 46, 5, 11, 0, 0, 46, 47, 3, 4, 2, 0, 47, 48, 5, 4, 0, 0, 48, 79, 1, 0, 0, 0, 49, 50, 5, 16, 0, 0, 50, 51, 5, 3, 0, 0, 51, 52, 3, 4, 2, 0, 52, 53, 5, 4, 0, 0, 53, 79, 1, 0, 0, 0, 54, 55, 5, 16, 0, 0, 55, 56, 5, 12, 0, 0, 56, 57, 3, 8, 4, 0, 57, 58, 5, 13, 0, 0, 58, 79, 1, 0, 0, 0, 59, 60, 5, 16, 0, 0, 60, 61, 5, 12, 0, 0, 61, 62, 3, 4, 2, 0, 62, 63, 5, 13, 0, 0, 63, 79, 1, 0, 0, 0, 64, 65, 5, 3, 0, 0, 65, 66, 3, 4, 2, 0, 66, 67, 5, 4, 0, 0, 67, 68, 5, 12, 0, 0, 68, 69, 3, 8, 4, 0, 69, 70, 5, 13, 0, 0, 70, 79, 1, 0, 0, 0, 71, 72, 5, 3, 0, 0, 72, 73, 3, 4, 2, 0, 73, 74, 5, 4, 0, 0, 74, 75, 5, 12, 0, 0, 75, 76, 3, 4, 2, 0, 76, 77, 5, 13, 0, 0, 77, 79, 1, 0, 0, 0, 78, 21, 1, 0, 0, 0, 78, 23, 1, 0, 0, 0, 78, 24, 1, 0, 0, 0, 78, 26, 1, 0, 0, 0, 78, 30, 1, 0, 0, 0, 78, 35, 1, 0, 0, 0, 78, 40, 1, 0, 0, 0, 78, 49, 1, 0, 0, 0, 78, 54, 1, 0, 0, 0, 78, 59, 1, 0, 0, 0, 78, 64, 1, 0, 0, 0, 78, 71, 1, 0, 0, 0, 79, 91, 1, 0, 0, 0, 80, 81, 10, 11, 0, 0, 81, 82, 7, 0, 0, 0, 82, 90, 3, 4, 2, 12, 83, 84, 10, 10, 0, 0, 84, 85, 7, 1, 0, 0, 85, 90, 3, 4, 2, 11, 86, 87, 10, 9, 0, 0, 87, 88, 5, 17, 0, 0, 88, 90, 3, 4, 2, 10, 89, 80, 1, 0, 0, 0, 89, 83, 1, 0, 0, 0, 89, 86, 1, 0, 0, 0, 90, 93, 1, 0, 0, 0, 91, 89, 1, 0, 0, 0, 91, 92, 1, 0, 0, 0, 92, 5, 1, 0, 0, 0, 93, 91, 1, 0, 0, 0, 94, 97, 5, 14, 0, 0, 95, 97, 5, 16, 0, 0, 96, 94, 1, 0, 0, 0, 96, 95, 1, 0, 0, 0, 97, 7, 1, 0, 0, 0, 98, 100, 5, 15, 0, 0, 99, 101, 3, 10, 5, 0, 100, 99, 1, 0, 0, 0, 100, 101, 1, 0, 0, 0, 101, 9, 1, 0, 0, 0, 102, 103, 6, 5, -1, 0, 103, 104, 7, 1, 0, 0, 104, 111, 3, 6, 3, 0, 105, 106, 7, 1, 0, 0, 106, 107, 5, 3, 0, 0, 107, 108, 3, 4, 2, 0, 108, 109, 5, 4, 0, 0, 109, 111, 1, 0, 0, 0, 110, 102, 1, 0, 0, 0, 110, 105, 1, 0, 0, 0, 111, 120, 1, 0, 0, 0, 112, 113, 10, 4, 0, 0, 113, 114, 7, 0, 0, 0, 114, 119, 3, 12, 6, 0, 115, 116, 10, 3, 0, 0, 116, 117, 7, 1, 0, 0, 117, 119, 3, 12, 6, 0, 118, 112, 1, 0, 0, 0, 118, 115, 1, 0, 0, 0, 119, 122, 1, 0, 0, 0, 120, 118, 1, 0, 0, 0, 120, 121, 1, 0, 0, 0, 121, 11, 1, 0, 0, 0, 122, 120, 1, 0, 0, 0, 123, 124, 6, 6, -1, 0, 124, 125, 5, 3, 0, 0, 125, 126, 3, 4, 2, 0, 126, 127, 5, 4, 0, 0, 127, 130, 1, 0, 0, 0, 128, 130, 3, 6, 3, 0, 129, 123, 1, 0, 0, 0, 129, 128, 1, 0, 0, 0, 130, 136, 1, 0, 0, 0, 131, 132, 10, 3, 0, 0, 132, 133, 7, 0, 0, 0, 133, 135, 3, 12, 6, 4, 134, 131, 1, 0, 0, 0, 135, 138, 1, 0, 0, 0, 136, 134, 1, 0, 0, 0, 136, 137, 1, 0, 0, 0, 137, 13, 1, 0, 0, 0, 138, 136, 1, 0, 0, 0, 10, 78, 89, 91, 96, 100, 110, 118, 120, 129, 136] \ No newline at end of file +[4, 1, 19, 152, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 5, 2, 84, 8, 2, 10, 2, 12, 2, 87, 9, 2, 1, 2, 1, 2, 3, 2, 91, 8, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 5, 2, 102, 8, 2, 10, 2, 12, 2, 105, 9, 2, 1, 3, 1, 3, 3, 3, 109, 8, 3, 1, 4, 1, 4, 3, 4, 113, 8, 4, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 3, 5, 123, 8, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 5, 5, 131, 8, 5, 10, 5, 12, 5, 134, 9, 5, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 3, 6, 142, 8, 6, 1, 6, 1, 6, 1, 6, 5, 6, 147, 8, 6, 10, 6, 12, 6, 150, 9, 6, 1, 6, 0, 3, 4, 10, 12, 7, 0, 2, 4, 6, 8, 10, 12, 0, 2, 1, 0, 5, 6, 2, 0, 2, 2, 7, 7, 167, 0, 14, 1, 0, 0, 0, 2, 18, 1, 0, 0, 0, 4, 90, 1, 0, 0, 0, 6, 108, 1, 0, 0, 0, 8, 110, 1, 0, 0, 0, 10, 122, 1, 0, 0, 0, 12, 141, 1, 0, 0, 0, 14, 15, 5, 17, 0, 0, 15, 16, 5, 1, 0, 0, 16, 17, 5, 17, 0, 0, 17, 1, 1, 0, 0, 0, 18, 19, 3, 4, 2, 0, 19, 20, 5, 0, 0, 1, 20, 3, 1, 0, 0, 0, 21, 22, 6, 2, -1, 0, 22, 91, 3, 6, 3, 0, 23, 91, 3, 0, 0, 0, 24, 25, 5, 2, 0, 0, 25, 91, 3, 4, 2, 14, 26, 27, 5, 3, 0, 0, 27, 28, 3, 4, 2, 0, 28, 29, 5, 4, 0, 0, 29, 91, 1, 0, 0, 0, 30, 31, 5, 8, 0, 0, 31, 32, 5, 3, 0, 0, 32, 33, 3, 4, 2, 0, 33, 34, 5, 4, 0, 0, 34, 91, 1, 0, 0, 0, 35, 36, 5, 9, 0, 0, 36, 37, 5, 3, 0, 0, 37, 38, 3, 0, 0, 0, 38, 39, 5, 4, 0, 0, 39, 91, 1, 0, 0, 0, 40, 41, 5, 8, 0, 0, 41, 42, 5, 3, 0, 0, 42, 43, 3, 8, 4, 0, 43, 44, 5, 10, 0, 0, 44, 45, 3, 8, 4, 0, 45, 46, 5, 11, 0, 0, 46, 47, 3, 4, 2, 0, 47, 48, 5, 4, 0, 0, 48, 91, 1, 0, 0, 0, 49, 50, 5, 17, 0, 0, 50, 51, 5, 3, 0, 0, 51, 52, 3, 4, 2, 0, 52, 53, 5, 4, 0, 0, 53, 91, 1, 0, 0, 0, 54, 55, 5, 17, 0, 0, 55, 56, 5, 12, 0, 0, 56, 57, 3, 8, 4, 0, 57, 58, 5, 13, 0, 0, 58, 91, 1, 0, 0, 0, 59, 60, 5, 17, 0, 0, 60, 61, 5, 12, 0, 0, 61, 62, 3, 4, 2, 0, 62, 63, 5, 13, 0, 0, 63, 91, 1, 0, 0, 0, 64, 65, 5, 3, 0, 0, 65, 66, 3, 4, 2, 0, 66, 67, 5, 4, 0, 0, 67, 68, 5, 12, 0, 0, 68, 69, 3, 8, 4, 0, 69, 70, 5, 13, 0, 0, 70, 91, 1, 0, 0, 0, 71, 72, 5, 3, 0, 0, 72, 73, 3, 4, 2, 0, 73, 74, 5, 4, 0, 0, 74, 75, 5, 12, 0, 0, 75, 76, 3, 4, 2, 0, 76, 77, 5, 13, 0, 0, 77, 91, 1, 0, 0, 0, 78, 79, 5, 15, 0, 0, 79, 80, 5, 3, 0, 0, 80, 85, 3, 4, 2, 0, 81, 82, 5, 11, 0, 0, 82, 84, 3, 4, 2, 0, 83, 81, 1, 0, 0, 0, 84, 87, 1, 0, 0, 0, 85, 83, 1, 0, 0, 0, 85, 86, 1, 0, 0, 0, 86, 88, 1, 0, 0, 0, 87, 85, 1, 0, 0, 0, 88, 89, 5, 4, 0, 0, 89, 91, 1, 0, 0, 0, 90, 21, 1, 0, 0, 0, 90, 23, 1, 0, 0, 0, 90, 24, 1, 0, 0, 0, 90, 26, 1, 0, 0, 0, 90, 30, 1, 0, 0, 0, 90, 35, 1, 0, 0, 0, 90, 40, 1, 0, 0, 0, 90, 49, 1, 0, 0, 0, 90, 54, 1, 0, 0, 0, 90, 59, 1, 0, 0, 0, 90, 64, 1, 0, 0, 0, 90, 71, 1, 0, 0, 0, 90, 78, 1, 0, 0, 0, 91, 103, 1, 0, 0, 0, 92, 93, 10, 12, 0, 0, 93, 94, 7, 0, 0, 0, 94, 102, 3, 4, 2, 13, 95, 96, 10, 11, 0, 0, 96, 97, 7, 1, 0, 0, 97, 102, 3, 4, 2, 12, 98, 99, 10, 10, 0, 0, 99, 100, 5, 18, 0, 0, 100, 102, 3, 4, 2, 11, 101, 92, 1, 0, 0, 0, 101, 95, 1, 0, 0, 0, 101, 98, 1, 0, 0, 0, 102, 105, 1, 0, 0, 0, 103, 101, 1, 0, 0, 0, 103, 104, 1, 0, 0, 0, 104, 5, 1, 0, 0, 0, 105, 103, 1, 0, 0, 0, 106, 109, 5, 14, 0, 0, 107, 109, 5, 17, 0, 0, 108, 106, 1, 0, 0, 0, 108, 107, 1, 0, 0, 0, 109, 7, 1, 0, 0, 0, 110, 112, 5, 16, 0, 0, 111, 113, 3, 10, 5, 0, 112, 111, 1, 0, 0, 0, 112, 113, 1, 0, 0, 0, 113, 9, 1, 0, 0, 0, 114, 115, 6, 5, -1, 0, 115, 116, 7, 1, 0, 0, 116, 123, 3, 6, 3, 0, 117, 118, 7, 1, 0, 0, 118, 119, 5, 3, 0, 0, 119, 120, 3, 4, 2, 0, 120, 121, 5, 4, 0, 0, 121, 123, 1, 0, 0, 0, 122, 114, 1, 0, 0, 0, 122, 117, 1, 0, 0, 0, 123, 132, 1, 0, 0, 0, 124, 125, 10, 4, 0, 0, 125, 126, 7, 0, 0, 0, 126, 131, 3, 12, 6, 0, 127, 128, 10, 3, 0, 0, 128, 129, 7, 1, 0, 0, 129, 131, 3, 12, 6, 0, 130, 124, 1, 0, 0, 0, 130, 127, 1, 0, 0, 0, 131, 134, 1, 0, 0, 0, 132, 130, 1, 0, 0, 0, 132, 133, 1, 0, 0, 0, 133, 11, 1, 0, 0, 0, 134, 132, 1, 0, 0, 0, 135, 136, 6, 6, -1, 0, 136, 137, 5, 3, 0, 0, 137, 138, 3, 4, 2, 0, 138, 139, 5, 4, 0, 0, 139, 142, 1, 0, 0, 0, 140, 142, 3, 6, 3, 0, 141, 135, 1, 0, 0, 0, 141, 140, 1, 0, 0, 0, 142, 148, 1, 0, 0, 0, 143, 144, 10, 3, 0, 0, 144, 145, 7, 0, 0, 0, 145, 147, 3, 12, 6, 4, 146, 143, 1, 0, 0, 0, 147, 150, 1, 0, 0, 0, 148, 146, 1, 0, 0, 0, 148, 149, 1, 0, 0, 0, 149, 13, 1, 0, 0, 0, 150, 148, 1, 0, 0, 0, 11, 85, 90, 101, 103, 108, 112, 122, 130, 132, 141, 148] \ No newline at end of file diff --git a/src/gems/expression/parsing/antlr/Expr.tokens b/src/gems/expression/parsing/antlr/Expr.tokens index c8638328..f367a876 100644 --- a/src/gems/expression/parsing/antlr/Expr.tokens +++ b/src/gems/expression/parsing/antlr/Expr.tokens @@ -12,10 +12,11 @@ T__10=11 T__11=12 T__12=13 NUMBER=14 -TIME=15 -IDENTIFIER=16 -COMPARISON=17 -WS=18 +MAX=15 +TIME=16 +IDENTIFIER=17 +COMPARISON=18 +WS=19 '.'=1 '-'=2 '('=3 @@ -29,4 +30,5 @@ WS=18 ','=11 '['=12 ']'=13 -'t'=15 +'max'=15 +'t'=16 diff --git a/src/gems/expression/parsing/antlr/ExprLexer.interp b/src/gems/expression/parsing/antlr/ExprLexer.interp index d761b1f1..8eaa90d8 100644 --- a/src/gems/expression/parsing/antlr/ExprLexer.interp +++ b/src/gems/expression/parsing/antlr/ExprLexer.interp @@ -14,6 +14,7 @@ null '[' ']' null +'max' 't' null null @@ -35,6 +36,7 @@ null null null NUMBER +MAX TIME IDENTIFIER COMPARISON @@ -58,6 +60,7 @@ DIGIT CHAR CHAR_OR_DIGIT NUMBER +MAX TIME IDENTIFIER COMPARISON @@ -71,4 +74,4 @@ mode names: DEFAULT_MODE atn: -[4, 0, 18, 127, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 2, 15, 7, 15, 2, 16, 7, 16, 2, 17, 7, 17, 2, 18, 7, 18, 2, 19, 7, 19, 2, 20, 7, 20, 1, 0, 1, 0, 1, 1, 1, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 1, 4, 1, 5, 1, 5, 1, 6, 1, 6, 1, 7, 1, 7, 1, 7, 1, 7, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 9, 1, 9, 1, 9, 1, 10, 1, 10, 1, 11, 1, 11, 1, 12, 1, 12, 1, 13, 1, 13, 1, 14, 1, 14, 1, 15, 1, 15, 3, 15, 93, 8, 15, 1, 16, 4, 16, 96, 8, 16, 11, 16, 12, 16, 97, 1, 16, 1, 16, 4, 16, 102, 8, 16, 11, 16, 12, 16, 103, 3, 16, 106, 8, 16, 1, 17, 1, 17, 1, 18, 1, 18, 5, 18, 112, 8, 18, 10, 18, 12, 18, 115, 9, 18, 1, 19, 1, 19, 1, 19, 1, 19, 1, 19, 3, 19, 122, 8, 19, 1, 20, 1, 20, 1, 20, 1, 20, 0, 0, 21, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 13, 7, 15, 8, 17, 9, 19, 10, 21, 11, 23, 12, 25, 13, 27, 0, 29, 0, 31, 0, 33, 14, 35, 15, 37, 16, 39, 17, 41, 18, 1, 0, 3, 1, 0, 48, 57, 3, 0, 65, 90, 95, 95, 97, 122, 3, 0, 9, 10, 13, 13, 32, 32, 130, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 13, 1, 0, 0, 0, 0, 15, 1, 0, 0, 0, 0, 17, 1, 0, 0, 0, 0, 19, 1, 0, 0, 0, 0, 21, 1, 0, 0, 0, 0, 23, 1, 0, 0, 0, 0, 25, 1, 0, 0, 0, 0, 33, 1, 0, 0, 0, 0, 35, 1, 0, 0, 0, 0, 37, 1, 0, 0, 0, 0, 39, 1, 0, 0, 0, 0, 41, 1, 0, 0, 0, 1, 43, 1, 0, 0, 0, 3, 45, 1, 0, 0, 0, 5, 47, 1, 0, 0, 0, 7, 49, 1, 0, 0, 0, 9, 51, 1, 0, 0, 0, 11, 53, 1, 0, 0, 0, 13, 55, 1, 0, 0, 0, 15, 57, 1, 0, 0, 0, 17, 61, 1, 0, 0, 0, 19, 77, 1, 0, 0, 0, 21, 80, 1, 0, 0, 0, 23, 82, 1, 0, 0, 0, 25, 84, 1, 0, 0, 0, 27, 86, 1, 0, 0, 0, 29, 88, 1, 0, 0, 0, 31, 92, 1, 0, 0, 0, 33, 95, 1, 0, 0, 0, 35, 107, 1, 0, 0, 0, 37, 109, 1, 0, 0, 0, 39, 121, 1, 0, 0, 0, 41, 123, 1, 0, 0, 0, 43, 44, 5, 46, 0, 0, 44, 2, 1, 0, 0, 0, 45, 46, 5, 45, 0, 0, 46, 4, 1, 0, 0, 0, 47, 48, 5, 40, 0, 0, 48, 6, 1, 0, 0, 0, 49, 50, 5, 41, 0, 0, 50, 8, 1, 0, 0, 0, 51, 52, 5, 47, 0, 0, 52, 10, 1, 0, 0, 0, 53, 54, 5, 42, 0, 0, 54, 12, 1, 0, 0, 0, 55, 56, 5, 43, 0, 0, 56, 14, 1, 0, 0, 0, 57, 58, 5, 115, 0, 0, 58, 59, 5, 117, 0, 0, 59, 60, 5, 109, 0, 0, 60, 16, 1, 0, 0, 0, 61, 62, 5, 115, 0, 0, 62, 63, 5, 117, 0, 0, 63, 64, 5, 109, 0, 0, 64, 65, 5, 95, 0, 0, 65, 66, 5, 99, 0, 0, 66, 67, 5, 111, 0, 0, 67, 68, 5, 110, 0, 0, 68, 69, 5, 110, 0, 0, 69, 70, 5, 101, 0, 0, 70, 71, 5, 99, 0, 0, 71, 72, 5, 116, 0, 0, 72, 73, 5, 105, 0, 0, 73, 74, 5, 111, 0, 0, 74, 75, 5, 110, 0, 0, 75, 76, 5, 115, 0, 0, 76, 18, 1, 0, 0, 0, 77, 78, 5, 46, 0, 0, 78, 79, 5, 46, 0, 0, 79, 20, 1, 0, 0, 0, 80, 81, 5, 44, 0, 0, 81, 22, 1, 0, 0, 0, 82, 83, 5, 91, 0, 0, 83, 24, 1, 0, 0, 0, 84, 85, 5, 93, 0, 0, 85, 26, 1, 0, 0, 0, 86, 87, 7, 0, 0, 0, 87, 28, 1, 0, 0, 0, 88, 89, 7, 1, 0, 0, 89, 30, 1, 0, 0, 0, 90, 93, 3, 29, 14, 0, 91, 93, 3, 27, 13, 0, 92, 90, 1, 0, 0, 0, 92, 91, 1, 0, 0, 0, 93, 32, 1, 0, 0, 0, 94, 96, 3, 27, 13, 0, 95, 94, 1, 0, 0, 0, 96, 97, 1, 0, 0, 0, 97, 95, 1, 0, 0, 0, 97, 98, 1, 0, 0, 0, 98, 105, 1, 0, 0, 0, 99, 101, 5, 46, 0, 0, 100, 102, 3, 27, 13, 0, 101, 100, 1, 0, 0, 0, 102, 103, 1, 0, 0, 0, 103, 101, 1, 0, 0, 0, 103, 104, 1, 0, 0, 0, 104, 106, 1, 0, 0, 0, 105, 99, 1, 0, 0, 0, 105, 106, 1, 0, 0, 0, 106, 34, 1, 0, 0, 0, 107, 108, 5, 116, 0, 0, 108, 36, 1, 0, 0, 0, 109, 113, 3, 29, 14, 0, 110, 112, 3, 31, 15, 0, 111, 110, 1, 0, 0, 0, 112, 115, 1, 0, 0, 0, 113, 111, 1, 0, 0, 0, 113, 114, 1, 0, 0, 0, 114, 38, 1, 0, 0, 0, 115, 113, 1, 0, 0, 0, 116, 122, 5, 61, 0, 0, 117, 118, 5, 62, 0, 0, 118, 122, 5, 61, 0, 0, 119, 120, 5, 60, 0, 0, 120, 122, 5, 61, 0, 0, 121, 116, 1, 0, 0, 0, 121, 117, 1, 0, 0, 0, 121, 119, 1, 0, 0, 0, 122, 40, 1, 0, 0, 0, 123, 124, 7, 2, 0, 0, 124, 125, 1, 0, 0, 0, 125, 126, 6, 20, 0, 0, 126, 42, 1, 0, 0, 0, 7, 0, 92, 97, 103, 105, 113, 121, 1, 6, 0, 0] \ No newline at end of file +[4, 0, 19, 133, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 2, 15, 7, 15, 2, 16, 7, 16, 2, 17, 7, 17, 2, 18, 7, 18, 2, 19, 7, 19, 2, 20, 7, 20, 2, 21, 7, 21, 1, 0, 1, 0, 1, 1, 1, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 1, 4, 1, 5, 1, 5, 1, 6, 1, 6, 1, 7, 1, 7, 1, 7, 1, 7, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 9, 1, 9, 1, 9, 1, 10, 1, 10, 1, 11, 1, 11, 1, 12, 1, 12, 1, 13, 1, 13, 1, 14, 1, 14, 1, 15, 1, 15, 3, 15, 95, 8, 15, 1, 16, 4, 16, 98, 8, 16, 11, 16, 12, 16, 99, 1, 16, 1, 16, 4, 16, 104, 8, 16, 11, 16, 12, 16, 105, 3, 16, 108, 8, 16, 1, 17, 1, 17, 1, 17, 1, 17, 1, 18, 1, 18, 1, 19, 1, 19, 5, 19, 118, 8, 19, 10, 19, 12, 19, 121, 9, 19, 1, 20, 1, 20, 1, 20, 1, 20, 1, 20, 3, 20, 128, 8, 20, 1, 21, 1, 21, 1, 21, 1, 21, 0, 0, 22, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 13, 7, 15, 8, 17, 9, 19, 10, 21, 11, 23, 12, 25, 13, 27, 0, 29, 0, 31, 0, 33, 14, 35, 15, 37, 16, 39, 17, 41, 18, 43, 19, 1, 0, 3, 1, 0, 48, 57, 3, 0, 65, 90, 95, 95, 97, 122, 3, 0, 9, 10, 13, 13, 32, 32, 136, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 13, 1, 0, 0, 0, 0, 15, 1, 0, 0, 0, 0, 17, 1, 0, 0, 0, 0, 19, 1, 0, 0, 0, 0, 21, 1, 0, 0, 0, 0, 23, 1, 0, 0, 0, 0, 25, 1, 0, 0, 0, 0, 33, 1, 0, 0, 0, 0, 35, 1, 0, 0, 0, 0, 37, 1, 0, 0, 0, 0, 39, 1, 0, 0, 0, 0, 41, 1, 0, 0, 0, 0, 43, 1, 0, 0, 0, 1, 45, 1, 0, 0, 0, 3, 47, 1, 0, 0, 0, 5, 49, 1, 0, 0, 0, 7, 51, 1, 0, 0, 0, 9, 53, 1, 0, 0, 0, 11, 55, 1, 0, 0, 0, 13, 57, 1, 0, 0, 0, 15, 59, 1, 0, 0, 0, 17, 63, 1, 0, 0, 0, 19, 79, 1, 0, 0, 0, 21, 82, 1, 0, 0, 0, 23, 84, 1, 0, 0, 0, 25, 86, 1, 0, 0, 0, 27, 88, 1, 0, 0, 0, 29, 90, 1, 0, 0, 0, 31, 94, 1, 0, 0, 0, 33, 97, 1, 0, 0, 0, 35, 109, 1, 0, 0, 0, 37, 113, 1, 0, 0, 0, 39, 115, 1, 0, 0, 0, 41, 127, 1, 0, 0, 0, 43, 129, 1, 0, 0, 0, 45, 46, 5, 46, 0, 0, 46, 2, 1, 0, 0, 0, 47, 48, 5, 45, 0, 0, 48, 4, 1, 0, 0, 0, 49, 50, 5, 40, 0, 0, 50, 6, 1, 0, 0, 0, 51, 52, 5, 41, 0, 0, 52, 8, 1, 0, 0, 0, 53, 54, 5, 47, 0, 0, 54, 10, 1, 0, 0, 0, 55, 56, 5, 42, 0, 0, 56, 12, 1, 0, 0, 0, 57, 58, 5, 43, 0, 0, 58, 14, 1, 0, 0, 0, 59, 60, 5, 115, 0, 0, 60, 61, 5, 117, 0, 0, 61, 62, 5, 109, 0, 0, 62, 16, 1, 0, 0, 0, 63, 64, 5, 115, 0, 0, 64, 65, 5, 117, 0, 0, 65, 66, 5, 109, 0, 0, 66, 67, 5, 95, 0, 0, 67, 68, 5, 99, 0, 0, 68, 69, 5, 111, 0, 0, 69, 70, 5, 110, 0, 0, 70, 71, 5, 110, 0, 0, 71, 72, 5, 101, 0, 0, 72, 73, 5, 99, 0, 0, 73, 74, 5, 116, 0, 0, 74, 75, 5, 105, 0, 0, 75, 76, 5, 111, 0, 0, 76, 77, 5, 110, 0, 0, 77, 78, 5, 115, 0, 0, 78, 18, 1, 0, 0, 0, 79, 80, 5, 46, 0, 0, 80, 81, 5, 46, 0, 0, 81, 20, 1, 0, 0, 0, 82, 83, 5, 44, 0, 0, 83, 22, 1, 0, 0, 0, 84, 85, 5, 91, 0, 0, 85, 24, 1, 0, 0, 0, 86, 87, 5, 93, 0, 0, 87, 26, 1, 0, 0, 0, 88, 89, 7, 0, 0, 0, 89, 28, 1, 0, 0, 0, 90, 91, 7, 1, 0, 0, 91, 30, 1, 0, 0, 0, 92, 95, 3, 29, 14, 0, 93, 95, 3, 27, 13, 0, 94, 92, 1, 0, 0, 0, 94, 93, 1, 0, 0, 0, 95, 32, 1, 0, 0, 0, 96, 98, 3, 27, 13, 0, 97, 96, 1, 0, 0, 0, 98, 99, 1, 0, 0, 0, 99, 97, 1, 0, 0, 0, 99, 100, 1, 0, 0, 0, 100, 107, 1, 0, 0, 0, 101, 103, 5, 46, 0, 0, 102, 104, 3, 27, 13, 0, 103, 102, 1, 0, 0, 0, 104, 105, 1, 0, 0, 0, 105, 103, 1, 0, 0, 0, 105, 106, 1, 0, 0, 0, 106, 108, 1, 0, 0, 0, 107, 101, 1, 0, 0, 0, 107, 108, 1, 0, 0, 0, 108, 34, 1, 0, 0, 0, 109, 110, 5, 109, 0, 0, 110, 111, 5, 97, 0, 0, 111, 112, 5, 120, 0, 0, 112, 36, 1, 0, 0, 0, 113, 114, 5, 116, 0, 0, 114, 38, 1, 0, 0, 0, 115, 119, 3, 29, 14, 0, 116, 118, 3, 31, 15, 0, 117, 116, 1, 0, 0, 0, 118, 121, 1, 0, 0, 0, 119, 117, 1, 0, 0, 0, 119, 120, 1, 0, 0, 0, 120, 40, 1, 0, 0, 0, 121, 119, 1, 0, 0, 0, 122, 128, 5, 61, 0, 0, 123, 124, 5, 62, 0, 0, 124, 128, 5, 61, 0, 0, 125, 126, 5, 60, 0, 0, 126, 128, 5, 61, 0, 0, 127, 122, 1, 0, 0, 0, 127, 123, 1, 0, 0, 0, 127, 125, 1, 0, 0, 0, 128, 42, 1, 0, 0, 0, 129, 130, 7, 2, 0, 0, 130, 131, 1, 0, 0, 0, 131, 132, 6, 21, 0, 0, 132, 44, 1, 0, 0, 0, 7, 0, 94, 99, 105, 107, 119, 127, 1, 6, 0, 0] \ No newline at end of file diff --git a/src/gems/expression/parsing/antlr/ExprLexer.py b/src/gems/expression/parsing/antlr/ExprLexer.py index 60c2d135..f7767124 100644 --- a/src/gems/expression/parsing/antlr/ExprLexer.py +++ b/src/gems/expression/parsing/antlr/ExprLexer.py @@ -1,9 +1,7 @@ # Generated from Expr.g4 by ANTLR 4.13.2 -import sys -from io import StringIO - from antlr4 import * - +from io import StringIO +import sys if sys.version_info[1] > 5: from typing import TextIO else: @@ -12,1141 +10,58 @@ def serializedATN(): return [ - 4, - 0, - 18, - 127, - 6, - -1, - 2, - 0, - 7, - 0, - 2, - 1, - 7, - 1, - 2, - 2, - 7, - 2, - 2, - 3, - 7, - 3, - 2, - 4, - 7, - 4, - 2, - 5, - 7, - 5, - 2, - 6, - 7, - 6, - 2, - 7, - 7, - 7, - 2, - 8, - 7, - 8, - 2, - 9, - 7, - 9, - 2, - 10, - 7, - 10, - 2, - 11, - 7, - 11, - 2, - 12, - 7, - 12, - 2, - 13, - 7, - 13, - 2, - 14, - 7, - 14, - 2, - 15, - 7, - 15, - 2, - 16, - 7, - 16, - 2, - 17, - 7, - 17, - 2, - 18, - 7, - 18, - 2, - 19, - 7, - 19, - 2, - 20, - 7, - 20, - 1, - 0, - 1, - 0, - 1, - 1, - 1, - 1, - 1, - 2, - 1, - 2, - 1, - 3, - 1, - 3, - 1, - 4, - 1, - 4, - 1, - 5, - 1, - 5, - 1, - 6, - 1, - 6, - 1, - 7, - 1, - 7, - 1, - 7, - 1, - 7, - 1, - 8, - 1, - 8, - 1, - 8, - 1, - 8, - 1, - 8, - 1, - 8, - 1, - 8, - 1, - 8, - 1, - 8, - 1, - 8, - 1, - 8, - 1, - 8, - 1, - 8, - 1, - 8, - 1, - 8, - 1, - 8, - 1, - 9, - 1, - 9, - 1, - 9, - 1, - 10, - 1, - 10, - 1, - 11, - 1, - 11, - 1, - 12, - 1, - 12, - 1, - 13, - 1, - 13, - 1, - 14, - 1, - 14, - 1, - 15, - 1, - 15, - 3, - 15, - 93, - 8, - 15, - 1, - 16, - 4, - 16, - 96, - 8, - 16, - 11, - 16, - 12, - 16, - 97, - 1, - 16, - 1, - 16, - 4, - 16, - 102, - 8, - 16, - 11, - 16, - 12, - 16, - 103, - 3, - 16, - 106, - 8, - 16, - 1, - 17, - 1, - 17, - 1, - 18, - 1, - 18, - 5, - 18, - 112, - 8, - 18, - 10, - 18, - 12, - 18, - 115, - 9, - 18, - 1, - 19, - 1, - 19, - 1, - 19, - 1, - 19, - 1, - 19, - 3, - 19, - 122, - 8, - 19, - 1, - 20, - 1, - 20, - 1, - 20, - 1, - 20, - 0, - 0, - 21, - 1, - 1, - 3, - 2, - 5, - 3, - 7, - 4, - 9, - 5, - 11, - 6, - 13, - 7, - 15, - 8, - 17, - 9, - 19, - 10, - 21, - 11, - 23, - 12, - 25, - 13, - 27, - 0, - 29, - 0, - 31, - 0, - 33, - 14, - 35, - 15, - 37, - 16, - 39, - 17, - 41, - 18, - 1, - 0, - 3, - 1, - 0, - 48, - 57, - 3, - 0, - 65, - 90, - 95, - 95, - 97, - 122, - 3, - 0, - 9, - 10, - 13, - 13, - 32, - 32, - 130, - 0, - 1, - 1, - 0, - 0, - 0, - 0, - 3, - 1, - 0, - 0, - 0, - 0, - 5, - 1, - 0, - 0, - 0, - 0, - 7, - 1, - 0, - 0, - 0, - 0, - 9, - 1, - 0, - 0, - 0, - 0, - 11, - 1, - 0, - 0, - 0, - 0, - 13, - 1, - 0, - 0, - 0, - 0, - 15, - 1, - 0, - 0, - 0, - 0, - 17, - 1, - 0, - 0, - 0, - 0, - 19, - 1, - 0, - 0, - 0, - 0, - 21, - 1, - 0, - 0, - 0, - 0, - 23, - 1, - 0, - 0, - 0, - 0, - 25, - 1, - 0, - 0, - 0, - 0, - 33, - 1, - 0, - 0, - 0, - 0, - 35, - 1, - 0, - 0, - 0, - 0, - 37, - 1, - 0, - 0, - 0, - 0, - 39, - 1, - 0, - 0, - 0, - 0, - 41, - 1, - 0, - 0, - 0, - 1, - 43, - 1, - 0, - 0, - 0, - 3, - 45, - 1, - 0, - 0, - 0, - 5, - 47, - 1, - 0, - 0, - 0, - 7, - 49, - 1, - 0, - 0, - 0, - 9, - 51, - 1, - 0, - 0, - 0, - 11, - 53, - 1, - 0, - 0, - 0, - 13, - 55, - 1, - 0, - 0, - 0, - 15, - 57, - 1, - 0, - 0, - 0, - 17, - 61, - 1, - 0, - 0, - 0, - 19, - 77, - 1, - 0, - 0, - 0, - 21, - 80, - 1, - 0, - 0, - 0, - 23, - 82, - 1, - 0, - 0, - 0, - 25, - 84, - 1, - 0, - 0, - 0, - 27, - 86, - 1, - 0, - 0, - 0, - 29, - 88, - 1, - 0, - 0, - 0, - 31, - 92, - 1, - 0, - 0, - 0, - 33, - 95, - 1, - 0, - 0, - 0, - 35, - 107, - 1, - 0, - 0, - 0, - 37, - 109, - 1, - 0, - 0, - 0, - 39, - 121, - 1, - 0, - 0, - 0, - 41, - 123, - 1, - 0, - 0, - 0, - 43, - 44, - 5, - 46, - 0, - 0, - 44, - 2, - 1, - 0, - 0, - 0, - 45, - 46, - 5, - 45, - 0, - 0, - 46, - 4, - 1, - 0, - 0, - 0, - 47, - 48, - 5, - 40, - 0, - 0, - 48, - 6, - 1, - 0, - 0, - 0, - 49, - 50, - 5, - 41, - 0, - 0, - 50, - 8, - 1, - 0, - 0, - 0, - 51, - 52, - 5, - 47, - 0, - 0, - 52, - 10, - 1, - 0, - 0, - 0, - 53, - 54, - 5, - 42, - 0, - 0, - 54, - 12, - 1, - 0, - 0, - 0, - 55, - 56, - 5, - 43, - 0, - 0, - 56, - 14, - 1, - 0, - 0, - 0, - 57, - 58, - 5, - 115, - 0, - 0, - 58, - 59, - 5, - 117, - 0, - 0, - 59, - 60, - 5, - 109, - 0, - 0, - 60, - 16, - 1, - 0, - 0, - 0, - 61, - 62, - 5, - 115, - 0, - 0, - 62, - 63, - 5, - 117, - 0, - 0, - 63, - 64, - 5, - 109, - 0, - 0, - 64, - 65, - 5, - 95, - 0, - 0, - 65, - 66, - 5, - 99, - 0, - 0, - 66, - 67, - 5, - 111, - 0, - 0, - 67, - 68, - 5, - 110, - 0, - 0, - 68, - 69, - 5, - 110, - 0, - 0, - 69, - 70, - 5, - 101, - 0, - 0, - 70, - 71, - 5, - 99, - 0, - 0, - 71, - 72, - 5, - 116, - 0, - 0, - 72, - 73, - 5, - 105, - 0, - 0, - 73, - 74, - 5, - 111, - 0, - 0, - 74, - 75, - 5, - 110, - 0, - 0, - 75, - 76, - 5, - 115, - 0, - 0, - 76, - 18, - 1, - 0, - 0, - 0, - 77, - 78, - 5, - 46, - 0, - 0, - 78, - 79, - 5, - 46, - 0, - 0, - 79, - 20, - 1, - 0, - 0, - 0, - 80, - 81, - 5, - 44, - 0, - 0, - 81, - 22, - 1, - 0, - 0, - 0, - 82, - 83, - 5, - 91, - 0, - 0, - 83, - 24, - 1, - 0, - 0, - 0, - 84, - 85, - 5, - 93, - 0, - 0, - 85, - 26, - 1, - 0, - 0, - 0, - 86, - 87, - 7, - 0, - 0, - 0, - 87, - 28, - 1, - 0, - 0, - 0, - 88, - 89, - 7, - 1, - 0, - 0, - 89, - 30, - 1, - 0, - 0, - 0, - 90, - 93, - 3, - 29, - 14, - 0, - 91, - 93, - 3, - 27, - 13, - 0, - 92, - 90, - 1, - 0, - 0, - 0, - 92, - 91, - 1, - 0, - 0, - 0, - 93, - 32, - 1, - 0, - 0, - 0, - 94, - 96, - 3, - 27, - 13, - 0, - 95, - 94, - 1, - 0, - 0, - 0, - 96, - 97, - 1, - 0, - 0, - 0, - 97, - 95, - 1, - 0, - 0, - 0, - 97, - 98, - 1, - 0, - 0, - 0, - 98, - 105, - 1, - 0, - 0, - 0, - 99, - 101, - 5, - 46, - 0, - 0, - 100, - 102, - 3, - 27, - 13, - 0, - 101, - 100, - 1, - 0, - 0, - 0, - 102, - 103, - 1, - 0, - 0, - 0, - 103, - 101, - 1, - 0, - 0, - 0, - 103, - 104, - 1, - 0, - 0, - 0, - 104, - 106, - 1, - 0, - 0, - 0, - 105, - 99, - 1, - 0, - 0, - 0, - 105, - 106, - 1, - 0, - 0, - 0, - 106, - 34, - 1, - 0, - 0, - 0, - 107, - 108, - 5, - 116, - 0, - 0, - 108, - 36, - 1, - 0, - 0, - 0, - 109, - 113, - 3, - 29, - 14, - 0, - 110, - 112, - 3, - 31, - 15, - 0, - 111, - 110, - 1, - 0, - 0, - 0, - 112, - 115, - 1, - 0, - 0, - 0, - 113, - 111, - 1, - 0, - 0, - 0, - 113, - 114, - 1, - 0, - 0, - 0, - 114, - 38, - 1, - 0, - 0, - 0, - 115, - 113, - 1, - 0, - 0, - 0, - 116, - 122, - 5, - 61, - 0, - 0, - 117, - 118, - 5, - 62, - 0, - 0, - 118, - 122, - 5, - 61, - 0, - 0, - 119, - 120, - 5, - 60, - 0, - 0, - 120, - 122, - 5, - 61, - 0, - 0, - 121, - 116, - 1, - 0, - 0, - 0, - 121, - 117, - 1, - 0, - 0, - 0, - 121, - 119, - 1, - 0, - 0, - 0, - 122, - 40, - 1, - 0, - 0, - 0, - 123, - 124, - 7, - 2, - 0, - 0, - 124, - 125, - 1, - 0, - 0, - 0, - 125, - 126, - 6, - 20, - 0, - 0, - 126, - 42, - 1, - 0, - 0, - 0, - 7, - 0, - 92, - 97, - 103, - 105, - 113, - 121, - 1, - 6, - 0, - 0, + 4,0,19,133,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5, + 2,6,7,6,2,7,7,7,2,8,7,8,2,9,7,9,2,10,7,10,2,11,7,11,2,12,7,12,2, + 13,7,13,2,14,7,14,2,15,7,15,2,16,7,16,2,17,7,17,2,18,7,18,2,19,7, + 19,2,20,7,20,2,21,7,21,1,0,1,0,1,1,1,1,1,2,1,2,1,3,1,3,1,4,1,4,1, + 5,1,5,1,6,1,6,1,7,1,7,1,7,1,7,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1, + 8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,9,1,9,1,9,1,10,1,10,1,11,1,11,1, + 12,1,12,1,13,1,13,1,14,1,14,1,15,1,15,3,15,95,8,15,1,16,4,16,98, + 8,16,11,16,12,16,99,1,16,1,16,4,16,104,8,16,11,16,12,16,105,3,16, + 108,8,16,1,17,1,17,1,17,1,17,1,18,1,18,1,19,1,19,5,19,118,8,19,10, + 19,12,19,121,9,19,1,20,1,20,1,20,1,20,1,20,3,20,128,8,20,1,21,1, + 21,1,21,1,21,0,0,22,1,1,3,2,5,3,7,4,9,5,11,6,13,7,15,8,17,9,19,10, + 21,11,23,12,25,13,27,0,29,0,31,0,33,14,35,15,37,16,39,17,41,18,43, + 19,1,0,3,1,0,48,57,3,0,65,90,95,95,97,122,3,0,9,10,13,13,32,32,136, + 0,1,1,0,0,0,0,3,1,0,0,0,0,5,1,0,0,0,0,7,1,0,0,0,0,9,1,0,0,0,0,11, + 1,0,0,0,0,13,1,0,0,0,0,15,1,0,0,0,0,17,1,0,0,0,0,19,1,0,0,0,0,21, + 1,0,0,0,0,23,1,0,0,0,0,25,1,0,0,0,0,33,1,0,0,0,0,35,1,0,0,0,0,37, + 1,0,0,0,0,39,1,0,0,0,0,41,1,0,0,0,0,43,1,0,0,0,1,45,1,0,0,0,3,47, + 1,0,0,0,5,49,1,0,0,0,7,51,1,0,0,0,9,53,1,0,0,0,11,55,1,0,0,0,13, + 57,1,0,0,0,15,59,1,0,0,0,17,63,1,0,0,0,19,79,1,0,0,0,21,82,1,0,0, + 0,23,84,1,0,0,0,25,86,1,0,0,0,27,88,1,0,0,0,29,90,1,0,0,0,31,94, + 1,0,0,0,33,97,1,0,0,0,35,109,1,0,0,0,37,113,1,0,0,0,39,115,1,0,0, + 0,41,127,1,0,0,0,43,129,1,0,0,0,45,46,5,46,0,0,46,2,1,0,0,0,47,48, + 5,45,0,0,48,4,1,0,0,0,49,50,5,40,0,0,50,6,1,0,0,0,51,52,5,41,0,0, + 52,8,1,0,0,0,53,54,5,47,0,0,54,10,1,0,0,0,55,56,5,42,0,0,56,12,1, + 0,0,0,57,58,5,43,0,0,58,14,1,0,0,0,59,60,5,115,0,0,60,61,5,117,0, + 0,61,62,5,109,0,0,62,16,1,0,0,0,63,64,5,115,0,0,64,65,5,117,0,0, + 65,66,5,109,0,0,66,67,5,95,0,0,67,68,5,99,0,0,68,69,5,111,0,0,69, + 70,5,110,0,0,70,71,5,110,0,0,71,72,5,101,0,0,72,73,5,99,0,0,73,74, + 5,116,0,0,74,75,5,105,0,0,75,76,5,111,0,0,76,77,5,110,0,0,77,78, + 5,115,0,0,78,18,1,0,0,0,79,80,5,46,0,0,80,81,5,46,0,0,81,20,1,0, + 0,0,82,83,5,44,0,0,83,22,1,0,0,0,84,85,5,91,0,0,85,24,1,0,0,0,86, + 87,5,93,0,0,87,26,1,0,0,0,88,89,7,0,0,0,89,28,1,0,0,0,90,91,7,1, + 0,0,91,30,1,0,0,0,92,95,3,29,14,0,93,95,3,27,13,0,94,92,1,0,0,0, + 94,93,1,0,0,0,95,32,1,0,0,0,96,98,3,27,13,0,97,96,1,0,0,0,98,99, + 1,0,0,0,99,97,1,0,0,0,99,100,1,0,0,0,100,107,1,0,0,0,101,103,5,46, + 0,0,102,104,3,27,13,0,103,102,1,0,0,0,104,105,1,0,0,0,105,103,1, + 0,0,0,105,106,1,0,0,0,106,108,1,0,0,0,107,101,1,0,0,0,107,108,1, + 0,0,0,108,34,1,0,0,0,109,110,5,109,0,0,110,111,5,97,0,0,111,112, + 5,120,0,0,112,36,1,0,0,0,113,114,5,116,0,0,114,38,1,0,0,0,115,119, + 3,29,14,0,116,118,3,31,15,0,117,116,1,0,0,0,118,121,1,0,0,0,119, + 117,1,0,0,0,119,120,1,0,0,0,120,40,1,0,0,0,121,119,1,0,0,0,122,128, + 5,61,0,0,123,124,5,62,0,0,124,128,5,61,0,0,125,126,5,60,0,0,126, + 128,5,61,0,0,127,122,1,0,0,0,127,123,1,0,0,0,127,125,1,0,0,0,128, + 42,1,0,0,0,129,130,7,2,0,0,130,131,1,0,0,0,131,132,6,21,0,0,132, + 44,1,0,0,0,7,0,94,99,105,107,119,127,1,6,0,0 ] - class ExprLexer(Lexer): + atn = ATNDeserializer().deserialize(serializedATN()) - decisionsToDFA = [DFA(ds, i) for i, ds in enumerate(atn.decisionToState)] + decisionsToDFA = [ DFA(ds, i) for i, ds in enumerate(atn.decisionToState) ] T__0 = 1 T__1 = 2 @@ -1162,66 +77,35 @@ class ExprLexer(Lexer): T__11 = 12 T__12 = 13 NUMBER = 14 - TIME = 15 - IDENTIFIER = 16 - COMPARISON = 17 - WS = 18 + MAX = 15 + TIME = 16 + IDENTIFIER = 17 + COMPARISON = 18 + WS = 19 - channelNames = ["DEFAULT_TOKEN_CHANNEL", "HIDDEN"] + channelNames = [ u"DEFAULT_TOKEN_CHANNEL", u"HIDDEN" ] - modeNames = ["DEFAULT_MODE"] + modeNames = [ "DEFAULT_MODE" ] - literalNames = [ - "", - "'.'", - "'-'", - "'('", - "')'", - "'/'", - "'*'", - "'+'", - "'sum'", - "'sum_connections'", - "'..'", - "','", - "'['", - "']'", - "'t'", - ] + literalNames = [ "", + "'.'", "'-'", "'('", "')'", "'/'", "'*'", "'+'", "'sum'", "'sum_connections'", + "'..'", "','", "'['", "']'", "'max'", "'t'" ] - symbolicNames = ["", "NUMBER", "TIME", "IDENTIFIER", "COMPARISON", "WS"] + symbolicNames = [ "", + "NUMBER", "MAX", "TIME", "IDENTIFIER", "COMPARISON", "WS" ] - ruleNames = [ - "T__0", - "T__1", - "T__2", - "T__3", - "T__4", - "T__5", - "T__6", - "T__7", - "T__8", - "T__9", - "T__10", - "T__11", - "T__12", - "DIGIT", - "CHAR", - "CHAR_OR_DIGIT", - "NUMBER", - "TIME", - "IDENTIFIER", - "COMPARISON", - "WS", - ] + ruleNames = [ "T__0", "T__1", "T__2", "T__3", "T__4", "T__5", "T__6", + "T__7", "T__8", "T__9", "T__10", "T__11", "T__12", "DIGIT", + "CHAR", "CHAR_OR_DIGIT", "NUMBER", "MAX", "TIME", "IDENTIFIER", + "COMPARISON", "WS" ] grammarFileName = "Expr.g4" - def __init__(self, input=None, output: TextIO = sys.stdout): + def __init__(self, input=None, output:TextIO = sys.stdout): super().__init__(input, output) self.checkVersion("4.13.2") - self._interp = LexerATNSimulator( - self, self.atn, self.decisionsToDFA, PredictionContextCache() - ) + self._interp = LexerATNSimulator(self, self.atn, self.decisionsToDFA, PredictionContextCache()) self._actions = None self._predicates = None + + diff --git a/src/gems/expression/parsing/antlr/ExprLexer.tokens b/src/gems/expression/parsing/antlr/ExprLexer.tokens index c8638328..f367a876 100644 --- a/src/gems/expression/parsing/antlr/ExprLexer.tokens +++ b/src/gems/expression/parsing/antlr/ExprLexer.tokens @@ -12,10 +12,11 @@ T__10=11 T__11=12 T__12=13 NUMBER=14 -TIME=15 -IDENTIFIER=16 -COMPARISON=17 -WS=18 +MAX=15 +TIME=16 +IDENTIFIER=17 +COMPARISON=18 +WS=19 '.'=1 '-'=2 '('=3 @@ -29,4 +30,5 @@ WS=18 ','=11 '['=12 ']'=13 -'t'=15 +'max'=15 +'t'=16 diff --git a/src/gems/expression/parsing/antlr/ExprParser.py b/src/gems/expression/parsing/antlr/ExprParser.py index 859d23dc..77e0781b 100644 --- a/src/gems/expression/parsing/antlr/ExprParser.py +++ b/src/gems/expression/parsing/antlr/ExprParser.py @@ -1,1320 +1,87 @@ # Generated from Expr.g4 by ANTLR 4.13.2 # encoding: utf-8 -import sys -from io import StringIO - from antlr4 import * - +from io import StringIO +import sys if sys.version_info[1] > 5: - from typing import TextIO + from typing import TextIO else: - from typing.io import TextIO - + from typing.io import TextIO def serializedATN(): return [ - 4, - 1, - 18, - 140, - 2, - 0, - 7, - 0, - 2, - 1, - 7, - 1, - 2, - 2, - 7, - 2, - 2, - 3, - 7, - 3, - 2, - 4, - 7, - 4, - 2, - 5, - 7, - 5, - 2, - 6, - 7, - 6, - 1, - 0, - 1, - 0, - 1, - 0, - 1, - 0, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 3, - 2, - 79, - 8, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 5, - 2, - 90, - 8, - 2, - 10, - 2, - 12, - 2, - 93, - 9, - 2, - 1, - 3, - 1, - 3, - 3, - 3, - 97, - 8, - 3, - 1, - 4, - 1, - 4, - 3, - 4, - 101, - 8, - 4, - 1, - 5, - 1, - 5, - 1, - 5, - 1, - 5, - 1, - 5, - 1, - 5, - 1, - 5, - 1, - 5, - 3, - 5, - 111, - 8, - 5, - 1, - 5, - 1, - 5, - 1, - 5, - 1, - 5, - 1, - 5, - 1, - 5, - 5, - 5, - 119, - 8, - 5, - 10, - 5, - 12, - 5, - 122, - 9, - 5, - 1, - 6, - 1, - 6, - 1, - 6, - 1, - 6, - 1, - 6, - 1, - 6, - 3, - 6, - 130, - 8, - 6, - 1, - 6, - 1, - 6, - 1, - 6, - 5, - 6, - 135, - 8, - 6, - 10, - 6, - 12, - 6, - 138, - 9, - 6, - 1, - 6, - 0, - 3, - 4, - 10, - 12, - 7, - 0, - 2, - 4, - 6, - 8, - 10, - 12, - 0, - 2, - 1, - 0, - 5, - 6, - 2, - 0, - 2, - 2, - 7, - 7, - 153, - 0, - 14, - 1, - 0, - 0, - 0, - 2, - 18, - 1, - 0, - 0, - 0, - 4, - 78, - 1, - 0, - 0, - 0, - 6, - 96, - 1, - 0, - 0, - 0, - 8, - 98, - 1, - 0, - 0, - 0, - 10, - 110, - 1, - 0, - 0, - 0, - 12, - 129, - 1, - 0, - 0, - 0, - 14, - 15, - 5, - 16, - 0, - 0, - 15, - 16, - 5, - 1, - 0, - 0, - 16, - 17, - 5, - 16, - 0, - 0, - 17, - 1, - 1, - 0, - 0, - 0, - 18, - 19, - 3, - 4, - 2, - 0, - 19, - 20, - 5, - 0, - 0, - 1, - 20, - 3, - 1, - 0, - 0, - 0, - 21, - 22, - 6, - 2, - -1, - 0, - 22, - 79, - 3, - 6, - 3, - 0, - 23, - 79, - 3, - 0, - 0, - 0, - 24, - 25, - 5, - 2, - 0, - 0, - 25, - 79, - 3, - 4, - 2, - 13, - 26, - 27, - 5, - 3, - 0, - 0, - 27, - 28, - 3, - 4, - 2, - 0, - 28, - 29, - 5, - 4, - 0, - 0, - 29, - 79, - 1, - 0, - 0, - 0, - 30, - 31, - 5, - 8, - 0, - 0, - 31, - 32, - 5, - 3, - 0, - 0, - 32, - 33, - 3, - 4, - 2, - 0, - 33, - 34, - 5, - 4, - 0, - 0, - 34, - 79, - 1, - 0, - 0, - 0, - 35, - 36, - 5, - 9, - 0, - 0, - 36, - 37, - 5, - 3, - 0, - 0, - 37, - 38, - 3, - 0, - 0, - 0, - 38, - 39, - 5, - 4, - 0, - 0, - 39, - 79, - 1, - 0, - 0, - 0, - 40, - 41, - 5, - 8, - 0, - 0, - 41, - 42, - 5, - 3, - 0, - 0, - 42, - 43, - 3, - 8, - 4, - 0, - 43, - 44, - 5, - 10, - 0, - 0, - 44, - 45, - 3, - 8, - 4, - 0, - 45, - 46, - 5, - 11, - 0, - 0, - 46, - 47, - 3, - 4, - 2, - 0, - 47, - 48, - 5, - 4, - 0, - 0, - 48, - 79, - 1, - 0, - 0, - 0, - 49, - 50, - 5, - 16, - 0, - 0, - 50, - 51, - 5, - 3, - 0, - 0, - 51, - 52, - 3, - 4, - 2, - 0, - 52, - 53, - 5, - 4, - 0, - 0, - 53, - 79, - 1, - 0, - 0, - 0, - 54, - 55, - 5, - 16, - 0, - 0, - 55, - 56, - 5, - 12, - 0, - 0, - 56, - 57, - 3, - 8, - 4, - 0, - 57, - 58, - 5, - 13, - 0, - 0, - 58, - 79, - 1, - 0, - 0, - 0, - 59, - 60, - 5, - 16, - 0, - 0, - 60, - 61, - 5, - 12, - 0, - 0, - 61, - 62, - 3, - 4, - 2, - 0, - 62, - 63, - 5, - 13, - 0, - 0, - 63, - 79, - 1, - 0, - 0, - 0, - 64, - 65, - 5, - 3, - 0, - 0, - 65, - 66, - 3, - 4, - 2, - 0, - 66, - 67, - 5, - 4, - 0, - 0, - 67, - 68, - 5, - 12, - 0, - 0, - 68, - 69, - 3, - 8, - 4, - 0, - 69, - 70, - 5, - 13, - 0, - 0, - 70, - 79, - 1, - 0, - 0, - 0, - 71, - 72, - 5, - 3, - 0, - 0, - 72, - 73, - 3, - 4, - 2, - 0, - 73, - 74, - 5, - 4, - 0, - 0, - 74, - 75, - 5, - 12, - 0, - 0, - 75, - 76, - 3, - 4, - 2, - 0, - 76, - 77, - 5, - 13, - 0, - 0, - 77, - 79, - 1, - 0, - 0, - 0, - 78, - 21, - 1, - 0, - 0, - 0, - 78, - 23, - 1, - 0, - 0, - 0, - 78, - 24, - 1, - 0, - 0, - 0, - 78, - 26, - 1, - 0, - 0, - 0, - 78, - 30, - 1, - 0, - 0, - 0, - 78, - 35, - 1, - 0, - 0, - 0, - 78, - 40, - 1, - 0, - 0, - 0, - 78, - 49, - 1, - 0, - 0, - 0, - 78, - 54, - 1, - 0, - 0, - 0, - 78, - 59, - 1, - 0, - 0, - 0, - 78, - 64, - 1, - 0, - 0, - 0, - 78, - 71, - 1, - 0, - 0, - 0, - 79, - 91, - 1, - 0, - 0, - 0, - 80, - 81, - 10, - 11, - 0, - 0, - 81, - 82, - 7, - 0, - 0, - 0, - 82, - 90, - 3, - 4, - 2, - 12, - 83, - 84, - 10, - 10, - 0, - 0, - 84, - 85, - 7, - 1, - 0, - 0, - 85, - 90, - 3, - 4, - 2, - 11, - 86, - 87, - 10, - 9, - 0, - 0, - 87, - 88, - 5, - 17, - 0, - 0, - 88, - 90, - 3, - 4, - 2, - 10, - 89, - 80, - 1, - 0, - 0, - 0, - 89, - 83, - 1, - 0, - 0, - 0, - 89, - 86, - 1, - 0, - 0, - 0, - 90, - 93, - 1, - 0, - 0, - 0, - 91, - 89, - 1, - 0, - 0, - 0, - 91, - 92, - 1, - 0, - 0, - 0, - 92, - 5, - 1, - 0, - 0, - 0, - 93, - 91, - 1, - 0, - 0, - 0, - 94, - 97, - 5, - 14, - 0, - 0, - 95, - 97, - 5, - 16, - 0, - 0, - 96, - 94, - 1, - 0, - 0, - 0, - 96, - 95, - 1, - 0, - 0, - 0, - 97, - 7, - 1, - 0, - 0, - 0, - 98, - 100, - 5, - 15, - 0, - 0, - 99, - 101, - 3, - 10, - 5, - 0, - 100, - 99, - 1, - 0, - 0, - 0, - 100, - 101, - 1, - 0, - 0, - 0, - 101, - 9, - 1, - 0, - 0, - 0, - 102, - 103, - 6, - 5, - -1, - 0, - 103, - 104, - 7, - 1, - 0, - 0, - 104, - 111, - 3, - 6, - 3, - 0, - 105, - 106, - 7, - 1, - 0, - 0, - 106, - 107, - 5, - 3, - 0, - 0, - 107, - 108, - 3, - 4, - 2, - 0, - 108, - 109, - 5, - 4, - 0, - 0, - 109, - 111, - 1, - 0, - 0, - 0, - 110, - 102, - 1, - 0, - 0, - 0, - 110, - 105, - 1, - 0, - 0, - 0, - 111, - 120, - 1, - 0, - 0, - 0, - 112, - 113, - 10, - 4, - 0, - 0, - 113, - 114, - 7, - 0, - 0, - 0, - 114, - 119, - 3, - 12, - 6, - 0, - 115, - 116, - 10, - 3, - 0, - 0, - 116, - 117, - 7, - 1, - 0, - 0, - 117, - 119, - 3, - 12, - 6, - 0, - 118, - 112, - 1, - 0, - 0, - 0, - 118, - 115, - 1, - 0, - 0, - 0, - 119, - 122, - 1, - 0, - 0, - 0, - 120, - 118, - 1, - 0, - 0, - 0, - 120, - 121, - 1, - 0, - 0, - 0, - 121, - 11, - 1, - 0, - 0, - 0, - 122, - 120, - 1, - 0, - 0, - 0, - 123, - 124, - 6, - 6, - -1, - 0, - 124, - 125, - 5, - 3, - 0, - 0, - 125, - 126, - 3, - 4, - 2, - 0, - 126, - 127, - 5, - 4, - 0, - 0, - 127, - 130, - 1, - 0, - 0, - 0, - 128, - 130, - 3, - 6, - 3, - 0, - 129, - 123, - 1, - 0, - 0, - 0, - 129, - 128, - 1, - 0, - 0, - 0, - 130, - 136, - 1, - 0, - 0, - 0, - 131, - 132, - 10, - 3, - 0, - 0, - 132, - 133, - 7, - 0, - 0, - 0, - 133, - 135, - 3, - 12, - 6, - 4, - 134, - 131, - 1, - 0, - 0, - 0, - 135, - 138, - 1, - 0, - 0, - 0, - 136, - 134, - 1, - 0, - 0, - 0, - 136, - 137, - 1, - 0, - 0, - 0, - 137, - 13, - 1, - 0, - 0, - 0, - 138, - 136, - 1, - 0, - 0, - 0, - 10, - 78, - 89, - 91, - 96, - 100, - 110, - 118, - 120, - 129, - 136, + 4,1,19,152,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7, + 6,1,0,1,0,1,0,1,0,1,1,1,1,1,1,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1, + 2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1, + 2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1, + 2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1, + 2,1,2,1,2,1,2,1,2,1,2,5,2,84,8,2,10,2,12,2,87,9,2,1,2,1,2,3,2,91, + 8,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,5,2,102,8,2,10,2,12,2,105, + 9,2,1,3,1,3,3,3,109,8,3,1,4,1,4,3,4,113,8,4,1,5,1,5,1,5,1,5,1,5, + 1,5,1,5,1,5,3,5,123,8,5,1,5,1,5,1,5,1,5,1,5,1,5,5,5,131,8,5,10,5, + 12,5,134,9,5,1,6,1,6,1,6,1,6,1,6,1,6,3,6,142,8,6,1,6,1,6,1,6,5,6, + 147,8,6,10,6,12,6,150,9,6,1,6,0,3,4,10,12,7,0,2,4,6,8,10,12,0,2, + 1,0,5,6,2,0,2,2,7,7,167,0,14,1,0,0,0,2,18,1,0,0,0,4,90,1,0,0,0,6, + 108,1,0,0,0,8,110,1,0,0,0,10,122,1,0,0,0,12,141,1,0,0,0,14,15,5, + 17,0,0,15,16,5,1,0,0,16,17,5,17,0,0,17,1,1,0,0,0,18,19,3,4,2,0,19, + 20,5,0,0,1,20,3,1,0,0,0,21,22,6,2,-1,0,22,91,3,6,3,0,23,91,3,0,0, + 0,24,25,5,2,0,0,25,91,3,4,2,14,26,27,5,3,0,0,27,28,3,4,2,0,28,29, + 5,4,0,0,29,91,1,0,0,0,30,31,5,8,0,0,31,32,5,3,0,0,32,33,3,4,2,0, + 33,34,5,4,0,0,34,91,1,0,0,0,35,36,5,9,0,0,36,37,5,3,0,0,37,38,3, + 0,0,0,38,39,5,4,0,0,39,91,1,0,0,0,40,41,5,8,0,0,41,42,5,3,0,0,42, + 43,3,8,4,0,43,44,5,10,0,0,44,45,3,8,4,0,45,46,5,11,0,0,46,47,3,4, + 2,0,47,48,5,4,0,0,48,91,1,0,0,0,49,50,5,17,0,0,50,51,5,3,0,0,51, + 52,3,4,2,0,52,53,5,4,0,0,53,91,1,0,0,0,54,55,5,17,0,0,55,56,5,12, + 0,0,56,57,3,8,4,0,57,58,5,13,0,0,58,91,1,0,0,0,59,60,5,17,0,0,60, + 61,5,12,0,0,61,62,3,4,2,0,62,63,5,13,0,0,63,91,1,0,0,0,64,65,5,3, + 0,0,65,66,3,4,2,0,66,67,5,4,0,0,67,68,5,12,0,0,68,69,3,8,4,0,69, + 70,5,13,0,0,70,91,1,0,0,0,71,72,5,3,0,0,72,73,3,4,2,0,73,74,5,4, + 0,0,74,75,5,12,0,0,75,76,3,4,2,0,76,77,5,13,0,0,77,91,1,0,0,0,78, + 79,5,15,0,0,79,80,5,3,0,0,80,85,3,4,2,0,81,82,5,11,0,0,82,84,3,4, + 2,0,83,81,1,0,0,0,84,87,1,0,0,0,85,83,1,0,0,0,85,86,1,0,0,0,86,88, + 1,0,0,0,87,85,1,0,0,0,88,89,5,4,0,0,89,91,1,0,0,0,90,21,1,0,0,0, + 90,23,1,0,0,0,90,24,1,0,0,0,90,26,1,0,0,0,90,30,1,0,0,0,90,35,1, + 0,0,0,90,40,1,0,0,0,90,49,1,0,0,0,90,54,1,0,0,0,90,59,1,0,0,0,90, + 64,1,0,0,0,90,71,1,0,0,0,90,78,1,0,0,0,91,103,1,0,0,0,92,93,10,12, + 0,0,93,94,7,0,0,0,94,102,3,4,2,13,95,96,10,11,0,0,96,97,7,1,0,0, + 97,102,3,4,2,12,98,99,10,10,0,0,99,100,5,18,0,0,100,102,3,4,2,11, + 101,92,1,0,0,0,101,95,1,0,0,0,101,98,1,0,0,0,102,105,1,0,0,0,103, + 101,1,0,0,0,103,104,1,0,0,0,104,5,1,0,0,0,105,103,1,0,0,0,106,109, + 5,14,0,0,107,109,5,17,0,0,108,106,1,0,0,0,108,107,1,0,0,0,109,7, + 1,0,0,0,110,112,5,16,0,0,111,113,3,10,5,0,112,111,1,0,0,0,112,113, + 1,0,0,0,113,9,1,0,0,0,114,115,6,5,-1,0,115,116,7,1,0,0,116,123,3, + 6,3,0,117,118,7,1,0,0,118,119,5,3,0,0,119,120,3,4,2,0,120,121,5, + 4,0,0,121,123,1,0,0,0,122,114,1,0,0,0,122,117,1,0,0,0,123,132,1, + 0,0,0,124,125,10,4,0,0,125,126,7,0,0,0,126,131,3,12,6,0,127,128, + 10,3,0,0,128,129,7,1,0,0,129,131,3,12,6,0,130,124,1,0,0,0,130,127, + 1,0,0,0,131,134,1,0,0,0,132,130,1,0,0,0,132,133,1,0,0,0,133,11,1, + 0,0,0,134,132,1,0,0,0,135,136,6,6,-1,0,136,137,5,3,0,0,137,138,3, + 4,2,0,138,139,5,4,0,0,139,142,1,0,0,0,140,142,3,6,3,0,141,135,1, + 0,0,0,141,140,1,0,0,0,142,148,1,0,0,0,143,144,10,3,0,0,144,145,7, + 0,0,0,145,147,3,12,6,4,146,143,1,0,0,0,147,150,1,0,0,0,148,146,1, + 0,0,0,148,149,1,0,0,0,149,13,1,0,0,0,150,148,1,0,0,0,11,85,90,101, + 103,108,112,122,130,132,141,148 ] +class ExprParser ( Parser ): -class ExprParser(Parser): grammarFileName = "Expr.g4" atn = ATNDeserializer().deserialize(serializedATN()) - decisionsToDFA = [DFA(ds, i) for i, ds in enumerate(atn.decisionToState)] + decisionsToDFA = [ DFA(ds, i) for i, ds in enumerate(atn.decisionToState) ] sharedContextCache = PredictionContextCache() - literalNames = [ - "", - "'.'", - "'-'", - "'('", - "')'", - "'/'", - "'*'", - "'+'", - "'sum'", - "'sum_connections'", - "'..'", - "','", - "'['", - "']'", - "", - "'t'", - ] + literalNames = [ "", "'.'", "'-'", "'('", "')'", "'/'", "'*'", + "'+'", "'sum'", "'sum_connections'", "'..'", "','", + "'['", "']'", "", "'max'", "'t'" ] - symbolicNames = [ - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "NUMBER", - "TIME", - "IDENTIFIER", - "COMPARISON", - "WS", - ] + symbolicNames = [ "", "", "", "", + "", "", "", "", + "", "", "", "", + "", "", "NUMBER", "MAX", "TIME", + "IDENTIFIER", "COMPARISON", "WS" ] RULE_portFieldExpr = 0 RULE_fullexpr = 1 @@ -1324,54 +91,47 @@ class ExprParser(Parser): RULE_shift_expr = 5 RULE_right_expr = 6 - ruleNames = [ - "portFieldExpr", - "fullexpr", - "expr", - "atom", - "shift", - "shift_expr", - "right_expr", - ] + ruleNames = [ "portFieldExpr", "fullexpr", "expr", "atom", "shift", + "shift_expr", "right_expr" ] EOF = Token.EOF - T__0 = 1 - T__1 = 2 - T__2 = 3 - T__3 = 4 - T__4 = 5 - T__5 = 6 - T__6 = 7 - T__7 = 8 - T__8 = 9 - T__9 = 10 - T__10 = 11 - T__11 = 12 - T__12 = 13 - NUMBER = 14 - TIME = 15 - IDENTIFIER = 16 - COMPARISON = 17 - WS = 18 - - def __init__(self, input: TokenStream, output: TextIO = sys.stdout): + T__0=1 + T__1=2 + T__2=3 + T__3=4 + T__4=5 + T__5=6 + T__6=7 + T__7=8 + T__8=9 + T__9=10 + T__10=11 + T__11=12 + T__12=13 + NUMBER=14 + MAX=15 + TIME=16 + IDENTIFIER=17 + COMPARISON=18 + WS=19 + + def __init__(self, input:TokenStream, output:TextIO = sys.stdout): super().__init__(input, output) self.checkVersion("4.13.2") - self._interp = ParserATNSimulator( - self, self.atn, self.decisionsToDFA, self.sharedContextCache - ) + self._interp = ParserATNSimulator(self, self.atn, self.decisionsToDFA, self.sharedContextCache) self._predicates = None + + + class PortFieldExprContext(ParserRuleContext): - __slots__ = "parser" + __slots__ = 'parser' - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): + def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): super().__init__(parent, invokingState) self.parser = parser - def IDENTIFIER(self, i: int = None): + def IDENTIFIER(self, i:int=None): if i is None: return self.getTokens(ExprParser.IDENTIFIER) else: @@ -1380,13 +140,17 @@ def IDENTIFIER(self, i: int = None): def getRuleIndex(self): return ExprParser.RULE_portFieldExpr - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitPortFieldExpr"): + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitPortFieldExpr" ): return visitor.visitPortFieldExpr(self) else: return visitor.visitChildren(self) + + + def portFieldExpr(self): + localctx = ExprParser.PortFieldExprContext(self, self._ctx, self.state) self.enterRule(localctx, 0, self.RULE_portFieldExpr) try: @@ -1405,17 +169,17 @@ def portFieldExpr(self): self.exitRule() return localctx + class FullexprContext(ParserRuleContext): - __slots__ = "parser" + __slots__ = 'parser' - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): + def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): super().__init__(parent, invokingState) self.parser = parser def expr(self): - return self.getTypedRuleContext(ExprParser.ExprContext, 0) + return self.getTypedRuleContext(ExprParser.ExprContext,0) + def EOF(self): return self.getToken(ExprParser.EOF, 0) @@ -1423,13 +187,17 @@ def EOF(self): def getRuleIndex(self): return ExprParser.RULE_fullexpr - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitFullexpr"): + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitFullexpr" ): return visitor.visitFullexpr(self) else: return visitor.visitChildren(self) + + + def fullexpr(self): + localctx = ExprParser.FullexprContext(self, self._ctx, self.state) self.enterRule(localctx, 2, self.RULE_fullexpr) try: @@ -1446,311 +214,347 @@ def fullexpr(self): self.exitRule() return localctx + class ExprContext(ParserRuleContext): - __slots__ = "parser" + __slots__ = 'parser' - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): + def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): super().__init__(parent, invokingState) self.parser = parser + def getRuleIndex(self): return ExprParser.RULE_expr - def copyFrom(self, ctx: ParserRuleContext): + + def copyFrom(self, ctx:ParserRuleContext): super().copyFrom(ctx) + class PortFieldSumContext(ExprContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.ExprContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) def portFieldExpr(self): - return self.getTypedRuleContext(ExprParser.PortFieldExprContext, 0) + return self.getTypedRuleContext(ExprParser.PortFieldExprContext,0) + - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitPortFieldSum"): + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitPortFieldSum" ): return visitor.visitPortFieldSum(self) else: return visitor.visitChildren(self) + class NegationContext(ExprContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.ExprContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) def expr(self): - return self.getTypedRuleContext(ExprParser.ExprContext, 0) + return self.getTypedRuleContext(ExprParser.ExprContext,0) + - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitNegation"): + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitNegation" ): return visitor.visitNegation(self) else: return visitor.visitChildren(self) + class UnsignedAtomContext(ExprContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.ExprContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) def atom(self): - return self.getTypedRuleContext(ExprParser.AtomContext, 0) + return self.getTypedRuleContext(ExprParser.AtomContext,0) + - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitUnsignedAtom"): + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitUnsignedAtom" ): return visitor.visitUnsignedAtom(self) else: return visitor.visitChildren(self) + class ExpressionContext(ExprContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.ExprContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) def expr(self): - return self.getTypedRuleContext(ExprParser.ExprContext, 0) + return self.getTypedRuleContext(ExprParser.ExprContext,0) + - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitExpression"): + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitExpression" ): return visitor.visitExpression(self) else: return visitor.visitChildren(self) + class ComparisonContext(ExprContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.ExprContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) - def expr(self, i: int = None): + def expr(self, i:int=None): if i is None: return self.getTypedRuleContexts(ExprParser.ExprContext) else: - return self.getTypedRuleContext(ExprParser.ExprContext, i) + return self.getTypedRuleContext(ExprParser.ExprContext,i) def COMPARISON(self): return self.getToken(ExprParser.COMPARISON, 0) - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitComparison"): + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitComparison" ): return visitor.visitComparison(self) else: return visitor.visitChildren(self) + class AllTimeSumContext(ExprContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.ExprContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) def expr(self): - return self.getTypedRuleContext(ExprParser.ExprContext, 0) + return self.getTypedRuleContext(ExprParser.ExprContext,0) + - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitAllTimeSum"): + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitAllTimeSum" ): return visitor.visitAllTimeSum(self) else: return visitor.visitChildren(self) + class TimeIndexExprContext(ExprContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.ExprContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) - def expr(self, i: int = None): + def expr(self, i:int=None): if i is None: return self.getTypedRuleContexts(ExprParser.ExprContext) else: - return self.getTypedRuleContext(ExprParser.ExprContext, i) + return self.getTypedRuleContext(ExprParser.ExprContext,i) + - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitTimeIndexExpr"): + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitTimeIndexExpr" ): return visitor.visitTimeIndexExpr(self) else: return visitor.visitChildren(self) + class AddsubContext(ExprContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.ExprContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext super().__init__(parser) - self.op = None # Token + self.op = None # Token self.copyFrom(ctx) - def expr(self, i: int = None): + def expr(self, i:int=None): if i is None: return self.getTypedRuleContexts(ExprParser.ExprContext) else: - return self.getTypedRuleContext(ExprParser.ExprContext, i) + return self.getTypedRuleContext(ExprParser.ExprContext,i) + - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitAddsub"): + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitAddsub" ): return visitor.visitAddsub(self) else: return visitor.visitChildren(self) + class TimeShiftExprContext(ExprContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.ExprContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) def expr(self): - return self.getTypedRuleContext(ExprParser.ExprContext, 0) + return self.getTypedRuleContext(ExprParser.ExprContext,0) def shift(self): - return self.getTypedRuleContext(ExprParser.ShiftContext, 0) + return self.getTypedRuleContext(ExprParser.ShiftContext,0) + - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitTimeShiftExpr"): + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitTimeShiftExpr" ): return visitor.visitTimeShiftExpr(self) else: return visitor.visitChildren(self) + class PortFieldContext(ExprContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.ExprContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) def portFieldExpr(self): - return self.getTypedRuleContext(ExprParser.PortFieldExprContext, 0) + return self.getTypedRuleContext(ExprParser.PortFieldExprContext,0) + - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitPortField"): + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitPortField" ): return visitor.visitPortField(self) else: return visitor.visitChildren(self) + class MuldivContext(ExprContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.ExprContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext super().__init__(parser) - self.op = None # Token + self.op = None # Token self.copyFrom(ctx) - def expr(self, i: int = None): + def expr(self, i:int=None): if i is None: return self.getTypedRuleContexts(ExprParser.ExprContext) else: - return self.getTypedRuleContext(ExprParser.ExprContext, i) + return self.getTypedRuleContext(ExprParser.ExprContext,i) - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitMuldiv"): + + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitMuldiv" ): return visitor.visitMuldiv(self) else: return visitor.visitChildren(self) + class TimeSumContext(ExprContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.ExprContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext super().__init__(parser) - self.from_ = None # ShiftContext - self.to = None # ShiftContext + self.from_ = None # ShiftContext + self.to = None # ShiftContext self.copyFrom(ctx) def expr(self): - return self.getTypedRuleContext(ExprParser.ExprContext, 0) + return self.getTypedRuleContext(ExprParser.ExprContext,0) - def shift(self, i: int = None): + def shift(self, i:int=None): if i is None: return self.getTypedRuleContexts(ExprParser.ShiftContext) else: - return self.getTypedRuleContext(ExprParser.ShiftContext, i) + return self.getTypedRuleContext(ExprParser.ShiftContext,i) - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitTimeSum"): + + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitTimeSum" ): return visitor.visitTimeSum(self) else: return visitor.visitChildren(self) + + class MaxExprContext(ExprContext): + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext + super().__init__(parser) + self.copyFrom(ctx) + + def MAX(self): + return self.getToken(ExprParser.MAX, 0) + def expr(self, i:int=None): + if i is None: + return self.getTypedRuleContexts(ExprParser.ExprContext) + else: + return self.getTypedRuleContext(ExprParser.ExprContext,i) + + + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitMaxExpr" ): + return visitor.visitMaxExpr(self) + else: + return visitor.visitChildren(self) + + class TimeIndexContext(ExprContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.ExprContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) def IDENTIFIER(self): return self.getToken(ExprParser.IDENTIFIER, 0) - def expr(self): - return self.getTypedRuleContext(ExprParser.ExprContext, 0) + return self.getTypedRuleContext(ExprParser.ExprContext,0) - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitTimeIndex"): + + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitTimeIndex" ): return visitor.visitTimeIndex(self) else: return visitor.visitChildren(self) + class TimeShiftContext(ExprContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.ExprContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) def IDENTIFIER(self): return self.getToken(ExprParser.IDENTIFIER, 0) - def shift(self): - return self.getTypedRuleContext(ExprParser.ShiftContext, 0) + return self.getTypedRuleContext(ExprParser.ShiftContext,0) + - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitTimeShift"): + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitTimeShift" ): return visitor.visitTimeShift(self) else: return visitor.visitChildren(self) + class FunctionContext(ExprContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.ExprContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) def IDENTIFIER(self): return self.getToken(ExprParser.IDENTIFIER, 0) - def expr(self): - return self.getTypedRuleContext(ExprParser.ExprContext, 0) + return self.getTypedRuleContext(ExprParser.ExprContext,0) - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitFunction"): + + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitFunction" ): return visitor.visitFunction(self) else: return visitor.visitChildren(self) - def expr(self, _p: int = 0): + + + def expr(self, _p:int=0): _parentctx = self._ctx _parentState = self.state localctx = ExprParser.ExprContext(self, self._ctx, _parentState) _prevctx = localctx _startState = 4 self.enterRecursionRule(localctx, 4, self.RULE_expr, _p) - self._la = 0 # Token type + self._la = 0 # Token type try: self.enterOuterAlt(localctx, 1) - self.state = 78 + self.state = 90 self._errHandler.sync(self) - la_ = self._interp.adaptivePredict(self._input, 0, self._ctx) + la_ = self._interp.adaptivePredict(self._input,1,self._ctx) if la_ == 1: localctx = ExprParser.UnsignedAtomContext(self, localctx) self._ctx = localctx @@ -1775,7 +579,7 @@ def expr(self, _p: int = 0): self.state = 24 self.match(ExprParser.T__1) self.state = 25 - self.expr(13) + self.expr(14) pass elif la_ == 4: @@ -1918,93 +722,100 @@ def expr(self, _p: int = 0): self.match(ExprParser.T__12) pass + elif la_ == 13: + localctx = ExprParser.MaxExprContext(self, localctx) + self._ctx = localctx + _prevctx = localctx + self.state = 78 + self.match(ExprParser.MAX) + self.state = 79 + self.match(ExprParser.T__2) + self.state = 80 + self.expr(0) + self.state = 85 + self._errHandler.sync(self) + _la = self._input.LA(1) + while _la==11: + self.state = 81 + self.match(ExprParser.T__10) + self.state = 82 + self.expr(0) + self.state = 87 + self._errHandler.sync(self) + _la = self._input.LA(1) + + self.state = 88 + self.match(ExprParser.T__3) + pass + + self._ctx.stop = self._input.LT(-1) - self.state = 91 + self.state = 103 self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input, 2, self._ctx) - while _alt != 2 and _alt != ATN.INVALID_ALT_NUMBER: - if _alt == 1: + _alt = self._interp.adaptivePredict(self._input,3,self._ctx) + while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER: + if _alt==1: if self._parseListeners is not None: self.triggerExitRuleEvent() _prevctx = localctx - self.state = 89 + self.state = 101 self._errHandler.sync(self) - la_ = self._interp.adaptivePredict(self._input, 1, self._ctx) + la_ = self._interp.adaptivePredict(self._input,2,self._ctx) if la_ == 1: - localctx = ExprParser.MuldivContext( - self, ExprParser.ExprContext(self, _parentctx, _parentState) - ) - self.pushNewRecursionContext( - localctx, _startState, self.RULE_expr - ) - self.state = 80 - if not self.precpred(self._ctx, 11): + localctx = ExprParser.MuldivContext(self, ExprParser.ExprContext(self, _parentctx, _parentState)) + self.pushNewRecursionContext(localctx, _startState, self.RULE_expr) + self.state = 92 + if not self.precpred(self._ctx, 12): from antlr4.error.Errors import FailedPredicateException - - raise FailedPredicateException( - self, "self.precpred(self._ctx, 11)" - ) - self.state = 81 + raise FailedPredicateException(self, "self.precpred(self._ctx, 12)") + self.state = 93 localctx.op = self._input.LT(1) _la = self._input.LA(1) - if not (_la == 5 or _la == 6): + if not(_la==5 or _la==6): localctx.op = self._errHandler.recoverInline(self) else: self._errHandler.reportMatch(self) self.consume() - self.state = 82 - self.expr(12) + self.state = 94 + self.expr(13) pass elif la_ == 2: - localctx = ExprParser.AddsubContext( - self, ExprParser.ExprContext(self, _parentctx, _parentState) - ) - self.pushNewRecursionContext( - localctx, _startState, self.RULE_expr - ) - self.state = 83 - if not self.precpred(self._ctx, 10): + localctx = ExprParser.AddsubContext(self, ExprParser.ExprContext(self, _parentctx, _parentState)) + self.pushNewRecursionContext(localctx, _startState, self.RULE_expr) + self.state = 95 + if not self.precpred(self._ctx, 11): from antlr4.error.Errors import FailedPredicateException - - raise FailedPredicateException( - self, "self.precpred(self._ctx, 10)" - ) - self.state = 84 + raise FailedPredicateException(self, "self.precpred(self._ctx, 11)") + self.state = 96 localctx.op = self._input.LT(1) _la = self._input.LA(1) - if not (_la == 2 or _la == 7): + if not(_la==2 or _la==7): localctx.op = self._errHandler.recoverInline(self) else: self._errHandler.reportMatch(self) self.consume() - self.state = 85 - self.expr(11) + self.state = 97 + self.expr(12) pass elif la_ == 3: - localctx = ExprParser.ComparisonContext( - self, ExprParser.ExprContext(self, _parentctx, _parentState) - ) - self.pushNewRecursionContext( - localctx, _startState, self.RULE_expr - ) - self.state = 86 - if not self.precpred(self._ctx, 9): + localctx = ExprParser.ComparisonContext(self, ExprParser.ExprContext(self, _parentctx, _parentState)) + self.pushNewRecursionContext(localctx, _startState, self.RULE_expr) + self.state = 98 + if not self.precpred(self._ctx, 10): from antlr4.error.Errors import FailedPredicateException - - raise FailedPredicateException( - self, "self.precpred(self._ctx, 9)" - ) - self.state = 87 + raise FailedPredicateException(self, "self.precpred(self._ctx, 10)") + self.state = 99 self.match(ExprParser.COMPARISON) - self.state = 88 - self.expr(10) + self.state = 100 + self.expr(11) pass - self.state = 93 + + self.state = 105 self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input, 2, self._ctx) + _alt = self._interp.adaptivePredict(self._input,3,self._ctx) except RecognitionException as re: localctx.exception = re @@ -2014,70 +825,75 @@ def expr(self, _p: int = 0): self.unrollRecursionContexts(_parentctx) return localctx + class AtomContext(ParserRuleContext): - __slots__ = "parser" + __slots__ = 'parser' - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): + def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): super().__init__(parent, invokingState) self.parser = parser + def getRuleIndex(self): return ExprParser.RULE_atom - def copyFrom(self, ctx: ParserRuleContext): + + def copyFrom(self, ctx:ParserRuleContext): super().copyFrom(ctx) + + class NumberContext(AtomContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.AtomContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.AtomContext super().__init__(parser) self.copyFrom(ctx) def NUMBER(self): return self.getToken(ExprParser.NUMBER, 0) - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitNumber"): + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitNumber" ): return visitor.visitNumber(self) else: return visitor.visitChildren(self) + class IdentifierContext(AtomContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.AtomContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.AtomContext super().__init__(parser) self.copyFrom(ctx) def IDENTIFIER(self): return self.getToken(ExprParser.IDENTIFIER, 0) - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitIdentifier"): + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitIdentifier" ): return visitor.visitIdentifier(self) else: return visitor.visitChildren(self) + + def atom(self): + localctx = ExprParser.AtomContext(self, self._ctx, self.state) self.enterRule(localctx, 6, self.RULE_atom) try: - self.state = 96 + self.state = 108 self._errHandler.sync(self) token = self._input.LA(1) if token in [14]: localctx = ExprParser.NumberContext(self, localctx) self.enterOuterAlt(localctx, 1) - self.state = 94 + self.state = 106 self.match(ExprParser.NUMBER) pass - elif token in [16]: + elif token in [17]: localctx = ExprParser.IdentifierContext(self, localctx) self.enterOuterAlt(localctx, 2) - self.state = 95 + self.state = 107 self.match(ExprParser.IDENTIFIER) pass else: @@ -2091,12 +907,11 @@ def atom(self): self.exitRule() return localctx + class ShiftContext(ParserRuleContext): - __slots__ = "parser" + __slots__ = 'parser' - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): + def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): super().__init__(parent, invokingState) self.parser = parser @@ -2104,32 +919,38 @@ def TIME(self): return self.getToken(ExprParser.TIME, 0) def shift_expr(self): - return self.getTypedRuleContext(ExprParser.Shift_exprContext, 0) + return self.getTypedRuleContext(ExprParser.Shift_exprContext,0) + def getRuleIndex(self): return ExprParser.RULE_shift - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitShift"): + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitShift" ): return visitor.visitShift(self) else: return visitor.visitChildren(self) + + + def shift(self): + localctx = ExprParser.ShiftContext(self, self._ctx, self.state) self.enterRule(localctx, 8, self.RULE_shift) - self._la = 0 # Token type + self._la = 0 # Token type try: self.enterOuterAlt(localctx, 1) - self.state = 98 + self.state = 110 self.match(ExprParser.TIME) - self.state = 100 + self.state = 112 self._errHandler.sync(self) _la = self._input.LA(1) - if _la == 2 or _la == 7: - self.state = 99 + if _la==2 or _la==7: + self.state = 111 self.shift_expr(0) + except RecognitionException as re: localctx.exception = re self._errHandler.reportError(self, re) @@ -2138,122 +959,129 @@ def shift(self): self.exitRule() return localctx + class Shift_exprContext(ParserRuleContext): - __slots__ = "parser" + __slots__ = 'parser' - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): + def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): super().__init__(parent, invokingState) self.parser = parser + def getRuleIndex(self): return ExprParser.RULE_shift_expr - def copyFrom(self, ctx: ParserRuleContext): + + def copyFrom(self, ctx:ParserRuleContext): super().copyFrom(ctx) + class SignedAtomContext(Shift_exprContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.Shift_exprContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.Shift_exprContext super().__init__(parser) - self.op = None # Token + self.op = None # Token self.copyFrom(ctx) def atom(self): - return self.getTypedRuleContext(ExprParser.AtomContext, 0) + return self.getTypedRuleContext(ExprParser.AtomContext,0) - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitSignedAtom"): + + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitSignedAtom" ): return visitor.visitSignedAtom(self) else: return visitor.visitChildren(self) + class SignedExpressionContext(Shift_exprContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.Shift_exprContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.Shift_exprContext super().__init__(parser) - self.op = None # Token + self.op = None # Token self.copyFrom(ctx) def expr(self): - return self.getTypedRuleContext(ExprParser.ExprContext, 0) + return self.getTypedRuleContext(ExprParser.ExprContext,0) - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitSignedExpression"): + + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitSignedExpression" ): return visitor.visitSignedExpression(self) else: return visitor.visitChildren(self) + class ShiftMuldivContext(Shift_exprContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.Shift_exprContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.Shift_exprContext super().__init__(parser) - self.op = None # Token + self.op = None # Token self.copyFrom(ctx) def shift_expr(self): - return self.getTypedRuleContext(ExprParser.Shift_exprContext, 0) + return self.getTypedRuleContext(ExprParser.Shift_exprContext,0) def right_expr(self): - return self.getTypedRuleContext(ExprParser.Right_exprContext, 0) + return self.getTypedRuleContext(ExprParser.Right_exprContext,0) - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitShiftMuldiv"): + + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitShiftMuldiv" ): return visitor.visitShiftMuldiv(self) else: return visitor.visitChildren(self) + class ShiftAddsubContext(Shift_exprContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.Shift_exprContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.Shift_exprContext super().__init__(parser) - self.op = None # Token + self.op = None # Token self.copyFrom(ctx) def shift_expr(self): - return self.getTypedRuleContext(ExprParser.Shift_exprContext, 0) + return self.getTypedRuleContext(ExprParser.Shift_exprContext,0) def right_expr(self): - return self.getTypedRuleContext(ExprParser.Right_exprContext, 0) + return self.getTypedRuleContext(ExprParser.Right_exprContext,0) + - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitShiftAddsub"): + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitShiftAddsub" ): return visitor.visitShiftAddsub(self) else: return visitor.visitChildren(self) - def shift_expr(self, _p: int = 0): + + + def shift_expr(self, _p:int=0): _parentctx = self._ctx _parentState = self.state localctx = ExprParser.Shift_exprContext(self, self._ctx, _parentState) _prevctx = localctx _startState = 10 self.enterRecursionRule(localctx, 10, self.RULE_shift_expr, _p) - self._la = 0 # Token type + self._la = 0 # Token type try: self.enterOuterAlt(localctx, 1) - self.state = 110 + self.state = 122 self._errHandler.sync(self) - la_ = self._interp.adaptivePredict(self._input, 5, self._ctx) + la_ = self._interp.adaptivePredict(self._input,6,self._ctx) if la_ == 1: localctx = ExprParser.SignedAtomContext(self, localctx) self._ctx = localctx _prevctx = localctx - self.state = 103 + self.state = 115 localctx.op = self._input.LT(1) _la = self._input.LA(1) - if not (_la == 2 or _la == 7): + if not(_la==2 or _la==7): localctx.op = self._errHandler.recoverInline(self) else: self._errHandler.reportMatch(self) self.consume() - self.state = 104 + self.state = 116 self.atom() pass @@ -2261,95 +1089,77 @@ def shift_expr(self, _p: int = 0): localctx = ExprParser.SignedExpressionContext(self, localctx) self._ctx = localctx _prevctx = localctx - self.state = 105 + self.state = 117 localctx.op = self._input.LT(1) _la = self._input.LA(1) - if not (_la == 2 or _la == 7): + if not(_la==2 or _la==7): localctx.op = self._errHandler.recoverInline(self) else: self._errHandler.reportMatch(self) self.consume() - self.state = 106 + self.state = 118 self.match(ExprParser.T__2) - self.state = 107 + self.state = 119 self.expr(0) - self.state = 108 + self.state = 120 self.match(ExprParser.T__3) pass + self._ctx.stop = self._input.LT(-1) - self.state = 120 + self.state = 132 self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input, 7, self._ctx) - while _alt != 2 and _alt != ATN.INVALID_ALT_NUMBER: - if _alt == 1: + _alt = self._interp.adaptivePredict(self._input,8,self._ctx) + while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER: + if _alt==1: if self._parseListeners is not None: self.triggerExitRuleEvent() _prevctx = localctx - self.state = 118 + self.state = 130 self._errHandler.sync(self) - la_ = self._interp.adaptivePredict(self._input, 6, self._ctx) + la_ = self._interp.adaptivePredict(self._input,7,self._ctx) if la_ == 1: - localctx = ExprParser.ShiftMuldivContext( - self, - ExprParser.Shift_exprContext( - self, _parentctx, _parentState - ), - ) - self.pushNewRecursionContext( - localctx, _startState, self.RULE_shift_expr - ) - self.state = 112 + localctx = ExprParser.ShiftMuldivContext(self, ExprParser.Shift_exprContext(self, _parentctx, _parentState)) + self.pushNewRecursionContext(localctx, _startState, self.RULE_shift_expr) + self.state = 124 if not self.precpred(self._ctx, 4): from antlr4.error.Errors import FailedPredicateException - - raise FailedPredicateException( - self, "self.precpred(self._ctx, 4)" - ) - self.state = 113 + raise FailedPredicateException(self, "self.precpred(self._ctx, 4)") + self.state = 125 localctx.op = self._input.LT(1) _la = self._input.LA(1) - if not (_la == 5 or _la == 6): + if not(_la==5 or _la==6): localctx.op = self._errHandler.recoverInline(self) else: self._errHandler.reportMatch(self) self.consume() - self.state = 114 + self.state = 126 self.right_expr(0) pass elif la_ == 2: - localctx = ExprParser.ShiftAddsubContext( - self, - ExprParser.Shift_exprContext( - self, _parentctx, _parentState - ), - ) - self.pushNewRecursionContext( - localctx, _startState, self.RULE_shift_expr - ) - self.state = 115 + localctx = ExprParser.ShiftAddsubContext(self, ExprParser.Shift_exprContext(self, _parentctx, _parentState)) + self.pushNewRecursionContext(localctx, _startState, self.RULE_shift_expr) + self.state = 127 if not self.precpred(self._ctx, 3): from antlr4.error.Errors import FailedPredicateException - - raise FailedPredicateException( - self, "self.precpred(self._ctx, 3)" - ) - self.state = 116 + raise FailedPredicateException(self, "self.precpred(self._ctx, 3)") + self.state = 128 localctx.op = self._input.LT(1) _la = self._input.LA(1) - if not (_la == 2 or _la == 7): + if not(_la==2 or _la==7): localctx.op = self._errHandler.recoverInline(self) else: self._errHandler.reportMatch(self) self.consume() - self.state = 117 + self.state = 129 self.right_expr(0) pass - self.state = 122 + + self.state = 134 self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input, 7, self._ctx) + _alt = self._interp.adaptivePredict(self._input,8,self._ctx) except RecognitionException as re: localctx.exception = re @@ -2359,84 +1169,90 @@ def shift_expr(self, _p: int = 0): self.unrollRecursionContexts(_parentctx) return localctx + class Right_exprContext(ParserRuleContext): - __slots__ = "parser" + __slots__ = 'parser' - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): + def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): super().__init__(parent, invokingState) self.parser = parser + def getRuleIndex(self): return ExprParser.RULE_right_expr - def copyFrom(self, ctx: ParserRuleContext): + + def copyFrom(self, ctx:ParserRuleContext): super().copyFrom(ctx) + class RightExpressionContext(Right_exprContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.Right_exprContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.Right_exprContext super().__init__(parser) self.copyFrom(ctx) def expr(self): - return self.getTypedRuleContext(ExprParser.ExprContext, 0) + return self.getTypedRuleContext(ExprParser.ExprContext,0) + - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitRightExpression"): + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitRightExpression" ): return visitor.visitRightExpression(self) else: return visitor.visitChildren(self) + class RightMuldivContext(Right_exprContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.Right_exprContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.Right_exprContext super().__init__(parser) - self.op = None # Token + self.op = None # Token self.copyFrom(ctx) - def right_expr(self, i: int = None): + def right_expr(self, i:int=None): if i is None: return self.getTypedRuleContexts(ExprParser.Right_exprContext) else: - return self.getTypedRuleContext(ExprParser.Right_exprContext, i) + return self.getTypedRuleContext(ExprParser.Right_exprContext,i) + - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitRightMuldiv"): + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitRightMuldiv" ): return visitor.visitRightMuldiv(self) else: return visitor.visitChildren(self) + class RightAtomContext(Right_exprContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.Right_exprContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.Right_exprContext super().__init__(parser) self.copyFrom(ctx) def atom(self): - return self.getTypedRuleContext(ExprParser.AtomContext, 0) + return self.getTypedRuleContext(ExprParser.AtomContext,0) + - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitRightAtom"): + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitRightAtom" ): return visitor.visitRightAtom(self) else: return visitor.visitChildren(self) - def right_expr(self, _p: int = 0): + + + def right_expr(self, _p:int=0): _parentctx = self._ctx _parentState = self.state localctx = ExprParser.Right_exprContext(self, self._ctx, _parentState) _prevctx = localctx _startState = 12 self.enterRecursionRule(localctx, 12, self.RULE_right_expr, _p) - self._la = 0 # Token type + self._la = 0 # Token type try: self.enterOuterAlt(localctx, 1) - self.state = 129 + self.state = 141 self._errHandler.sync(self) token = self._input.LA(1) if token in [3]: @@ -2444,59 +1260,51 @@ def right_expr(self, _p: int = 0): self._ctx = localctx _prevctx = localctx - self.state = 124 + self.state = 136 self.match(ExprParser.T__2) - self.state = 125 + self.state = 137 self.expr(0) - self.state = 126 + self.state = 138 self.match(ExprParser.T__3) pass - elif token in [14, 16]: + elif token in [14, 17]: localctx = ExprParser.RightAtomContext(self, localctx) self._ctx = localctx _prevctx = localctx - self.state = 128 + self.state = 140 self.atom() pass else: raise NoViableAltException(self) self._ctx.stop = self._input.LT(-1) - self.state = 136 + self.state = 148 self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input, 9, self._ctx) - while _alt != 2 and _alt != ATN.INVALID_ALT_NUMBER: - if _alt == 1: + _alt = self._interp.adaptivePredict(self._input,10,self._ctx) + while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER: + if _alt==1: if self._parseListeners is not None: self.triggerExitRuleEvent() _prevctx = localctx - localctx = ExprParser.RightMuldivContext( - self, - ExprParser.Right_exprContext(self, _parentctx, _parentState), - ) - self.pushNewRecursionContext( - localctx, _startState, self.RULE_right_expr - ) - self.state = 131 + localctx = ExprParser.RightMuldivContext(self, ExprParser.Right_exprContext(self, _parentctx, _parentState)) + self.pushNewRecursionContext(localctx, _startState, self.RULE_right_expr) + self.state = 143 if not self.precpred(self._ctx, 3): from antlr4.error.Errors import FailedPredicateException - - raise FailedPredicateException( - self, "self.precpred(self._ctx, 3)" - ) - self.state = 132 + raise FailedPredicateException(self, "self.precpred(self._ctx, 3)") + self.state = 144 localctx.op = self._input.LT(1) _la = self._input.LA(1) - if not (_la == 5 or _la == 6): + if not(_la==5 or _la==6): localctx.op = self._errHandler.recoverInline(self) else: self._errHandler.reportMatch(self) self.consume() - self.state = 133 - self.right_expr(4) - self.state = 138 + self.state = 145 + self.right_expr(4) + self.state = 150 self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input, 9, self._ctx) + _alt = self._interp.adaptivePredict(self._input,10,self._ctx) except RecognitionException as re: localctx.exception = re @@ -2506,7 +1314,9 @@ def right_expr(self, _p: int = 0): self.unrollRecursionContexts(_parentctx) return localctx - def sempred(self, localctx: RuleContext, ruleIndex: int, predIndex: int): + + + def sempred(self, localctx:RuleContext, ruleIndex:int, predIndex:int): if self._predicates == None: self._predicates = dict() self._predicates[2] = self.expr_sempred @@ -2518,23 +1328,33 @@ def sempred(self, localctx: RuleContext, ruleIndex: int, predIndex: int): else: return pred(localctx, predIndex) - def expr_sempred(self, localctx: ExprContext, predIndex: int): - if predIndex == 0: - return self.precpred(self._ctx, 11) + def expr_sempred(self, localctx:ExprContext, predIndex:int): + if predIndex == 0: + return self.precpred(self._ctx, 12) + + + if predIndex == 1: + return self.precpred(self._ctx, 11) + + + if predIndex == 2: + return self.precpred(self._ctx, 10) + + + def shift_expr_sempred(self, localctx:Shift_exprContext, predIndex:int): + if predIndex == 3: + return self.precpred(self._ctx, 4) + + + if predIndex == 4: + return self.precpred(self._ctx, 3) + - if predIndex == 1: - return self.precpred(self._ctx, 10) + def right_expr_sempred(self, localctx:Right_exprContext, predIndex:int): + if predIndex == 5: + return self.precpred(self._ctx, 3) + - if predIndex == 2: - return self.precpred(self._ctx, 9) - def shift_expr_sempred(self, localctx: Shift_exprContext, predIndex: int): - if predIndex == 3: - return self.precpred(self._ctx, 4) - if predIndex == 4: - return self.precpred(self._ctx, 3) - def right_expr_sempred(self, localctx: Right_exprContext, predIndex: int): - if predIndex == 5: - return self.precpred(self._ctx, 3) diff --git a/src/gems/expression/parsing/antlr/ExprVisitor.py b/src/gems/expression/parsing/antlr/ExprVisitor.py index a98fbbaf..7e9dfe69 100644 --- a/src/gems/expression/parsing/antlr/ExprVisitor.py +++ b/src/gems/expression/parsing/antlr/ExprVisitor.py @@ -1,6 +1,5 @@ # Generated from Expr.g4 by ANTLR 4.13.2 from antlr4 import * - if "." in __name__: from .ExprParser import ExprParser else: @@ -8,115 +7,147 @@ # This class defines a complete generic visitor for a parse tree produced by ExprParser. - class ExprVisitor(ParseTreeVisitor): + # Visit a parse tree produced by ExprParser#portFieldExpr. - def visitPortFieldExpr(self, ctx: ExprParser.PortFieldExprContext): + def visitPortFieldExpr(self, ctx:ExprParser.PortFieldExprContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#fullexpr. - def visitFullexpr(self, ctx: ExprParser.FullexprContext): + def visitFullexpr(self, ctx:ExprParser.FullexprContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#portFieldSum. - def visitPortFieldSum(self, ctx: ExprParser.PortFieldSumContext): + def visitPortFieldSum(self, ctx:ExprParser.PortFieldSumContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#negation. - def visitNegation(self, ctx: ExprParser.NegationContext): + def visitNegation(self, ctx:ExprParser.NegationContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#unsignedAtom. - def visitUnsignedAtom(self, ctx: ExprParser.UnsignedAtomContext): + def visitUnsignedAtom(self, ctx:ExprParser.UnsignedAtomContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#expression. - def visitExpression(self, ctx: ExprParser.ExpressionContext): + def visitExpression(self, ctx:ExprParser.ExpressionContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#comparison. - def visitComparison(self, ctx: ExprParser.ComparisonContext): + def visitComparison(self, ctx:ExprParser.ComparisonContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#allTimeSum. - def visitAllTimeSum(self, ctx: ExprParser.AllTimeSumContext): + def visitAllTimeSum(self, ctx:ExprParser.AllTimeSumContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#timeIndexExpr. - def visitTimeIndexExpr(self, ctx: ExprParser.TimeIndexExprContext): + def visitTimeIndexExpr(self, ctx:ExprParser.TimeIndexExprContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#addsub. - def visitAddsub(self, ctx: ExprParser.AddsubContext): + def visitAddsub(self, ctx:ExprParser.AddsubContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#timeShiftExpr. - def visitTimeShiftExpr(self, ctx: ExprParser.TimeShiftExprContext): + def visitTimeShiftExpr(self, ctx:ExprParser.TimeShiftExprContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#portField. - def visitPortField(self, ctx: ExprParser.PortFieldContext): + def visitPortField(self, ctx:ExprParser.PortFieldContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#muldiv. - def visitMuldiv(self, ctx: ExprParser.MuldivContext): + def visitMuldiv(self, ctx:ExprParser.MuldivContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#timeSum. - def visitTimeSum(self, ctx: ExprParser.TimeSumContext): + def visitTimeSum(self, ctx:ExprParser.TimeSumContext): return self.visitChildren(ctx) + + # Visit a parse tree produced by ExprParser#maxExpr. + def visitMaxExpr(self, ctx:ExprParser.MaxExprContext): + return self.visitChildren(ctx) + + # Visit a parse tree produced by ExprParser#timeIndex. - def visitTimeIndex(self, ctx: ExprParser.TimeIndexContext): + def visitTimeIndex(self, ctx:ExprParser.TimeIndexContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#timeShift. - def visitTimeShift(self, ctx: ExprParser.TimeShiftContext): + def visitTimeShift(self, ctx:ExprParser.TimeShiftContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#function. - def visitFunction(self, ctx: ExprParser.FunctionContext): + def visitFunction(self, ctx:ExprParser.FunctionContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#number. - def visitNumber(self, ctx: ExprParser.NumberContext): + def visitNumber(self, ctx:ExprParser.NumberContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#identifier. - def visitIdentifier(self, ctx: ExprParser.IdentifierContext): + def visitIdentifier(self, ctx:ExprParser.IdentifierContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#shift. - def visitShift(self, ctx: ExprParser.ShiftContext): + def visitShift(self, ctx:ExprParser.ShiftContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#signedAtom. - def visitSignedAtom(self, ctx: ExprParser.SignedAtomContext): + def visitSignedAtom(self, ctx:ExprParser.SignedAtomContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#signedExpression. - def visitSignedExpression(self, ctx: ExprParser.SignedExpressionContext): + def visitSignedExpression(self, ctx:ExprParser.SignedExpressionContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#shiftMuldiv. - def visitShiftMuldiv(self, ctx: ExprParser.ShiftMuldivContext): + def visitShiftMuldiv(self, ctx:ExprParser.ShiftMuldivContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#shiftAddsub. - def visitShiftAddsub(self, ctx: ExprParser.ShiftAddsubContext): + def visitShiftAddsub(self, ctx:ExprParser.ShiftAddsubContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#rightExpression. - def visitRightExpression(self, ctx: ExprParser.RightExpressionContext): + def visitRightExpression(self, ctx:ExprParser.RightExpressionContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#rightMuldiv. - def visitRightMuldiv(self, ctx: ExprParser.RightMuldivContext): + def visitRightMuldiv(self, ctx:ExprParser.RightMuldivContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#rightAtom. - def visitRightAtom(self, ctx: ExprParser.RightAtomContext): + def visitRightAtom(self, ctx:ExprParser.RightAtomContext): return self.visitChildren(ctx) -del ExprParser + +del ExprParser \ No newline at end of file diff --git a/src/gems/expression/parsing/parse_expression.py b/src/gems/expression/parsing/parse_expression.py index a0bc80e6..419e8153 100644 --- a/src/gems/expression/parsing/parse_expression.py +++ b/src/gems/expression/parsing/parse_expression.py @@ -22,6 +22,7 @@ ComparisonNode, PortFieldAggregatorNode, PortFieldNode, + MaxNode ) from gems.expression.parsing.antlr.ExprLexer import ExprLexer from gems.expression.parsing.antlr.ExprParser import ExprParser @@ -232,6 +233,9 @@ def visitRightMuldiv(self, ctx: ExprParser.RightMuldivContext) -> ExpressionNode def visitRightAtom(self, ctx: ExprParser.RightAtomContext) -> ExpressionNode: return ctx.atom().accept(self) # type: ignore + def visitMaxExpr(self, ctx: ExprParser.MaxExprContext) -> ExpressionNode: + operands: list[ExpressionNode] = [expr.accept(self) for expr in ctx.expr()] + return MaxNode(operands=operands) _FUNCTIONS = { "expec": ExpressionNode.expec, diff --git a/src/gems/expression/print.py b/src/gems/expression/print.py index 50308d87..9586f8dd 100644 --- a/src/gems/expression/print.py +++ b/src/gems/expression/print.py @@ -25,6 +25,7 @@ TimeEvalNode, TimeShiftNode, TimeSumNode, + MaxNode ) from .expression import ( @@ -129,7 +130,10 @@ def port_field(self, node: PortFieldNode) -> str: def port_field_aggregator(self, node: PortFieldAggregatorNode) -> str: return f"({visit(node.operand, self)}.{node.aggregator})" - + + def max_node(self, node: MaxNode) -> str: + operand_strings = [visit(op, self) for op in node.operands] + return f"max({', '.join(operand_strings)})" def print_expr(expression: ExpressionNode) -> str: return visit(expression, PrinterVisitor()) diff --git a/src/gems/expression/visitor.py b/src/gems/expression/visitor.py index 7180b6ab..23ab59b4 100644 --- a/src/gems/expression/visitor.py +++ b/src/gems/expression/visitor.py @@ -38,6 +38,7 @@ TimeShiftNode, TimeSumNode, VariableNode, + MaxNode ) T = TypeVar("T") @@ -127,6 +128,10 @@ def port_field(self, node: PortFieldNode) -> T: @abstractmethod def port_field_aggregator(self, node: PortFieldAggregatorNode) -> T: ... + + @abstractmethod + def max_node(self, node: MaxNode) -> T: + ... def visit(root: ExpressionNode, visitor: ExpressionVisitor[T]) -> T: @@ -171,6 +176,8 @@ def visit(root: ExpressionNode, visitor: ExpressionVisitor[T]) -> T: return visitor.port_field(root) elif isinstance(root, PortFieldAggregatorNode): return visitor.port_field_aggregator(root) + elif isinstance(root, MaxNode): + return visitor.max_node(root) raise ValueError(f"Unknown expression node type {root.__class__}") @@ -199,6 +206,9 @@ def __mul__(self, other: T) -> T: def __truediv__(self, other: T) -> T: pass + @abstractmethod + def __max__(self, other: T) -> T: + pass T_op = TypeVar("T_op", bound=SupportsOperations) @@ -228,3 +238,6 @@ def division(self, node: DivisionNode) -> T_op: left_value = visit(node.left, self) right_value = visit(node.right, self) return left_value / right_value + + def max_node(self, node) -> ExpressionNode: + return MaxNode(operands=[visit(op, self) for op in node.operands]) \ No newline at end of file diff --git a/src/gems/model/max.py b/src/gems/model/max.py new file mode 100644 index 00000000..ef882ba9 --- /dev/null +++ b/src/gems/model/max.py @@ -0,0 +1,80 @@ +from typing import Any +from gems.expression import ExpressionVisitor, visit +from gems.expression import LiteralNode, VariableNode, ParameterNode, MaxNode, TimeShiftNode +from gems.expression.visitor import visit + +class _MaxExpressionChecker(ExpressionVisitor[None]): + """ + Visits the whole expression to check there is no: + comparison, other port field, component-associated parametrs or variables... + """ + def literal(self, node: LiteralNode) -> None: + pass # Les littéraux sont constants + + def parameter(self, node: ParameterNode) -> None: + pass # Les paramètres sont constants + + def variable(self, node: VariableNode) -> None: + raise ValueError("MaxNode cannot contain a variable.") + + def max_node(self, node: MaxNode) -> None: + if len(node.operands) < 2: + raise ValueError("MaxNode requires at least two operands") + for operand in node.operands: + visit(operand, self) + + def time_shift(self, node: Any) -> None: + raise ValueError("MaxNode cannot contain a time shift operation.") + + def addition(self, node: Any) -> None: + raise ValueError("MaxNode cannot contain an addition operation.") + + def comparison(self, node: Any) -> None: + raise ValueError("MaxNode cannot contain a comparison operator.") + + def all_time_sum(self, node: Any) -> None: + raise ValueError("MaxNode cannot contain an all-time sum operation.") + + def comp_parameter(self, node: Any) -> None: + raise ValueError("MaxNode cannot contain a component parameter.") + + def comp_variable(self, node: Any) -> None: + raise ValueError("MaxNode cannot contain a component variable.") + + def division(self, node: Any) -> None: + raise ValueError("MaxNode cannot contain a division operation.") + + def multiplication(self, node: Any) -> None: + raise ValueError("MaxNode cannot contain a multiplication operation.") + + def negation(self, node: Any) -> None: + raise ValueError("MaxNode cannot contain a negation operation.") + + def pb_parameter(self, node: Any) -> None: + raise ValueError("MaxNode cannot contain a problem parameter.") + + def pb_variable(self, node: Any) -> None: + raise ValueError("MaxNode cannot contain a problem variable.") + + def port_field(self, node: Any) -> None: + raise ValueError("MaxNode cannot reference a port field.") + + def port_field_aggregator(self, node: Any) -> None: + raise ValueError("MaxNode cannot contain port field aggregation.") + + def scenario_operator(self, node: Any) -> None: + raise ValueError("MaxNode cannot contain a scenario operator.") + + def time_eval(self, node: Any) -> None: + raise ValueError("MaxNode cannot contain a time evaluation operation.") + + def time_sum(self, node: Any) -> None: + raise ValueError("MaxNode cannot contain a time sum operation.") + +def _validate_max_expression(node: MaxNode) -> None: + """ + Valide l'expression d'un MaxNode en visitant ses opérandes avec _MaxExpressionChecker. + """ + checker = _MaxExpressionChecker() + for operand in node.operands: + visit(operand, checker) \ No newline at end of file diff --git a/src/gems/model/port.py b/src/gems/model/port.py index cb07319b..a52c38f6 100644 --- a/src/gems/model/port.py +++ b/src/gems/model/port.py @@ -38,6 +38,7 @@ TimeEvalNode, TimeShiftNode, TimeSumNode, + MaxNode, ) from gems.expression.visitor import visit @@ -167,7 +168,9 @@ def port_field(self, node: PortFieldNode) -> None: def port_field_aggregator(self, node: PortFieldAggregatorNode) -> None: raise ValueError("Port definition cannot contain port field aggregation.") - + + def max_node(self, node: MaxNode) -> None: + raise ValueError("Port definition must not contain a max expression.") def _validate_port_field_expression(definition: PortFieldDefinition) -> None: - visit(definition.definition, _PortFieldExpressionChecker()) + visit(definition.definition, _PortFieldExpressionChecker()) \ No newline at end of file diff --git a/src/gems/simulation/linearize.py b/src/gems/simulation/linearize.py index 7e8dbf15..6108ed0b 100644 --- a/src/gems/simulation/linearize.py +++ b/src/gems/simulation/linearize.py @@ -46,6 +46,7 @@ TimeStep, TimeSumNode, VariableNode, + MaxNode, ) from gems.expression.visitor import visit from gems.simulation.linear_expression import LinearExpression, Term, TermKey @@ -280,7 +281,9 @@ def port_field_aggregator( raise ValueError( "Port fields aggregators must be replaced before linearization." ) - + + def max_node(self, node: MaxNode) -> LinearExpressionData: + raise ValueError("MaxNode is not supported in linear expressions, as it needs constants.") def linearize_expression( expression: ExpressionNode, From e6141a9c18387e77195c438e65af51c13c1e9995 Mon Sep 17 00:00:00 2001 From: killian-scalian Date: Wed, 30 Jul 2025 17:52:22 +0200 Subject: [PATCH 02/15] Implement second draft --- src/gems/expression/__init__.py | 1 + src/gems/expression/degree.py | 5 +- src/gems/expression/equality.py | 1 + src/gems/expression/evaluate.py | 4 +- src/gems/expression/expression.py | 66 +++++++++++++++++-------- src/gems/model/max.py | 80 ------------------------------- src/gems/simulation/linearize.py | 7 ++- 7 files changed, 60 insertions(+), 104 deletions(-) delete mode 100644 src/gems/model/max.py diff --git a/src/gems/expression/__init__.py b/src/gems/expression/__init__.py index 500a58a6..d2166af1 100644 --- a/src/gems/expression/__init__.py +++ b/src/gems/expression/__init__.py @@ -31,6 +31,7 @@ VariableNode, MaxNode, TimeShiftNode, + max_expr, literal, param, sum_expressions, diff --git a/src/gems/expression/degree.py b/src/gems/expression/degree.py index 0165c885..86220f4e 100644 --- a/src/gems/expression/degree.py +++ b/src/gems/expression/degree.py @@ -53,8 +53,7 @@ def negation(self, node: NegationNode) -> int: # TODO: Take into account simplification that can occur with literal coefficient for add, sub, mult, div def addition(self, node: AdditionNode) -> int: - degrees = [visit(o, self) for o in node.operands] - return max(degrees) + return max([visit(o, self) for o in node.operands]) def multiplication(self, node: MultiplicationNode) -> int: return visit(node.left, self) + visit(node.right, self) @@ -112,7 +111,7 @@ def port_field_aggregator(self, node: PortFieldAggregatorNode) -> int: return visit(node.operand, self) def max_node(self, node: MaxNode) -> int: - return 0 # always constant if operands are constants + return max([visit(o, self) for o in node.operands]) def compute_degree(expression: ExpressionNode) -> int: return visit(expression, ExpressionDegreeVisitor()) diff --git a/src/gems/expression/equality.py b/src/gems/expression/equality.py index 4268a730..68ba38d8 100644 --- a/src/gems/expression/equality.py +++ b/src/gems/expression/equality.py @@ -139,6 +139,7 @@ def addition(self, left: AdditionNode, right: AdditionNode) -> bool: def max_node(self, left: MaxNode, right: MaxNode) -> bool: if len(left.operands) != len(right.operands): return False + print("yoooo", left.operands, right.operands, all(self.visit(l_op, r_op) for l_op, r_op in zip(left.operands, right.operands))) return all(self.visit(l_op, r_op) for l_op, r_op in zip(left.operands, right.operands)) def multiplication( diff --git a/src/gems/expression/evaluate.py b/src/gems/expression/evaluate.py index e98828af..ddc48b62 100644 --- a/src/gems/expression/evaluate.py +++ b/src/gems/expression/evaluate.py @@ -139,7 +139,9 @@ def port_field(self, node: PortFieldNode) -> float: def port_field_aggregator(self, node: PortFieldAggregatorNode) -> float: raise NotImplementedError() - + + def max_node(self, node: MaxNode) -> float: + return max(visit(op, self) for op in node.operands) def evaluate(expression: ExpressionNode, value_provider: ValueProvider) -> float: return visit(expression, EvaluationVisitor(value_provider)) diff --git a/src/gems/expression/expression.py b/src/gems/expression/expression.py index 12af35b2..5f25d23a 100644 --- a/src/gems/expression/expression.py +++ b/src/gems/expression/expression.py @@ -64,13 +64,6 @@ def __rsub__(self, lhs: Any) -> "ExpressionNode": lhs = _wrap_in_node(lhs) return lhs + self - def max(self, rhs: Any) -> "ExpressionNode": - lhs = self - operands = [] - operands.extend(lhs.operands if isinstance(lhs, MaxNode) else [_wrap_in_node(lhs)]) - operands.extend(rhs.operands if isinstance(rhs, MaxNode) else [_wrap_in_node(rhs)]) - return MaxNode(operands) - def __mul__(self, rhs: Any) -> "ExpressionNode": return _apply_if_node(rhs, lambda x: MultiplicationNode(self, x)) @@ -157,6 +150,53 @@ def var(name: str) -> VariableNode: return VariableNode(name) +@dataclass(frozen=True, eq=False) +class MaxNode(ExpressionNode): + operands: List[ExpressionNode] + + def __post_init__(self): + if len(self.operands) < 2: + raise ValueError("MaxNode requires at least two operands") + for operand in self.operands: + if self._contains_forbidden_node(operand): + raise ValueError(f"Node {operand} is not allowed in this structure.") + + def _contains_forbidden_node(self, node: ExpressionNode) -> bool: + match node: + case VariableNode() | ComponentVariableNode() | ProblemVariableNode() | ComparisonNode() | PortFieldNode() | PortFieldAggregatorNode(): + return True + + case MaxNode(operands=ops): + return any(self._contains_forbidden_node(op) for op in ops) + + case TimeShiftNode(operand=op, time_shift=ts): + return self._contains_forbidden_node(op) or self._contains_forbidden_node(ts) + + case AdditionNode(operands=ops): + return any(self._contains_forbidden_node(op) for op in ops) + + case DivisionNode(left=l, right=r) | MultiplicationNode(left=l, right=r): + return self._contains_forbidden_node(l) or self._contains_forbidden_node(r) + + case AllTimeSumNode(operand=op) | NegationNode(operand=op) | ScenarioOperatorNode(operand=op): + return self._contains_forbidden_node(op) + + case TimeEvalNode(operand=op, eval_time=et): + return self._contains_forbidden_node(op) or self._contains_forbidden_node(et) + + case TimeSumNode(operand=op, from_time=ft, to_time=tt): + return self._contains_forbidden_node(op) or self._contains_forbidden_node(ft) or self._contains_forbidden_node(tt) + + case ComponentParameterNode() | ProblemParameterNode() | ParameterNode() | LiteralNode(): + return False + + case _: + # By default for each new Node, we reject the "max" operation + return True + +def max_expr(*operands: Any) -> MaxNode: + return MaxNode(operands=[_wrap_in_node(op) for op in operands]) + @dataclass(frozen=True, eq=False) class PortFieldNode(ExpressionNode): """ @@ -391,18 +431,6 @@ class Comparator(enum.Enum): class ComparisonNode(BinaryOperatorNode): comparator: Comparator -@dataclass(frozen=True, eq=False) -class MaxNode(ExpressionNode): - operands: List[ExpressionNode] - def __post_init__(self): - if len(self.operands) < 2: - raise ValueError("MaxNode requires at least two operands") - if not all(isinstance(op, ExpressionNode) for op in self.operands): - raise TypeError("All operands must be instances of ExpressionNode") - from gems.model.max import _validate_max_expression - _validate_max_expression(self) - - @dataclass(frozen=True, eq=False) class AdditionNode(ExpressionNode): diff --git a/src/gems/model/max.py b/src/gems/model/max.py deleted file mode 100644 index ef882ba9..00000000 --- a/src/gems/model/max.py +++ /dev/null @@ -1,80 +0,0 @@ -from typing import Any -from gems.expression import ExpressionVisitor, visit -from gems.expression import LiteralNode, VariableNode, ParameterNode, MaxNode, TimeShiftNode -from gems.expression.visitor import visit - -class _MaxExpressionChecker(ExpressionVisitor[None]): - """ - Visits the whole expression to check there is no: - comparison, other port field, component-associated parametrs or variables... - """ - def literal(self, node: LiteralNode) -> None: - pass # Les littéraux sont constants - - def parameter(self, node: ParameterNode) -> None: - pass # Les paramètres sont constants - - def variable(self, node: VariableNode) -> None: - raise ValueError("MaxNode cannot contain a variable.") - - def max_node(self, node: MaxNode) -> None: - if len(node.operands) < 2: - raise ValueError("MaxNode requires at least two operands") - for operand in node.operands: - visit(operand, self) - - def time_shift(self, node: Any) -> None: - raise ValueError("MaxNode cannot contain a time shift operation.") - - def addition(self, node: Any) -> None: - raise ValueError("MaxNode cannot contain an addition operation.") - - def comparison(self, node: Any) -> None: - raise ValueError("MaxNode cannot contain a comparison operator.") - - def all_time_sum(self, node: Any) -> None: - raise ValueError("MaxNode cannot contain an all-time sum operation.") - - def comp_parameter(self, node: Any) -> None: - raise ValueError("MaxNode cannot contain a component parameter.") - - def comp_variable(self, node: Any) -> None: - raise ValueError("MaxNode cannot contain a component variable.") - - def division(self, node: Any) -> None: - raise ValueError("MaxNode cannot contain a division operation.") - - def multiplication(self, node: Any) -> None: - raise ValueError("MaxNode cannot contain a multiplication operation.") - - def negation(self, node: Any) -> None: - raise ValueError("MaxNode cannot contain a negation operation.") - - def pb_parameter(self, node: Any) -> None: - raise ValueError("MaxNode cannot contain a problem parameter.") - - def pb_variable(self, node: Any) -> None: - raise ValueError("MaxNode cannot contain a problem variable.") - - def port_field(self, node: Any) -> None: - raise ValueError("MaxNode cannot reference a port field.") - - def port_field_aggregator(self, node: Any) -> None: - raise ValueError("MaxNode cannot contain port field aggregation.") - - def scenario_operator(self, node: Any) -> None: - raise ValueError("MaxNode cannot contain a scenario operator.") - - def time_eval(self, node: Any) -> None: - raise ValueError("MaxNode cannot contain a time evaluation operation.") - - def time_sum(self, node: Any) -> None: - raise ValueError("MaxNode cannot contain a time sum operation.") - -def _validate_max_expression(node: MaxNode) -> None: - """ - Valide l'expression d'un MaxNode en visitant ses opérandes avec _MaxExpressionChecker. - """ - checker = _MaxExpressionChecker() - for operand in node.operands: - visit(operand, checker) \ No newline at end of file diff --git a/src/gems/simulation/linearize.py b/src/gems/simulation/linearize.py index 6108ed0b..c905d140 100644 --- a/src/gems/simulation/linearize.py +++ b/src/gems/simulation/linearize.py @@ -283,7 +283,12 @@ def port_field_aggregator( ) def max_node(self, node: MaxNode) -> LinearExpressionData: - raise ValueError("MaxNode is not supported in linear expressions, as it needs constants.") + operands = [visit(o, self) for o in node.operands] + terms: list = [] + if any(o.terms for o in operands): + raise ValueError("Cannot linearize max expressions with variable terms.") + max_const = max(o.constant for o in operands) + return LinearExpressionData(terms=terms, constant=max_const) def linearize_expression( expression: ExpressionNode, From 71c7777e0210fb88ec4879f93229d364a70e4095 Mon Sep 17 00:00:00 2001 From: killian-scalian Date: Fri, 1 Aug 2025 16:23:53 +0200 Subject: [PATCH 03/15] ruff, isort and tests --- src/gems/expression/degree.py | 7 +- src/gems/expression/evaluate_parameters.py | 6 +- src/gems/expression/expression.py | 47 ++++++++++--- src/gems/expression/print.py | 5 +- src/gems/expression/visitor.py | 70 +++++++------------ .../parsing/test_expression_parsing.py | 29 +++++++- .../expressions/visitor/test_copy.py | 29 +++++--- .../expressions/visitor/test_degree.py | 14 +++- .../expressions/visitor/test_equality.py | 24 ++++++- .../expressions/visitor/test_evaluation.py | 7 ++ .../expressions/visitor/test_indexing.py | 15 +++- .../expressions/visitor/test_linearization.py | 3 + .../visitor/test_max_expression_checker.py | 51 ++++++++++++++ .../expressions/visitor/test_printer.py | 9 ++- 14 files changed, 236 insertions(+), 80 deletions(-) create mode 100644 tests/unittests/expressions/visitor/test_max_expression_checker.py diff --git a/src/gems/expression/degree.py b/src/gems/expression/degree.py index 86220f4e..52b55dc0 100644 --- a/src/gems/expression/degree.py +++ b/src/gems/expression/degree.py @@ -98,9 +98,7 @@ def all_time_sum(self, node: AllTimeSumNode) -> int: return visit(node.operand, self) def scenario_operator(self, node: ScenarioOperatorNode) -> int: - scenario_operator_cls = getattr( - gems.expression.scenario_operator, node.name - ) + scenario_operator_cls = getattr(gems.expression.scenario_operator, node.name) # TODO: Carefully check if this formula is correct return scenario_operator_cls.degree() * visit(node.operand, self) @@ -113,6 +111,7 @@ def port_field_aggregator(self, node: PortFieldAggregatorNode) -> int: def max_node(self, node: MaxNode) -> int: return max([visit(o, self) for o in node.operands]) + def compute_degree(expression: ExpressionNode) -> int: return visit(expression, ExpressionDegreeVisitor()) @@ -128,4 +127,4 @@ def is_linear(expr: ExpressionNode) -> bool: """ True if the expression is linear with respect to variables. """ - return compute_degree(expr) <= 1 \ No newline at end of file + return compute_degree(expr) <= 1 diff --git a/src/gems/expression/evaluate_parameters.py b/src/gems/expression/evaluate_parameters.py index b605af54..77b0d70f 100644 --- a/src/gems/expression/evaluate_parameters.py +++ b/src/gems/expression/evaluate_parameters.py @@ -27,12 +27,10 @@ class ParameterValueProvider(ABC): @abstractmethod - def get_parameter_value(self, name: str) -> float: - ... + def get_parameter_value(self, name: str) -> float: ... @abstractmethod - def get_component_parameter_value(self, component_id: str, name: str) -> float: - ... + def get_component_parameter_value(self, component_id: str, name: str) -> float: ... @dataclass(frozen=True) diff --git a/src/gems/expression/expression.py b/src/gems/expression/expression.py index 5f25d23a..31100dcf 100644 --- a/src/gems/expression/expression.py +++ b/src/gems/expression/expression.py @@ -13,6 +13,7 @@ """ Defines the model for generic expressions. """ + import enum import inspect from dataclasses import dataclass @@ -163,40 +164,68 @@ def __post_init__(self): def _contains_forbidden_node(self, node: ExpressionNode) -> bool: match node: - case VariableNode() | ComponentVariableNode() | ProblemVariableNode() | ComparisonNode() | PortFieldNode() | PortFieldAggregatorNode(): + case ( + VariableNode() + | ComponentVariableNode() + | ProblemVariableNode() + | ComparisonNode() + | PortFieldNode() + | PortFieldAggregatorNode() + ): return True case MaxNode(operands=ops): return any(self._contains_forbidden_node(op) for op in ops) case TimeShiftNode(operand=op, time_shift=ts): - return self._contains_forbidden_node(op) or self._contains_forbidden_node(ts) + return self._contains_forbidden_node( + op + ) or self._contains_forbidden_node(ts) case AdditionNode(operands=ops): return any(self._contains_forbidden_node(op) for op in ops) case DivisionNode(left=l, right=r) | MultiplicationNode(left=l, right=r): - return self._contains_forbidden_node(l) or self._contains_forbidden_node(r) - - case AllTimeSumNode(operand=op) | NegationNode(operand=op) | ScenarioOperatorNode(operand=op): + return self._contains_forbidden_node( + l + ) or self._contains_forbidden_node(r) + + case ( + AllTimeSumNode(operand=op) + | NegationNode(operand=op) + | ScenarioOperatorNode(operand=op) + ): return self._contains_forbidden_node(op) case TimeEvalNode(operand=op, eval_time=et): - return self._contains_forbidden_node(op) or self._contains_forbidden_node(et) + return self._contains_forbidden_node( + op + ) or self._contains_forbidden_node(et) case TimeSumNode(operand=op, from_time=ft, to_time=tt): - return self._contains_forbidden_node(op) or self._contains_forbidden_node(ft) or self._contains_forbidden_node(tt) - - case ComponentParameterNode() | ProblemParameterNode() | ParameterNode() | LiteralNode(): + return ( + self._contains_forbidden_node(op) + or self._contains_forbidden_node(ft) + or self._contains_forbidden_node(tt) + ) + + case ( + ComponentParameterNode() + | ProblemParameterNode() + | ParameterNode() + | LiteralNode() + ): return False case _: # By default for each new Node, we reject the "max" operation return True + def max_expr(*operands: Any) -> MaxNode: return MaxNode(operands=[_wrap_in_node(op) for op in operands]) + @dataclass(frozen=True, eq=False) class PortFieldNode(ExpressionNode): """ diff --git a/src/gems/expression/print.py b/src/gems/expression/print.py index 9586f8dd..c5b67111 100644 --- a/src/gems/expression/print.py +++ b/src/gems/expression/print.py @@ -25,7 +25,7 @@ TimeEvalNode, TimeShiftNode, TimeSumNode, - MaxNode + MaxNode, ) from .expression import ( @@ -130,10 +130,11 @@ def port_field(self, node: PortFieldNode) -> str: def port_field_aggregator(self, node: PortFieldAggregatorNode) -> str: return f"({visit(node.operand, self)}.{node.aggregator})" - + def max_node(self, node: MaxNode) -> str: operand_strings = [visit(op, self) for op in node.operands] return f"max({', '.join(operand_strings)})" + def print_expr(expression: ExpressionNode) -> str: return visit(expression, PrinterVisitor()) diff --git a/src/gems/expression/visitor.py b/src/gems/expression/visitor.py index 23ab59b4..836fbcea 100644 --- a/src/gems/expression/visitor.py +++ b/src/gems/expression/visitor.py @@ -13,6 +13,7 @@ """ Defines abstract base class for visitors of expressions. """ + import typing from abc import ABC, abstractmethod from typing import Generic, Protocol, TypeVar @@ -38,7 +39,7 @@ TimeShiftNode, TimeSumNode, VariableNode, - MaxNode + MaxNode, ) T = TypeVar("T") @@ -54,84 +55,64 @@ class ExpressionVisitor(ABC, Generic[T]): """ @abstractmethod - def literal(self, node: LiteralNode) -> T: - ... + def literal(self, node: LiteralNode) -> T: ... @abstractmethod - def negation(self, node: NegationNode) -> T: - ... + def negation(self, node: NegationNode) -> T: ... @abstractmethod - def addition(self, node: AdditionNode) -> T: - ... + def addition(self, node: AdditionNode) -> T: ... @abstractmethod - def multiplication(self, node: MultiplicationNode) -> T: - ... + def multiplication(self, node: MultiplicationNode) -> T: ... @abstractmethod - def division(self, node: DivisionNode) -> T: - ... + def division(self, node: DivisionNode) -> T: ... @abstractmethod - def comparison(self, node: ComparisonNode) -> T: - ... + def comparison(self, node: ComparisonNode) -> T: ... @abstractmethod - def variable(self, node: VariableNode) -> T: - ... + def variable(self, node: VariableNode) -> T: ... @abstractmethod - def parameter(self, node: ParameterNode) -> T: - ... + def parameter(self, node: ParameterNode) -> T: ... @abstractmethod - def comp_parameter(self, node: ComponentParameterNode) -> T: - ... + def comp_parameter(self, node: ComponentParameterNode) -> T: ... @abstractmethod - def comp_variable(self, node: ComponentVariableNode) -> T: - ... + def comp_variable(self, node: ComponentVariableNode) -> T: ... @abstractmethod - def pb_parameter(self, node: ProblemParameterNode) -> T: - ... + def pb_parameter(self, node: ProblemParameterNode) -> T: ... @abstractmethod - def pb_variable(self, node: ProblemVariableNode) -> T: - ... + def pb_variable(self, node: ProblemVariableNode) -> T: ... @abstractmethod - def time_shift(self, node: TimeShiftNode) -> T: - ... + def time_shift(self, node: TimeShiftNode) -> T: ... @abstractmethod - def time_eval(self, node: TimeEvalNode) -> T: - ... + def time_eval(self, node: TimeEvalNode) -> T: ... @abstractmethod - def time_sum(self, node: TimeSumNode) -> T: - ... + def time_sum(self, node: TimeSumNode) -> T: ... @abstractmethod - def all_time_sum(self, node: AllTimeSumNode) -> T: - ... + def all_time_sum(self, node: AllTimeSumNode) -> T: ... @abstractmethod - def scenario_operator(self, node: ScenarioOperatorNode) -> T: - ... + def scenario_operator(self, node: ScenarioOperatorNode) -> T: ... @abstractmethod - def port_field(self, node: PortFieldNode) -> T: - ... + def port_field(self, node: PortFieldNode) -> T: ... @abstractmethod - def port_field_aggregator(self, node: PortFieldAggregatorNode) -> T: - ... - + def port_field_aggregator(self, node: PortFieldAggregatorNode) -> T: ... + @abstractmethod - def max_node(self, node: MaxNode) -> T: - ... + def max_node(self, node: MaxNode) -> T: ... def visit(root: ExpressionNode, visitor: ExpressionVisitor[T]) -> T: @@ -210,6 +191,7 @@ def __truediv__(self, other: T) -> T: def __max__(self, other: T) -> T: pass + T_op = TypeVar("T_op", bound=SupportsOperations) @@ -238,6 +220,6 @@ def division(self, node: DivisionNode) -> T_op: left_value = visit(node.left, self) right_value = visit(node.right, self) return left_value / right_value - + def max_node(self, node) -> ExpressionNode: - return MaxNode(operands=[visit(op, self) for op in node.operands]) \ No newline at end of file + return MaxNode(operands=[visit(op, self) for op in node.operands]) diff --git a/tests/unittests/expressions/parsing/test_expression_parsing.py b/tests/unittests/expressions/parsing/test_expression_parsing.py index d6558d7f..ab9bfb15 100644 --- a/tests/unittests/expressions/parsing/test_expression_parsing.py +++ b/tests/unittests/expressions/parsing/test_expression_parsing.py @@ -13,7 +13,7 @@ import pytest -from gems.expression import ExpressionNode, literal, param, print_expr, var +from gems.expression import ExpressionNode, literal, max_expr, param, print_expr, var from gems.expression.equality import expressions_equal from gems.expression.expression import port_field from gems.expression.parsing.parse_expression import ( @@ -119,6 +119,12 @@ "expec(sum(cost * generation))", (param("cost") * var("generation")).time_sum().expec(), ), + ( + {}, + {}, + "max(1, 2)", + max_expr(literal(1), literal(2)), + ), ], ) def test_parsing_visitor( @@ -156,3 +162,24 @@ def test_parse_cancellation_should_throw(expression_str: str) -> None: match=r"An error occurred during parsing: ParseCancellationException", ): parse_expression(expression_str, identifiers) + + +@pytest.mark.parametrize( + "expression_str", + [ + "max(1 3)", + "max(x, y)", + ], +) +def test_parse_max_errors(expression_str: str) -> None: + # Console log error is displayed ! + identifiers = ModelIdentifiers( + variables={"x"}, + parameters=set(), + ) + + with pytest.raises( + AntaresParseException, + match=r"An error occurred during parsing:*", + ): + parse_expression(expression_str, identifiers) diff --git a/tests/unittests/expressions/visitor/test_copy.py b/tests/unittests/expressions/visitor/test_copy.py index 52a20b3f..5e258a34 100644 --- a/tests/unittests/expressions/visitor/test_copy.py +++ b/tests/unittests/expressions/visitor/test_copy.py @@ -10,6 +10,7 @@ # # This file is part of the Antares project. +import pytest from gems.expression import ( AdditionNode, @@ -23,23 +24,31 @@ from gems.expression.expression import ( AllTimeSumNode, ComponentParameterNode, + MaxNode, MultiplicationNode, TimeEvalNode, TimeShiftNode, ) -def test_copy_ast() -> None: - ast = AllTimeSumNode( - DivisionNode( - TimeEvalNode( - AdditionNode([LiteralNode(1), VariableNode("x")]), ParameterNode("p") - ), - TimeShiftNode( - MultiplicationNode(LiteralNode(1), VariableNode("x")), - ComponentParameterNode("comp1", "p"), +@pytest.mark.parametrize( + "ast", + [ + AllTimeSumNode( + DivisionNode( + TimeEvalNode( + AdditionNode([LiteralNode(1), VariableNode("x")]), + ParameterNode("p"), + ), + TimeShiftNode( + MultiplicationNode(LiteralNode(1), VariableNode("x")), + ComponentParameterNode("comp1", "p"), + ), ), ), - ) + MaxNode([LiteralNode(5), LiteralNode(10)]), + ], +) +def test_copy_ast(ast) -> None: copy = copy_expression(ast) assert expressions_equal(ast, copy) diff --git a/tests/unittests/expressions/visitor/test_degree.py b/tests/unittests/expressions/visitor/test_degree.py index 72996d64..8c16acb4 100644 --- a/tests/unittests/expressions/visitor/test_degree.py +++ b/tests/unittests/expressions/visitor/test_degree.py @@ -12,7 +12,14 @@ import pytest -from gems.expression import ExpressionDegreeVisitor, LiteralNode, param, var, visit +from gems.expression import ( + ExpressionDegreeVisitor, + LiteralNode, + max_expr, + param, + var, + visit, +) def test_degree() -> None: @@ -34,3 +41,8 @@ def test_degree_computation_should_take_into_account_simplifications() -> None: expr = LiteralNode(0) * x assert visit(expr, ExpressionDegreeVisitor()) == 0 + + +def test_max_degree() -> None: + expr = max_expr((5 * 3 + 3) / 1, 4) + assert visit(expr, ExpressionDegreeVisitor()) == 0 diff --git a/tests/unittests/expressions/visitor/test_equality.py b/tests/unittests/expressions/visitor/test_equality.py index bcdec8ff..0e5262bc 100644 --- a/tests/unittests/expressions/visitor/test_equality.py +++ b/tests/unittests/expressions/visitor/test_equality.py @@ -12,10 +12,31 @@ import pytest -from gems.expression import ExpressionNode, copy_expression, literal, param, var +from gems.expression import ( + ExpressionNode, + copy_expression, + literal, + max_expr, + param, + var, +) from gems.expression.equality import expressions_equal +@pytest.mark.parametrize( + "left, right, expected_equal", + [ + (max_expr(5, 87), max_expr(5, 87), True), + (max_expr(5, 87), max_expr(87, 5), False), + (max_expr(1, param("a")), max_expr(1, param("a")), True), + (max_expr(1, param("a")), max_expr(param("a"), 1), False), + (max_expr(1, param("a")), max_expr(1, param("b")), False), + ], +) +def test_max_expr_equality(left, right, expected_equal): + assert expressions_equal(left, right) == expected_equal + + @pytest.mark.parametrize( "expr", [ @@ -30,6 +51,7 @@ var("x").time_sum(), var("x") + 5 <= 2, var("x").expec(), + max_expr(1, param("a")), ], ) def test_equals(expr: ExpressionNode) -> None: diff --git a/tests/unittests/expressions/visitor/test_evaluation.py b/tests/unittests/expressions/visitor/test_evaluation.py index 62e25183..83093c31 100644 --- a/tests/unittests/expressions/visitor/test_evaluation.py +++ b/tests/unittests/expressions/visitor/test_evaluation.py @@ -22,6 +22,7 @@ EvaluationVisitor, ExpressionNode, LiteralNode, + MaxNode, ParameterNode, PrinterVisitor, ValueProvider, @@ -90,6 +91,12 @@ def test_ast() -> None: context = EvaluationContext(variables={"x": 3}, parameters={"p": 4}) assert visit(expr, EvaluationVisitor(context)) == 1 + expr = MaxNode(operands=[LiteralNode(1), ParameterNode("a")]) + assert visit(expr, PrinterVisitor()) == "max(1, a)" + + context = EvaluationContext(parameters={"a": 4}) + assert visit(expr, EvaluationVisitor(context)) == 4 + def test_operators() -> None: x = var("x") diff --git a/tests/unittests/expressions/visitor/test_indexing.py b/tests/unittests/expressions/visitor/test_indexing.py index 6a40f0d7..740cc3a0 100644 --- a/tests/unittests/expressions/visitor/test_indexing.py +++ b/tests/unittests/expressions/visitor/test_indexing.py @@ -10,8 +10,9 @@ # # This file is part of the Antares project. +import pytest -from gems.expression import param, var +from gems.expression import max_expr, param, var from gems.expression.indexing import IndexingStructureProvider, compute_indexation from gems.expression.indexing_structure import IndexingStructure @@ -42,6 +43,18 @@ def test_shift() -> None: assert compute_indexation(expr, provider) == IndexingStructure(True, True) +@pytest.mark.parametrize( + "expr, expected_indexing", + [ + (max_expr(param("a"), 3), IndexingStructure(True, True)), + (max_expr(1, 3), IndexingStructure(False, False)), + ], +) +def test_max(expr, expected_indexing) -> None: + provider = StructureProvider() + assert compute_indexation(expr, provider) == expected_indexing + + def test_time_eval() -> None: x = var("x") expr = x.eval(1) diff --git a/tests/unittests/expressions/visitor/test_linearization.py b/tests/unittests/expressions/visitor/test_linearization.py index 64a033a4..eae06f35 100644 --- a/tests/unittests/expressions/visitor/test_linearization.py +++ b/tests/unittests/expressions/visitor/test_linearization.py @@ -16,11 +16,13 @@ from gems.expression import ExpressionNode, LiteralNode, literal, var from gems.expression.expression import ( + AdditionNode, ComponentVariableNode, CurrentScenarioIndex, TimeShift, comp_param, comp_var, + max_expr, problem_var, ) from gems.expression.indexing import IndexingStructureProvider @@ -128,6 +130,7 @@ def _expand_and_linearize( ((X + 2).time_sum(), X_at(t=0) + X_at(t=1) + constant(4)), ((X + 2).time_sum(-1, 0), X_at(t=-1) + X_at(t=0) + constant(4)), ((X + 2).time_sum(-1, 0), X_at(t=-1) + X_at(t=0) + constant(4)), + (max_expr(LiteralNode(2) + LiteralNode(1), LiteralNode(0)), constant(3)), ], ) def test_linearization_of_nested_time_operations( diff --git a/tests/unittests/expressions/visitor/test_max_expression_checker.py b/tests/unittests/expressions/visitor/test_max_expression_checker.py new file mode 100644 index 00000000..1456a156 --- /dev/null +++ b/tests/unittests/expressions/visitor/test_max_expression_checker.py @@ -0,0 +1,51 @@ +import pytest + +from gems.expression import ( + Comparator, + ComparisonNode, + ExpressionNode, + VariableNode, + max_expr, +) +from gems.expression.expression import ( + ComponentVariableNode, + PortFieldAggregatorNode, + PortFieldNode, + ProblemVariableNode, +) + +NodeList = [ + ComparisonNode, + ExpressionNode, + VariableNode, + ComponentVariableNode, + ProblemVariableNode, + PortFieldNode, + PortFieldAggregatorNode, +] + + +@pytest.mark.parametrize( + "node, left_arg, right_arg", + [ + (VariableNode, ("x",), ("y",)), + ( + PortFieldAggregatorNode, + (ExpressionNode, "PortAggregator"), + (ExpressionNode, "PortAggregator"), + ), + (PortFieldNode, ("port", "name"), ("port", "name2")), + ( + ProblemVariableNode, + ("comp", "name", "time_index", "scenario_index"), + ("comp", "name", "time_index", "scenario_index"), + ), + (ComponentVariableNode, ("component_id", "name"), ("component_id2", "name2")), + (ComparisonNode, ("x", "y", Comparator.GREATER_THAN), 4), + ], +) +def test_max_expr_checker(node, left_arg, right_arg) -> None: + left = node(*left_arg) + right = right_arg if isinstance(right_arg, int) else node(*right_arg) + with pytest.raises(ValueError): + max_expr(left, right) diff --git a/tests/unittests/expressions/visitor/test_printer.py b/tests/unittests/expressions/visitor/test_printer.py index a41250af..7ca37e6a 100644 --- a/tests/unittests/expressions/visitor/test_printer.py +++ b/tests/unittests/expressions/visitor/test_printer.py @@ -10,12 +10,15 @@ # # This file is part of the Antares project. -from gems.expression import ExpressionNode, PrinterVisitor, param, var, visit +from gems.expression import ExpressionNode, PrinterVisitor, max_expr, param, var, visit def test_comparison() -> None: x = var("x") p = param("p") - expr: ExpressionNode = (5 * x + 3) >= p - 2 + expr: ExpressionNode = (5 * x + 3 + max_expr(5, 8)) >= p - 2 - assert visit(expr, PrinterVisitor()) == "((5.0 * x) + 3.0) >= (p - 2.0)" + assert ( + visit(expr, PrinterVisitor()) + == "((5.0 * x) + 3.0 + max(5.0, 8.0)) >= (p - 2.0)" + ) From 10b635c3d875a8fcd5be468ecd5630e6533a17dc Mon Sep 17 00:00:00 2001 From: killian-scalian Date: Fri, 1 Aug 2025 16:49:58 +0200 Subject: [PATCH 04/15] ruff --- src/gems/expression/copy.py | 1 - src/gems/expression/equality.py | 7 +- src/gems/expression/evaluate.py | 15 +- src/gems/expression/indexing.py | 16 +- .../expression/parsing/antlr/ExprLexer.py | 1300 +++++++++- .../expression/parsing/antlr/ExprParser.py | 2199 +++++++++++++---- .../expression/parsing/antlr/ExprVisitor.py | 89 +- .../expression/parsing/parse_expression.py | 3 +- 8 files changed, 3057 insertions(+), 573 deletions(-) diff --git a/src/gems/expression/copy.py b/src/gems/expression/copy.py index eea34d74..8662178f 100644 --- a/src/gems/expression/copy.py +++ b/src/gems/expression/copy.py @@ -11,7 +11,6 @@ # This file is part of the Antares project. from dataclasses import dataclass -from typing import List, cast from .expression import ( AllTimeSumNode, diff --git a/src/gems/expression/equality.py b/src/gems/expression/equality.py index 68ba38d8..d7ce4e0e 100644 --- a/src/gems/expression/equality.py +++ b/src/gems/expression/equality.py @@ -24,7 +24,7 @@ NegationNode, ParameterNode, VariableNode, - MaxNode + MaxNode, ) from gems.expression.expression import ( AllTimeSumNode, @@ -139,8 +139,9 @@ def addition(self, left: AdditionNode, right: AdditionNode) -> bool: def max_node(self, left: MaxNode, right: MaxNode) -> bool: if len(left.operands) != len(right.operands): return False - print("yoooo", left.operands, right.operands, all(self.visit(l_op, r_op) for l_op, r_op in zip(left.operands, right.operands))) - return all(self.visit(l_op, r_op) for l_op, r_op in zip(left.operands, right.operands)) + return all( + self.visit(l_op, r_op) for l_op, r_op in zip(left.operands, right.operands) + ) def multiplication( self, left: MultiplicationNode, right: MultiplicationNode diff --git a/src/gems/expression/evaluate.py b/src/gems/expression/evaluate.py index ddc48b62..5b324699 100644 --- a/src/gems/expression/evaluate.py +++ b/src/gems/expression/evaluate.py @@ -47,20 +47,16 @@ class ValueProvider(ABC): """ @abstractmethod - def get_variable_value(self, name: str) -> float: - ... + def get_variable_value(self, name: str) -> float: ... @abstractmethod - def get_parameter_value(self, name: str) -> float: - ... + def get_parameter_value(self, name: str) -> float: ... @abstractmethod - def get_component_variable_value(self, component_id: str, name: str) -> float: - ... + def get_component_variable_value(self, component_id: str, name: str) -> float: ... @abstractmethod - def get_component_parameter_value(self, component_id: str, name: str) -> float: - ... + def get_component_parameter_value(self, component_id: str, name: str) -> float: ... @dataclass(frozen=True) @@ -139,9 +135,10 @@ def port_field(self, node: PortFieldNode) -> float: def port_field_aggregator(self, node: PortFieldAggregatorNode) -> float: raise NotImplementedError() - + def max_node(self, node: MaxNode) -> float: return max(visit(op, self) for op in node.operands) + def evaluate(expression: ExpressionNode, value_provider: ValueProvider) -> float: return visit(expression, EvaluationVisitor(value_provider)) diff --git a/src/gems/expression/indexing.py b/src/gems/expression/indexing.py index ba6fa8e0..7d56cb56 100644 --- a/src/gems/expression/indexing.py +++ b/src/gems/expression/indexing.py @@ -37,31 +37,27 @@ TimeShiftNode, TimeSumNode, VariableNode, - MaxNode + MaxNode, ) from .visitor import ExpressionVisitor, T, visit class IndexingStructureProvider(ABC): @abstractmethod - def get_parameter_structure(self, name: str) -> IndexingStructure: - ... + def get_parameter_structure(self, name: str) -> IndexingStructure: ... @abstractmethod - def get_variable_structure(self, name: str) -> IndexingStructure: - ... + def get_variable_structure(self, name: str) -> IndexingStructure: ... @abstractmethod def get_component_variable_structure( self, component_id: str, name: str - ) -> IndexingStructure: - ... + ) -> IndexingStructure: ... @abstractmethod def get_component_parameter_structure( self, component_id: str, name: str - ) -> IndexingStructure: - ... + ) -> IndexingStructure: ... @dataclass(frozen=True) @@ -159,7 +155,7 @@ def port_field_aggregator(self, node: PortFieldAggregatorNode) -> IndexingStruct raise ValueError( "Port fields aggregators must be resolved before computing indexing structure." ) - + def max_node(self, node: MaxNode) -> IndexingStructure: return self._combine(node.operands) diff --git a/src/gems/expression/parsing/antlr/ExprLexer.py b/src/gems/expression/parsing/antlr/ExprLexer.py index f7767124..86bdaa43 100644 --- a/src/gems/expression/parsing/antlr/ExprLexer.py +++ b/src/gems/expression/parsing/antlr/ExprLexer.py @@ -2,6 +2,7 @@ from antlr4 import * from io import StringIO import sys + if sys.version_info[1] > 5: from typing import TextIO else: @@ -10,58 +11,1191 @@ def serializedATN(): return [ - 4,0,19,133,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5, - 2,6,7,6,2,7,7,7,2,8,7,8,2,9,7,9,2,10,7,10,2,11,7,11,2,12,7,12,2, - 13,7,13,2,14,7,14,2,15,7,15,2,16,7,16,2,17,7,17,2,18,7,18,2,19,7, - 19,2,20,7,20,2,21,7,21,1,0,1,0,1,1,1,1,1,2,1,2,1,3,1,3,1,4,1,4,1, - 5,1,5,1,6,1,6,1,7,1,7,1,7,1,7,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1, - 8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,9,1,9,1,9,1,10,1,10,1,11,1,11,1, - 12,1,12,1,13,1,13,1,14,1,14,1,15,1,15,3,15,95,8,15,1,16,4,16,98, - 8,16,11,16,12,16,99,1,16,1,16,4,16,104,8,16,11,16,12,16,105,3,16, - 108,8,16,1,17,1,17,1,17,1,17,1,18,1,18,1,19,1,19,5,19,118,8,19,10, - 19,12,19,121,9,19,1,20,1,20,1,20,1,20,1,20,3,20,128,8,20,1,21,1, - 21,1,21,1,21,0,0,22,1,1,3,2,5,3,7,4,9,5,11,6,13,7,15,8,17,9,19,10, - 21,11,23,12,25,13,27,0,29,0,31,0,33,14,35,15,37,16,39,17,41,18,43, - 19,1,0,3,1,0,48,57,3,0,65,90,95,95,97,122,3,0,9,10,13,13,32,32,136, - 0,1,1,0,0,0,0,3,1,0,0,0,0,5,1,0,0,0,0,7,1,0,0,0,0,9,1,0,0,0,0,11, - 1,0,0,0,0,13,1,0,0,0,0,15,1,0,0,0,0,17,1,0,0,0,0,19,1,0,0,0,0,21, - 1,0,0,0,0,23,1,0,0,0,0,25,1,0,0,0,0,33,1,0,0,0,0,35,1,0,0,0,0,37, - 1,0,0,0,0,39,1,0,0,0,0,41,1,0,0,0,0,43,1,0,0,0,1,45,1,0,0,0,3,47, - 1,0,0,0,5,49,1,0,0,0,7,51,1,0,0,0,9,53,1,0,0,0,11,55,1,0,0,0,13, - 57,1,0,0,0,15,59,1,0,0,0,17,63,1,0,0,0,19,79,1,0,0,0,21,82,1,0,0, - 0,23,84,1,0,0,0,25,86,1,0,0,0,27,88,1,0,0,0,29,90,1,0,0,0,31,94, - 1,0,0,0,33,97,1,0,0,0,35,109,1,0,0,0,37,113,1,0,0,0,39,115,1,0,0, - 0,41,127,1,0,0,0,43,129,1,0,0,0,45,46,5,46,0,0,46,2,1,0,0,0,47,48, - 5,45,0,0,48,4,1,0,0,0,49,50,5,40,0,0,50,6,1,0,0,0,51,52,5,41,0,0, - 52,8,1,0,0,0,53,54,5,47,0,0,54,10,1,0,0,0,55,56,5,42,0,0,56,12,1, - 0,0,0,57,58,5,43,0,0,58,14,1,0,0,0,59,60,5,115,0,0,60,61,5,117,0, - 0,61,62,5,109,0,0,62,16,1,0,0,0,63,64,5,115,0,0,64,65,5,117,0,0, - 65,66,5,109,0,0,66,67,5,95,0,0,67,68,5,99,0,0,68,69,5,111,0,0,69, - 70,5,110,0,0,70,71,5,110,0,0,71,72,5,101,0,0,72,73,5,99,0,0,73,74, - 5,116,0,0,74,75,5,105,0,0,75,76,5,111,0,0,76,77,5,110,0,0,77,78, - 5,115,0,0,78,18,1,0,0,0,79,80,5,46,0,0,80,81,5,46,0,0,81,20,1,0, - 0,0,82,83,5,44,0,0,83,22,1,0,0,0,84,85,5,91,0,0,85,24,1,0,0,0,86, - 87,5,93,0,0,87,26,1,0,0,0,88,89,7,0,0,0,89,28,1,0,0,0,90,91,7,1, - 0,0,91,30,1,0,0,0,92,95,3,29,14,0,93,95,3,27,13,0,94,92,1,0,0,0, - 94,93,1,0,0,0,95,32,1,0,0,0,96,98,3,27,13,0,97,96,1,0,0,0,98,99, - 1,0,0,0,99,97,1,0,0,0,99,100,1,0,0,0,100,107,1,0,0,0,101,103,5,46, - 0,0,102,104,3,27,13,0,103,102,1,0,0,0,104,105,1,0,0,0,105,103,1, - 0,0,0,105,106,1,0,0,0,106,108,1,0,0,0,107,101,1,0,0,0,107,108,1, - 0,0,0,108,34,1,0,0,0,109,110,5,109,0,0,110,111,5,97,0,0,111,112, - 5,120,0,0,112,36,1,0,0,0,113,114,5,116,0,0,114,38,1,0,0,0,115,119, - 3,29,14,0,116,118,3,31,15,0,117,116,1,0,0,0,118,121,1,0,0,0,119, - 117,1,0,0,0,119,120,1,0,0,0,120,40,1,0,0,0,121,119,1,0,0,0,122,128, - 5,61,0,0,123,124,5,62,0,0,124,128,5,61,0,0,125,126,5,60,0,0,126, - 128,5,61,0,0,127,122,1,0,0,0,127,123,1,0,0,0,127,125,1,0,0,0,128, - 42,1,0,0,0,129,130,7,2,0,0,130,131,1,0,0,0,131,132,6,21,0,0,132, - 44,1,0,0,0,7,0,94,99,105,107,119,127,1,6,0,0 + 4, + 0, + 19, + 133, + 6, + -1, + 2, + 0, + 7, + 0, + 2, + 1, + 7, + 1, + 2, + 2, + 7, + 2, + 2, + 3, + 7, + 3, + 2, + 4, + 7, + 4, + 2, + 5, + 7, + 5, + 2, + 6, + 7, + 6, + 2, + 7, + 7, + 7, + 2, + 8, + 7, + 8, + 2, + 9, + 7, + 9, + 2, + 10, + 7, + 10, + 2, + 11, + 7, + 11, + 2, + 12, + 7, + 12, + 2, + 13, + 7, + 13, + 2, + 14, + 7, + 14, + 2, + 15, + 7, + 15, + 2, + 16, + 7, + 16, + 2, + 17, + 7, + 17, + 2, + 18, + 7, + 18, + 2, + 19, + 7, + 19, + 2, + 20, + 7, + 20, + 2, + 21, + 7, + 21, + 1, + 0, + 1, + 0, + 1, + 1, + 1, + 1, + 1, + 2, + 1, + 2, + 1, + 3, + 1, + 3, + 1, + 4, + 1, + 4, + 1, + 5, + 1, + 5, + 1, + 6, + 1, + 6, + 1, + 7, + 1, + 7, + 1, + 7, + 1, + 7, + 1, + 8, + 1, + 8, + 1, + 8, + 1, + 8, + 1, + 8, + 1, + 8, + 1, + 8, + 1, + 8, + 1, + 8, + 1, + 8, + 1, + 8, + 1, + 8, + 1, + 8, + 1, + 8, + 1, + 8, + 1, + 8, + 1, + 9, + 1, + 9, + 1, + 9, + 1, + 10, + 1, + 10, + 1, + 11, + 1, + 11, + 1, + 12, + 1, + 12, + 1, + 13, + 1, + 13, + 1, + 14, + 1, + 14, + 1, + 15, + 1, + 15, + 3, + 15, + 95, + 8, + 15, + 1, + 16, + 4, + 16, + 98, + 8, + 16, + 11, + 16, + 12, + 16, + 99, + 1, + 16, + 1, + 16, + 4, + 16, + 104, + 8, + 16, + 11, + 16, + 12, + 16, + 105, + 3, + 16, + 108, + 8, + 16, + 1, + 17, + 1, + 17, + 1, + 17, + 1, + 17, + 1, + 18, + 1, + 18, + 1, + 19, + 1, + 19, + 5, + 19, + 118, + 8, + 19, + 10, + 19, + 12, + 19, + 121, + 9, + 19, + 1, + 20, + 1, + 20, + 1, + 20, + 1, + 20, + 1, + 20, + 3, + 20, + 128, + 8, + 20, + 1, + 21, + 1, + 21, + 1, + 21, + 1, + 21, + 0, + 0, + 22, + 1, + 1, + 3, + 2, + 5, + 3, + 7, + 4, + 9, + 5, + 11, + 6, + 13, + 7, + 15, + 8, + 17, + 9, + 19, + 10, + 21, + 11, + 23, + 12, + 25, + 13, + 27, + 0, + 29, + 0, + 31, + 0, + 33, + 14, + 35, + 15, + 37, + 16, + 39, + 17, + 41, + 18, + 43, + 19, + 1, + 0, + 3, + 1, + 0, + 48, + 57, + 3, + 0, + 65, + 90, + 95, + 95, + 97, + 122, + 3, + 0, + 9, + 10, + 13, + 13, + 32, + 32, + 136, + 0, + 1, + 1, + 0, + 0, + 0, + 0, + 3, + 1, + 0, + 0, + 0, + 0, + 5, + 1, + 0, + 0, + 0, + 0, + 7, + 1, + 0, + 0, + 0, + 0, + 9, + 1, + 0, + 0, + 0, + 0, + 11, + 1, + 0, + 0, + 0, + 0, + 13, + 1, + 0, + 0, + 0, + 0, + 15, + 1, + 0, + 0, + 0, + 0, + 17, + 1, + 0, + 0, + 0, + 0, + 19, + 1, + 0, + 0, + 0, + 0, + 21, + 1, + 0, + 0, + 0, + 0, + 23, + 1, + 0, + 0, + 0, + 0, + 25, + 1, + 0, + 0, + 0, + 0, + 33, + 1, + 0, + 0, + 0, + 0, + 35, + 1, + 0, + 0, + 0, + 0, + 37, + 1, + 0, + 0, + 0, + 0, + 39, + 1, + 0, + 0, + 0, + 0, + 41, + 1, + 0, + 0, + 0, + 0, + 43, + 1, + 0, + 0, + 0, + 1, + 45, + 1, + 0, + 0, + 0, + 3, + 47, + 1, + 0, + 0, + 0, + 5, + 49, + 1, + 0, + 0, + 0, + 7, + 51, + 1, + 0, + 0, + 0, + 9, + 53, + 1, + 0, + 0, + 0, + 11, + 55, + 1, + 0, + 0, + 0, + 13, + 57, + 1, + 0, + 0, + 0, + 15, + 59, + 1, + 0, + 0, + 0, + 17, + 63, + 1, + 0, + 0, + 0, + 19, + 79, + 1, + 0, + 0, + 0, + 21, + 82, + 1, + 0, + 0, + 0, + 23, + 84, + 1, + 0, + 0, + 0, + 25, + 86, + 1, + 0, + 0, + 0, + 27, + 88, + 1, + 0, + 0, + 0, + 29, + 90, + 1, + 0, + 0, + 0, + 31, + 94, + 1, + 0, + 0, + 0, + 33, + 97, + 1, + 0, + 0, + 0, + 35, + 109, + 1, + 0, + 0, + 0, + 37, + 113, + 1, + 0, + 0, + 0, + 39, + 115, + 1, + 0, + 0, + 0, + 41, + 127, + 1, + 0, + 0, + 0, + 43, + 129, + 1, + 0, + 0, + 0, + 45, + 46, + 5, + 46, + 0, + 0, + 46, + 2, + 1, + 0, + 0, + 0, + 47, + 48, + 5, + 45, + 0, + 0, + 48, + 4, + 1, + 0, + 0, + 0, + 49, + 50, + 5, + 40, + 0, + 0, + 50, + 6, + 1, + 0, + 0, + 0, + 51, + 52, + 5, + 41, + 0, + 0, + 52, + 8, + 1, + 0, + 0, + 0, + 53, + 54, + 5, + 47, + 0, + 0, + 54, + 10, + 1, + 0, + 0, + 0, + 55, + 56, + 5, + 42, + 0, + 0, + 56, + 12, + 1, + 0, + 0, + 0, + 57, + 58, + 5, + 43, + 0, + 0, + 58, + 14, + 1, + 0, + 0, + 0, + 59, + 60, + 5, + 115, + 0, + 0, + 60, + 61, + 5, + 117, + 0, + 0, + 61, + 62, + 5, + 109, + 0, + 0, + 62, + 16, + 1, + 0, + 0, + 0, + 63, + 64, + 5, + 115, + 0, + 0, + 64, + 65, + 5, + 117, + 0, + 0, + 65, + 66, + 5, + 109, + 0, + 0, + 66, + 67, + 5, + 95, + 0, + 0, + 67, + 68, + 5, + 99, + 0, + 0, + 68, + 69, + 5, + 111, + 0, + 0, + 69, + 70, + 5, + 110, + 0, + 0, + 70, + 71, + 5, + 110, + 0, + 0, + 71, + 72, + 5, + 101, + 0, + 0, + 72, + 73, + 5, + 99, + 0, + 0, + 73, + 74, + 5, + 116, + 0, + 0, + 74, + 75, + 5, + 105, + 0, + 0, + 75, + 76, + 5, + 111, + 0, + 0, + 76, + 77, + 5, + 110, + 0, + 0, + 77, + 78, + 5, + 115, + 0, + 0, + 78, + 18, + 1, + 0, + 0, + 0, + 79, + 80, + 5, + 46, + 0, + 0, + 80, + 81, + 5, + 46, + 0, + 0, + 81, + 20, + 1, + 0, + 0, + 0, + 82, + 83, + 5, + 44, + 0, + 0, + 83, + 22, + 1, + 0, + 0, + 0, + 84, + 85, + 5, + 91, + 0, + 0, + 85, + 24, + 1, + 0, + 0, + 0, + 86, + 87, + 5, + 93, + 0, + 0, + 87, + 26, + 1, + 0, + 0, + 0, + 88, + 89, + 7, + 0, + 0, + 0, + 89, + 28, + 1, + 0, + 0, + 0, + 90, + 91, + 7, + 1, + 0, + 0, + 91, + 30, + 1, + 0, + 0, + 0, + 92, + 95, + 3, + 29, + 14, + 0, + 93, + 95, + 3, + 27, + 13, + 0, + 94, + 92, + 1, + 0, + 0, + 0, + 94, + 93, + 1, + 0, + 0, + 0, + 95, + 32, + 1, + 0, + 0, + 0, + 96, + 98, + 3, + 27, + 13, + 0, + 97, + 96, + 1, + 0, + 0, + 0, + 98, + 99, + 1, + 0, + 0, + 0, + 99, + 97, + 1, + 0, + 0, + 0, + 99, + 100, + 1, + 0, + 0, + 0, + 100, + 107, + 1, + 0, + 0, + 0, + 101, + 103, + 5, + 46, + 0, + 0, + 102, + 104, + 3, + 27, + 13, + 0, + 103, + 102, + 1, + 0, + 0, + 0, + 104, + 105, + 1, + 0, + 0, + 0, + 105, + 103, + 1, + 0, + 0, + 0, + 105, + 106, + 1, + 0, + 0, + 0, + 106, + 108, + 1, + 0, + 0, + 0, + 107, + 101, + 1, + 0, + 0, + 0, + 107, + 108, + 1, + 0, + 0, + 0, + 108, + 34, + 1, + 0, + 0, + 0, + 109, + 110, + 5, + 109, + 0, + 0, + 110, + 111, + 5, + 97, + 0, + 0, + 111, + 112, + 5, + 120, + 0, + 0, + 112, + 36, + 1, + 0, + 0, + 0, + 113, + 114, + 5, + 116, + 0, + 0, + 114, + 38, + 1, + 0, + 0, + 0, + 115, + 119, + 3, + 29, + 14, + 0, + 116, + 118, + 3, + 31, + 15, + 0, + 117, + 116, + 1, + 0, + 0, + 0, + 118, + 121, + 1, + 0, + 0, + 0, + 119, + 117, + 1, + 0, + 0, + 0, + 119, + 120, + 1, + 0, + 0, + 0, + 120, + 40, + 1, + 0, + 0, + 0, + 121, + 119, + 1, + 0, + 0, + 0, + 122, + 128, + 5, + 61, + 0, + 0, + 123, + 124, + 5, + 62, + 0, + 0, + 124, + 128, + 5, + 61, + 0, + 0, + 125, + 126, + 5, + 60, + 0, + 0, + 126, + 128, + 5, + 61, + 0, + 0, + 127, + 122, + 1, + 0, + 0, + 0, + 127, + 123, + 1, + 0, + 0, + 0, + 127, + 125, + 1, + 0, + 0, + 0, + 128, + 42, + 1, + 0, + 0, + 0, + 129, + 130, + 7, + 2, + 0, + 0, + 130, + 131, + 1, + 0, + 0, + 0, + 131, + 132, + 6, + 21, + 0, + 0, + 132, + 44, + 1, + 0, + 0, + 0, + 7, + 0, + 94, + 99, + 105, + 107, + 119, + 127, + 1, + 6, + 0, + 0, ] -class ExprLexer(Lexer): +class ExprLexer(Lexer): atn = ATNDeserializer().deserialize(serializedATN()) - decisionsToDFA = [ DFA(ds, i) for i, ds in enumerate(atn.decisionToState) ] + decisionsToDFA = [DFA(ds, i) for i, ds in enumerate(atn.decisionToState)] T__0 = 1 T__1 = 2 @@ -83,29 +1217,71 @@ class ExprLexer(Lexer): COMPARISON = 18 WS = 19 - channelNames = [ u"DEFAULT_TOKEN_CHANNEL", u"HIDDEN" ] + channelNames = ["DEFAULT_TOKEN_CHANNEL", "HIDDEN"] - modeNames = [ "DEFAULT_MODE" ] + modeNames = ["DEFAULT_MODE"] - literalNames = [ "", - "'.'", "'-'", "'('", "')'", "'/'", "'*'", "'+'", "'sum'", "'sum_connections'", - "'..'", "','", "'['", "']'", "'max'", "'t'" ] + literalNames = [ + "", + "'.'", + "'-'", + "'('", + "')'", + "'/'", + "'*'", + "'+'", + "'sum'", + "'sum_connections'", + "'..'", + "','", + "'['", + "']'", + "'max'", + "'t'", + ] - symbolicNames = [ "", - "NUMBER", "MAX", "TIME", "IDENTIFIER", "COMPARISON", "WS" ] + symbolicNames = [ + "", + "NUMBER", + "MAX", + "TIME", + "IDENTIFIER", + "COMPARISON", + "WS", + ] - ruleNames = [ "T__0", "T__1", "T__2", "T__3", "T__4", "T__5", "T__6", - "T__7", "T__8", "T__9", "T__10", "T__11", "T__12", "DIGIT", - "CHAR", "CHAR_OR_DIGIT", "NUMBER", "MAX", "TIME", "IDENTIFIER", - "COMPARISON", "WS" ] + ruleNames = [ + "T__0", + "T__1", + "T__2", + "T__3", + "T__4", + "T__5", + "T__6", + "T__7", + "T__8", + "T__9", + "T__10", + "T__11", + "T__12", + "DIGIT", + "CHAR", + "CHAR_OR_DIGIT", + "NUMBER", + "MAX", + "TIME", + "IDENTIFIER", + "COMPARISON", + "WS", + ] grammarFileName = "Expr.g4" - def __init__(self, input=None, output:TextIO = sys.stdout): + def __init__(self, input=None, output: TextIO = sys.stdout): super().__init__(input, output) self.checkVersion("4.13.2") - self._interp = LexerATNSimulator(self, self.atn, self.decisionsToDFA, PredictionContextCache()) + self._interp = LexerATNSimulator( + self, self.atn, self.decisionsToDFA, PredictionContextCache() + ) self._actions = None self._predicates = None - - diff --git a/src/gems/expression/parsing/antlr/ExprParser.py b/src/gems/expression/parsing/antlr/ExprParser.py index 77e0781b..3175ed5f 100644 --- a/src/gems/expression/parsing/antlr/ExprParser.py +++ b/src/gems/expression/parsing/antlr/ExprParser.py @@ -3,85 +3,1430 @@ from antlr4 import * from io import StringIO import sys + if sys.version_info[1] > 5: - from typing import TextIO + from typing import TextIO else: - from typing.io import TextIO + from typing.io import TextIO + def serializedATN(): return [ - 4,1,19,152,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7, - 6,1,0,1,0,1,0,1,0,1,1,1,1,1,1,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1, - 2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1, - 2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1, - 2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1, - 2,1,2,1,2,1,2,1,2,1,2,5,2,84,8,2,10,2,12,2,87,9,2,1,2,1,2,3,2,91, - 8,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,5,2,102,8,2,10,2,12,2,105, - 9,2,1,3,1,3,3,3,109,8,3,1,4,1,4,3,4,113,8,4,1,5,1,5,1,5,1,5,1,5, - 1,5,1,5,1,5,3,5,123,8,5,1,5,1,5,1,5,1,5,1,5,1,5,5,5,131,8,5,10,5, - 12,5,134,9,5,1,6,1,6,1,6,1,6,1,6,1,6,3,6,142,8,6,1,6,1,6,1,6,5,6, - 147,8,6,10,6,12,6,150,9,6,1,6,0,3,4,10,12,7,0,2,4,6,8,10,12,0,2, - 1,0,5,6,2,0,2,2,7,7,167,0,14,1,0,0,0,2,18,1,0,0,0,4,90,1,0,0,0,6, - 108,1,0,0,0,8,110,1,0,0,0,10,122,1,0,0,0,12,141,1,0,0,0,14,15,5, - 17,0,0,15,16,5,1,0,0,16,17,5,17,0,0,17,1,1,0,0,0,18,19,3,4,2,0,19, - 20,5,0,0,1,20,3,1,0,0,0,21,22,6,2,-1,0,22,91,3,6,3,0,23,91,3,0,0, - 0,24,25,5,2,0,0,25,91,3,4,2,14,26,27,5,3,0,0,27,28,3,4,2,0,28,29, - 5,4,0,0,29,91,1,0,0,0,30,31,5,8,0,0,31,32,5,3,0,0,32,33,3,4,2,0, - 33,34,5,4,0,0,34,91,1,0,0,0,35,36,5,9,0,0,36,37,5,3,0,0,37,38,3, - 0,0,0,38,39,5,4,0,0,39,91,1,0,0,0,40,41,5,8,0,0,41,42,5,3,0,0,42, - 43,3,8,4,0,43,44,5,10,0,0,44,45,3,8,4,0,45,46,5,11,0,0,46,47,3,4, - 2,0,47,48,5,4,0,0,48,91,1,0,0,0,49,50,5,17,0,0,50,51,5,3,0,0,51, - 52,3,4,2,0,52,53,5,4,0,0,53,91,1,0,0,0,54,55,5,17,0,0,55,56,5,12, - 0,0,56,57,3,8,4,0,57,58,5,13,0,0,58,91,1,0,0,0,59,60,5,17,0,0,60, - 61,5,12,0,0,61,62,3,4,2,0,62,63,5,13,0,0,63,91,1,0,0,0,64,65,5,3, - 0,0,65,66,3,4,2,0,66,67,5,4,0,0,67,68,5,12,0,0,68,69,3,8,4,0,69, - 70,5,13,0,0,70,91,1,0,0,0,71,72,5,3,0,0,72,73,3,4,2,0,73,74,5,4, - 0,0,74,75,5,12,0,0,75,76,3,4,2,0,76,77,5,13,0,0,77,91,1,0,0,0,78, - 79,5,15,0,0,79,80,5,3,0,0,80,85,3,4,2,0,81,82,5,11,0,0,82,84,3,4, - 2,0,83,81,1,0,0,0,84,87,1,0,0,0,85,83,1,0,0,0,85,86,1,0,0,0,86,88, - 1,0,0,0,87,85,1,0,0,0,88,89,5,4,0,0,89,91,1,0,0,0,90,21,1,0,0,0, - 90,23,1,0,0,0,90,24,1,0,0,0,90,26,1,0,0,0,90,30,1,0,0,0,90,35,1, - 0,0,0,90,40,1,0,0,0,90,49,1,0,0,0,90,54,1,0,0,0,90,59,1,0,0,0,90, - 64,1,0,0,0,90,71,1,0,0,0,90,78,1,0,0,0,91,103,1,0,0,0,92,93,10,12, - 0,0,93,94,7,0,0,0,94,102,3,4,2,13,95,96,10,11,0,0,96,97,7,1,0,0, - 97,102,3,4,2,12,98,99,10,10,0,0,99,100,5,18,0,0,100,102,3,4,2,11, - 101,92,1,0,0,0,101,95,1,0,0,0,101,98,1,0,0,0,102,105,1,0,0,0,103, - 101,1,0,0,0,103,104,1,0,0,0,104,5,1,0,0,0,105,103,1,0,0,0,106,109, - 5,14,0,0,107,109,5,17,0,0,108,106,1,0,0,0,108,107,1,0,0,0,109,7, - 1,0,0,0,110,112,5,16,0,0,111,113,3,10,5,0,112,111,1,0,0,0,112,113, - 1,0,0,0,113,9,1,0,0,0,114,115,6,5,-1,0,115,116,7,1,0,0,116,123,3, - 6,3,0,117,118,7,1,0,0,118,119,5,3,0,0,119,120,3,4,2,0,120,121,5, - 4,0,0,121,123,1,0,0,0,122,114,1,0,0,0,122,117,1,0,0,0,123,132,1, - 0,0,0,124,125,10,4,0,0,125,126,7,0,0,0,126,131,3,12,6,0,127,128, - 10,3,0,0,128,129,7,1,0,0,129,131,3,12,6,0,130,124,1,0,0,0,130,127, - 1,0,0,0,131,134,1,0,0,0,132,130,1,0,0,0,132,133,1,0,0,0,133,11,1, - 0,0,0,134,132,1,0,0,0,135,136,6,6,-1,0,136,137,5,3,0,0,137,138,3, - 4,2,0,138,139,5,4,0,0,139,142,1,0,0,0,140,142,3,6,3,0,141,135,1, - 0,0,0,141,140,1,0,0,0,142,148,1,0,0,0,143,144,10,3,0,0,144,145,7, - 0,0,0,145,147,3,12,6,4,146,143,1,0,0,0,147,150,1,0,0,0,148,146,1, - 0,0,0,148,149,1,0,0,0,149,13,1,0,0,0,150,148,1,0,0,0,11,85,90,101, - 103,108,112,122,130,132,141,148 + 4, + 1, + 19, + 152, + 2, + 0, + 7, + 0, + 2, + 1, + 7, + 1, + 2, + 2, + 7, + 2, + 2, + 3, + 7, + 3, + 2, + 4, + 7, + 4, + 2, + 5, + 7, + 5, + 2, + 6, + 7, + 6, + 1, + 0, + 1, + 0, + 1, + 0, + 1, + 0, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 5, + 2, + 84, + 8, + 2, + 10, + 2, + 12, + 2, + 87, + 9, + 2, + 1, + 2, + 1, + 2, + 3, + 2, + 91, + 8, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 5, + 2, + 102, + 8, + 2, + 10, + 2, + 12, + 2, + 105, + 9, + 2, + 1, + 3, + 1, + 3, + 3, + 3, + 109, + 8, + 3, + 1, + 4, + 1, + 4, + 3, + 4, + 113, + 8, + 4, + 1, + 5, + 1, + 5, + 1, + 5, + 1, + 5, + 1, + 5, + 1, + 5, + 1, + 5, + 1, + 5, + 3, + 5, + 123, + 8, + 5, + 1, + 5, + 1, + 5, + 1, + 5, + 1, + 5, + 1, + 5, + 1, + 5, + 5, + 5, + 131, + 8, + 5, + 10, + 5, + 12, + 5, + 134, + 9, + 5, + 1, + 6, + 1, + 6, + 1, + 6, + 1, + 6, + 1, + 6, + 1, + 6, + 3, + 6, + 142, + 8, + 6, + 1, + 6, + 1, + 6, + 1, + 6, + 5, + 6, + 147, + 8, + 6, + 10, + 6, + 12, + 6, + 150, + 9, + 6, + 1, + 6, + 0, + 3, + 4, + 10, + 12, + 7, + 0, + 2, + 4, + 6, + 8, + 10, + 12, + 0, + 2, + 1, + 0, + 5, + 6, + 2, + 0, + 2, + 2, + 7, + 7, + 167, + 0, + 14, + 1, + 0, + 0, + 0, + 2, + 18, + 1, + 0, + 0, + 0, + 4, + 90, + 1, + 0, + 0, + 0, + 6, + 108, + 1, + 0, + 0, + 0, + 8, + 110, + 1, + 0, + 0, + 0, + 10, + 122, + 1, + 0, + 0, + 0, + 12, + 141, + 1, + 0, + 0, + 0, + 14, + 15, + 5, + 17, + 0, + 0, + 15, + 16, + 5, + 1, + 0, + 0, + 16, + 17, + 5, + 17, + 0, + 0, + 17, + 1, + 1, + 0, + 0, + 0, + 18, + 19, + 3, + 4, + 2, + 0, + 19, + 20, + 5, + 0, + 0, + 1, + 20, + 3, + 1, + 0, + 0, + 0, + 21, + 22, + 6, + 2, + -1, + 0, + 22, + 91, + 3, + 6, + 3, + 0, + 23, + 91, + 3, + 0, + 0, + 0, + 24, + 25, + 5, + 2, + 0, + 0, + 25, + 91, + 3, + 4, + 2, + 14, + 26, + 27, + 5, + 3, + 0, + 0, + 27, + 28, + 3, + 4, + 2, + 0, + 28, + 29, + 5, + 4, + 0, + 0, + 29, + 91, + 1, + 0, + 0, + 0, + 30, + 31, + 5, + 8, + 0, + 0, + 31, + 32, + 5, + 3, + 0, + 0, + 32, + 33, + 3, + 4, + 2, + 0, + 33, + 34, + 5, + 4, + 0, + 0, + 34, + 91, + 1, + 0, + 0, + 0, + 35, + 36, + 5, + 9, + 0, + 0, + 36, + 37, + 5, + 3, + 0, + 0, + 37, + 38, + 3, + 0, + 0, + 0, + 38, + 39, + 5, + 4, + 0, + 0, + 39, + 91, + 1, + 0, + 0, + 0, + 40, + 41, + 5, + 8, + 0, + 0, + 41, + 42, + 5, + 3, + 0, + 0, + 42, + 43, + 3, + 8, + 4, + 0, + 43, + 44, + 5, + 10, + 0, + 0, + 44, + 45, + 3, + 8, + 4, + 0, + 45, + 46, + 5, + 11, + 0, + 0, + 46, + 47, + 3, + 4, + 2, + 0, + 47, + 48, + 5, + 4, + 0, + 0, + 48, + 91, + 1, + 0, + 0, + 0, + 49, + 50, + 5, + 17, + 0, + 0, + 50, + 51, + 5, + 3, + 0, + 0, + 51, + 52, + 3, + 4, + 2, + 0, + 52, + 53, + 5, + 4, + 0, + 0, + 53, + 91, + 1, + 0, + 0, + 0, + 54, + 55, + 5, + 17, + 0, + 0, + 55, + 56, + 5, + 12, + 0, + 0, + 56, + 57, + 3, + 8, + 4, + 0, + 57, + 58, + 5, + 13, + 0, + 0, + 58, + 91, + 1, + 0, + 0, + 0, + 59, + 60, + 5, + 17, + 0, + 0, + 60, + 61, + 5, + 12, + 0, + 0, + 61, + 62, + 3, + 4, + 2, + 0, + 62, + 63, + 5, + 13, + 0, + 0, + 63, + 91, + 1, + 0, + 0, + 0, + 64, + 65, + 5, + 3, + 0, + 0, + 65, + 66, + 3, + 4, + 2, + 0, + 66, + 67, + 5, + 4, + 0, + 0, + 67, + 68, + 5, + 12, + 0, + 0, + 68, + 69, + 3, + 8, + 4, + 0, + 69, + 70, + 5, + 13, + 0, + 0, + 70, + 91, + 1, + 0, + 0, + 0, + 71, + 72, + 5, + 3, + 0, + 0, + 72, + 73, + 3, + 4, + 2, + 0, + 73, + 74, + 5, + 4, + 0, + 0, + 74, + 75, + 5, + 12, + 0, + 0, + 75, + 76, + 3, + 4, + 2, + 0, + 76, + 77, + 5, + 13, + 0, + 0, + 77, + 91, + 1, + 0, + 0, + 0, + 78, + 79, + 5, + 15, + 0, + 0, + 79, + 80, + 5, + 3, + 0, + 0, + 80, + 85, + 3, + 4, + 2, + 0, + 81, + 82, + 5, + 11, + 0, + 0, + 82, + 84, + 3, + 4, + 2, + 0, + 83, + 81, + 1, + 0, + 0, + 0, + 84, + 87, + 1, + 0, + 0, + 0, + 85, + 83, + 1, + 0, + 0, + 0, + 85, + 86, + 1, + 0, + 0, + 0, + 86, + 88, + 1, + 0, + 0, + 0, + 87, + 85, + 1, + 0, + 0, + 0, + 88, + 89, + 5, + 4, + 0, + 0, + 89, + 91, + 1, + 0, + 0, + 0, + 90, + 21, + 1, + 0, + 0, + 0, + 90, + 23, + 1, + 0, + 0, + 0, + 90, + 24, + 1, + 0, + 0, + 0, + 90, + 26, + 1, + 0, + 0, + 0, + 90, + 30, + 1, + 0, + 0, + 0, + 90, + 35, + 1, + 0, + 0, + 0, + 90, + 40, + 1, + 0, + 0, + 0, + 90, + 49, + 1, + 0, + 0, + 0, + 90, + 54, + 1, + 0, + 0, + 0, + 90, + 59, + 1, + 0, + 0, + 0, + 90, + 64, + 1, + 0, + 0, + 0, + 90, + 71, + 1, + 0, + 0, + 0, + 90, + 78, + 1, + 0, + 0, + 0, + 91, + 103, + 1, + 0, + 0, + 0, + 92, + 93, + 10, + 12, + 0, + 0, + 93, + 94, + 7, + 0, + 0, + 0, + 94, + 102, + 3, + 4, + 2, + 13, + 95, + 96, + 10, + 11, + 0, + 0, + 96, + 97, + 7, + 1, + 0, + 0, + 97, + 102, + 3, + 4, + 2, + 12, + 98, + 99, + 10, + 10, + 0, + 0, + 99, + 100, + 5, + 18, + 0, + 0, + 100, + 102, + 3, + 4, + 2, + 11, + 101, + 92, + 1, + 0, + 0, + 0, + 101, + 95, + 1, + 0, + 0, + 0, + 101, + 98, + 1, + 0, + 0, + 0, + 102, + 105, + 1, + 0, + 0, + 0, + 103, + 101, + 1, + 0, + 0, + 0, + 103, + 104, + 1, + 0, + 0, + 0, + 104, + 5, + 1, + 0, + 0, + 0, + 105, + 103, + 1, + 0, + 0, + 0, + 106, + 109, + 5, + 14, + 0, + 0, + 107, + 109, + 5, + 17, + 0, + 0, + 108, + 106, + 1, + 0, + 0, + 0, + 108, + 107, + 1, + 0, + 0, + 0, + 109, + 7, + 1, + 0, + 0, + 0, + 110, + 112, + 5, + 16, + 0, + 0, + 111, + 113, + 3, + 10, + 5, + 0, + 112, + 111, + 1, + 0, + 0, + 0, + 112, + 113, + 1, + 0, + 0, + 0, + 113, + 9, + 1, + 0, + 0, + 0, + 114, + 115, + 6, + 5, + -1, + 0, + 115, + 116, + 7, + 1, + 0, + 0, + 116, + 123, + 3, + 6, + 3, + 0, + 117, + 118, + 7, + 1, + 0, + 0, + 118, + 119, + 5, + 3, + 0, + 0, + 119, + 120, + 3, + 4, + 2, + 0, + 120, + 121, + 5, + 4, + 0, + 0, + 121, + 123, + 1, + 0, + 0, + 0, + 122, + 114, + 1, + 0, + 0, + 0, + 122, + 117, + 1, + 0, + 0, + 0, + 123, + 132, + 1, + 0, + 0, + 0, + 124, + 125, + 10, + 4, + 0, + 0, + 125, + 126, + 7, + 0, + 0, + 0, + 126, + 131, + 3, + 12, + 6, + 0, + 127, + 128, + 10, + 3, + 0, + 0, + 128, + 129, + 7, + 1, + 0, + 0, + 129, + 131, + 3, + 12, + 6, + 0, + 130, + 124, + 1, + 0, + 0, + 0, + 130, + 127, + 1, + 0, + 0, + 0, + 131, + 134, + 1, + 0, + 0, + 0, + 132, + 130, + 1, + 0, + 0, + 0, + 132, + 133, + 1, + 0, + 0, + 0, + 133, + 11, + 1, + 0, + 0, + 0, + 134, + 132, + 1, + 0, + 0, + 0, + 135, + 136, + 6, + 6, + -1, + 0, + 136, + 137, + 5, + 3, + 0, + 0, + 137, + 138, + 3, + 4, + 2, + 0, + 138, + 139, + 5, + 4, + 0, + 0, + 139, + 142, + 1, + 0, + 0, + 0, + 140, + 142, + 3, + 6, + 3, + 0, + 141, + 135, + 1, + 0, + 0, + 0, + 141, + 140, + 1, + 0, + 0, + 0, + 142, + 148, + 1, + 0, + 0, + 0, + 143, + 144, + 10, + 3, + 0, + 0, + 144, + 145, + 7, + 0, + 0, + 0, + 145, + 147, + 3, + 12, + 6, + 4, + 146, + 143, + 1, + 0, + 0, + 0, + 147, + 150, + 1, + 0, + 0, + 0, + 148, + 146, + 1, + 0, + 0, + 0, + 148, + 149, + 1, + 0, + 0, + 0, + 149, + 13, + 1, + 0, + 0, + 0, + 150, + 148, + 1, + 0, + 0, + 0, + 11, + 85, + 90, + 101, + 103, + 108, + 112, + 122, + 130, + 132, + 141, + 148, ] -class ExprParser ( Parser ): +class ExprParser(Parser): grammarFileName = "Expr.g4" atn = ATNDeserializer().deserialize(serializedATN()) - decisionsToDFA = [ DFA(ds, i) for i, ds in enumerate(atn.decisionToState) ] + decisionsToDFA = [DFA(ds, i) for i, ds in enumerate(atn.decisionToState)] sharedContextCache = PredictionContextCache() - literalNames = [ "", "'.'", "'-'", "'('", "')'", "'/'", "'*'", - "'+'", "'sum'", "'sum_connections'", "'..'", "','", - "'['", "']'", "", "'max'", "'t'" ] + literalNames = [ + "", + "'.'", + "'-'", + "'('", + "')'", + "'/'", + "'*'", + "'+'", + "'sum'", + "'sum_connections'", + "'..'", + "','", + "'['", + "']'", + "", + "'max'", + "'t'", + ] - symbolicNames = [ "", "", "", "", - "", "", "", "", - "", "", "", "", - "", "", "NUMBER", "MAX", "TIME", - "IDENTIFIER", "COMPARISON", "WS" ] + symbolicNames = [ + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "NUMBER", + "MAX", + "TIME", + "IDENTIFIER", + "COMPARISON", + "WS", + ] RULE_portFieldExpr = 0 RULE_fullexpr = 1 @@ -91,47 +1436,55 @@ class ExprParser ( Parser ): RULE_shift_expr = 5 RULE_right_expr = 6 - ruleNames = [ "portFieldExpr", "fullexpr", "expr", "atom", "shift", - "shift_expr", "right_expr" ] + ruleNames = [ + "portFieldExpr", + "fullexpr", + "expr", + "atom", + "shift", + "shift_expr", + "right_expr", + ] EOF = Token.EOF - T__0=1 - T__1=2 - T__2=3 - T__3=4 - T__4=5 - T__5=6 - T__6=7 - T__7=8 - T__8=9 - T__9=10 - T__10=11 - T__11=12 - T__12=13 - NUMBER=14 - MAX=15 - TIME=16 - IDENTIFIER=17 - COMPARISON=18 - WS=19 - - def __init__(self, input:TokenStream, output:TextIO = sys.stdout): + T__0 = 1 + T__1 = 2 + T__2 = 3 + T__3 = 4 + T__4 = 5 + T__5 = 6 + T__6 = 7 + T__7 = 8 + T__8 = 9 + T__9 = 10 + T__10 = 11 + T__11 = 12 + T__12 = 13 + NUMBER = 14 + MAX = 15 + TIME = 16 + IDENTIFIER = 17 + COMPARISON = 18 + WS = 19 + + def __init__(self, input: TokenStream, output: TextIO = sys.stdout): super().__init__(input, output) self.checkVersion("4.13.2") - self._interp = ParserATNSimulator(self, self.atn, self.decisionsToDFA, self.sharedContextCache) + self._interp = ParserATNSimulator( + self, self.atn, self.decisionsToDFA, self.sharedContextCache + ) self._predicates = None - - - class PortFieldExprContext(ParserRuleContext): - __slots__ = 'parser' + __slots__ = "parser" - def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): + def __init__( + self, parser, parent: ParserRuleContext = None, invokingState: int = -1 + ): super().__init__(parent, invokingState) self.parser = parser - def IDENTIFIER(self, i:int=None): + def IDENTIFIER(self, i: int = None): if i is None: return self.getTokens(ExprParser.IDENTIFIER) else: @@ -140,17 +1493,13 @@ def IDENTIFIER(self, i:int=None): def getRuleIndex(self): return ExprParser.RULE_portFieldExpr - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitPortFieldExpr" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitPortFieldExpr"): return visitor.visitPortFieldExpr(self) else: return visitor.visitChildren(self) - - - def portFieldExpr(self): - localctx = ExprParser.PortFieldExprContext(self, self._ctx, self.state) self.enterRule(localctx, 0, self.RULE_portFieldExpr) try: @@ -169,17 +1518,17 @@ def portFieldExpr(self): self.exitRule() return localctx - class FullexprContext(ParserRuleContext): - __slots__ = 'parser' + __slots__ = "parser" - def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): + def __init__( + self, parser, parent: ParserRuleContext = None, invokingState: int = -1 + ): super().__init__(parent, invokingState) self.parser = parser def expr(self): - return self.getTypedRuleContext(ExprParser.ExprContext,0) - + return self.getTypedRuleContext(ExprParser.ExprContext, 0) def EOF(self): return self.getToken(ExprParser.EOF, 0) @@ -187,17 +1536,13 @@ def EOF(self): def getRuleIndex(self): return ExprParser.RULE_fullexpr - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitFullexpr" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitFullexpr"): return visitor.visitFullexpr(self) else: return visitor.visitChildren(self) - - - def fullexpr(self): - localctx = ExprParser.FullexprContext(self, self._ctx, self.state) self.enterRule(localctx, 2, self.RULE_fullexpr) try: @@ -214,347 +1559,333 @@ def fullexpr(self): self.exitRule() return localctx - class ExprContext(ParserRuleContext): - __slots__ = 'parser' + __slots__ = "parser" - def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): + def __init__( + self, parser, parent: ParserRuleContext = None, invokingState: int = -1 + ): super().__init__(parent, invokingState) self.parser = parser - def getRuleIndex(self): return ExprParser.RULE_expr - - def copyFrom(self, ctx:ParserRuleContext): + def copyFrom(self, ctx: ParserRuleContext): super().copyFrom(ctx) - class PortFieldSumContext(ExprContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) def portFieldExpr(self): - return self.getTypedRuleContext(ExprParser.PortFieldExprContext,0) + return self.getTypedRuleContext(ExprParser.PortFieldExprContext, 0) - - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitPortFieldSum" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitPortFieldSum"): return visitor.visitPortFieldSum(self) else: return visitor.visitChildren(self) - class NegationContext(ExprContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) def expr(self): - return self.getTypedRuleContext(ExprParser.ExprContext,0) - + return self.getTypedRuleContext(ExprParser.ExprContext, 0) - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitNegation" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitNegation"): return visitor.visitNegation(self) else: return visitor.visitChildren(self) - class UnsignedAtomContext(ExprContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) def atom(self): - return self.getTypedRuleContext(ExprParser.AtomContext,0) + return self.getTypedRuleContext(ExprParser.AtomContext, 0) - - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitUnsignedAtom" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitUnsignedAtom"): return visitor.visitUnsignedAtom(self) else: return visitor.visitChildren(self) - class ExpressionContext(ExprContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) def expr(self): - return self.getTypedRuleContext(ExprParser.ExprContext,0) - + return self.getTypedRuleContext(ExprParser.ExprContext, 0) - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitExpression" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitExpression"): return visitor.visitExpression(self) else: return visitor.visitChildren(self) - class ComparisonContext(ExprContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) - def expr(self, i:int=None): + def expr(self, i: int = None): if i is None: return self.getTypedRuleContexts(ExprParser.ExprContext) else: - return self.getTypedRuleContext(ExprParser.ExprContext,i) + return self.getTypedRuleContext(ExprParser.ExprContext, i) def COMPARISON(self): return self.getToken(ExprParser.COMPARISON, 0) - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitComparison" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitComparison"): return visitor.visitComparison(self) else: return visitor.visitChildren(self) - class AllTimeSumContext(ExprContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) def expr(self): - return self.getTypedRuleContext(ExprParser.ExprContext,0) - + return self.getTypedRuleContext(ExprParser.ExprContext, 0) - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitAllTimeSum" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitAllTimeSum"): return visitor.visitAllTimeSum(self) else: return visitor.visitChildren(self) - class TimeIndexExprContext(ExprContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) - def expr(self, i:int=None): + def expr(self, i: int = None): if i is None: return self.getTypedRuleContexts(ExprParser.ExprContext) else: - return self.getTypedRuleContext(ExprParser.ExprContext,i) + return self.getTypedRuleContext(ExprParser.ExprContext, i) - - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitTimeIndexExpr" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitTimeIndexExpr"): return visitor.visitTimeIndexExpr(self) else: return visitor.visitChildren(self) - class AddsubContext(ExprContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.ExprContext super().__init__(parser) - self.op = None # Token + self.op = None # Token self.copyFrom(ctx) - def expr(self, i:int=None): + def expr(self, i: int = None): if i is None: return self.getTypedRuleContexts(ExprParser.ExprContext) else: - return self.getTypedRuleContext(ExprParser.ExprContext,i) - + return self.getTypedRuleContext(ExprParser.ExprContext, i) - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitAddsub" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitAddsub"): return visitor.visitAddsub(self) else: return visitor.visitChildren(self) - class TimeShiftExprContext(ExprContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) def expr(self): - return self.getTypedRuleContext(ExprParser.ExprContext,0) + return self.getTypedRuleContext(ExprParser.ExprContext, 0) def shift(self): - return self.getTypedRuleContext(ExprParser.ShiftContext,0) + return self.getTypedRuleContext(ExprParser.ShiftContext, 0) - - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitTimeShiftExpr" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitTimeShiftExpr"): return visitor.visitTimeShiftExpr(self) else: return visitor.visitChildren(self) - class PortFieldContext(ExprContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) def portFieldExpr(self): - return self.getTypedRuleContext(ExprParser.PortFieldExprContext,0) - + return self.getTypedRuleContext(ExprParser.PortFieldExprContext, 0) - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitPortField" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitPortField"): return visitor.visitPortField(self) else: return visitor.visitChildren(self) - class MuldivContext(ExprContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.ExprContext super().__init__(parser) - self.op = None # Token + self.op = None # Token self.copyFrom(ctx) - def expr(self, i:int=None): + def expr(self, i: int = None): if i is None: return self.getTypedRuleContexts(ExprParser.ExprContext) else: - return self.getTypedRuleContext(ExprParser.ExprContext,i) + return self.getTypedRuleContext(ExprParser.ExprContext, i) - - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitMuldiv" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitMuldiv"): return visitor.visitMuldiv(self) else: return visitor.visitChildren(self) - class TimeSumContext(ExprContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.ExprContext super().__init__(parser) - self.from_ = None # ShiftContext - self.to = None # ShiftContext + self.from_ = None # ShiftContext + self.to = None # ShiftContext self.copyFrom(ctx) def expr(self): - return self.getTypedRuleContext(ExprParser.ExprContext,0) + return self.getTypedRuleContext(ExprParser.ExprContext, 0) - def shift(self, i:int=None): + def shift(self, i: int = None): if i is None: return self.getTypedRuleContexts(ExprParser.ShiftContext) else: - return self.getTypedRuleContext(ExprParser.ShiftContext,i) - + return self.getTypedRuleContext(ExprParser.ShiftContext, i) - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitTimeSum" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitTimeSum"): return visitor.visitTimeSum(self) else: return visitor.visitChildren(self) - class MaxExprContext(ExprContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) def MAX(self): return self.getToken(ExprParser.MAX, 0) - def expr(self, i:int=None): + + def expr(self, i: int = None): if i is None: return self.getTypedRuleContexts(ExprParser.ExprContext) else: - return self.getTypedRuleContext(ExprParser.ExprContext,i) - + return self.getTypedRuleContext(ExprParser.ExprContext, i) - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitMaxExpr" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitMaxExpr"): return visitor.visitMaxExpr(self) else: return visitor.visitChildren(self) - class TimeIndexContext(ExprContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) def IDENTIFIER(self): return self.getToken(ExprParser.IDENTIFIER, 0) - def expr(self): - return self.getTypedRuleContext(ExprParser.ExprContext,0) + def expr(self): + return self.getTypedRuleContext(ExprParser.ExprContext, 0) - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitTimeIndex" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitTimeIndex"): return visitor.visitTimeIndex(self) else: return visitor.visitChildren(self) - class TimeShiftContext(ExprContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) def IDENTIFIER(self): return self.getToken(ExprParser.IDENTIFIER, 0) - def shift(self): - return self.getTypedRuleContext(ExprParser.ShiftContext,0) + def shift(self): + return self.getTypedRuleContext(ExprParser.ShiftContext, 0) - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitTimeShift" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitTimeShift"): return visitor.visitTimeShift(self) else: return visitor.visitChildren(self) - class FunctionContext(ExprContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) def IDENTIFIER(self): return self.getToken(ExprParser.IDENTIFIER, 0) - def expr(self): - return self.getTypedRuleContext(ExprParser.ExprContext,0) + def expr(self): + return self.getTypedRuleContext(ExprParser.ExprContext, 0) - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitFunction" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitFunction"): return visitor.visitFunction(self) else: return visitor.visitChildren(self) - - - def expr(self, _p:int=0): + def expr(self, _p: int = 0): _parentctx = self._ctx _parentState = self.state localctx = ExprParser.ExprContext(self, self._ctx, _parentState) _prevctx = localctx _startState = 4 self.enterRecursionRule(localctx, 4, self.RULE_expr, _p) - self._la = 0 # Token type + self._la = 0 # Token type try: self.enterOuterAlt(localctx, 1) self.state = 90 self._errHandler.sync(self) - la_ = self._interp.adaptivePredict(self._input,1,self._ctx) + la_ = self._interp.adaptivePredict(self._input, 1, self._ctx) if la_ == 1: localctx = ExprParser.UnsignedAtomContext(self, localctx) self._ctx = localctx @@ -735,7 +2066,7 @@ def expr(self, _p:int=0): self.state = 85 self._errHandler.sync(self) _la = self._input.LA(1) - while _la==11: + while _la == 11: self.state = 81 self.match(ExprParser.T__10) self.state = 82 @@ -748,30 +2079,36 @@ def expr(self, _p:int=0): self.match(ExprParser.T__3) pass - self._ctx.stop = self._input.LT(-1) self.state = 103 self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input,3,self._ctx) - while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER: - if _alt==1: + _alt = self._interp.adaptivePredict(self._input, 3, self._ctx) + while _alt != 2 and _alt != ATN.INVALID_ALT_NUMBER: + if _alt == 1: if self._parseListeners is not None: self.triggerExitRuleEvent() _prevctx = localctx self.state = 101 self._errHandler.sync(self) - la_ = self._interp.adaptivePredict(self._input,2,self._ctx) + la_ = self._interp.adaptivePredict(self._input, 2, self._ctx) if la_ == 1: - localctx = ExprParser.MuldivContext(self, ExprParser.ExprContext(self, _parentctx, _parentState)) - self.pushNewRecursionContext(localctx, _startState, self.RULE_expr) + localctx = ExprParser.MuldivContext( + self, ExprParser.ExprContext(self, _parentctx, _parentState) + ) + self.pushNewRecursionContext( + localctx, _startState, self.RULE_expr + ) self.state = 92 if not self.precpred(self._ctx, 12): from antlr4.error.Errors import FailedPredicateException - raise FailedPredicateException(self, "self.precpred(self._ctx, 12)") + + raise FailedPredicateException( + self, "self.precpred(self._ctx, 12)" + ) self.state = 93 localctx.op = self._input.LT(1) _la = self._input.LA(1) - if not(_la==5 or _la==6): + if not (_la == 5 or _la == 6): localctx.op = self._errHandler.recoverInline(self) else: self._errHandler.reportMatch(self) @@ -781,16 +2118,23 @@ def expr(self, _p:int=0): pass elif la_ == 2: - localctx = ExprParser.AddsubContext(self, ExprParser.ExprContext(self, _parentctx, _parentState)) - self.pushNewRecursionContext(localctx, _startState, self.RULE_expr) + localctx = ExprParser.AddsubContext( + self, ExprParser.ExprContext(self, _parentctx, _parentState) + ) + self.pushNewRecursionContext( + localctx, _startState, self.RULE_expr + ) self.state = 95 if not self.precpred(self._ctx, 11): from antlr4.error.Errors import FailedPredicateException - raise FailedPredicateException(self, "self.precpred(self._ctx, 11)") + + raise FailedPredicateException( + self, "self.precpred(self._ctx, 11)" + ) self.state = 96 localctx.op = self._input.LT(1) _la = self._input.LA(1) - if not(_la==2 or _la==7): + if not (_la == 2 or _la == 7): localctx.op = self._errHandler.recoverInline(self) else: self._errHandler.reportMatch(self) @@ -800,22 +2144,28 @@ def expr(self, _p:int=0): pass elif la_ == 3: - localctx = ExprParser.ComparisonContext(self, ExprParser.ExprContext(self, _parentctx, _parentState)) - self.pushNewRecursionContext(localctx, _startState, self.RULE_expr) + localctx = ExprParser.ComparisonContext( + self, ExprParser.ExprContext(self, _parentctx, _parentState) + ) + self.pushNewRecursionContext( + localctx, _startState, self.RULE_expr + ) self.state = 98 if not self.precpred(self._ctx, 10): from antlr4.error.Errors import FailedPredicateException - raise FailedPredicateException(self, "self.precpred(self._ctx, 10)") + + raise FailedPredicateException( + self, "self.precpred(self._ctx, 10)" + ) self.state = 99 self.match(ExprParser.COMPARISON) self.state = 100 self.expr(11) pass - self.state = 105 self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input,3,self._ctx) + _alt = self._interp.adaptivePredict(self._input, 3, self._ctx) except RecognitionException as re: localctx.exception = re @@ -825,59 +2175,54 @@ def expr(self, _p:int=0): self.unrollRecursionContexts(_parentctx) return localctx - class AtomContext(ParserRuleContext): - __slots__ = 'parser' + __slots__ = "parser" - def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): + def __init__( + self, parser, parent: ParserRuleContext = None, invokingState: int = -1 + ): super().__init__(parent, invokingState) self.parser = parser - def getRuleIndex(self): return ExprParser.RULE_atom - - def copyFrom(self, ctx:ParserRuleContext): + def copyFrom(self, ctx: ParserRuleContext): super().copyFrom(ctx) - - class NumberContext(AtomContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.AtomContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.AtomContext super().__init__(parser) self.copyFrom(ctx) def NUMBER(self): return self.getToken(ExprParser.NUMBER, 0) - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitNumber" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitNumber"): return visitor.visitNumber(self) else: return visitor.visitChildren(self) - class IdentifierContext(AtomContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.AtomContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.AtomContext super().__init__(parser) self.copyFrom(ctx) def IDENTIFIER(self): return self.getToken(ExprParser.IDENTIFIER, 0) - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitIdentifier" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitIdentifier"): return visitor.visitIdentifier(self) else: return visitor.visitChildren(self) - - def atom(self): - localctx = ExprParser.AtomContext(self, self._ctx, self.state) self.enterRule(localctx, 6, self.RULE_atom) try: @@ -907,11 +2252,12 @@ def atom(self): self.exitRule() return localctx - class ShiftContext(ParserRuleContext): - __slots__ = 'parser' + __slots__ = "parser" - def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): + def __init__( + self, parser, parent: ParserRuleContext = None, invokingState: int = -1 + ): super().__init__(parent, invokingState) self.parser = parser @@ -919,26 +2265,21 @@ def TIME(self): return self.getToken(ExprParser.TIME, 0) def shift_expr(self): - return self.getTypedRuleContext(ExprParser.Shift_exprContext,0) - + return self.getTypedRuleContext(ExprParser.Shift_exprContext, 0) def getRuleIndex(self): return ExprParser.RULE_shift - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitShift" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitShift"): return visitor.visitShift(self) else: return visitor.visitChildren(self) - - - def shift(self): - localctx = ExprParser.ShiftContext(self, self._ctx, self.state) self.enterRule(localctx, 8, self.RULE_shift) - self._la = 0 # Token type + self._la = 0 # Token type try: self.enterOuterAlt(localctx, 1) self.state = 110 @@ -946,11 +2287,10 @@ def shift(self): self.state = 112 self._errHandler.sync(self) _la = self._input.LA(1) - if _la==2 or _la==7: + if _la == 2 or _la == 7: self.state = 111 self.shift_expr(0) - except RecognitionException as re: localctx.exception = re self._errHandler.reportError(self, re) @@ -959,115 +2299,108 @@ def shift(self): self.exitRule() return localctx - class Shift_exprContext(ParserRuleContext): - __slots__ = 'parser' + __slots__ = "parser" - def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): + def __init__( + self, parser, parent: ParserRuleContext = None, invokingState: int = -1 + ): super().__init__(parent, invokingState) self.parser = parser - def getRuleIndex(self): return ExprParser.RULE_shift_expr - - def copyFrom(self, ctx:ParserRuleContext): + def copyFrom(self, ctx: ParserRuleContext): super().copyFrom(ctx) - class SignedAtomContext(Shift_exprContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.Shift_exprContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.Shift_exprContext super().__init__(parser) - self.op = None # Token + self.op = None # Token self.copyFrom(ctx) def atom(self): - return self.getTypedRuleContext(ExprParser.AtomContext,0) + return self.getTypedRuleContext(ExprParser.AtomContext, 0) - - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitSignedAtom" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitSignedAtom"): return visitor.visitSignedAtom(self) else: return visitor.visitChildren(self) - class SignedExpressionContext(Shift_exprContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.Shift_exprContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.Shift_exprContext super().__init__(parser) - self.op = None # Token + self.op = None # Token self.copyFrom(ctx) def expr(self): - return self.getTypedRuleContext(ExprParser.ExprContext,0) - + return self.getTypedRuleContext(ExprParser.ExprContext, 0) - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitSignedExpression" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitSignedExpression"): return visitor.visitSignedExpression(self) else: return visitor.visitChildren(self) - class ShiftMuldivContext(Shift_exprContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.Shift_exprContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.Shift_exprContext super().__init__(parser) - self.op = None # Token + self.op = None # Token self.copyFrom(ctx) def shift_expr(self): - return self.getTypedRuleContext(ExprParser.Shift_exprContext,0) + return self.getTypedRuleContext(ExprParser.Shift_exprContext, 0) def right_expr(self): - return self.getTypedRuleContext(ExprParser.Right_exprContext,0) - + return self.getTypedRuleContext(ExprParser.Right_exprContext, 0) - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitShiftMuldiv" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitShiftMuldiv"): return visitor.visitShiftMuldiv(self) else: return visitor.visitChildren(self) - class ShiftAddsubContext(Shift_exprContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.Shift_exprContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.Shift_exprContext super().__init__(parser) - self.op = None # Token + self.op = None # Token self.copyFrom(ctx) def shift_expr(self): - return self.getTypedRuleContext(ExprParser.Shift_exprContext,0) + return self.getTypedRuleContext(ExprParser.Shift_exprContext, 0) def right_expr(self): - return self.getTypedRuleContext(ExprParser.Right_exprContext,0) + return self.getTypedRuleContext(ExprParser.Right_exprContext, 0) - - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitShiftAddsub" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitShiftAddsub"): return visitor.visitShiftAddsub(self) else: return visitor.visitChildren(self) - - - def shift_expr(self, _p:int=0): + def shift_expr(self, _p: int = 0): _parentctx = self._ctx _parentState = self.state localctx = ExprParser.Shift_exprContext(self, self._ctx, _parentState) _prevctx = localctx _startState = 10 self.enterRecursionRule(localctx, 10, self.RULE_shift_expr, _p) - self._la = 0 # Token type + self._la = 0 # Token type try: self.enterOuterAlt(localctx, 1) self.state = 122 self._errHandler.sync(self) - la_ = self._interp.adaptivePredict(self._input,6,self._ctx) + la_ = self._interp.adaptivePredict(self._input, 6, self._ctx) if la_ == 1: localctx = ExprParser.SignedAtomContext(self, localctx) self._ctx = localctx @@ -1076,7 +2409,7 @@ def shift_expr(self, _p:int=0): self.state = 115 localctx.op = self._input.LT(1) _la = self._input.LA(1) - if not(_la==2 or _la==7): + if not (_la == 2 or _la == 7): localctx.op = self._errHandler.recoverInline(self) else: self._errHandler.reportMatch(self) @@ -1092,7 +2425,7 @@ def shift_expr(self, _p:int=0): self.state = 117 localctx.op = self._input.LT(1) _la = self._input.LA(1) - if not(_la==2 or _la==7): + if not (_la == 2 or _la == 7): localctx.op = self._errHandler.recoverInline(self) else: self._errHandler.reportMatch(self) @@ -1105,30 +2438,39 @@ def shift_expr(self, _p:int=0): self.match(ExprParser.T__3) pass - self._ctx.stop = self._input.LT(-1) self.state = 132 self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input,8,self._ctx) - while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER: - if _alt==1: + _alt = self._interp.adaptivePredict(self._input, 8, self._ctx) + while _alt != 2 and _alt != ATN.INVALID_ALT_NUMBER: + if _alt == 1: if self._parseListeners is not None: self.triggerExitRuleEvent() _prevctx = localctx self.state = 130 self._errHandler.sync(self) - la_ = self._interp.adaptivePredict(self._input,7,self._ctx) + la_ = self._interp.adaptivePredict(self._input, 7, self._ctx) if la_ == 1: - localctx = ExprParser.ShiftMuldivContext(self, ExprParser.Shift_exprContext(self, _parentctx, _parentState)) - self.pushNewRecursionContext(localctx, _startState, self.RULE_shift_expr) + localctx = ExprParser.ShiftMuldivContext( + self, + ExprParser.Shift_exprContext( + self, _parentctx, _parentState + ), + ) + self.pushNewRecursionContext( + localctx, _startState, self.RULE_shift_expr + ) self.state = 124 if not self.precpred(self._ctx, 4): from antlr4.error.Errors import FailedPredicateException - raise FailedPredicateException(self, "self.precpred(self._ctx, 4)") + + raise FailedPredicateException( + self, "self.precpred(self._ctx, 4)" + ) self.state = 125 localctx.op = self._input.LT(1) _la = self._input.LA(1) - if not(_la==5 or _la==6): + if not (_la == 5 or _la == 6): localctx.op = self._errHandler.recoverInline(self) else: self._errHandler.reportMatch(self) @@ -1138,16 +2480,26 @@ def shift_expr(self, _p:int=0): pass elif la_ == 2: - localctx = ExprParser.ShiftAddsubContext(self, ExprParser.Shift_exprContext(self, _parentctx, _parentState)) - self.pushNewRecursionContext(localctx, _startState, self.RULE_shift_expr) + localctx = ExprParser.ShiftAddsubContext( + self, + ExprParser.Shift_exprContext( + self, _parentctx, _parentState + ), + ) + self.pushNewRecursionContext( + localctx, _startState, self.RULE_shift_expr + ) self.state = 127 if not self.precpred(self._ctx, 3): from antlr4.error.Errors import FailedPredicateException - raise FailedPredicateException(self, "self.precpred(self._ctx, 3)") + + raise FailedPredicateException( + self, "self.precpred(self._ctx, 3)" + ) self.state = 128 localctx.op = self._input.LT(1) _la = self._input.LA(1) - if not(_la==2 or _la==7): + if not (_la == 2 or _la == 7): localctx.op = self._errHandler.recoverInline(self) else: self._errHandler.reportMatch(self) @@ -1156,10 +2508,9 @@ def shift_expr(self, _p:int=0): self.right_expr(0) pass - self.state = 134 self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input,8,self._ctx) + _alt = self._interp.adaptivePredict(self._input, 8, self._ctx) except RecognitionException as re: localctx.exception = re @@ -1169,87 +2520,81 @@ def shift_expr(self, _p:int=0): self.unrollRecursionContexts(_parentctx) return localctx - class Right_exprContext(ParserRuleContext): - __slots__ = 'parser' + __slots__ = "parser" - def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): + def __init__( + self, parser, parent: ParserRuleContext = None, invokingState: int = -1 + ): super().__init__(parent, invokingState) self.parser = parser - def getRuleIndex(self): return ExprParser.RULE_right_expr - - def copyFrom(self, ctx:ParserRuleContext): + def copyFrom(self, ctx: ParserRuleContext): super().copyFrom(ctx) - class RightExpressionContext(Right_exprContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.Right_exprContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.Right_exprContext super().__init__(parser) self.copyFrom(ctx) def expr(self): - return self.getTypedRuleContext(ExprParser.ExprContext,0) + return self.getTypedRuleContext(ExprParser.ExprContext, 0) - - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitRightExpression" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitRightExpression"): return visitor.visitRightExpression(self) else: return visitor.visitChildren(self) - class RightMuldivContext(Right_exprContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.Right_exprContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.Right_exprContext super().__init__(parser) - self.op = None # Token + self.op = None # Token self.copyFrom(ctx) - def right_expr(self, i:int=None): + def right_expr(self, i: int = None): if i is None: return self.getTypedRuleContexts(ExprParser.Right_exprContext) else: - return self.getTypedRuleContext(ExprParser.Right_exprContext,i) - + return self.getTypedRuleContext(ExprParser.Right_exprContext, i) - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitRightMuldiv" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitRightMuldiv"): return visitor.visitRightMuldiv(self) else: return visitor.visitChildren(self) - class RightAtomContext(Right_exprContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.Right_exprContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.Right_exprContext super().__init__(parser) self.copyFrom(ctx) def atom(self): - return self.getTypedRuleContext(ExprParser.AtomContext,0) + return self.getTypedRuleContext(ExprParser.AtomContext, 0) - - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitRightAtom" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitRightAtom"): return visitor.visitRightAtom(self) else: return visitor.visitChildren(self) - - - def right_expr(self, _p:int=0): + def right_expr(self, _p: int = 0): _parentctx = self._ctx _parentState = self.state localctx = ExprParser.Right_exprContext(self, self._ctx, _parentState) _prevctx = localctx _startState = 12 self.enterRecursionRule(localctx, 12, self.RULE_right_expr, _p) - self._la = 0 # Token type + self._la = 0 # Token type try: self.enterOuterAlt(localctx, 1) self.state = 141 @@ -1280,31 +2625,39 @@ def right_expr(self, _p:int=0): self._ctx.stop = self._input.LT(-1) self.state = 148 self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input,10,self._ctx) - while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER: - if _alt==1: + _alt = self._interp.adaptivePredict(self._input, 10, self._ctx) + while _alt != 2 and _alt != ATN.INVALID_ALT_NUMBER: + if _alt == 1: if self._parseListeners is not None: self.triggerExitRuleEvent() _prevctx = localctx - localctx = ExprParser.RightMuldivContext(self, ExprParser.Right_exprContext(self, _parentctx, _parentState)) - self.pushNewRecursionContext(localctx, _startState, self.RULE_right_expr) + localctx = ExprParser.RightMuldivContext( + self, + ExprParser.Right_exprContext(self, _parentctx, _parentState), + ) + self.pushNewRecursionContext( + localctx, _startState, self.RULE_right_expr + ) self.state = 143 if not self.precpred(self._ctx, 3): from antlr4.error.Errors import FailedPredicateException - raise FailedPredicateException(self, "self.precpred(self._ctx, 3)") + + raise FailedPredicateException( + self, "self.precpred(self._ctx, 3)" + ) self.state = 144 localctx.op = self._input.LT(1) _la = self._input.LA(1) - if not(_la==5 or _la==6): + if not (_la == 5 or _la == 6): localctx.op = self._errHandler.recoverInline(self) else: self._errHandler.reportMatch(self) self.consume() self.state = 145 - self.right_expr(4) + self.right_expr(4) self.state = 150 self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input,10,self._ctx) + _alt = self._interp.adaptivePredict(self._input, 10, self._ctx) except RecognitionException as re: localctx.exception = re @@ -1314,9 +2667,7 @@ def right_expr(self, _p:int=0): self.unrollRecursionContexts(_parentctx) return localctx - - - def sempred(self, localctx:RuleContext, ruleIndex:int, predIndex:int): + def sempred(self, localctx: RuleContext, ruleIndex: int, predIndex: int): if self._predicates == None: self._predicates = dict() self._predicates[2] = self.expr_sempred @@ -1328,33 +2679,23 @@ def sempred(self, localctx:RuleContext, ruleIndex:int, predIndex:int): else: return pred(localctx, predIndex) - def expr_sempred(self, localctx:ExprContext, predIndex:int): - if predIndex == 0: - return self.precpred(self._ctx, 12) - - - if predIndex == 1: - return self.precpred(self._ctx, 11) - - - if predIndex == 2: - return self.precpred(self._ctx, 10) - - - def shift_expr_sempred(self, localctx:Shift_exprContext, predIndex:int): - if predIndex == 3: - return self.precpred(self._ctx, 4) - - - if predIndex == 4: - return self.precpred(self._ctx, 3) - + def expr_sempred(self, localctx: ExprContext, predIndex: int): + if predIndex == 0: + return self.precpred(self._ctx, 12) - def right_expr_sempred(self, localctx:Right_exprContext, predIndex:int): - if predIndex == 5: - return self.precpred(self._ctx, 3) - + if predIndex == 1: + return self.precpred(self._ctx, 11) + if predIndex == 2: + return self.precpred(self._ctx, 10) + def shift_expr_sempred(self, localctx: Shift_exprContext, predIndex: int): + if predIndex == 3: + return self.precpred(self._ctx, 4) + if predIndex == 4: + return self.precpred(self._ctx, 3) + def right_expr_sempred(self, localctx: Right_exprContext, predIndex: int): + if predIndex == 5: + return self.precpred(self._ctx, 3) diff --git a/src/gems/expression/parsing/antlr/ExprVisitor.py b/src/gems/expression/parsing/antlr/ExprVisitor.py index 7e9dfe69..c79c9be7 100644 --- a/src/gems/expression/parsing/antlr/ExprVisitor.py +++ b/src/gems/expression/parsing/antlr/ExprVisitor.py @@ -1,5 +1,6 @@ # Generated from Expr.g4 by ANTLR 4.13.2 from antlr4 import * + if "." in __name__: from .ExprParser import ExprParser else: @@ -7,147 +8,119 @@ # This class defines a complete generic visitor for a parse tree produced by ExprParser. -class ExprVisitor(ParseTreeVisitor): +class ExprVisitor(ParseTreeVisitor): # Visit a parse tree produced by ExprParser#portFieldExpr. - def visitPortFieldExpr(self, ctx:ExprParser.PortFieldExprContext): + def visitPortFieldExpr(self, ctx: ExprParser.PortFieldExprContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#fullexpr. - def visitFullexpr(self, ctx:ExprParser.FullexprContext): + def visitFullexpr(self, ctx: ExprParser.FullexprContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#portFieldSum. - def visitPortFieldSum(self, ctx:ExprParser.PortFieldSumContext): + def visitPortFieldSum(self, ctx: ExprParser.PortFieldSumContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#negation. - def visitNegation(self, ctx:ExprParser.NegationContext): + def visitNegation(self, ctx: ExprParser.NegationContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#unsignedAtom. - def visitUnsignedAtom(self, ctx:ExprParser.UnsignedAtomContext): + def visitUnsignedAtom(self, ctx: ExprParser.UnsignedAtomContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#expression. - def visitExpression(self, ctx:ExprParser.ExpressionContext): + def visitExpression(self, ctx: ExprParser.ExpressionContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#comparison. - def visitComparison(self, ctx:ExprParser.ComparisonContext): + def visitComparison(self, ctx: ExprParser.ComparisonContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#allTimeSum. - def visitAllTimeSum(self, ctx:ExprParser.AllTimeSumContext): + def visitAllTimeSum(self, ctx: ExprParser.AllTimeSumContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#timeIndexExpr. - def visitTimeIndexExpr(self, ctx:ExprParser.TimeIndexExprContext): + def visitTimeIndexExpr(self, ctx: ExprParser.TimeIndexExprContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#addsub. - def visitAddsub(self, ctx:ExprParser.AddsubContext): + def visitAddsub(self, ctx: ExprParser.AddsubContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#timeShiftExpr. - def visitTimeShiftExpr(self, ctx:ExprParser.TimeShiftExprContext): + def visitTimeShiftExpr(self, ctx: ExprParser.TimeShiftExprContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#portField. - def visitPortField(self, ctx:ExprParser.PortFieldContext): + def visitPortField(self, ctx: ExprParser.PortFieldContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#muldiv. - def visitMuldiv(self, ctx:ExprParser.MuldivContext): + def visitMuldiv(self, ctx: ExprParser.MuldivContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#timeSum. - def visitTimeSum(self, ctx:ExprParser.TimeSumContext): + def visitTimeSum(self, ctx: ExprParser.TimeSumContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#maxExpr. - def visitMaxExpr(self, ctx:ExprParser.MaxExprContext): + def visitMaxExpr(self, ctx: ExprParser.MaxExprContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#timeIndex. - def visitTimeIndex(self, ctx:ExprParser.TimeIndexContext): + def visitTimeIndex(self, ctx: ExprParser.TimeIndexContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#timeShift. - def visitTimeShift(self, ctx:ExprParser.TimeShiftContext): + def visitTimeShift(self, ctx: ExprParser.TimeShiftContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#function. - def visitFunction(self, ctx:ExprParser.FunctionContext): + def visitFunction(self, ctx: ExprParser.FunctionContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#number. - def visitNumber(self, ctx:ExprParser.NumberContext): + def visitNumber(self, ctx: ExprParser.NumberContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#identifier. - def visitIdentifier(self, ctx:ExprParser.IdentifierContext): + def visitIdentifier(self, ctx: ExprParser.IdentifierContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#shift. - def visitShift(self, ctx:ExprParser.ShiftContext): + def visitShift(self, ctx: ExprParser.ShiftContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#signedAtom. - def visitSignedAtom(self, ctx:ExprParser.SignedAtomContext): + def visitSignedAtom(self, ctx: ExprParser.SignedAtomContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#signedExpression. - def visitSignedExpression(self, ctx:ExprParser.SignedExpressionContext): + def visitSignedExpression(self, ctx: ExprParser.SignedExpressionContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#shiftMuldiv. - def visitShiftMuldiv(self, ctx:ExprParser.ShiftMuldivContext): + def visitShiftMuldiv(self, ctx: ExprParser.ShiftMuldivContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#shiftAddsub. - def visitShiftAddsub(self, ctx:ExprParser.ShiftAddsubContext): + def visitShiftAddsub(self, ctx: ExprParser.ShiftAddsubContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#rightExpression. - def visitRightExpression(self, ctx:ExprParser.RightExpressionContext): + def visitRightExpression(self, ctx: ExprParser.RightExpressionContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#rightMuldiv. - def visitRightMuldiv(self, ctx:ExprParser.RightMuldivContext): + def visitRightMuldiv(self, ctx: ExprParser.RightMuldivContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#rightAtom. - def visitRightAtom(self, ctx:ExprParser.RightAtomContext): + def visitRightAtom(self, ctx: ExprParser.RightAtomContext): return self.visitChildren(ctx) - -del ExprParser \ No newline at end of file +del ExprParser diff --git a/src/gems/expression/parsing/parse_expression.py b/src/gems/expression/parsing/parse_expression.py index 419e8153..491bf8e5 100644 --- a/src/gems/expression/parsing/parse_expression.py +++ b/src/gems/expression/parsing/parse_expression.py @@ -22,7 +22,7 @@ ComparisonNode, PortFieldAggregatorNode, PortFieldNode, - MaxNode + MaxNode, ) from gems.expression.parsing.antlr.ExprLexer import ExprLexer from gems.expression.parsing.antlr.ExprParser import ExprParser @@ -237,6 +237,7 @@ def visitMaxExpr(self, ctx: ExprParser.MaxExprContext) -> ExpressionNode: operands: list[ExpressionNode] = [expr.accept(self) for expr in ctx.expr()] return MaxNode(operands=operands) + _FUNCTIONS = { "expec": ExpressionNode.expec, } From 3790aa492537831a7703fad3f4293a9f9b82c60e Mon Sep 17 00:00:00 2001 From: killian-scalian Date: Fri, 1 Aug 2025 16:53:54 +0200 Subject: [PATCH 05/15] format + isort --- src/gems/expression/evaluate.py | 2 +- src/gems/expression/indexing.py | 2 +- src/gems/model/port.py | 7 ++++--- src/gems/simulation/linearize.py | 5 +++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/gems/expression/evaluate.py b/src/gems/expression/evaluate.py index 5b324699..1ecf54c8 100644 --- a/src/gems/expression/evaluate.py +++ b/src/gems/expression/evaluate.py @@ -18,6 +18,7 @@ AllTimeSumNode, ComponentParameterNode, ComponentVariableNode, + MaxNode, PortFieldAggregatorNode, PortFieldNode, ProblemParameterNode, @@ -25,7 +26,6 @@ TimeEvalNode, TimeShiftNode, TimeSumNode, - MaxNode, ) from .expression import ( diff --git a/src/gems/expression/indexing.py b/src/gems/expression/indexing.py index 7d56cb56..f93f1255 100644 --- a/src/gems/expression/indexing.py +++ b/src/gems/expression/indexing.py @@ -25,6 +25,7 @@ DivisionNode, ExpressionNode, LiteralNode, + MaxNode, MultiplicationNode, NegationNode, ParameterNode, @@ -37,7 +38,6 @@ TimeShiftNode, TimeSumNode, VariableNode, - MaxNode, ) from .visitor import ExpressionVisitor, T, visit diff --git a/src/gems/model/port.py b/src/gems/model/port.py index a52c38f6..c3724d66 100644 --- a/src/gems/model/port.py +++ b/src/gems/model/port.py @@ -30,6 +30,7 @@ BinaryOperatorNode, ComponentParameterNode, ComponentVariableNode, + MaxNode, PortFieldAggregatorNode, PortFieldNode, ProblemParameterNode, @@ -38,7 +39,6 @@ TimeEvalNode, TimeShiftNode, TimeSumNode, - MaxNode, ) from gems.expression.visitor import visit @@ -168,9 +168,10 @@ def port_field(self, node: PortFieldNode) -> None: def port_field_aggregator(self, node: PortFieldAggregatorNode) -> None: raise ValueError("Port definition cannot contain port field aggregation.") - + def max_node(self, node: MaxNode) -> None: raise ValueError("Port definition must not contain a max expression.") + def _validate_port_field_expression(definition: PortFieldDefinition) -> None: - visit(definition.definition, _PortFieldExpressionChecker()) \ No newline at end of file + visit(definition.definition, _PortFieldExpressionChecker()) diff --git a/src/gems/simulation/linearize.py b/src/gems/simulation/linearize.py index c905d140..4c86aedd 100644 --- a/src/gems/simulation/linearize.py +++ b/src/gems/simulation/linearize.py @@ -29,6 +29,7 @@ CurrentScenarioIndex, ExpressionNode, LiteralNode, + MaxNode, NoScenarioIndex, NoTimeIndex, OneScenarioIndex, @@ -46,7 +47,6 @@ TimeStep, TimeSumNode, VariableNode, - MaxNode, ) from gems.expression.visitor import visit from gems.simulation.linear_expression import LinearExpression, Term, TermKey @@ -281,7 +281,7 @@ def port_field_aggregator( raise ValueError( "Port fields aggregators must be replaced before linearization." ) - + def max_node(self, node: MaxNode) -> LinearExpressionData: operands = [visit(o, self) for o in node.operands] terms: list = [] @@ -290,6 +290,7 @@ def max_node(self, node: MaxNode) -> LinearExpressionData: max_const = max(o.constant for o in operands) return LinearExpressionData(terms=terms, constant=max_const) + def linearize_expression( expression: ExpressionNode, timestep: Optional[int], From 9c6ef03a939283efb4755f35d5c2ca7429345ceb Mon Sep 17 00:00:00 2001 From: killian-scalian Date: Fri, 1 Aug 2025 17:06:54 +0200 Subject: [PATCH 06/15] black format --- src/gems/expression/evaluate.py | 12 +++-- src/gems/expression/evaluate_parameters.py | 6 ++- src/gems/expression/indexing.py | 12 +++-- src/gems/expression/visitor.py | 62 ++++++++++++++-------- 4 files changed, 61 insertions(+), 31 deletions(-) diff --git a/src/gems/expression/evaluate.py b/src/gems/expression/evaluate.py index 1ecf54c8..7a875748 100644 --- a/src/gems/expression/evaluate.py +++ b/src/gems/expression/evaluate.py @@ -47,16 +47,20 @@ class ValueProvider(ABC): """ @abstractmethod - def get_variable_value(self, name: str) -> float: ... + def get_variable_value(self, name: str) -> float: + ... @abstractmethod - def get_parameter_value(self, name: str) -> float: ... + def get_parameter_value(self, name: str) -> float: + ... @abstractmethod - def get_component_variable_value(self, component_id: str, name: str) -> float: ... + def get_component_variable_value(self, component_id: str, name: str) -> float: + ... @abstractmethod - def get_component_parameter_value(self, component_id: str, name: str) -> float: ... + def get_component_parameter_value(self, component_id: str, name: str) -> float: + ... @dataclass(frozen=True) diff --git a/src/gems/expression/evaluate_parameters.py b/src/gems/expression/evaluate_parameters.py index 77b0d70f..b605af54 100644 --- a/src/gems/expression/evaluate_parameters.py +++ b/src/gems/expression/evaluate_parameters.py @@ -27,10 +27,12 @@ class ParameterValueProvider(ABC): @abstractmethod - def get_parameter_value(self, name: str) -> float: ... + def get_parameter_value(self, name: str) -> float: + ... @abstractmethod - def get_component_parameter_value(self, component_id: str, name: str) -> float: ... + def get_component_parameter_value(self, component_id: str, name: str) -> float: + ... @dataclass(frozen=True) diff --git a/src/gems/expression/indexing.py b/src/gems/expression/indexing.py index f93f1255..8c4f79b2 100644 --- a/src/gems/expression/indexing.py +++ b/src/gems/expression/indexing.py @@ -44,20 +44,24 @@ class IndexingStructureProvider(ABC): @abstractmethod - def get_parameter_structure(self, name: str) -> IndexingStructure: ... + def get_parameter_structure(self, name: str) -> IndexingStructure: + ... @abstractmethod - def get_variable_structure(self, name: str) -> IndexingStructure: ... + def get_variable_structure(self, name: str) -> IndexingStructure: + ... @abstractmethod def get_component_variable_structure( self, component_id: str, name: str - ) -> IndexingStructure: ... + ) -> IndexingStructure: + ... @abstractmethod def get_component_parameter_structure( self, component_id: str, name: str - ) -> IndexingStructure: ... + ) -> IndexingStructure: + ... @dataclass(frozen=True) diff --git a/src/gems/expression/visitor.py b/src/gems/expression/visitor.py index 836fbcea..1e04d86c 100644 --- a/src/gems/expression/visitor.py +++ b/src/gems/expression/visitor.py @@ -27,6 +27,7 @@ DivisionNode, ExpressionNode, LiteralNode, + MaxNode, MultiplicationNode, NegationNode, ParameterNode, @@ -39,7 +40,6 @@ TimeShiftNode, TimeSumNode, VariableNode, - MaxNode, ) T = TypeVar("T") @@ -55,64 +55,84 @@ class ExpressionVisitor(ABC, Generic[T]): """ @abstractmethod - def literal(self, node: LiteralNode) -> T: ... + def literal(self, node: LiteralNode) -> T: + ... @abstractmethod - def negation(self, node: NegationNode) -> T: ... + def negation(self, node: NegationNode) -> T: + ... @abstractmethod - def addition(self, node: AdditionNode) -> T: ... + def addition(self, node: AdditionNode) -> T: + ... @abstractmethod - def multiplication(self, node: MultiplicationNode) -> T: ... + def multiplication(self, node: MultiplicationNode) -> T: + ... @abstractmethod - def division(self, node: DivisionNode) -> T: ... + def division(self, node: DivisionNode) -> T: + ... @abstractmethod - def comparison(self, node: ComparisonNode) -> T: ... + def comparison(self, node: ComparisonNode) -> T: + ... @abstractmethod - def variable(self, node: VariableNode) -> T: ... + def variable(self, node: VariableNode) -> T: + ... @abstractmethod - def parameter(self, node: ParameterNode) -> T: ... + def parameter(self, node: ParameterNode) -> T: + ... @abstractmethod - def comp_parameter(self, node: ComponentParameterNode) -> T: ... + def comp_parameter(self, node: ComponentParameterNode) -> T: + ... @abstractmethod - def comp_variable(self, node: ComponentVariableNode) -> T: ... + def comp_variable(self, node: ComponentVariableNode) -> T: + ... @abstractmethod - def pb_parameter(self, node: ProblemParameterNode) -> T: ... + def pb_parameter(self, node: ProblemParameterNode) -> T: + ... @abstractmethod - def pb_variable(self, node: ProblemVariableNode) -> T: ... + def pb_variable(self, node: ProblemVariableNode) -> T: + ... @abstractmethod - def time_shift(self, node: TimeShiftNode) -> T: ... + def time_shift(self, node: TimeShiftNode) -> T: + ... @abstractmethod - def time_eval(self, node: TimeEvalNode) -> T: ... + def time_eval(self, node: TimeEvalNode) -> T: + ... @abstractmethod - def time_sum(self, node: TimeSumNode) -> T: ... + def time_sum(self, node: TimeSumNode) -> T: + ... @abstractmethod - def all_time_sum(self, node: AllTimeSumNode) -> T: ... + def all_time_sum(self, node: AllTimeSumNode) -> T: + ... @abstractmethod - def scenario_operator(self, node: ScenarioOperatorNode) -> T: ... + def scenario_operator(self, node: ScenarioOperatorNode) -> T: + ... @abstractmethod - def port_field(self, node: PortFieldNode) -> T: ... + def port_field(self, node: PortFieldNode) -> T: + ... @abstractmethod - def port_field_aggregator(self, node: PortFieldAggregatorNode) -> T: ... + def port_field_aggregator(self, node: PortFieldAggregatorNode) -> T: + ... @abstractmethod - def max_node(self, node: MaxNode) -> T: ... + def max_node(self, node: MaxNode) -> T: + ... def visit(root: ExpressionNode, visitor: ExpressionVisitor[T]) -> T: From 9bede1c18506547fbe67552de11ac714699c7f3b Mon Sep 17 00:00:00 2001 From: killian-scalian Date: Fri, 1 Aug 2025 17:18:33 +0200 Subject: [PATCH 07/15] typing improvement --- src/gems/expression/copy.py | 1 + src/gems/expression/expression.py | 2 +- src/gems/expression/visitor.py | 5 +++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/gems/expression/copy.py b/src/gems/expression/copy.py index 8662178f..eea34d74 100644 --- a/src/gems/expression/copy.py +++ b/src/gems/expression/copy.py @@ -11,6 +11,7 @@ # This file is part of the Antares project. from dataclasses import dataclass +from typing import List, cast from .expression import ( AllTimeSumNode, diff --git a/src/gems/expression/expression.py b/src/gems/expression/expression.py index 31100dcf..d42af6ff 100644 --- a/src/gems/expression/expression.py +++ b/src/gems/expression/expression.py @@ -155,7 +155,7 @@ def var(name: str) -> VariableNode: class MaxNode(ExpressionNode): operands: List[ExpressionNode] - def __post_init__(self): + def __post_init__(self) -> None: if len(self.operands) < 2: raise ValueError("MaxNode requires at least two operands") for operand in self.operands: diff --git a/src/gems/expression/visitor.py b/src/gems/expression/visitor.py index 1e04d86c..aa9407fa 100644 --- a/src/gems/expression/visitor.py +++ b/src/gems/expression/visitor.py @@ -241,5 +241,6 @@ def division(self, node: DivisionNode) -> T_op: right_value = visit(node.right, self) return left_value / right_value - def max_node(self, node) -> ExpressionNode: - return MaxNode(operands=[visit(op, self) for op in node.operands]) + def max_node(self, node: MaxNode) -> T_op: + res = [visit(op, self) for op in node.operands] + return max(res) From 9f038e0369adebb37cde09fa013699ee522f288e Mon Sep 17 00:00:00 2001 From: killian-scalian Date: Fri, 1 Aug 2025 17:31:11 +0200 Subject: [PATCH 08/15] typing check --- src/gems/expression/copy.py | 2 +- src/gems/expression/visitor.py | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/gems/expression/copy.py b/src/gems/expression/copy.py index eea34d74..bfcf266d 100644 --- a/src/gems/expression/copy.py +++ b/src/gems/expression/copy.py @@ -35,7 +35,7 @@ @dataclass(frozen=True) -class CopyVisitor(ExpressionVisitorOperations[ExpressionNode]): +class CopyVisitor(ExpressionVisitorOperations[ExpressionNode]): # type: ignore """ Simply copies the whole AST. """ diff --git a/src/gems/expression/visitor.py b/src/gems/expression/visitor.py index aa9407fa..b65a4bfa 100644 --- a/src/gems/expression/visitor.py +++ b/src/gems/expression/visitor.py @@ -207,9 +207,17 @@ def __mul__(self, other: T) -> T: def __truediv__(self, other: T) -> T: pass - @abstractmethod - def __max__(self, other: T) -> T: - pass + def __lt__(self, other: T) -> bool: + ... + + def __le__(self, other: T) -> bool: + ... + + def __gt__(self, other: T) -> bool: + ... + + def __ge__(self, other: T) -> bool: + ... T_op = TypeVar("T_op", bound=SupportsOperations) From b01aac0dfc8561ea2afc2c1bc6f4a542e94dec94 Mon Sep 17 00:00:00 2001 From: killian-scalian Date: Fri, 1 Aug 2025 17:36:37 +0200 Subject: [PATCH 09/15] last format --- src/gems/expression/copy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gems/expression/copy.py b/src/gems/expression/copy.py index bfcf266d..b777597b 100644 --- a/src/gems/expression/copy.py +++ b/src/gems/expression/copy.py @@ -35,7 +35,7 @@ @dataclass(frozen=True) -class CopyVisitor(ExpressionVisitorOperations[ExpressionNode]): # type: ignore +class CopyVisitor(ExpressionVisitorOperations[ExpressionNode]): # type: ignore """ Simply copies the whole AST. """ From d9b3011e9242df6ee58939656e48cbd699f743fb Mon Sep 17 00:00:00 2001 From: killian-scalian Date: Fri, 1 Aug 2025 17:50:27 +0200 Subject: [PATCH 10/15] ignore typing --- src/gems/expression/visitor.py | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/src/gems/expression/visitor.py b/src/gems/expression/visitor.py index b65a4bfa..adab543c 100644 --- a/src/gems/expression/visitor.py +++ b/src/gems/expression/visitor.py @@ -207,18 +207,6 @@ def __mul__(self, other: T) -> T: def __truediv__(self, other: T) -> T: pass - def __lt__(self, other: T) -> bool: - ... - - def __le__(self, other: T) -> bool: - ... - - def __gt__(self, other: T) -> bool: - ... - - def __ge__(self, other: T) -> bool: - ... - T_op = TypeVar("T_op", bound=SupportsOperations) @@ -249,6 +237,5 @@ def division(self, node: DivisionNode) -> T_op: right_value = visit(node.right, self) return left_value / right_value - def max_node(self, node: MaxNode) -> T_op: - res = [visit(op, self) for op in node.operands] - return max(res) + def max_node(self, node: MaxNode) -> ExpressionNode: # type: ignore + return MaxNode(operands=[visit(op, self) for op in node.operands]) # type: ignore From 5a23546c32313c2298d1babacf9a8846b7909ed8 Mon Sep 17 00:00:00 2001 From: killian-scalian Date: Fri, 1 Aug 2025 17:58:39 +0200 Subject: [PATCH 11/15] ignore again --- src/gems/expression/evaluate.py | 2 +- src/gems/expression/visitor.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gems/expression/evaluate.py b/src/gems/expression/evaluate.py index 7a875748..00528153 100644 --- a/src/gems/expression/evaluate.py +++ b/src/gems/expression/evaluate.py @@ -140,7 +140,7 @@ def port_field(self, node: PortFieldNode) -> float: def port_field_aggregator(self, node: PortFieldAggregatorNode) -> float: raise NotImplementedError() - def max_node(self, node: MaxNode) -> float: + def max_node(self, node: MaxNode) -> float: # type: ignore return max(visit(op, self) for op in node.operands) diff --git a/src/gems/expression/visitor.py b/src/gems/expression/visitor.py index adab543c..f86a9f22 100644 --- a/src/gems/expression/visitor.py +++ b/src/gems/expression/visitor.py @@ -14,7 +14,7 @@ Defines abstract base class for visitors of expressions. """ -import typing +from typing import cast from abc import ABC, abstractmethod from typing import Generic, Protocol, TypeVar From c9209ca7e07897eb822c9b4e04da2203014ad34e Mon Sep 17 00:00:00 2001 From: killian-scalian Date: Fri, 1 Aug 2025 18:07:39 +0200 Subject: [PATCH 12/15] black --- src/gems/expression/evaluate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gems/expression/evaluate.py b/src/gems/expression/evaluate.py index 00528153..4614d5e1 100644 --- a/src/gems/expression/evaluate.py +++ b/src/gems/expression/evaluate.py @@ -140,7 +140,7 @@ def port_field(self, node: PortFieldNode) -> float: def port_field_aggregator(self, node: PortFieldAggregatorNode) -> float: raise NotImplementedError() - def max_node(self, node: MaxNode) -> float: # type: ignore + def max_node(self, node: MaxNode) -> float: # type: ignore return max(visit(op, self) for op in node.operands) From bbc80ecd09d8f6c3cffc7123b30934155eb90e64 Mon Sep 17 00:00:00 2001 From: killian-scalian Date: Tue, 5 Aug 2025 14:25:27 +0200 Subject: [PATCH 13/15] minor changes --- src/gems/expression/copy.py | 2 +- src/gems/expression/visitor.py | 1 - .../expressions/visitor/test_linearization.py | 1 - .../expressions/visitor/test_max_expression_checker.py | 10 ---------- 4 files changed, 1 insertion(+), 13 deletions(-) diff --git a/src/gems/expression/copy.py b/src/gems/expression/copy.py index b777597b..eea34d74 100644 --- a/src/gems/expression/copy.py +++ b/src/gems/expression/copy.py @@ -35,7 +35,7 @@ @dataclass(frozen=True) -class CopyVisitor(ExpressionVisitorOperations[ExpressionNode]): # type: ignore +class CopyVisitor(ExpressionVisitorOperations[ExpressionNode]): """ Simply copies the whole AST. """ diff --git a/src/gems/expression/visitor.py b/src/gems/expression/visitor.py index f86a9f22..5baafd6b 100644 --- a/src/gems/expression/visitor.py +++ b/src/gems/expression/visitor.py @@ -14,7 +14,6 @@ Defines abstract base class for visitors of expressions. """ -from typing import cast from abc import ABC, abstractmethod from typing import Generic, Protocol, TypeVar diff --git a/tests/unittests/expressions/visitor/test_linearization.py b/tests/unittests/expressions/visitor/test_linearization.py index eae06f35..ef567878 100644 --- a/tests/unittests/expressions/visitor/test_linearization.py +++ b/tests/unittests/expressions/visitor/test_linearization.py @@ -16,7 +16,6 @@ from gems.expression import ExpressionNode, LiteralNode, literal, var from gems.expression.expression import ( - AdditionNode, ComponentVariableNode, CurrentScenarioIndex, TimeShift, diff --git a/tests/unittests/expressions/visitor/test_max_expression_checker.py b/tests/unittests/expressions/visitor/test_max_expression_checker.py index 1456a156..fe3664de 100644 --- a/tests/unittests/expressions/visitor/test_max_expression_checker.py +++ b/tests/unittests/expressions/visitor/test_max_expression_checker.py @@ -14,16 +14,6 @@ ProblemVariableNode, ) -NodeList = [ - ComparisonNode, - ExpressionNode, - VariableNode, - ComponentVariableNode, - ProblemVariableNode, - PortFieldNode, - PortFieldAggregatorNode, -] - @pytest.mark.parametrize( "node, left_arg, right_arg", From 6f4eace41926940efe0077bd5b742a44afc84aa6 Mon Sep 17 00:00:00 2001 From: killian-scalian Date: Tue, 5 Aug 2025 15:54:34 +0200 Subject: [PATCH 14/15] max handling correctly with MAX --- grammar/Expr.g4 | 2 +- .../expression/parsing/antlr/ExprLexer.py | 1300 +--------- .../expression/parsing/antlr/ExprParser.py | 2199 ++++------------- .../expression/parsing/antlr/ExprVisitor.py | 89 +- 4 files changed, 550 insertions(+), 3040 deletions(-) diff --git a/grammar/Expr.g4 b/grammar/Expr.g4 index a08208a8..4249ded2 100644 --- a/grammar/Expr.g4 +++ b/grammar/Expr.g4 @@ -33,7 +33,7 @@ expr | IDENTIFIER '[' expr ']' # timeIndex | '(' expr ')' '[' shift ']' # timeShiftExpr | '(' expr ')' '[' expr ']' # timeIndexExpr - | 'max' '(' expr (',' expr)* ')' # maxExpr + | MAX '(' expr (',' expr)* ')' # maxExpr ; atom diff --git a/src/gems/expression/parsing/antlr/ExprLexer.py b/src/gems/expression/parsing/antlr/ExprLexer.py index 86bdaa43..f7767124 100644 --- a/src/gems/expression/parsing/antlr/ExprLexer.py +++ b/src/gems/expression/parsing/antlr/ExprLexer.py @@ -2,7 +2,6 @@ from antlr4 import * from io import StringIO import sys - if sys.version_info[1] > 5: from typing import TextIO else: @@ -11,1191 +10,58 @@ def serializedATN(): return [ - 4, - 0, - 19, - 133, - 6, - -1, - 2, - 0, - 7, - 0, - 2, - 1, - 7, - 1, - 2, - 2, - 7, - 2, - 2, - 3, - 7, - 3, - 2, - 4, - 7, - 4, - 2, - 5, - 7, - 5, - 2, - 6, - 7, - 6, - 2, - 7, - 7, - 7, - 2, - 8, - 7, - 8, - 2, - 9, - 7, - 9, - 2, - 10, - 7, - 10, - 2, - 11, - 7, - 11, - 2, - 12, - 7, - 12, - 2, - 13, - 7, - 13, - 2, - 14, - 7, - 14, - 2, - 15, - 7, - 15, - 2, - 16, - 7, - 16, - 2, - 17, - 7, - 17, - 2, - 18, - 7, - 18, - 2, - 19, - 7, - 19, - 2, - 20, - 7, - 20, - 2, - 21, - 7, - 21, - 1, - 0, - 1, - 0, - 1, - 1, - 1, - 1, - 1, - 2, - 1, - 2, - 1, - 3, - 1, - 3, - 1, - 4, - 1, - 4, - 1, - 5, - 1, - 5, - 1, - 6, - 1, - 6, - 1, - 7, - 1, - 7, - 1, - 7, - 1, - 7, - 1, - 8, - 1, - 8, - 1, - 8, - 1, - 8, - 1, - 8, - 1, - 8, - 1, - 8, - 1, - 8, - 1, - 8, - 1, - 8, - 1, - 8, - 1, - 8, - 1, - 8, - 1, - 8, - 1, - 8, - 1, - 8, - 1, - 9, - 1, - 9, - 1, - 9, - 1, - 10, - 1, - 10, - 1, - 11, - 1, - 11, - 1, - 12, - 1, - 12, - 1, - 13, - 1, - 13, - 1, - 14, - 1, - 14, - 1, - 15, - 1, - 15, - 3, - 15, - 95, - 8, - 15, - 1, - 16, - 4, - 16, - 98, - 8, - 16, - 11, - 16, - 12, - 16, - 99, - 1, - 16, - 1, - 16, - 4, - 16, - 104, - 8, - 16, - 11, - 16, - 12, - 16, - 105, - 3, - 16, - 108, - 8, - 16, - 1, - 17, - 1, - 17, - 1, - 17, - 1, - 17, - 1, - 18, - 1, - 18, - 1, - 19, - 1, - 19, - 5, - 19, - 118, - 8, - 19, - 10, - 19, - 12, - 19, - 121, - 9, - 19, - 1, - 20, - 1, - 20, - 1, - 20, - 1, - 20, - 1, - 20, - 3, - 20, - 128, - 8, - 20, - 1, - 21, - 1, - 21, - 1, - 21, - 1, - 21, - 0, - 0, - 22, - 1, - 1, - 3, - 2, - 5, - 3, - 7, - 4, - 9, - 5, - 11, - 6, - 13, - 7, - 15, - 8, - 17, - 9, - 19, - 10, - 21, - 11, - 23, - 12, - 25, - 13, - 27, - 0, - 29, - 0, - 31, - 0, - 33, - 14, - 35, - 15, - 37, - 16, - 39, - 17, - 41, - 18, - 43, - 19, - 1, - 0, - 3, - 1, - 0, - 48, - 57, - 3, - 0, - 65, - 90, - 95, - 95, - 97, - 122, - 3, - 0, - 9, - 10, - 13, - 13, - 32, - 32, - 136, - 0, - 1, - 1, - 0, - 0, - 0, - 0, - 3, - 1, - 0, - 0, - 0, - 0, - 5, - 1, - 0, - 0, - 0, - 0, - 7, - 1, - 0, - 0, - 0, - 0, - 9, - 1, - 0, - 0, - 0, - 0, - 11, - 1, - 0, - 0, - 0, - 0, - 13, - 1, - 0, - 0, - 0, - 0, - 15, - 1, - 0, - 0, - 0, - 0, - 17, - 1, - 0, - 0, - 0, - 0, - 19, - 1, - 0, - 0, - 0, - 0, - 21, - 1, - 0, - 0, - 0, - 0, - 23, - 1, - 0, - 0, - 0, - 0, - 25, - 1, - 0, - 0, - 0, - 0, - 33, - 1, - 0, - 0, - 0, - 0, - 35, - 1, - 0, - 0, - 0, - 0, - 37, - 1, - 0, - 0, - 0, - 0, - 39, - 1, - 0, - 0, - 0, - 0, - 41, - 1, - 0, - 0, - 0, - 0, - 43, - 1, - 0, - 0, - 0, - 1, - 45, - 1, - 0, - 0, - 0, - 3, - 47, - 1, - 0, - 0, - 0, - 5, - 49, - 1, - 0, - 0, - 0, - 7, - 51, - 1, - 0, - 0, - 0, - 9, - 53, - 1, - 0, - 0, - 0, - 11, - 55, - 1, - 0, - 0, - 0, - 13, - 57, - 1, - 0, - 0, - 0, - 15, - 59, - 1, - 0, - 0, - 0, - 17, - 63, - 1, - 0, - 0, - 0, - 19, - 79, - 1, - 0, - 0, - 0, - 21, - 82, - 1, - 0, - 0, - 0, - 23, - 84, - 1, - 0, - 0, - 0, - 25, - 86, - 1, - 0, - 0, - 0, - 27, - 88, - 1, - 0, - 0, - 0, - 29, - 90, - 1, - 0, - 0, - 0, - 31, - 94, - 1, - 0, - 0, - 0, - 33, - 97, - 1, - 0, - 0, - 0, - 35, - 109, - 1, - 0, - 0, - 0, - 37, - 113, - 1, - 0, - 0, - 0, - 39, - 115, - 1, - 0, - 0, - 0, - 41, - 127, - 1, - 0, - 0, - 0, - 43, - 129, - 1, - 0, - 0, - 0, - 45, - 46, - 5, - 46, - 0, - 0, - 46, - 2, - 1, - 0, - 0, - 0, - 47, - 48, - 5, - 45, - 0, - 0, - 48, - 4, - 1, - 0, - 0, - 0, - 49, - 50, - 5, - 40, - 0, - 0, - 50, - 6, - 1, - 0, - 0, - 0, - 51, - 52, - 5, - 41, - 0, - 0, - 52, - 8, - 1, - 0, - 0, - 0, - 53, - 54, - 5, - 47, - 0, - 0, - 54, - 10, - 1, - 0, - 0, - 0, - 55, - 56, - 5, - 42, - 0, - 0, - 56, - 12, - 1, - 0, - 0, - 0, - 57, - 58, - 5, - 43, - 0, - 0, - 58, - 14, - 1, - 0, - 0, - 0, - 59, - 60, - 5, - 115, - 0, - 0, - 60, - 61, - 5, - 117, - 0, - 0, - 61, - 62, - 5, - 109, - 0, - 0, - 62, - 16, - 1, - 0, - 0, - 0, - 63, - 64, - 5, - 115, - 0, - 0, - 64, - 65, - 5, - 117, - 0, - 0, - 65, - 66, - 5, - 109, - 0, - 0, - 66, - 67, - 5, - 95, - 0, - 0, - 67, - 68, - 5, - 99, - 0, - 0, - 68, - 69, - 5, - 111, - 0, - 0, - 69, - 70, - 5, - 110, - 0, - 0, - 70, - 71, - 5, - 110, - 0, - 0, - 71, - 72, - 5, - 101, - 0, - 0, - 72, - 73, - 5, - 99, - 0, - 0, - 73, - 74, - 5, - 116, - 0, - 0, - 74, - 75, - 5, - 105, - 0, - 0, - 75, - 76, - 5, - 111, - 0, - 0, - 76, - 77, - 5, - 110, - 0, - 0, - 77, - 78, - 5, - 115, - 0, - 0, - 78, - 18, - 1, - 0, - 0, - 0, - 79, - 80, - 5, - 46, - 0, - 0, - 80, - 81, - 5, - 46, - 0, - 0, - 81, - 20, - 1, - 0, - 0, - 0, - 82, - 83, - 5, - 44, - 0, - 0, - 83, - 22, - 1, - 0, - 0, - 0, - 84, - 85, - 5, - 91, - 0, - 0, - 85, - 24, - 1, - 0, - 0, - 0, - 86, - 87, - 5, - 93, - 0, - 0, - 87, - 26, - 1, - 0, - 0, - 0, - 88, - 89, - 7, - 0, - 0, - 0, - 89, - 28, - 1, - 0, - 0, - 0, - 90, - 91, - 7, - 1, - 0, - 0, - 91, - 30, - 1, - 0, - 0, - 0, - 92, - 95, - 3, - 29, - 14, - 0, - 93, - 95, - 3, - 27, - 13, - 0, - 94, - 92, - 1, - 0, - 0, - 0, - 94, - 93, - 1, - 0, - 0, - 0, - 95, - 32, - 1, - 0, - 0, - 0, - 96, - 98, - 3, - 27, - 13, - 0, - 97, - 96, - 1, - 0, - 0, - 0, - 98, - 99, - 1, - 0, - 0, - 0, - 99, - 97, - 1, - 0, - 0, - 0, - 99, - 100, - 1, - 0, - 0, - 0, - 100, - 107, - 1, - 0, - 0, - 0, - 101, - 103, - 5, - 46, - 0, - 0, - 102, - 104, - 3, - 27, - 13, - 0, - 103, - 102, - 1, - 0, - 0, - 0, - 104, - 105, - 1, - 0, - 0, - 0, - 105, - 103, - 1, - 0, - 0, - 0, - 105, - 106, - 1, - 0, - 0, - 0, - 106, - 108, - 1, - 0, - 0, - 0, - 107, - 101, - 1, - 0, - 0, - 0, - 107, - 108, - 1, - 0, - 0, - 0, - 108, - 34, - 1, - 0, - 0, - 0, - 109, - 110, - 5, - 109, - 0, - 0, - 110, - 111, - 5, - 97, - 0, - 0, - 111, - 112, - 5, - 120, - 0, - 0, - 112, - 36, - 1, - 0, - 0, - 0, - 113, - 114, - 5, - 116, - 0, - 0, - 114, - 38, - 1, - 0, - 0, - 0, - 115, - 119, - 3, - 29, - 14, - 0, - 116, - 118, - 3, - 31, - 15, - 0, - 117, - 116, - 1, - 0, - 0, - 0, - 118, - 121, - 1, - 0, - 0, - 0, - 119, - 117, - 1, - 0, - 0, - 0, - 119, - 120, - 1, - 0, - 0, - 0, - 120, - 40, - 1, - 0, - 0, - 0, - 121, - 119, - 1, - 0, - 0, - 0, - 122, - 128, - 5, - 61, - 0, - 0, - 123, - 124, - 5, - 62, - 0, - 0, - 124, - 128, - 5, - 61, - 0, - 0, - 125, - 126, - 5, - 60, - 0, - 0, - 126, - 128, - 5, - 61, - 0, - 0, - 127, - 122, - 1, - 0, - 0, - 0, - 127, - 123, - 1, - 0, - 0, - 0, - 127, - 125, - 1, - 0, - 0, - 0, - 128, - 42, - 1, - 0, - 0, - 0, - 129, - 130, - 7, - 2, - 0, - 0, - 130, - 131, - 1, - 0, - 0, - 0, - 131, - 132, - 6, - 21, - 0, - 0, - 132, - 44, - 1, - 0, - 0, - 0, - 7, - 0, - 94, - 99, - 105, - 107, - 119, - 127, - 1, - 6, - 0, - 0, + 4,0,19,133,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5, + 2,6,7,6,2,7,7,7,2,8,7,8,2,9,7,9,2,10,7,10,2,11,7,11,2,12,7,12,2, + 13,7,13,2,14,7,14,2,15,7,15,2,16,7,16,2,17,7,17,2,18,7,18,2,19,7, + 19,2,20,7,20,2,21,7,21,1,0,1,0,1,1,1,1,1,2,1,2,1,3,1,3,1,4,1,4,1, + 5,1,5,1,6,1,6,1,7,1,7,1,7,1,7,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1, + 8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,9,1,9,1,9,1,10,1,10,1,11,1,11,1, + 12,1,12,1,13,1,13,1,14,1,14,1,15,1,15,3,15,95,8,15,1,16,4,16,98, + 8,16,11,16,12,16,99,1,16,1,16,4,16,104,8,16,11,16,12,16,105,3,16, + 108,8,16,1,17,1,17,1,17,1,17,1,18,1,18,1,19,1,19,5,19,118,8,19,10, + 19,12,19,121,9,19,1,20,1,20,1,20,1,20,1,20,3,20,128,8,20,1,21,1, + 21,1,21,1,21,0,0,22,1,1,3,2,5,3,7,4,9,5,11,6,13,7,15,8,17,9,19,10, + 21,11,23,12,25,13,27,0,29,0,31,0,33,14,35,15,37,16,39,17,41,18,43, + 19,1,0,3,1,0,48,57,3,0,65,90,95,95,97,122,3,0,9,10,13,13,32,32,136, + 0,1,1,0,0,0,0,3,1,0,0,0,0,5,1,0,0,0,0,7,1,0,0,0,0,9,1,0,0,0,0,11, + 1,0,0,0,0,13,1,0,0,0,0,15,1,0,0,0,0,17,1,0,0,0,0,19,1,0,0,0,0,21, + 1,0,0,0,0,23,1,0,0,0,0,25,1,0,0,0,0,33,1,0,0,0,0,35,1,0,0,0,0,37, + 1,0,0,0,0,39,1,0,0,0,0,41,1,0,0,0,0,43,1,0,0,0,1,45,1,0,0,0,3,47, + 1,0,0,0,5,49,1,0,0,0,7,51,1,0,0,0,9,53,1,0,0,0,11,55,1,0,0,0,13, + 57,1,0,0,0,15,59,1,0,0,0,17,63,1,0,0,0,19,79,1,0,0,0,21,82,1,0,0, + 0,23,84,1,0,0,0,25,86,1,0,0,0,27,88,1,0,0,0,29,90,1,0,0,0,31,94, + 1,0,0,0,33,97,1,0,0,0,35,109,1,0,0,0,37,113,1,0,0,0,39,115,1,0,0, + 0,41,127,1,0,0,0,43,129,1,0,0,0,45,46,5,46,0,0,46,2,1,0,0,0,47,48, + 5,45,0,0,48,4,1,0,0,0,49,50,5,40,0,0,50,6,1,0,0,0,51,52,5,41,0,0, + 52,8,1,0,0,0,53,54,5,47,0,0,54,10,1,0,0,0,55,56,5,42,0,0,56,12,1, + 0,0,0,57,58,5,43,0,0,58,14,1,0,0,0,59,60,5,115,0,0,60,61,5,117,0, + 0,61,62,5,109,0,0,62,16,1,0,0,0,63,64,5,115,0,0,64,65,5,117,0,0, + 65,66,5,109,0,0,66,67,5,95,0,0,67,68,5,99,0,0,68,69,5,111,0,0,69, + 70,5,110,0,0,70,71,5,110,0,0,71,72,5,101,0,0,72,73,5,99,0,0,73,74, + 5,116,0,0,74,75,5,105,0,0,75,76,5,111,0,0,76,77,5,110,0,0,77,78, + 5,115,0,0,78,18,1,0,0,0,79,80,5,46,0,0,80,81,5,46,0,0,81,20,1,0, + 0,0,82,83,5,44,0,0,83,22,1,0,0,0,84,85,5,91,0,0,85,24,1,0,0,0,86, + 87,5,93,0,0,87,26,1,0,0,0,88,89,7,0,0,0,89,28,1,0,0,0,90,91,7,1, + 0,0,91,30,1,0,0,0,92,95,3,29,14,0,93,95,3,27,13,0,94,92,1,0,0,0, + 94,93,1,0,0,0,95,32,1,0,0,0,96,98,3,27,13,0,97,96,1,0,0,0,98,99, + 1,0,0,0,99,97,1,0,0,0,99,100,1,0,0,0,100,107,1,0,0,0,101,103,5,46, + 0,0,102,104,3,27,13,0,103,102,1,0,0,0,104,105,1,0,0,0,105,103,1, + 0,0,0,105,106,1,0,0,0,106,108,1,0,0,0,107,101,1,0,0,0,107,108,1, + 0,0,0,108,34,1,0,0,0,109,110,5,109,0,0,110,111,5,97,0,0,111,112, + 5,120,0,0,112,36,1,0,0,0,113,114,5,116,0,0,114,38,1,0,0,0,115,119, + 3,29,14,0,116,118,3,31,15,0,117,116,1,0,0,0,118,121,1,0,0,0,119, + 117,1,0,0,0,119,120,1,0,0,0,120,40,1,0,0,0,121,119,1,0,0,0,122,128, + 5,61,0,0,123,124,5,62,0,0,124,128,5,61,0,0,125,126,5,60,0,0,126, + 128,5,61,0,0,127,122,1,0,0,0,127,123,1,0,0,0,127,125,1,0,0,0,128, + 42,1,0,0,0,129,130,7,2,0,0,130,131,1,0,0,0,131,132,6,21,0,0,132, + 44,1,0,0,0,7,0,94,99,105,107,119,127,1,6,0,0 ] - class ExprLexer(Lexer): + atn = ATNDeserializer().deserialize(serializedATN()) - decisionsToDFA = [DFA(ds, i) for i, ds in enumerate(atn.decisionToState)] + decisionsToDFA = [ DFA(ds, i) for i, ds in enumerate(atn.decisionToState) ] T__0 = 1 T__1 = 2 @@ -1217,71 +83,29 @@ class ExprLexer(Lexer): COMPARISON = 18 WS = 19 - channelNames = ["DEFAULT_TOKEN_CHANNEL", "HIDDEN"] + channelNames = [ u"DEFAULT_TOKEN_CHANNEL", u"HIDDEN" ] - modeNames = ["DEFAULT_MODE"] + modeNames = [ "DEFAULT_MODE" ] - literalNames = [ - "", - "'.'", - "'-'", - "'('", - "')'", - "'/'", - "'*'", - "'+'", - "'sum'", - "'sum_connections'", - "'..'", - "','", - "'['", - "']'", - "'max'", - "'t'", - ] + literalNames = [ "", + "'.'", "'-'", "'('", "')'", "'/'", "'*'", "'+'", "'sum'", "'sum_connections'", + "'..'", "','", "'['", "']'", "'max'", "'t'" ] - symbolicNames = [ - "", - "NUMBER", - "MAX", - "TIME", - "IDENTIFIER", - "COMPARISON", - "WS", - ] + symbolicNames = [ "", + "NUMBER", "MAX", "TIME", "IDENTIFIER", "COMPARISON", "WS" ] - ruleNames = [ - "T__0", - "T__1", - "T__2", - "T__3", - "T__4", - "T__5", - "T__6", - "T__7", - "T__8", - "T__9", - "T__10", - "T__11", - "T__12", - "DIGIT", - "CHAR", - "CHAR_OR_DIGIT", - "NUMBER", - "MAX", - "TIME", - "IDENTIFIER", - "COMPARISON", - "WS", - ] + ruleNames = [ "T__0", "T__1", "T__2", "T__3", "T__4", "T__5", "T__6", + "T__7", "T__8", "T__9", "T__10", "T__11", "T__12", "DIGIT", + "CHAR", "CHAR_OR_DIGIT", "NUMBER", "MAX", "TIME", "IDENTIFIER", + "COMPARISON", "WS" ] grammarFileName = "Expr.g4" - def __init__(self, input=None, output: TextIO = sys.stdout): + def __init__(self, input=None, output:TextIO = sys.stdout): super().__init__(input, output) self.checkVersion("4.13.2") - self._interp = LexerATNSimulator( - self, self.atn, self.decisionsToDFA, PredictionContextCache() - ) + self._interp = LexerATNSimulator(self, self.atn, self.decisionsToDFA, PredictionContextCache()) self._actions = None self._predicates = None + + diff --git a/src/gems/expression/parsing/antlr/ExprParser.py b/src/gems/expression/parsing/antlr/ExprParser.py index 3175ed5f..77e0781b 100644 --- a/src/gems/expression/parsing/antlr/ExprParser.py +++ b/src/gems/expression/parsing/antlr/ExprParser.py @@ -3,1430 +3,85 @@ from antlr4 import * from io import StringIO import sys - if sys.version_info[1] > 5: - from typing import TextIO + from typing import TextIO else: - from typing.io import TextIO - + from typing.io import TextIO def serializedATN(): return [ - 4, - 1, - 19, - 152, - 2, - 0, - 7, - 0, - 2, - 1, - 7, - 1, - 2, - 2, - 7, - 2, - 2, - 3, - 7, - 3, - 2, - 4, - 7, - 4, - 2, - 5, - 7, - 5, - 2, - 6, - 7, - 6, - 1, - 0, - 1, - 0, - 1, - 0, - 1, - 0, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 5, - 2, - 84, - 8, - 2, - 10, - 2, - 12, - 2, - 87, - 9, - 2, - 1, - 2, - 1, - 2, - 3, - 2, - 91, - 8, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 5, - 2, - 102, - 8, - 2, - 10, - 2, - 12, - 2, - 105, - 9, - 2, - 1, - 3, - 1, - 3, - 3, - 3, - 109, - 8, - 3, - 1, - 4, - 1, - 4, - 3, - 4, - 113, - 8, - 4, - 1, - 5, - 1, - 5, - 1, - 5, - 1, - 5, - 1, - 5, - 1, - 5, - 1, - 5, - 1, - 5, - 3, - 5, - 123, - 8, - 5, - 1, - 5, - 1, - 5, - 1, - 5, - 1, - 5, - 1, - 5, - 1, - 5, - 5, - 5, - 131, - 8, - 5, - 10, - 5, - 12, - 5, - 134, - 9, - 5, - 1, - 6, - 1, - 6, - 1, - 6, - 1, - 6, - 1, - 6, - 1, - 6, - 3, - 6, - 142, - 8, - 6, - 1, - 6, - 1, - 6, - 1, - 6, - 5, - 6, - 147, - 8, - 6, - 10, - 6, - 12, - 6, - 150, - 9, - 6, - 1, - 6, - 0, - 3, - 4, - 10, - 12, - 7, - 0, - 2, - 4, - 6, - 8, - 10, - 12, - 0, - 2, - 1, - 0, - 5, - 6, - 2, - 0, - 2, - 2, - 7, - 7, - 167, - 0, - 14, - 1, - 0, - 0, - 0, - 2, - 18, - 1, - 0, - 0, - 0, - 4, - 90, - 1, - 0, - 0, - 0, - 6, - 108, - 1, - 0, - 0, - 0, - 8, - 110, - 1, - 0, - 0, - 0, - 10, - 122, - 1, - 0, - 0, - 0, - 12, - 141, - 1, - 0, - 0, - 0, - 14, - 15, - 5, - 17, - 0, - 0, - 15, - 16, - 5, - 1, - 0, - 0, - 16, - 17, - 5, - 17, - 0, - 0, - 17, - 1, - 1, - 0, - 0, - 0, - 18, - 19, - 3, - 4, - 2, - 0, - 19, - 20, - 5, - 0, - 0, - 1, - 20, - 3, - 1, - 0, - 0, - 0, - 21, - 22, - 6, - 2, - -1, - 0, - 22, - 91, - 3, - 6, - 3, - 0, - 23, - 91, - 3, - 0, - 0, - 0, - 24, - 25, - 5, - 2, - 0, - 0, - 25, - 91, - 3, - 4, - 2, - 14, - 26, - 27, - 5, - 3, - 0, - 0, - 27, - 28, - 3, - 4, - 2, - 0, - 28, - 29, - 5, - 4, - 0, - 0, - 29, - 91, - 1, - 0, - 0, - 0, - 30, - 31, - 5, - 8, - 0, - 0, - 31, - 32, - 5, - 3, - 0, - 0, - 32, - 33, - 3, - 4, - 2, - 0, - 33, - 34, - 5, - 4, - 0, - 0, - 34, - 91, - 1, - 0, - 0, - 0, - 35, - 36, - 5, - 9, - 0, - 0, - 36, - 37, - 5, - 3, - 0, - 0, - 37, - 38, - 3, - 0, - 0, - 0, - 38, - 39, - 5, - 4, - 0, - 0, - 39, - 91, - 1, - 0, - 0, - 0, - 40, - 41, - 5, - 8, - 0, - 0, - 41, - 42, - 5, - 3, - 0, - 0, - 42, - 43, - 3, - 8, - 4, - 0, - 43, - 44, - 5, - 10, - 0, - 0, - 44, - 45, - 3, - 8, - 4, - 0, - 45, - 46, - 5, - 11, - 0, - 0, - 46, - 47, - 3, - 4, - 2, - 0, - 47, - 48, - 5, - 4, - 0, - 0, - 48, - 91, - 1, - 0, - 0, - 0, - 49, - 50, - 5, - 17, - 0, - 0, - 50, - 51, - 5, - 3, - 0, - 0, - 51, - 52, - 3, - 4, - 2, - 0, - 52, - 53, - 5, - 4, - 0, - 0, - 53, - 91, - 1, - 0, - 0, - 0, - 54, - 55, - 5, - 17, - 0, - 0, - 55, - 56, - 5, - 12, - 0, - 0, - 56, - 57, - 3, - 8, - 4, - 0, - 57, - 58, - 5, - 13, - 0, - 0, - 58, - 91, - 1, - 0, - 0, - 0, - 59, - 60, - 5, - 17, - 0, - 0, - 60, - 61, - 5, - 12, - 0, - 0, - 61, - 62, - 3, - 4, - 2, - 0, - 62, - 63, - 5, - 13, - 0, - 0, - 63, - 91, - 1, - 0, - 0, - 0, - 64, - 65, - 5, - 3, - 0, - 0, - 65, - 66, - 3, - 4, - 2, - 0, - 66, - 67, - 5, - 4, - 0, - 0, - 67, - 68, - 5, - 12, - 0, - 0, - 68, - 69, - 3, - 8, - 4, - 0, - 69, - 70, - 5, - 13, - 0, - 0, - 70, - 91, - 1, - 0, - 0, - 0, - 71, - 72, - 5, - 3, - 0, - 0, - 72, - 73, - 3, - 4, - 2, - 0, - 73, - 74, - 5, - 4, - 0, - 0, - 74, - 75, - 5, - 12, - 0, - 0, - 75, - 76, - 3, - 4, - 2, - 0, - 76, - 77, - 5, - 13, - 0, - 0, - 77, - 91, - 1, - 0, - 0, - 0, - 78, - 79, - 5, - 15, - 0, - 0, - 79, - 80, - 5, - 3, - 0, - 0, - 80, - 85, - 3, - 4, - 2, - 0, - 81, - 82, - 5, - 11, - 0, - 0, - 82, - 84, - 3, - 4, - 2, - 0, - 83, - 81, - 1, - 0, - 0, - 0, - 84, - 87, - 1, - 0, - 0, - 0, - 85, - 83, - 1, - 0, - 0, - 0, - 85, - 86, - 1, - 0, - 0, - 0, - 86, - 88, - 1, - 0, - 0, - 0, - 87, - 85, - 1, - 0, - 0, - 0, - 88, - 89, - 5, - 4, - 0, - 0, - 89, - 91, - 1, - 0, - 0, - 0, - 90, - 21, - 1, - 0, - 0, - 0, - 90, - 23, - 1, - 0, - 0, - 0, - 90, - 24, - 1, - 0, - 0, - 0, - 90, - 26, - 1, - 0, - 0, - 0, - 90, - 30, - 1, - 0, - 0, - 0, - 90, - 35, - 1, - 0, - 0, - 0, - 90, - 40, - 1, - 0, - 0, - 0, - 90, - 49, - 1, - 0, - 0, - 0, - 90, - 54, - 1, - 0, - 0, - 0, - 90, - 59, - 1, - 0, - 0, - 0, - 90, - 64, - 1, - 0, - 0, - 0, - 90, - 71, - 1, - 0, - 0, - 0, - 90, - 78, - 1, - 0, - 0, - 0, - 91, - 103, - 1, - 0, - 0, - 0, - 92, - 93, - 10, - 12, - 0, - 0, - 93, - 94, - 7, - 0, - 0, - 0, - 94, - 102, - 3, - 4, - 2, - 13, - 95, - 96, - 10, - 11, - 0, - 0, - 96, - 97, - 7, - 1, - 0, - 0, - 97, - 102, - 3, - 4, - 2, - 12, - 98, - 99, - 10, - 10, - 0, - 0, - 99, - 100, - 5, - 18, - 0, - 0, - 100, - 102, - 3, - 4, - 2, - 11, - 101, - 92, - 1, - 0, - 0, - 0, - 101, - 95, - 1, - 0, - 0, - 0, - 101, - 98, - 1, - 0, - 0, - 0, - 102, - 105, - 1, - 0, - 0, - 0, - 103, - 101, - 1, - 0, - 0, - 0, - 103, - 104, - 1, - 0, - 0, - 0, - 104, - 5, - 1, - 0, - 0, - 0, - 105, - 103, - 1, - 0, - 0, - 0, - 106, - 109, - 5, - 14, - 0, - 0, - 107, - 109, - 5, - 17, - 0, - 0, - 108, - 106, - 1, - 0, - 0, - 0, - 108, - 107, - 1, - 0, - 0, - 0, - 109, - 7, - 1, - 0, - 0, - 0, - 110, - 112, - 5, - 16, - 0, - 0, - 111, - 113, - 3, - 10, - 5, - 0, - 112, - 111, - 1, - 0, - 0, - 0, - 112, - 113, - 1, - 0, - 0, - 0, - 113, - 9, - 1, - 0, - 0, - 0, - 114, - 115, - 6, - 5, - -1, - 0, - 115, - 116, - 7, - 1, - 0, - 0, - 116, - 123, - 3, - 6, - 3, - 0, - 117, - 118, - 7, - 1, - 0, - 0, - 118, - 119, - 5, - 3, - 0, - 0, - 119, - 120, - 3, - 4, - 2, - 0, - 120, - 121, - 5, - 4, - 0, - 0, - 121, - 123, - 1, - 0, - 0, - 0, - 122, - 114, - 1, - 0, - 0, - 0, - 122, - 117, - 1, - 0, - 0, - 0, - 123, - 132, - 1, - 0, - 0, - 0, - 124, - 125, - 10, - 4, - 0, - 0, - 125, - 126, - 7, - 0, - 0, - 0, - 126, - 131, - 3, - 12, - 6, - 0, - 127, - 128, - 10, - 3, - 0, - 0, - 128, - 129, - 7, - 1, - 0, - 0, - 129, - 131, - 3, - 12, - 6, - 0, - 130, - 124, - 1, - 0, - 0, - 0, - 130, - 127, - 1, - 0, - 0, - 0, - 131, - 134, - 1, - 0, - 0, - 0, - 132, - 130, - 1, - 0, - 0, - 0, - 132, - 133, - 1, - 0, - 0, - 0, - 133, - 11, - 1, - 0, - 0, - 0, - 134, - 132, - 1, - 0, - 0, - 0, - 135, - 136, - 6, - 6, - -1, - 0, - 136, - 137, - 5, - 3, - 0, - 0, - 137, - 138, - 3, - 4, - 2, - 0, - 138, - 139, - 5, - 4, - 0, - 0, - 139, - 142, - 1, - 0, - 0, - 0, - 140, - 142, - 3, - 6, - 3, - 0, - 141, - 135, - 1, - 0, - 0, - 0, - 141, - 140, - 1, - 0, - 0, - 0, - 142, - 148, - 1, - 0, - 0, - 0, - 143, - 144, - 10, - 3, - 0, - 0, - 144, - 145, - 7, - 0, - 0, - 0, - 145, - 147, - 3, - 12, - 6, - 4, - 146, - 143, - 1, - 0, - 0, - 0, - 147, - 150, - 1, - 0, - 0, - 0, - 148, - 146, - 1, - 0, - 0, - 0, - 148, - 149, - 1, - 0, - 0, - 0, - 149, - 13, - 1, - 0, - 0, - 0, - 150, - 148, - 1, - 0, - 0, - 0, - 11, - 85, - 90, - 101, - 103, - 108, - 112, - 122, - 130, - 132, - 141, - 148, + 4,1,19,152,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7, + 6,1,0,1,0,1,0,1,0,1,1,1,1,1,1,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1, + 2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1, + 2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1, + 2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1, + 2,1,2,1,2,1,2,1,2,1,2,5,2,84,8,2,10,2,12,2,87,9,2,1,2,1,2,3,2,91, + 8,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,5,2,102,8,2,10,2,12,2,105, + 9,2,1,3,1,3,3,3,109,8,3,1,4,1,4,3,4,113,8,4,1,5,1,5,1,5,1,5,1,5, + 1,5,1,5,1,5,3,5,123,8,5,1,5,1,5,1,5,1,5,1,5,1,5,5,5,131,8,5,10,5, + 12,5,134,9,5,1,6,1,6,1,6,1,6,1,6,1,6,3,6,142,8,6,1,6,1,6,1,6,5,6, + 147,8,6,10,6,12,6,150,9,6,1,6,0,3,4,10,12,7,0,2,4,6,8,10,12,0,2, + 1,0,5,6,2,0,2,2,7,7,167,0,14,1,0,0,0,2,18,1,0,0,0,4,90,1,0,0,0,6, + 108,1,0,0,0,8,110,1,0,0,0,10,122,1,0,0,0,12,141,1,0,0,0,14,15,5, + 17,0,0,15,16,5,1,0,0,16,17,5,17,0,0,17,1,1,0,0,0,18,19,3,4,2,0,19, + 20,5,0,0,1,20,3,1,0,0,0,21,22,6,2,-1,0,22,91,3,6,3,0,23,91,3,0,0, + 0,24,25,5,2,0,0,25,91,3,4,2,14,26,27,5,3,0,0,27,28,3,4,2,0,28,29, + 5,4,0,0,29,91,1,0,0,0,30,31,5,8,0,0,31,32,5,3,0,0,32,33,3,4,2,0, + 33,34,5,4,0,0,34,91,1,0,0,0,35,36,5,9,0,0,36,37,5,3,0,0,37,38,3, + 0,0,0,38,39,5,4,0,0,39,91,1,0,0,0,40,41,5,8,0,0,41,42,5,3,0,0,42, + 43,3,8,4,0,43,44,5,10,0,0,44,45,3,8,4,0,45,46,5,11,0,0,46,47,3,4, + 2,0,47,48,5,4,0,0,48,91,1,0,0,0,49,50,5,17,0,0,50,51,5,3,0,0,51, + 52,3,4,2,0,52,53,5,4,0,0,53,91,1,0,0,0,54,55,5,17,0,0,55,56,5,12, + 0,0,56,57,3,8,4,0,57,58,5,13,0,0,58,91,1,0,0,0,59,60,5,17,0,0,60, + 61,5,12,0,0,61,62,3,4,2,0,62,63,5,13,0,0,63,91,1,0,0,0,64,65,5,3, + 0,0,65,66,3,4,2,0,66,67,5,4,0,0,67,68,5,12,0,0,68,69,3,8,4,0,69, + 70,5,13,0,0,70,91,1,0,0,0,71,72,5,3,0,0,72,73,3,4,2,0,73,74,5,4, + 0,0,74,75,5,12,0,0,75,76,3,4,2,0,76,77,5,13,0,0,77,91,1,0,0,0,78, + 79,5,15,0,0,79,80,5,3,0,0,80,85,3,4,2,0,81,82,5,11,0,0,82,84,3,4, + 2,0,83,81,1,0,0,0,84,87,1,0,0,0,85,83,1,0,0,0,85,86,1,0,0,0,86,88, + 1,0,0,0,87,85,1,0,0,0,88,89,5,4,0,0,89,91,1,0,0,0,90,21,1,0,0,0, + 90,23,1,0,0,0,90,24,1,0,0,0,90,26,1,0,0,0,90,30,1,0,0,0,90,35,1, + 0,0,0,90,40,1,0,0,0,90,49,1,0,0,0,90,54,1,0,0,0,90,59,1,0,0,0,90, + 64,1,0,0,0,90,71,1,0,0,0,90,78,1,0,0,0,91,103,1,0,0,0,92,93,10,12, + 0,0,93,94,7,0,0,0,94,102,3,4,2,13,95,96,10,11,0,0,96,97,7,1,0,0, + 97,102,3,4,2,12,98,99,10,10,0,0,99,100,5,18,0,0,100,102,3,4,2,11, + 101,92,1,0,0,0,101,95,1,0,0,0,101,98,1,0,0,0,102,105,1,0,0,0,103, + 101,1,0,0,0,103,104,1,0,0,0,104,5,1,0,0,0,105,103,1,0,0,0,106,109, + 5,14,0,0,107,109,5,17,0,0,108,106,1,0,0,0,108,107,1,0,0,0,109,7, + 1,0,0,0,110,112,5,16,0,0,111,113,3,10,5,0,112,111,1,0,0,0,112,113, + 1,0,0,0,113,9,1,0,0,0,114,115,6,5,-1,0,115,116,7,1,0,0,116,123,3, + 6,3,0,117,118,7,1,0,0,118,119,5,3,0,0,119,120,3,4,2,0,120,121,5, + 4,0,0,121,123,1,0,0,0,122,114,1,0,0,0,122,117,1,0,0,0,123,132,1, + 0,0,0,124,125,10,4,0,0,125,126,7,0,0,0,126,131,3,12,6,0,127,128, + 10,3,0,0,128,129,7,1,0,0,129,131,3,12,6,0,130,124,1,0,0,0,130,127, + 1,0,0,0,131,134,1,0,0,0,132,130,1,0,0,0,132,133,1,0,0,0,133,11,1, + 0,0,0,134,132,1,0,0,0,135,136,6,6,-1,0,136,137,5,3,0,0,137,138,3, + 4,2,0,138,139,5,4,0,0,139,142,1,0,0,0,140,142,3,6,3,0,141,135,1, + 0,0,0,141,140,1,0,0,0,142,148,1,0,0,0,143,144,10,3,0,0,144,145,7, + 0,0,0,145,147,3,12,6,4,146,143,1,0,0,0,147,150,1,0,0,0,148,146,1, + 0,0,0,148,149,1,0,0,0,149,13,1,0,0,0,150,148,1,0,0,0,11,85,90,101, + 103,108,112,122,130,132,141,148 ] +class ExprParser ( Parser ): -class ExprParser(Parser): grammarFileName = "Expr.g4" atn = ATNDeserializer().deserialize(serializedATN()) - decisionsToDFA = [DFA(ds, i) for i, ds in enumerate(atn.decisionToState)] + decisionsToDFA = [ DFA(ds, i) for i, ds in enumerate(atn.decisionToState) ] sharedContextCache = PredictionContextCache() - literalNames = [ - "", - "'.'", - "'-'", - "'('", - "')'", - "'/'", - "'*'", - "'+'", - "'sum'", - "'sum_connections'", - "'..'", - "','", - "'['", - "']'", - "", - "'max'", - "'t'", - ] + literalNames = [ "", "'.'", "'-'", "'('", "')'", "'/'", "'*'", + "'+'", "'sum'", "'sum_connections'", "'..'", "','", + "'['", "']'", "", "'max'", "'t'" ] - symbolicNames = [ - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "NUMBER", - "MAX", - "TIME", - "IDENTIFIER", - "COMPARISON", - "WS", - ] + symbolicNames = [ "", "", "", "", + "", "", "", "", + "", "", "", "", + "", "", "NUMBER", "MAX", "TIME", + "IDENTIFIER", "COMPARISON", "WS" ] RULE_portFieldExpr = 0 RULE_fullexpr = 1 @@ -1436,55 +91,47 @@ class ExprParser(Parser): RULE_shift_expr = 5 RULE_right_expr = 6 - ruleNames = [ - "portFieldExpr", - "fullexpr", - "expr", - "atom", - "shift", - "shift_expr", - "right_expr", - ] + ruleNames = [ "portFieldExpr", "fullexpr", "expr", "atom", "shift", + "shift_expr", "right_expr" ] EOF = Token.EOF - T__0 = 1 - T__1 = 2 - T__2 = 3 - T__3 = 4 - T__4 = 5 - T__5 = 6 - T__6 = 7 - T__7 = 8 - T__8 = 9 - T__9 = 10 - T__10 = 11 - T__11 = 12 - T__12 = 13 - NUMBER = 14 - MAX = 15 - TIME = 16 - IDENTIFIER = 17 - COMPARISON = 18 - WS = 19 - - def __init__(self, input: TokenStream, output: TextIO = sys.stdout): + T__0=1 + T__1=2 + T__2=3 + T__3=4 + T__4=5 + T__5=6 + T__6=7 + T__7=8 + T__8=9 + T__9=10 + T__10=11 + T__11=12 + T__12=13 + NUMBER=14 + MAX=15 + TIME=16 + IDENTIFIER=17 + COMPARISON=18 + WS=19 + + def __init__(self, input:TokenStream, output:TextIO = sys.stdout): super().__init__(input, output) self.checkVersion("4.13.2") - self._interp = ParserATNSimulator( - self, self.atn, self.decisionsToDFA, self.sharedContextCache - ) + self._interp = ParserATNSimulator(self, self.atn, self.decisionsToDFA, self.sharedContextCache) self._predicates = None + + + class PortFieldExprContext(ParserRuleContext): - __slots__ = "parser" + __slots__ = 'parser' - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): + def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): super().__init__(parent, invokingState) self.parser = parser - def IDENTIFIER(self, i: int = None): + def IDENTIFIER(self, i:int=None): if i is None: return self.getTokens(ExprParser.IDENTIFIER) else: @@ -1493,13 +140,17 @@ def IDENTIFIER(self, i: int = None): def getRuleIndex(self): return ExprParser.RULE_portFieldExpr - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitPortFieldExpr"): + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitPortFieldExpr" ): return visitor.visitPortFieldExpr(self) else: return visitor.visitChildren(self) + + + def portFieldExpr(self): + localctx = ExprParser.PortFieldExprContext(self, self._ctx, self.state) self.enterRule(localctx, 0, self.RULE_portFieldExpr) try: @@ -1518,17 +169,17 @@ def portFieldExpr(self): self.exitRule() return localctx + class FullexprContext(ParserRuleContext): - __slots__ = "parser" + __slots__ = 'parser' - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): + def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): super().__init__(parent, invokingState) self.parser = parser def expr(self): - return self.getTypedRuleContext(ExprParser.ExprContext, 0) + return self.getTypedRuleContext(ExprParser.ExprContext,0) + def EOF(self): return self.getToken(ExprParser.EOF, 0) @@ -1536,13 +187,17 @@ def EOF(self): def getRuleIndex(self): return ExprParser.RULE_fullexpr - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitFullexpr"): + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitFullexpr" ): return visitor.visitFullexpr(self) else: return visitor.visitChildren(self) + + + def fullexpr(self): + localctx = ExprParser.FullexprContext(self, self._ctx, self.state) self.enterRule(localctx, 2, self.RULE_fullexpr) try: @@ -1559,333 +214,347 @@ def fullexpr(self): self.exitRule() return localctx + class ExprContext(ParserRuleContext): - __slots__ = "parser" + __slots__ = 'parser' - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): + def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): super().__init__(parent, invokingState) self.parser = parser + def getRuleIndex(self): return ExprParser.RULE_expr - def copyFrom(self, ctx: ParserRuleContext): + + def copyFrom(self, ctx:ParserRuleContext): super().copyFrom(ctx) + class PortFieldSumContext(ExprContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.ExprContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) def portFieldExpr(self): - return self.getTypedRuleContext(ExprParser.PortFieldExprContext, 0) + return self.getTypedRuleContext(ExprParser.PortFieldExprContext,0) - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitPortFieldSum"): + + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitPortFieldSum" ): return visitor.visitPortFieldSum(self) else: return visitor.visitChildren(self) + class NegationContext(ExprContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.ExprContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) def expr(self): - return self.getTypedRuleContext(ExprParser.ExprContext, 0) + return self.getTypedRuleContext(ExprParser.ExprContext,0) + - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitNegation"): + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitNegation" ): return visitor.visitNegation(self) else: return visitor.visitChildren(self) + class UnsignedAtomContext(ExprContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.ExprContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) def atom(self): - return self.getTypedRuleContext(ExprParser.AtomContext, 0) + return self.getTypedRuleContext(ExprParser.AtomContext,0) - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitUnsignedAtom"): + + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitUnsignedAtom" ): return visitor.visitUnsignedAtom(self) else: return visitor.visitChildren(self) + class ExpressionContext(ExprContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.ExprContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) def expr(self): - return self.getTypedRuleContext(ExprParser.ExprContext, 0) + return self.getTypedRuleContext(ExprParser.ExprContext,0) + - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitExpression"): + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitExpression" ): return visitor.visitExpression(self) else: return visitor.visitChildren(self) + class ComparisonContext(ExprContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.ExprContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) - def expr(self, i: int = None): + def expr(self, i:int=None): if i is None: return self.getTypedRuleContexts(ExprParser.ExprContext) else: - return self.getTypedRuleContext(ExprParser.ExprContext, i) + return self.getTypedRuleContext(ExprParser.ExprContext,i) def COMPARISON(self): return self.getToken(ExprParser.COMPARISON, 0) - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitComparison"): + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitComparison" ): return visitor.visitComparison(self) else: return visitor.visitChildren(self) + class AllTimeSumContext(ExprContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.ExprContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) def expr(self): - return self.getTypedRuleContext(ExprParser.ExprContext, 0) + return self.getTypedRuleContext(ExprParser.ExprContext,0) + - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitAllTimeSum"): + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitAllTimeSum" ): return visitor.visitAllTimeSum(self) else: return visitor.visitChildren(self) + class TimeIndexExprContext(ExprContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.ExprContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) - def expr(self, i: int = None): + def expr(self, i:int=None): if i is None: return self.getTypedRuleContexts(ExprParser.ExprContext) else: - return self.getTypedRuleContext(ExprParser.ExprContext, i) + return self.getTypedRuleContext(ExprParser.ExprContext,i) - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitTimeIndexExpr"): + + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitTimeIndexExpr" ): return visitor.visitTimeIndexExpr(self) else: return visitor.visitChildren(self) + class AddsubContext(ExprContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.ExprContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext super().__init__(parser) - self.op = None # Token + self.op = None # Token self.copyFrom(ctx) - def expr(self, i: int = None): + def expr(self, i:int=None): if i is None: return self.getTypedRuleContexts(ExprParser.ExprContext) else: - return self.getTypedRuleContext(ExprParser.ExprContext, i) + return self.getTypedRuleContext(ExprParser.ExprContext,i) + - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitAddsub"): + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitAddsub" ): return visitor.visitAddsub(self) else: return visitor.visitChildren(self) + class TimeShiftExprContext(ExprContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.ExprContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) def expr(self): - return self.getTypedRuleContext(ExprParser.ExprContext, 0) + return self.getTypedRuleContext(ExprParser.ExprContext,0) def shift(self): - return self.getTypedRuleContext(ExprParser.ShiftContext, 0) + return self.getTypedRuleContext(ExprParser.ShiftContext,0) - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitTimeShiftExpr"): + + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitTimeShiftExpr" ): return visitor.visitTimeShiftExpr(self) else: return visitor.visitChildren(self) + class PortFieldContext(ExprContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.ExprContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) def portFieldExpr(self): - return self.getTypedRuleContext(ExprParser.PortFieldExprContext, 0) + return self.getTypedRuleContext(ExprParser.PortFieldExprContext,0) + - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitPortField"): + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitPortField" ): return visitor.visitPortField(self) else: return visitor.visitChildren(self) + class MuldivContext(ExprContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.ExprContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext super().__init__(parser) - self.op = None # Token + self.op = None # Token self.copyFrom(ctx) - def expr(self, i: int = None): + def expr(self, i:int=None): if i is None: return self.getTypedRuleContexts(ExprParser.ExprContext) else: - return self.getTypedRuleContext(ExprParser.ExprContext, i) + return self.getTypedRuleContext(ExprParser.ExprContext,i) - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitMuldiv"): + + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitMuldiv" ): return visitor.visitMuldiv(self) else: return visitor.visitChildren(self) + class TimeSumContext(ExprContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.ExprContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext super().__init__(parser) - self.from_ = None # ShiftContext - self.to = None # ShiftContext + self.from_ = None # ShiftContext + self.to = None # ShiftContext self.copyFrom(ctx) def expr(self): - return self.getTypedRuleContext(ExprParser.ExprContext, 0) + return self.getTypedRuleContext(ExprParser.ExprContext,0) - def shift(self, i: int = None): + def shift(self, i:int=None): if i is None: return self.getTypedRuleContexts(ExprParser.ShiftContext) else: - return self.getTypedRuleContext(ExprParser.ShiftContext, i) + return self.getTypedRuleContext(ExprParser.ShiftContext,i) + - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitTimeSum"): + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitTimeSum" ): return visitor.visitTimeSum(self) else: return visitor.visitChildren(self) + class MaxExprContext(ExprContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.ExprContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) def MAX(self): return self.getToken(ExprParser.MAX, 0) - - def expr(self, i: int = None): + def expr(self, i:int=None): if i is None: return self.getTypedRuleContexts(ExprParser.ExprContext) else: - return self.getTypedRuleContext(ExprParser.ExprContext, i) + return self.getTypedRuleContext(ExprParser.ExprContext,i) + - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitMaxExpr"): + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitMaxExpr" ): return visitor.visitMaxExpr(self) else: return visitor.visitChildren(self) + class TimeIndexContext(ExprContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.ExprContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) def IDENTIFIER(self): return self.getToken(ExprParser.IDENTIFIER, 0) - def expr(self): - return self.getTypedRuleContext(ExprParser.ExprContext, 0) + return self.getTypedRuleContext(ExprParser.ExprContext,0) + - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitTimeIndex"): + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitTimeIndex" ): return visitor.visitTimeIndex(self) else: return visitor.visitChildren(self) + class TimeShiftContext(ExprContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.ExprContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) def IDENTIFIER(self): return self.getToken(ExprParser.IDENTIFIER, 0) - def shift(self): - return self.getTypedRuleContext(ExprParser.ShiftContext, 0) + return self.getTypedRuleContext(ExprParser.ShiftContext,0) + - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitTimeShift"): + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitTimeShift" ): return visitor.visitTimeShift(self) else: return visitor.visitChildren(self) + class FunctionContext(ExprContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.ExprContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) def IDENTIFIER(self): return self.getToken(ExprParser.IDENTIFIER, 0) - def expr(self): - return self.getTypedRuleContext(ExprParser.ExprContext, 0) + return self.getTypedRuleContext(ExprParser.ExprContext,0) - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitFunction"): + + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitFunction" ): return visitor.visitFunction(self) else: return visitor.visitChildren(self) - def expr(self, _p: int = 0): + + + def expr(self, _p:int=0): _parentctx = self._ctx _parentState = self.state localctx = ExprParser.ExprContext(self, self._ctx, _parentState) _prevctx = localctx _startState = 4 self.enterRecursionRule(localctx, 4, self.RULE_expr, _p) - self._la = 0 # Token type + self._la = 0 # Token type try: self.enterOuterAlt(localctx, 1) self.state = 90 self._errHandler.sync(self) - la_ = self._interp.adaptivePredict(self._input, 1, self._ctx) + la_ = self._interp.adaptivePredict(self._input,1,self._ctx) if la_ == 1: localctx = ExprParser.UnsignedAtomContext(self, localctx) self._ctx = localctx @@ -2066,7 +735,7 @@ def expr(self, _p: int = 0): self.state = 85 self._errHandler.sync(self) _la = self._input.LA(1) - while _la == 11: + while _la==11: self.state = 81 self.match(ExprParser.T__10) self.state = 82 @@ -2079,36 +748,30 @@ def expr(self, _p: int = 0): self.match(ExprParser.T__3) pass + self._ctx.stop = self._input.LT(-1) self.state = 103 self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input, 3, self._ctx) - while _alt != 2 and _alt != ATN.INVALID_ALT_NUMBER: - if _alt == 1: + _alt = self._interp.adaptivePredict(self._input,3,self._ctx) + while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER: + if _alt==1: if self._parseListeners is not None: self.triggerExitRuleEvent() _prevctx = localctx self.state = 101 self._errHandler.sync(self) - la_ = self._interp.adaptivePredict(self._input, 2, self._ctx) + la_ = self._interp.adaptivePredict(self._input,2,self._ctx) if la_ == 1: - localctx = ExprParser.MuldivContext( - self, ExprParser.ExprContext(self, _parentctx, _parentState) - ) - self.pushNewRecursionContext( - localctx, _startState, self.RULE_expr - ) + localctx = ExprParser.MuldivContext(self, ExprParser.ExprContext(self, _parentctx, _parentState)) + self.pushNewRecursionContext(localctx, _startState, self.RULE_expr) self.state = 92 if not self.precpred(self._ctx, 12): from antlr4.error.Errors import FailedPredicateException - - raise FailedPredicateException( - self, "self.precpred(self._ctx, 12)" - ) + raise FailedPredicateException(self, "self.precpred(self._ctx, 12)") self.state = 93 localctx.op = self._input.LT(1) _la = self._input.LA(1) - if not (_la == 5 or _la == 6): + if not(_la==5 or _la==6): localctx.op = self._errHandler.recoverInline(self) else: self._errHandler.reportMatch(self) @@ -2118,23 +781,16 @@ def expr(self, _p: int = 0): pass elif la_ == 2: - localctx = ExprParser.AddsubContext( - self, ExprParser.ExprContext(self, _parentctx, _parentState) - ) - self.pushNewRecursionContext( - localctx, _startState, self.RULE_expr - ) + localctx = ExprParser.AddsubContext(self, ExprParser.ExprContext(self, _parentctx, _parentState)) + self.pushNewRecursionContext(localctx, _startState, self.RULE_expr) self.state = 95 if not self.precpred(self._ctx, 11): from antlr4.error.Errors import FailedPredicateException - - raise FailedPredicateException( - self, "self.precpred(self._ctx, 11)" - ) + raise FailedPredicateException(self, "self.precpred(self._ctx, 11)") self.state = 96 localctx.op = self._input.LT(1) _la = self._input.LA(1) - if not (_la == 2 or _la == 7): + if not(_la==2 or _la==7): localctx.op = self._errHandler.recoverInline(self) else: self._errHandler.reportMatch(self) @@ -2144,28 +800,22 @@ def expr(self, _p: int = 0): pass elif la_ == 3: - localctx = ExprParser.ComparisonContext( - self, ExprParser.ExprContext(self, _parentctx, _parentState) - ) - self.pushNewRecursionContext( - localctx, _startState, self.RULE_expr - ) + localctx = ExprParser.ComparisonContext(self, ExprParser.ExprContext(self, _parentctx, _parentState)) + self.pushNewRecursionContext(localctx, _startState, self.RULE_expr) self.state = 98 if not self.precpred(self._ctx, 10): from antlr4.error.Errors import FailedPredicateException - - raise FailedPredicateException( - self, "self.precpred(self._ctx, 10)" - ) + raise FailedPredicateException(self, "self.precpred(self._ctx, 10)") self.state = 99 self.match(ExprParser.COMPARISON) self.state = 100 self.expr(11) pass + self.state = 105 self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input, 3, self._ctx) + _alt = self._interp.adaptivePredict(self._input,3,self._ctx) except RecognitionException as re: localctx.exception = re @@ -2175,54 +825,59 @@ def expr(self, _p: int = 0): self.unrollRecursionContexts(_parentctx) return localctx + class AtomContext(ParserRuleContext): - __slots__ = "parser" + __slots__ = 'parser' - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): + def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): super().__init__(parent, invokingState) self.parser = parser + def getRuleIndex(self): return ExprParser.RULE_atom - def copyFrom(self, ctx: ParserRuleContext): + + def copyFrom(self, ctx:ParserRuleContext): super().copyFrom(ctx) + + class NumberContext(AtomContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.AtomContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.AtomContext super().__init__(parser) self.copyFrom(ctx) def NUMBER(self): return self.getToken(ExprParser.NUMBER, 0) - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitNumber"): + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitNumber" ): return visitor.visitNumber(self) else: return visitor.visitChildren(self) + class IdentifierContext(AtomContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.AtomContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.AtomContext super().__init__(parser) self.copyFrom(ctx) def IDENTIFIER(self): return self.getToken(ExprParser.IDENTIFIER, 0) - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitIdentifier"): + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitIdentifier" ): return visitor.visitIdentifier(self) else: return visitor.visitChildren(self) + + def atom(self): + localctx = ExprParser.AtomContext(self, self._ctx, self.state) self.enterRule(localctx, 6, self.RULE_atom) try: @@ -2252,12 +907,11 @@ def atom(self): self.exitRule() return localctx + class ShiftContext(ParserRuleContext): - __slots__ = "parser" + __slots__ = 'parser' - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): + def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): super().__init__(parent, invokingState) self.parser = parser @@ -2265,21 +919,26 @@ def TIME(self): return self.getToken(ExprParser.TIME, 0) def shift_expr(self): - return self.getTypedRuleContext(ExprParser.Shift_exprContext, 0) + return self.getTypedRuleContext(ExprParser.Shift_exprContext,0) + def getRuleIndex(self): return ExprParser.RULE_shift - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitShift"): + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitShift" ): return visitor.visitShift(self) else: return visitor.visitChildren(self) + + + def shift(self): + localctx = ExprParser.ShiftContext(self, self._ctx, self.state) self.enterRule(localctx, 8, self.RULE_shift) - self._la = 0 # Token type + self._la = 0 # Token type try: self.enterOuterAlt(localctx, 1) self.state = 110 @@ -2287,10 +946,11 @@ def shift(self): self.state = 112 self._errHandler.sync(self) _la = self._input.LA(1) - if _la == 2 or _la == 7: + if _la==2 or _la==7: self.state = 111 self.shift_expr(0) + except RecognitionException as re: localctx.exception = re self._errHandler.reportError(self, re) @@ -2299,108 +959,115 @@ def shift(self): self.exitRule() return localctx + class Shift_exprContext(ParserRuleContext): - __slots__ = "parser" + __slots__ = 'parser' - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): + def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): super().__init__(parent, invokingState) self.parser = parser + def getRuleIndex(self): return ExprParser.RULE_shift_expr - def copyFrom(self, ctx: ParserRuleContext): + + def copyFrom(self, ctx:ParserRuleContext): super().copyFrom(ctx) + class SignedAtomContext(Shift_exprContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.Shift_exprContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.Shift_exprContext super().__init__(parser) - self.op = None # Token + self.op = None # Token self.copyFrom(ctx) def atom(self): - return self.getTypedRuleContext(ExprParser.AtomContext, 0) + return self.getTypedRuleContext(ExprParser.AtomContext,0) - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitSignedAtom"): + + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitSignedAtom" ): return visitor.visitSignedAtom(self) else: return visitor.visitChildren(self) + class SignedExpressionContext(Shift_exprContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.Shift_exprContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.Shift_exprContext super().__init__(parser) - self.op = None # Token + self.op = None # Token self.copyFrom(ctx) def expr(self): - return self.getTypedRuleContext(ExprParser.ExprContext, 0) + return self.getTypedRuleContext(ExprParser.ExprContext,0) + - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitSignedExpression"): + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitSignedExpression" ): return visitor.visitSignedExpression(self) else: return visitor.visitChildren(self) + class ShiftMuldivContext(Shift_exprContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.Shift_exprContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.Shift_exprContext super().__init__(parser) - self.op = None # Token + self.op = None # Token self.copyFrom(ctx) def shift_expr(self): - return self.getTypedRuleContext(ExprParser.Shift_exprContext, 0) + return self.getTypedRuleContext(ExprParser.Shift_exprContext,0) def right_expr(self): - return self.getTypedRuleContext(ExprParser.Right_exprContext, 0) + return self.getTypedRuleContext(ExprParser.Right_exprContext,0) + - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitShiftMuldiv"): + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitShiftMuldiv" ): return visitor.visitShiftMuldiv(self) else: return visitor.visitChildren(self) + class ShiftAddsubContext(Shift_exprContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.Shift_exprContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.Shift_exprContext super().__init__(parser) - self.op = None # Token + self.op = None # Token self.copyFrom(ctx) def shift_expr(self): - return self.getTypedRuleContext(ExprParser.Shift_exprContext, 0) + return self.getTypedRuleContext(ExprParser.Shift_exprContext,0) def right_expr(self): - return self.getTypedRuleContext(ExprParser.Right_exprContext, 0) + return self.getTypedRuleContext(ExprParser.Right_exprContext,0) - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitShiftAddsub"): + + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitShiftAddsub" ): return visitor.visitShiftAddsub(self) else: return visitor.visitChildren(self) - def shift_expr(self, _p: int = 0): + + + def shift_expr(self, _p:int=0): _parentctx = self._ctx _parentState = self.state localctx = ExprParser.Shift_exprContext(self, self._ctx, _parentState) _prevctx = localctx _startState = 10 self.enterRecursionRule(localctx, 10, self.RULE_shift_expr, _p) - self._la = 0 # Token type + self._la = 0 # Token type try: self.enterOuterAlt(localctx, 1) self.state = 122 self._errHandler.sync(self) - la_ = self._interp.adaptivePredict(self._input, 6, self._ctx) + la_ = self._interp.adaptivePredict(self._input,6,self._ctx) if la_ == 1: localctx = ExprParser.SignedAtomContext(self, localctx) self._ctx = localctx @@ -2409,7 +1076,7 @@ def shift_expr(self, _p: int = 0): self.state = 115 localctx.op = self._input.LT(1) _la = self._input.LA(1) - if not (_la == 2 or _la == 7): + if not(_la==2 or _la==7): localctx.op = self._errHandler.recoverInline(self) else: self._errHandler.reportMatch(self) @@ -2425,7 +1092,7 @@ def shift_expr(self, _p: int = 0): self.state = 117 localctx.op = self._input.LT(1) _la = self._input.LA(1) - if not (_la == 2 or _la == 7): + if not(_la==2 or _la==7): localctx.op = self._errHandler.recoverInline(self) else: self._errHandler.reportMatch(self) @@ -2438,39 +1105,30 @@ def shift_expr(self, _p: int = 0): self.match(ExprParser.T__3) pass + self._ctx.stop = self._input.LT(-1) self.state = 132 self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input, 8, self._ctx) - while _alt != 2 and _alt != ATN.INVALID_ALT_NUMBER: - if _alt == 1: + _alt = self._interp.adaptivePredict(self._input,8,self._ctx) + while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER: + if _alt==1: if self._parseListeners is not None: self.triggerExitRuleEvent() _prevctx = localctx self.state = 130 self._errHandler.sync(self) - la_ = self._interp.adaptivePredict(self._input, 7, self._ctx) + la_ = self._interp.adaptivePredict(self._input,7,self._ctx) if la_ == 1: - localctx = ExprParser.ShiftMuldivContext( - self, - ExprParser.Shift_exprContext( - self, _parentctx, _parentState - ), - ) - self.pushNewRecursionContext( - localctx, _startState, self.RULE_shift_expr - ) + localctx = ExprParser.ShiftMuldivContext(self, ExprParser.Shift_exprContext(self, _parentctx, _parentState)) + self.pushNewRecursionContext(localctx, _startState, self.RULE_shift_expr) self.state = 124 if not self.precpred(self._ctx, 4): from antlr4.error.Errors import FailedPredicateException - - raise FailedPredicateException( - self, "self.precpred(self._ctx, 4)" - ) + raise FailedPredicateException(self, "self.precpred(self._ctx, 4)") self.state = 125 localctx.op = self._input.LT(1) _la = self._input.LA(1) - if not (_la == 5 or _la == 6): + if not(_la==5 or _la==6): localctx.op = self._errHandler.recoverInline(self) else: self._errHandler.reportMatch(self) @@ -2480,26 +1138,16 @@ def shift_expr(self, _p: int = 0): pass elif la_ == 2: - localctx = ExprParser.ShiftAddsubContext( - self, - ExprParser.Shift_exprContext( - self, _parentctx, _parentState - ), - ) - self.pushNewRecursionContext( - localctx, _startState, self.RULE_shift_expr - ) + localctx = ExprParser.ShiftAddsubContext(self, ExprParser.Shift_exprContext(self, _parentctx, _parentState)) + self.pushNewRecursionContext(localctx, _startState, self.RULE_shift_expr) self.state = 127 if not self.precpred(self._ctx, 3): from antlr4.error.Errors import FailedPredicateException - - raise FailedPredicateException( - self, "self.precpred(self._ctx, 3)" - ) + raise FailedPredicateException(self, "self.precpred(self._ctx, 3)") self.state = 128 localctx.op = self._input.LT(1) _la = self._input.LA(1) - if not (_la == 2 or _la == 7): + if not(_la==2 or _la==7): localctx.op = self._errHandler.recoverInline(self) else: self._errHandler.reportMatch(self) @@ -2508,9 +1156,10 @@ def shift_expr(self, _p: int = 0): self.right_expr(0) pass + self.state = 134 self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input, 8, self._ctx) + _alt = self._interp.adaptivePredict(self._input,8,self._ctx) except RecognitionException as re: localctx.exception = re @@ -2520,81 +1169,87 @@ def shift_expr(self, _p: int = 0): self.unrollRecursionContexts(_parentctx) return localctx + class Right_exprContext(ParserRuleContext): - __slots__ = "parser" + __slots__ = 'parser' - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): + def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): super().__init__(parent, invokingState) self.parser = parser + def getRuleIndex(self): return ExprParser.RULE_right_expr - def copyFrom(self, ctx: ParserRuleContext): + + def copyFrom(self, ctx:ParserRuleContext): super().copyFrom(ctx) + class RightExpressionContext(Right_exprContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.Right_exprContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.Right_exprContext super().__init__(parser) self.copyFrom(ctx) def expr(self): - return self.getTypedRuleContext(ExprParser.ExprContext, 0) + return self.getTypedRuleContext(ExprParser.ExprContext,0) - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitRightExpression"): + + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitRightExpression" ): return visitor.visitRightExpression(self) else: return visitor.visitChildren(self) + class RightMuldivContext(Right_exprContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.Right_exprContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.Right_exprContext super().__init__(parser) - self.op = None # Token + self.op = None # Token self.copyFrom(ctx) - def right_expr(self, i: int = None): + def right_expr(self, i:int=None): if i is None: return self.getTypedRuleContexts(ExprParser.Right_exprContext) else: - return self.getTypedRuleContext(ExprParser.Right_exprContext, i) + return self.getTypedRuleContext(ExprParser.Right_exprContext,i) + - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitRightMuldiv"): + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitRightMuldiv" ): return visitor.visitRightMuldiv(self) else: return visitor.visitChildren(self) + class RightAtomContext(Right_exprContext): - def __init__( - self, parser, ctx: ParserRuleContext - ): # actually a ExprParser.Right_exprContext + + def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.Right_exprContext super().__init__(parser) self.copyFrom(ctx) def atom(self): - return self.getTypedRuleContext(ExprParser.AtomContext, 0) + return self.getTypedRuleContext(ExprParser.AtomContext,0) - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitRightAtom"): + + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitRightAtom" ): return visitor.visitRightAtom(self) else: return visitor.visitChildren(self) - def right_expr(self, _p: int = 0): + + + def right_expr(self, _p:int=0): _parentctx = self._ctx _parentState = self.state localctx = ExprParser.Right_exprContext(self, self._ctx, _parentState) _prevctx = localctx _startState = 12 self.enterRecursionRule(localctx, 12, self.RULE_right_expr, _p) - self._la = 0 # Token type + self._la = 0 # Token type try: self.enterOuterAlt(localctx, 1) self.state = 141 @@ -2625,39 +1280,31 @@ def right_expr(self, _p: int = 0): self._ctx.stop = self._input.LT(-1) self.state = 148 self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input, 10, self._ctx) - while _alt != 2 and _alt != ATN.INVALID_ALT_NUMBER: - if _alt == 1: + _alt = self._interp.adaptivePredict(self._input,10,self._ctx) + while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER: + if _alt==1: if self._parseListeners is not None: self.triggerExitRuleEvent() _prevctx = localctx - localctx = ExprParser.RightMuldivContext( - self, - ExprParser.Right_exprContext(self, _parentctx, _parentState), - ) - self.pushNewRecursionContext( - localctx, _startState, self.RULE_right_expr - ) + localctx = ExprParser.RightMuldivContext(self, ExprParser.Right_exprContext(self, _parentctx, _parentState)) + self.pushNewRecursionContext(localctx, _startState, self.RULE_right_expr) self.state = 143 if not self.precpred(self._ctx, 3): from antlr4.error.Errors import FailedPredicateException - - raise FailedPredicateException( - self, "self.precpred(self._ctx, 3)" - ) + raise FailedPredicateException(self, "self.precpred(self._ctx, 3)") self.state = 144 localctx.op = self._input.LT(1) _la = self._input.LA(1) - if not (_la == 5 or _la == 6): + if not(_la==5 or _la==6): localctx.op = self._errHandler.recoverInline(self) else: self._errHandler.reportMatch(self) self.consume() self.state = 145 - self.right_expr(4) + self.right_expr(4) self.state = 150 self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input, 10, self._ctx) + _alt = self._interp.adaptivePredict(self._input,10,self._ctx) except RecognitionException as re: localctx.exception = re @@ -2667,7 +1314,9 @@ def right_expr(self, _p: int = 0): self.unrollRecursionContexts(_parentctx) return localctx - def sempred(self, localctx: RuleContext, ruleIndex: int, predIndex: int): + + + def sempred(self, localctx:RuleContext, ruleIndex:int, predIndex:int): if self._predicates == None: self._predicates = dict() self._predicates[2] = self.expr_sempred @@ -2679,23 +1328,33 @@ def sempred(self, localctx: RuleContext, ruleIndex: int, predIndex: int): else: return pred(localctx, predIndex) - def expr_sempred(self, localctx: ExprContext, predIndex: int): - if predIndex == 0: - return self.precpred(self._ctx, 12) + def expr_sempred(self, localctx:ExprContext, predIndex:int): + if predIndex == 0: + return self.precpred(self._ctx, 12) + + + if predIndex == 1: + return self.precpred(self._ctx, 11) + + + if predIndex == 2: + return self.precpred(self._ctx, 10) + + + def shift_expr_sempred(self, localctx:Shift_exprContext, predIndex:int): + if predIndex == 3: + return self.precpred(self._ctx, 4) + + + if predIndex == 4: + return self.precpred(self._ctx, 3) + - if predIndex == 1: - return self.precpred(self._ctx, 11) + def right_expr_sempred(self, localctx:Right_exprContext, predIndex:int): + if predIndex == 5: + return self.precpred(self._ctx, 3) + - if predIndex == 2: - return self.precpred(self._ctx, 10) - def shift_expr_sempred(self, localctx: Shift_exprContext, predIndex: int): - if predIndex == 3: - return self.precpred(self._ctx, 4) - if predIndex == 4: - return self.precpred(self._ctx, 3) - def right_expr_sempred(self, localctx: Right_exprContext, predIndex: int): - if predIndex == 5: - return self.precpred(self._ctx, 3) diff --git a/src/gems/expression/parsing/antlr/ExprVisitor.py b/src/gems/expression/parsing/antlr/ExprVisitor.py index c79c9be7..7e9dfe69 100644 --- a/src/gems/expression/parsing/antlr/ExprVisitor.py +++ b/src/gems/expression/parsing/antlr/ExprVisitor.py @@ -1,6 +1,5 @@ # Generated from Expr.g4 by ANTLR 4.13.2 from antlr4 import * - if "." in __name__: from .ExprParser import ExprParser else: @@ -8,119 +7,147 @@ # This class defines a complete generic visitor for a parse tree produced by ExprParser. - class ExprVisitor(ParseTreeVisitor): + # Visit a parse tree produced by ExprParser#portFieldExpr. - def visitPortFieldExpr(self, ctx: ExprParser.PortFieldExprContext): + def visitPortFieldExpr(self, ctx:ExprParser.PortFieldExprContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#fullexpr. - def visitFullexpr(self, ctx: ExprParser.FullexprContext): + def visitFullexpr(self, ctx:ExprParser.FullexprContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#portFieldSum. - def visitPortFieldSum(self, ctx: ExprParser.PortFieldSumContext): + def visitPortFieldSum(self, ctx:ExprParser.PortFieldSumContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#negation. - def visitNegation(self, ctx: ExprParser.NegationContext): + def visitNegation(self, ctx:ExprParser.NegationContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#unsignedAtom. - def visitUnsignedAtom(self, ctx: ExprParser.UnsignedAtomContext): + def visitUnsignedAtom(self, ctx:ExprParser.UnsignedAtomContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#expression. - def visitExpression(self, ctx: ExprParser.ExpressionContext): + def visitExpression(self, ctx:ExprParser.ExpressionContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#comparison. - def visitComparison(self, ctx: ExprParser.ComparisonContext): + def visitComparison(self, ctx:ExprParser.ComparisonContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#allTimeSum. - def visitAllTimeSum(self, ctx: ExprParser.AllTimeSumContext): + def visitAllTimeSum(self, ctx:ExprParser.AllTimeSumContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#timeIndexExpr. - def visitTimeIndexExpr(self, ctx: ExprParser.TimeIndexExprContext): + def visitTimeIndexExpr(self, ctx:ExprParser.TimeIndexExprContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#addsub. - def visitAddsub(self, ctx: ExprParser.AddsubContext): + def visitAddsub(self, ctx:ExprParser.AddsubContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#timeShiftExpr. - def visitTimeShiftExpr(self, ctx: ExprParser.TimeShiftExprContext): + def visitTimeShiftExpr(self, ctx:ExprParser.TimeShiftExprContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#portField. - def visitPortField(self, ctx: ExprParser.PortFieldContext): + def visitPortField(self, ctx:ExprParser.PortFieldContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#muldiv. - def visitMuldiv(self, ctx: ExprParser.MuldivContext): + def visitMuldiv(self, ctx:ExprParser.MuldivContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#timeSum. - def visitTimeSum(self, ctx: ExprParser.TimeSumContext): + def visitTimeSum(self, ctx:ExprParser.TimeSumContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#maxExpr. - def visitMaxExpr(self, ctx: ExprParser.MaxExprContext): + def visitMaxExpr(self, ctx:ExprParser.MaxExprContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#timeIndex. - def visitTimeIndex(self, ctx: ExprParser.TimeIndexContext): + def visitTimeIndex(self, ctx:ExprParser.TimeIndexContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#timeShift. - def visitTimeShift(self, ctx: ExprParser.TimeShiftContext): + def visitTimeShift(self, ctx:ExprParser.TimeShiftContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#function. - def visitFunction(self, ctx: ExprParser.FunctionContext): + def visitFunction(self, ctx:ExprParser.FunctionContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#number. - def visitNumber(self, ctx: ExprParser.NumberContext): + def visitNumber(self, ctx:ExprParser.NumberContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#identifier. - def visitIdentifier(self, ctx: ExprParser.IdentifierContext): + def visitIdentifier(self, ctx:ExprParser.IdentifierContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#shift. - def visitShift(self, ctx: ExprParser.ShiftContext): + def visitShift(self, ctx:ExprParser.ShiftContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#signedAtom. - def visitSignedAtom(self, ctx: ExprParser.SignedAtomContext): + def visitSignedAtom(self, ctx:ExprParser.SignedAtomContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#signedExpression. - def visitSignedExpression(self, ctx: ExprParser.SignedExpressionContext): + def visitSignedExpression(self, ctx:ExprParser.SignedExpressionContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#shiftMuldiv. - def visitShiftMuldiv(self, ctx: ExprParser.ShiftMuldivContext): + def visitShiftMuldiv(self, ctx:ExprParser.ShiftMuldivContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#shiftAddsub. - def visitShiftAddsub(self, ctx: ExprParser.ShiftAddsubContext): + def visitShiftAddsub(self, ctx:ExprParser.ShiftAddsubContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#rightExpression. - def visitRightExpression(self, ctx: ExprParser.RightExpressionContext): + def visitRightExpression(self, ctx:ExprParser.RightExpressionContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#rightMuldiv. - def visitRightMuldiv(self, ctx: ExprParser.RightMuldivContext): + def visitRightMuldiv(self, ctx:ExprParser.RightMuldivContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#rightAtom. - def visitRightAtom(self, ctx: ExprParser.RightAtomContext): + def visitRightAtom(self, ctx:ExprParser.RightAtomContext): return self.visitChildren(ctx) -del ExprParser + +del ExprParser \ No newline at end of file From 40dc7b9bcf7d27b02c91245d25ded9256bdf9f93 Mon Sep 17 00:00:00 2001 From: killian-scalian Date: Tue, 5 Aug 2025 15:59:02 +0200 Subject: [PATCH 15/15] formatting --- .../expression/parsing/antlr/ExprLexer.py | 1300 +++++++++- .../expression/parsing/antlr/ExprParser.py | 2199 +++++++++++++---- .../expression/parsing/antlr/ExprVisitor.py | 89 +- 3 files changed, 3039 insertions(+), 549 deletions(-) diff --git a/src/gems/expression/parsing/antlr/ExprLexer.py b/src/gems/expression/parsing/antlr/ExprLexer.py index f7767124..86bdaa43 100644 --- a/src/gems/expression/parsing/antlr/ExprLexer.py +++ b/src/gems/expression/parsing/antlr/ExprLexer.py @@ -2,6 +2,7 @@ from antlr4 import * from io import StringIO import sys + if sys.version_info[1] > 5: from typing import TextIO else: @@ -10,58 +11,1191 @@ def serializedATN(): return [ - 4,0,19,133,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5, - 2,6,7,6,2,7,7,7,2,8,7,8,2,9,7,9,2,10,7,10,2,11,7,11,2,12,7,12,2, - 13,7,13,2,14,7,14,2,15,7,15,2,16,7,16,2,17,7,17,2,18,7,18,2,19,7, - 19,2,20,7,20,2,21,7,21,1,0,1,0,1,1,1,1,1,2,1,2,1,3,1,3,1,4,1,4,1, - 5,1,5,1,6,1,6,1,7,1,7,1,7,1,7,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1, - 8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,9,1,9,1,9,1,10,1,10,1,11,1,11,1, - 12,1,12,1,13,1,13,1,14,1,14,1,15,1,15,3,15,95,8,15,1,16,4,16,98, - 8,16,11,16,12,16,99,1,16,1,16,4,16,104,8,16,11,16,12,16,105,3,16, - 108,8,16,1,17,1,17,1,17,1,17,1,18,1,18,1,19,1,19,5,19,118,8,19,10, - 19,12,19,121,9,19,1,20,1,20,1,20,1,20,1,20,3,20,128,8,20,1,21,1, - 21,1,21,1,21,0,0,22,1,1,3,2,5,3,7,4,9,5,11,6,13,7,15,8,17,9,19,10, - 21,11,23,12,25,13,27,0,29,0,31,0,33,14,35,15,37,16,39,17,41,18,43, - 19,1,0,3,1,0,48,57,3,0,65,90,95,95,97,122,3,0,9,10,13,13,32,32,136, - 0,1,1,0,0,0,0,3,1,0,0,0,0,5,1,0,0,0,0,7,1,0,0,0,0,9,1,0,0,0,0,11, - 1,0,0,0,0,13,1,0,0,0,0,15,1,0,0,0,0,17,1,0,0,0,0,19,1,0,0,0,0,21, - 1,0,0,0,0,23,1,0,0,0,0,25,1,0,0,0,0,33,1,0,0,0,0,35,1,0,0,0,0,37, - 1,0,0,0,0,39,1,0,0,0,0,41,1,0,0,0,0,43,1,0,0,0,1,45,1,0,0,0,3,47, - 1,0,0,0,5,49,1,0,0,0,7,51,1,0,0,0,9,53,1,0,0,0,11,55,1,0,0,0,13, - 57,1,0,0,0,15,59,1,0,0,0,17,63,1,0,0,0,19,79,1,0,0,0,21,82,1,0,0, - 0,23,84,1,0,0,0,25,86,1,0,0,0,27,88,1,0,0,0,29,90,1,0,0,0,31,94, - 1,0,0,0,33,97,1,0,0,0,35,109,1,0,0,0,37,113,1,0,0,0,39,115,1,0,0, - 0,41,127,1,0,0,0,43,129,1,0,0,0,45,46,5,46,0,0,46,2,1,0,0,0,47,48, - 5,45,0,0,48,4,1,0,0,0,49,50,5,40,0,0,50,6,1,0,0,0,51,52,5,41,0,0, - 52,8,1,0,0,0,53,54,5,47,0,0,54,10,1,0,0,0,55,56,5,42,0,0,56,12,1, - 0,0,0,57,58,5,43,0,0,58,14,1,0,0,0,59,60,5,115,0,0,60,61,5,117,0, - 0,61,62,5,109,0,0,62,16,1,0,0,0,63,64,5,115,0,0,64,65,5,117,0,0, - 65,66,5,109,0,0,66,67,5,95,0,0,67,68,5,99,0,0,68,69,5,111,0,0,69, - 70,5,110,0,0,70,71,5,110,0,0,71,72,5,101,0,0,72,73,5,99,0,0,73,74, - 5,116,0,0,74,75,5,105,0,0,75,76,5,111,0,0,76,77,5,110,0,0,77,78, - 5,115,0,0,78,18,1,0,0,0,79,80,5,46,0,0,80,81,5,46,0,0,81,20,1,0, - 0,0,82,83,5,44,0,0,83,22,1,0,0,0,84,85,5,91,0,0,85,24,1,0,0,0,86, - 87,5,93,0,0,87,26,1,0,0,0,88,89,7,0,0,0,89,28,1,0,0,0,90,91,7,1, - 0,0,91,30,1,0,0,0,92,95,3,29,14,0,93,95,3,27,13,0,94,92,1,0,0,0, - 94,93,1,0,0,0,95,32,1,0,0,0,96,98,3,27,13,0,97,96,1,0,0,0,98,99, - 1,0,0,0,99,97,1,0,0,0,99,100,1,0,0,0,100,107,1,0,0,0,101,103,5,46, - 0,0,102,104,3,27,13,0,103,102,1,0,0,0,104,105,1,0,0,0,105,103,1, - 0,0,0,105,106,1,0,0,0,106,108,1,0,0,0,107,101,1,0,0,0,107,108,1, - 0,0,0,108,34,1,0,0,0,109,110,5,109,0,0,110,111,5,97,0,0,111,112, - 5,120,0,0,112,36,1,0,0,0,113,114,5,116,0,0,114,38,1,0,0,0,115,119, - 3,29,14,0,116,118,3,31,15,0,117,116,1,0,0,0,118,121,1,0,0,0,119, - 117,1,0,0,0,119,120,1,0,0,0,120,40,1,0,0,0,121,119,1,0,0,0,122,128, - 5,61,0,0,123,124,5,62,0,0,124,128,5,61,0,0,125,126,5,60,0,0,126, - 128,5,61,0,0,127,122,1,0,0,0,127,123,1,0,0,0,127,125,1,0,0,0,128, - 42,1,0,0,0,129,130,7,2,0,0,130,131,1,0,0,0,131,132,6,21,0,0,132, - 44,1,0,0,0,7,0,94,99,105,107,119,127,1,6,0,0 + 4, + 0, + 19, + 133, + 6, + -1, + 2, + 0, + 7, + 0, + 2, + 1, + 7, + 1, + 2, + 2, + 7, + 2, + 2, + 3, + 7, + 3, + 2, + 4, + 7, + 4, + 2, + 5, + 7, + 5, + 2, + 6, + 7, + 6, + 2, + 7, + 7, + 7, + 2, + 8, + 7, + 8, + 2, + 9, + 7, + 9, + 2, + 10, + 7, + 10, + 2, + 11, + 7, + 11, + 2, + 12, + 7, + 12, + 2, + 13, + 7, + 13, + 2, + 14, + 7, + 14, + 2, + 15, + 7, + 15, + 2, + 16, + 7, + 16, + 2, + 17, + 7, + 17, + 2, + 18, + 7, + 18, + 2, + 19, + 7, + 19, + 2, + 20, + 7, + 20, + 2, + 21, + 7, + 21, + 1, + 0, + 1, + 0, + 1, + 1, + 1, + 1, + 1, + 2, + 1, + 2, + 1, + 3, + 1, + 3, + 1, + 4, + 1, + 4, + 1, + 5, + 1, + 5, + 1, + 6, + 1, + 6, + 1, + 7, + 1, + 7, + 1, + 7, + 1, + 7, + 1, + 8, + 1, + 8, + 1, + 8, + 1, + 8, + 1, + 8, + 1, + 8, + 1, + 8, + 1, + 8, + 1, + 8, + 1, + 8, + 1, + 8, + 1, + 8, + 1, + 8, + 1, + 8, + 1, + 8, + 1, + 8, + 1, + 9, + 1, + 9, + 1, + 9, + 1, + 10, + 1, + 10, + 1, + 11, + 1, + 11, + 1, + 12, + 1, + 12, + 1, + 13, + 1, + 13, + 1, + 14, + 1, + 14, + 1, + 15, + 1, + 15, + 3, + 15, + 95, + 8, + 15, + 1, + 16, + 4, + 16, + 98, + 8, + 16, + 11, + 16, + 12, + 16, + 99, + 1, + 16, + 1, + 16, + 4, + 16, + 104, + 8, + 16, + 11, + 16, + 12, + 16, + 105, + 3, + 16, + 108, + 8, + 16, + 1, + 17, + 1, + 17, + 1, + 17, + 1, + 17, + 1, + 18, + 1, + 18, + 1, + 19, + 1, + 19, + 5, + 19, + 118, + 8, + 19, + 10, + 19, + 12, + 19, + 121, + 9, + 19, + 1, + 20, + 1, + 20, + 1, + 20, + 1, + 20, + 1, + 20, + 3, + 20, + 128, + 8, + 20, + 1, + 21, + 1, + 21, + 1, + 21, + 1, + 21, + 0, + 0, + 22, + 1, + 1, + 3, + 2, + 5, + 3, + 7, + 4, + 9, + 5, + 11, + 6, + 13, + 7, + 15, + 8, + 17, + 9, + 19, + 10, + 21, + 11, + 23, + 12, + 25, + 13, + 27, + 0, + 29, + 0, + 31, + 0, + 33, + 14, + 35, + 15, + 37, + 16, + 39, + 17, + 41, + 18, + 43, + 19, + 1, + 0, + 3, + 1, + 0, + 48, + 57, + 3, + 0, + 65, + 90, + 95, + 95, + 97, + 122, + 3, + 0, + 9, + 10, + 13, + 13, + 32, + 32, + 136, + 0, + 1, + 1, + 0, + 0, + 0, + 0, + 3, + 1, + 0, + 0, + 0, + 0, + 5, + 1, + 0, + 0, + 0, + 0, + 7, + 1, + 0, + 0, + 0, + 0, + 9, + 1, + 0, + 0, + 0, + 0, + 11, + 1, + 0, + 0, + 0, + 0, + 13, + 1, + 0, + 0, + 0, + 0, + 15, + 1, + 0, + 0, + 0, + 0, + 17, + 1, + 0, + 0, + 0, + 0, + 19, + 1, + 0, + 0, + 0, + 0, + 21, + 1, + 0, + 0, + 0, + 0, + 23, + 1, + 0, + 0, + 0, + 0, + 25, + 1, + 0, + 0, + 0, + 0, + 33, + 1, + 0, + 0, + 0, + 0, + 35, + 1, + 0, + 0, + 0, + 0, + 37, + 1, + 0, + 0, + 0, + 0, + 39, + 1, + 0, + 0, + 0, + 0, + 41, + 1, + 0, + 0, + 0, + 0, + 43, + 1, + 0, + 0, + 0, + 1, + 45, + 1, + 0, + 0, + 0, + 3, + 47, + 1, + 0, + 0, + 0, + 5, + 49, + 1, + 0, + 0, + 0, + 7, + 51, + 1, + 0, + 0, + 0, + 9, + 53, + 1, + 0, + 0, + 0, + 11, + 55, + 1, + 0, + 0, + 0, + 13, + 57, + 1, + 0, + 0, + 0, + 15, + 59, + 1, + 0, + 0, + 0, + 17, + 63, + 1, + 0, + 0, + 0, + 19, + 79, + 1, + 0, + 0, + 0, + 21, + 82, + 1, + 0, + 0, + 0, + 23, + 84, + 1, + 0, + 0, + 0, + 25, + 86, + 1, + 0, + 0, + 0, + 27, + 88, + 1, + 0, + 0, + 0, + 29, + 90, + 1, + 0, + 0, + 0, + 31, + 94, + 1, + 0, + 0, + 0, + 33, + 97, + 1, + 0, + 0, + 0, + 35, + 109, + 1, + 0, + 0, + 0, + 37, + 113, + 1, + 0, + 0, + 0, + 39, + 115, + 1, + 0, + 0, + 0, + 41, + 127, + 1, + 0, + 0, + 0, + 43, + 129, + 1, + 0, + 0, + 0, + 45, + 46, + 5, + 46, + 0, + 0, + 46, + 2, + 1, + 0, + 0, + 0, + 47, + 48, + 5, + 45, + 0, + 0, + 48, + 4, + 1, + 0, + 0, + 0, + 49, + 50, + 5, + 40, + 0, + 0, + 50, + 6, + 1, + 0, + 0, + 0, + 51, + 52, + 5, + 41, + 0, + 0, + 52, + 8, + 1, + 0, + 0, + 0, + 53, + 54, + 5, + 47, + 0, + 0, + 54, + 10, + 1, + 0, + 0, + 0, + 55, + 56, + 5, + 42, + 0, + 0, + 56, + 12, + 1, + 0, + 0, + 0, + 57, + 58, + 5, + 43, + 0, + 0, + 58, + 14, + 1, + 0, + 0, + 0, + 59, + 60, + 5, + 115, + 0, + 0, + 60, + 61, + 5, + 117, + 0, + 0, + 61, + 62, + 5, + 109, + 0, + 0, + 62, + 16, + 1, + 0, + 0, + 0, + 63, + 64, + 5, + 115, + 0, + 0, + 64, + 65, + 5, + 117, + 0, + 0, + 65, + 66, + 5, + 109, + 0, + 0, + 66, + 67, + 5, + 95, + 0, + 0, + 67, + 68, + 5, + 99, + 0, + 0, + 68, + 69, + 5, + 111, + 0, + 0, + 69, + 70, + 5, + 110, + 0, + 0, + 70, + 71, + 5, + 110, + 0, + 0, + 71, + 72, + 5, + 101, + 0, + 0, + 72, + 73, + 5, + 99, + 0, + 0, + 73, + 74, + 5, + 116, + 0, + 0, + 74, + 75, + 5, + 105, + 0, + 0, + 75, + 76, + 5, + 111, + 0, + 0, + 76, + 77, + 5, + 110, + 0, + 0, + 77, + 78, + 5, + 115, + 0, + 0, + 78, + 18, + 1, + 0, + 0, + 0, + 79, + 80, + 5, + 46, + 0, + 0, + 80, + 81, + 5, + 46, + 0, + 0, + 81, + 20, + 1, + 0, + 0, + 0, + 82, + 83, + 5, + 44, + 0, + 0, + 83, + 22, + 1, + 0, + 0, + 0, + 84, + 85, + 5, + 91, + 0, + 0, + 85, + 24, + 1, + 0, + 0, + 0, + 86, + 87, + 5, + 93, + 0, + 0, + 87, + 26, + 1, + 0, + 0, + 0, + 88, + 89, + 7, + 0, + 0, + 0, + 89, + 28, + 1, + 0, + 0, + 0, + 90, + 91, + 7, + 1, + 0, + 0, + 91, + 30, + 1, + 0, + 0, + 0, + 92, + 95, + 3, + 29, + 14, + 0, + 93, + 95, + 3, + 27, + 13, + 0, + 94, + 92, + 1, + 0, + 0, + 0, + 94, + 93, + 1, + 0, + 0, + 0, + 95, + 32, + 1, + 0, + 0, + 0, + 96, + 98, + 3, + 27, + 13, + 0, + 97, + 96, + 1, + 0, + 0, + 0, + 98, + 99, + 1, + 0, + 0, + 0, + 99, + 97, + 1, + 0, + 0, + 0, + 99, + 100, + 1, + 0, + 0, + 0, + 100, + 107, + 1, + 0, + 0, + 0, + 101, + 103, + 5, + 46, + 0, + 0, + 102, + 104, + 3, + 27, + 13, + 0, + 103, + 102, + 1, + 0, + 0, + 0, + 104, + 105, + 1, + 0, + 0, + 0, + 105, + 103, + 1, + 0, + 0, + 0, + 105, + 106, + 1, + 0, + 0, + 0, + 106, + 108, + 1, + 0, + 0, + 0, + 107, + 101, + 1, + 0, + 0, + 0, + 107, + 108, + 1, + 0, + 0, + 0, + 108, + 34, + 1, + 0, + 0, + 0, + 109, + 110, + 5, + 109, + 0, + 0, + 110, + 111, + 5, + 97, + 0, + 0, + 111, + 112, + 5, + 120, + 0, + 0, + 112, + 36, + 1, + 0, + 0, + 0, + 113, + 114, + 5, + 116, + 0, + 0, + 114, + 38, + 1, + 0, + 0, + 0, + 115, + 119, + 3, + 29, + 14, + 0, + 116, + 118, + 3, + 31, + 15, + 0, + 117, + 116, + 1, + 0, + 0, + 0, + 118, + 121, + 1, + 0, + 0, + 0, + 119, + 117, + 1, + 0, + 0, + 0, + 119, + 120, + 1, + 0, + 0, + 0, + 120, + 40, + 1, + 0, + 0, + 0, + 121, + 119, + 1, + 0, + 0, + 0, + 122, + 128, + 5, + 61, + 0, + 0, + 123, + 124, + 5, + 62, + 0, + 0, + 124, + 128, + 5, + 61, + 0, + 0, + 125, + 126, + 5, + 60, + 0, + 0, + 126, + 128, + 5, + 61, + 0, + 0, + 127, + 122, + 1, + 0, + 0, + 0, + 127, + 123, + 1, + 0, + 0, + 0, + 127, + 125, + 1, + 0, + 0, + 0, + 128, + 42, + 1, + 0, + 0, + 0, + 129, + 130, + 7, + 2, + 0, + 0, + 130, + 131, + 1, + 0, + 0, + 0, + 131, + 132, + 6, + 21, + 0, + 0, + 132, + 44, + 1, + 0, + 0, + 0, + 7, + 0, + 94, + 99, + 105, + 107, + 119, + 127, + 1, + 6, + 0, + 0, ] -class ExprLexer(Lexer): +class ExprLexer(Lexer): atn = ATNDeserializer().deserialize(serializedATN()) - decisionsToDFA = [ DFA(ds, i) for i, ds in enumerate(atn.decisionToState) ] + decisionsToDFA = [DFA(ds, i) for i, ds in enumerate(atn.decisionToState)] T__0 = 1 T__1 = 2 @@ -83,29 +1217,71 @@ class ExprLexer(Lexer): COMPARISON = 18 WS = 19 - channelNames = [ u"DEFAULT_TOKEN_CHANNEL", u"HIDDEN" ] + channelNames = ["DEFAULT_TOKEN_CHANNEL", "HIDDEN"] - modeNames = [ "DEFAULT_MODE" ] + modeNames = ["DEFAULT_MODE"] - literalNames = [ "", - "'.'", "'-'", "'('", "')'", "'/'", "'*'", "'+'", "'sum'", "'sum_connections'", - "'..'", "','", "'['", "']'", "'max'", "'t'" ] + literalNames = [ + "", + "'.'", + "'-'", + "'('", + "')'", + "'/'", + "'*'", + "'+'", + "'sum'", + "'sum_connections'", + "'..'", + "','", + "'['", + "']'", + "'max'", + "'t'", + ] - symbolicNames = [ "", - "NUMBER", "MAX", "TIME", "IDENTIFIER", "COMPARISON", "WS" ] + symbolicNames = [ + "", + "NUMBER", + "MAX", + "TIME", + "IDENTIFIER", + "COMPARISON", + "WS", + ] - ruleNames = [ "T__0", "T__1", "T__2", "T__3", "T__4", "T__5", "T__6", - "T__7", "T__8", "T__9", "T__10", "T__11", "T__12", "DIGIT", - "CHAR", "CHAR_OR_DIGIT", "NUMBER", "MAX", "TIME", "IDENTIFIER", - "COMPARISON", "WS" ] + ruleNames = [ + "T__0", + "T__1", + "T__2", + "T__3", + "T__4", + "T__5", + "T__6", + "T__7", + "T__8", + "T__9", + "T__10", + "T__11", + "T__12", + "DIGIT", + "CHAR", + "CHAR_OR_DIGIT", + "NUMBER", + "MAX", + "TIME", + "IDENTIFIER", + "COMPARISON", + "WS", + ] grammarFileName = "Expr.g4" - def __init__(self, input=None, output:TextIO = sys.stdout): + def __init__(self, input=None, output: TextIO = sys.stdout): super().__init__(input, output) self.checkVersion("4.13.2") - self._interp = LexerATNSimulator(self, self.atn, self.decisionsToDFA, PredictionContextCache()) + self._interp = LexerATNSimulator( + self, self.atn, self.decisionsToDFA, PredictionContextCache() + ) self._actions = None self._predicates = None - - diff --git a/src/gems/expression/parsing/antlr/ExprParser.py b/src/gems/expression/parsing/antlr/ExprParser.py index 77e0781b..3175ed5f 100644 --- a/src/gems/expression/parsing/antlr/ExprParser.py +++ b/src/gems/expression/parsing/antlr/ExprParser.py @@ -3,85 +3,1430 @@ from antlr4 import * from io import StringIO import sys + if sys.version_info[1] > 5: - from typing import TextIO + from typing import TextIO else: - from typing.io import TextIO + from typing.io import TextIO + def serializedATN(): return [ - 4,1,19,152,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7, - 6,1,0,1,0,1,0,1,0,1,1,1,1,1,1,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1, - 2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1, - 2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1, - 2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1, - 2,1,2,1,2,1,2,1,2,1,2,5,2,84,8,2,10,2,12,2,87,9,2,1,2,1,2,3,2,91, - 8,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,5,2,102,8,2,10,2,12,2,105, - 9,2,1,3,1,3,3,3,109,8,3,1,4,1,4,3,4,113,8,4,1,5,1,5,1,5,1,5,1,5, - 1,5,1,5,1,5,3,5,123,8,5,1,5,1,5,1,5,1,5,1,5,1,5,5,5,131,8,5,10,5, - 12,5,134,9,5,1,6,1,6,1,6,1,6,1,6,1,6,3,6,142,8,6,1,6,1,6,1,6,5,6, - 147,8,6,10,6,12,6,150,9,6,1,6,0,3,4,10,12,7,0,2,4,6,8,10,12,0,2, - 1,0,5,6,2,0,2,2,7,7,167,0,14,1,0,0,0,2,18,1,0,0,0,4,90,1,0,0,0,6, - 108,1,0,0,0,8,110,1,0,0,0,10,122,1,0,0,0,12,141,1,0,0,0,14,15,5, - 17,0,0,15,16,5,1,0,0,16,17,5,17,0,0,17,1,1,0,0,0,18,19,3,4,2,0,19, - 20,5,0,0,1,20,3,1,0,0,0,21,22,6,2,-1,0,22,91,3,6,3,0,23,91,3,0,0, - 0,24,25,5,2,0,0,25,91,3,4,2,14,26,27,5,3,0,0,27,28,3,4,2,0,28,29, - 5,4,0,0,29,91,1,0,0,0,30,31,5,8,0,0,31,32,5,3,0,0,32,33,3,4,2,0, - 33,34,5,4,0,0,34,91,1,0,0,0,35,36,5,9,0,0,36,37,5,3,0,0,37,38,3, - 0,0,0,38,39,5,4,0,0,39,91,1,0,0,0,40,41,5,8,0,0,41,42,5,3,0,0,42, - 43,3,8,4,0,43,44,5,10,0,0,44,45,3,8,4,0,45,46,5,11,0,0,46,47,3,4, - 2,0,47,48,5,4,0,0,48,91,1,0,0,0,49,50,5,17,0,0,50,51,5,3,0,0,51, - 52,3,4,2,0,52,53,5,4,0,0,53,91,1,0,0,0,54,55,5,17,0,0,55,56,5,12, - 0,0,56,57,3,8,4,0,57,58,5,13,0,0,58,91,1,0,0,0,59,60,5,17,0,0,60, - 61,5,12,0,0,61,62,3,4,2,0,62,63,5,13,0,0,63,91,1,0,0,0,64,65,5,3, - 0,0,65,66,3,4,2,0,66,67,5,4,0,0,67,68,5,12,0,0,68,69,3,8,4,0,69, - 70,5,13,0,0,70,91,1,0,0,0,71,72,5,3,0,0,72,73,3,4,2,0,73,74,5,4, - 0,0,74,75,5,12,0,0,75,76,3,4,2,0,76,77,5,13,0,0,77,91,1,0,0,0,78, - 79,5,15,0,0,79,80,5,3,0,0,80,85,3,4,2,0,81,82,5,11,0,0,82,84,3,4, - 2,0,83,81,1,0,0,0,84,87,1,0,0,0,85,83,1,0,0,0,85,86,1,0,0,0,86,88, - 1,0,0,0,87,85,1,0,0,0,88,89,5,4,0,0,89,91,1,0,0,0,90,21,1,0,0,0, - 90,23,1,0,0,0,90,24,1,0,0,0,90,26,1,0,0,0,90,30,1,0,0,0,90,35,1, - 0,0,0,90,40,1,0,0,0,90,49,1,0,0,0,90,54,1,0,0,0,90,59,1,0,0,0,90, - 64,1,0,0,0,90,71,1,0,0,0,90,78,1,0,0,0,91,103,1,0,0,0,92,93,10,12, - 0,0,93,94,7,0,0,0,94,102,3,4,2,13,95,96,10,11,0,0,96,97,7,1,0,0, - 97,102,3,4,2,12,98,99,10,10,0,0,99,100,5,18,0,0,100,102,3,4,2,11, - 101,92,1,0,0,0,101,95,1,0,0,0,101,98,1,0,0,0,102,105,1,0,0,0,103, - 101,1,0,0,0,103,104,1,0,0,0,104,5,1,0,0,0,105,103,1,0,0,0,106,109, - 5,14,0,0,107,109,5,17,0,0,108,106,1,0,0,0,108,107,1,0,0,0,109,7, - 1,0,0,0,110,112,5,16,0,0,111,113,3,10,5,0,112,111,1,0,0,0,112,113, - 1,0,0,0,113,9,1,0,0,0,114,115,6,5,-1,0,115,116,7,1,0,0,116,123,3, - 6,3,0,117,118,7,1,0,0,118,119,5,3,0,0,119,120,3,4,2,0,120,121,5, - 4,0,0,121,123,1,0,0,0,122,114,1,0,0,0,122,117,1,0,0,0,123,132,1, - 0,0,0,124,125,10,4,0,0,125,126,7,0,0,0,126,131,3,12,6,0,127,128, - 10,3,0,0,128,129,7,1,0,0,129,131,3,12,6,0,130,124,1,0,0,0,130,127, - 1,0,0,0,131,134,1,0,0,0,132,130,1,0,0,0,132,133,1,0,0,0,133,11,1, - 0,0,0,134,132,1,0,0,0,135,136,6,6,-1,0,136,137,5,3,0,0,137,138,3, - 4,2,0,138,139,5,4,0,0,139,142,1,0,0,0,140,142,3,6,3,0,141,135,1, - 0,0,0,141,140,1,0,0,0,142,148,1,0,0,0,143,144,10,3,0,0,144,145,7, - 0,0,0,145,147,3,12,6,4,146,143,1,0,0,0,147,150,1,0,0,0,148,146,1, - 0,0,0,148,149,1,0,0,0,149,13,1,0,0,0,150,148,1,0,0,0,11,85,90,101, - 103,108,112,122,130,132,141,148 + 4, + 1, + 19, + 152, + 2, + 0, + 7, + 0, + 2, + 1, + 7, + 1, + 2, + 2, + 7, + 2, + 2, + 3, + 7, + 3, + 2, + 4, + 7, + 4, + 2, + 5, + 7, + 5, + 2, + 6, + 7, + 6, + 1, + 0, + 1, + 0, + 1, + 0, + 1, + 0, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 5, + 2, + 84, + 8, + 2, + 10, + 2, + 12, + 2, + 87, + 9, + 2, + 1, + 2, + 1, + 2, + 3, + 2, + 91, + 8, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 5, + 2, + 102, + 8, + 2, + 10, + 2, + 12, + 2, + 105, + 9, + 2, + 1, + 3, + 1, + 3, + 3, + 3, + 109, + 8, + 3, + 1, + 4, + 1, + 4, + 3, + 4, + 113, + 8, + 4, + 1, + 5, + 1, + 5, + 1, + 5, + 1, + 5, + 1, + 5, + 1, + 5, + 1, + 5, + 1, + 5, + 3, + 5, + 123, + 8, + 5, + 1, + 5, + 1, + 5, + 1, + 5, + 1, + 5, + 1, + 5, + 1, + 5, + 5, + 5, + 131, + 8, + 5, + 10, + 5, + 12, + 5, + 134, + 9, + 5, + 1, + 6, + 1, + 6, + 1, + 6, + 1, + 6, + 1, + 6, + 1, + 6, + 3, + 6, + 142, + 8, + 6, + 1, + 6, + 1, + 6, + 1, + 6, + 5, + 6, + 147, + 8, + 6, + 10, + 6, + 12, + 6, + 150, + 9, + 6, + 1, + 6, + 0, + 3, + 4, + 10, + 12, + 7, + 0, + 2, + 4, + 6, + 8, + 10, + 12, + 0, + 2, + 1, + 0, + 5, + 6, + 2, + 0, + 2, + 2, + 7, + 7, + 167, + 0, + 14, + 1, + 0, + 0, + 0, + 2, + 18, + 1, + 0, + 0, + 0, + 4, + 90, + 1, + 0, + 0, + 0, + 6, + 108, + 1, + 0, + 0, + 0, + 8, + 110, + 1, + 0, + 0, + 0, + 10, + 122, + 1, + 0, + 0, + 0, + 12, + 141, + 1, + 0, + 0, + 0, + 14, + 15, + 5, + 17, + 0, + 0, + 15, + 16, + 5, + 1, + 0, + 0, + 16, + 17, + 5, + 17, + 0, + 0, + 17, + 1, + 1, + 0, + 0, + 0, + 18, + 19, + 3, + 4, + 2, + 0, + 19, + 20, + 5, + 0, + 0, + 1, + 20, + 3, + 1, + 0, + 0, + 0, + 21, + 22, + 6, + 2, + -1, + 0, + 22, + 91, + 3, + 6, + 3, + 0, + 23, + 91, + 3, + 0, + 0, + 0, + 24, + 25, + 5, + 2, + 0, + 0, + 25, + 91, + 3, + 4, + 2, + 14, + 26, + 27, + 5, + 3, + 0, + 0, + 27, + 28, + 3, + 4, + 2, + 0, + 28, + 29, + 5, + 4, + 0, + 0, + 29, + 91, + 1, + 0, + 0, + 0, + 30, + 31, + 5, + 8, + 0, + 0, + 31, + 32, + 5, + 3, + 0, + 0, + 32, + 33, + 3, + 4, + 2, + 0, + 33, + 34, + 5, + 4, + 0, + 0, + 34, + 91, + 1, + 0, + 0, + 0, + 35, + 36, + 5, + 9, + 0, + 0, + 36, + 37, + 5, + 3, + 0, + 0, + 37, + 38, + 3, + 0, + 0, + 0, + 38, + 39, + 5, + 4, + 0, + 0, + 39, + 91, + 1, + 0, + 0, + 0, + 40, + 41, + 5, + 8, + 0, + 0, + 41, + 42, + 5, + 3, + 0, + 0, + 42, + 43, + 3, + 8, + 4, + 0, + 43, + 44, + 5, + 10, + 0, + 0, + 44, + 45, + 3, + 8, + 4, + 0, + 45, + 46, + 5, + 11, + 0, + 0, + 46, + 47, + 3, + 4, + 2, + 0, + 47, + 48, + 5, + 4, + 0, + 0, + 48, + 91, + 1, + 0, + 0, + 0, + 49, + 50, + 5, + 17, + 0, + 0, + 50, + 51, + 5, + 3, + 0, + 0, + 51, + 52, + 3, + 4, + 2, + 0, + 52, + 53, + 5, + 4, + 0, + 0, + 53, + 91, + 1, + 0, + 0, + 0, + 54, + 55, + 5, + 17, + 0, + 0, + 55, + 56, + 5, + 12, + 0, + 0, + 56, + 57, + 3, + 8, + 4, + 0, + 57, + 58, + 5, + 13, + 0, + 0, + 58, + 91, + 1, + 0, + 0, + 0, + 59, + 60, + 5, + 17, + 0, + 0, + 60, + 61, + 5, + 12, + 0, + 0, + 61, + 62, + 3, + 4, + 2, + 0, + 62, + 63, + 5, + 13, + 0, + 0, + 63, + 91, + 1, + 0, + 0, + 0, + 64, + 65, + 5, + 3, + 0, + 0, + 65, + 66, + 3, + 4, + 2, + 0, + 66, + 67, + 5, + 4, + 0, + 0, + 67, + 68, + 5, + 12, + 0, + 0, + 68, + 69, + 3, + 8, + 4, + 0, + 69, + 70, + 5, + 13, + 0, + 0, + 70, + 91, + 1, + 0, + 0, + 0, + 71, + 72, + 5, + 3, + 0, + 0, + 72, + 73, + 3, + 4, + 2, + 0, + 73, + 74, + 5, + 4, + 0, + 0, + 74, + 75, + 5, + 12, + 0, + 0, + 75, + 76, + 3, + 4, + 2, + 0, + 76, + 77, + 5, + 13, + 0, + 0, + 77, + 91, + 1, + 0, + 0, + 0, + 78, + 79, + 5, + 15, + 0, + 0, + 79, + 80, + 5, + 3, + 0, + 0, + 80, + 85, + 3, + 4, + 2, + 0, + 81, + 82, + 5, + 11, + 0, + 0, + 82, + 84, + 3, + 4, + 2, + 0, + 83, + 81, + 1, + 0, + 0, + 0, + 84, + 87, + 1, + 0, + 0, + 0, + 85, + 83, + 1, + 0, + 0, + 0, + 85, + 86, + 1, + 0, + 0, + 0, + 86, + 88, + 1, + 0, + 0, + 0, + 87, + 85, + 1, + 0, + 0, + 0, + 88, + 89, + 5, + 4, + 0, + 0, + 89, + 91, + 1, + 0, + 0, + 0, + 90, + 21, + 1, + 0, + 0, + 0, + 90, + 23, + 1, + 0, + 0, + 0, + 90, + 24, + 1, + 0, + 0, + 0, + 90, + 26, + 1, + 0, + 0, + 0, + 90, + 30, + 1, + 0, + 0, + 0, + 90, + 35, + 1, + 0, + 0, + 0, + 90, + 40, + 1, + 0, + 0, + 0, + 90, + 49, + 1, + 0, + 0, + 0, + 90, + 54, + 1, + 0, + 0, + 0, + 90, + 59, + 1, + 0, + 0, + 0, + 90, + 64, + 1, + 0, + 0, + 0, + 90, + 71, + 1, + 0, + 0, + 0, + 90, + 78, + 1, + 0, + 0, + 0, + 91, + 103, + 1, + 0, + 0, + 0, + 92, + 93, + 10, + 12, + 0, + 0, + 93, + 94, + 7, + 0, + 0, + 0, + 94, + 102, + 3, + 4, + 2, + 13, + 95, + 96, + 10, + 11, + 0, + 0, + 96, + 97, + 7, + 1, + 0, + 0, + 97, + 102, + 3, + 4, + 2, + 12, + 98, + 99, + 10, + 10, + 0, + 0, + 99, + 100, + 5, + 18, + 0, + 0, + 100, + 102, + 3, + 4, + 2, + 11, + 101, + 92, + 1, + 0, + 0, + 0, + 101, + 95, + 1, + 0, + 0, + 0, + 101, + 98, + 1, + 0, + 0, + 0, + 102, + 105, + 1, + 0, + 0, + 0, + 103, + 101, + 1, + 0, + 0, + 0, + 103, + 104, + 1, + 0, + 0, + 0, + 104, + 5, + 1, + 0, + 0, + 0, + 105, + 103, + 1, + 0, + 0, + 0, + 106, + 109, + 5, + 14, + 0, + 0, + 107, + 109, + 5, + 17, + 0, + 0, + 108, + 106, + 1, + 0, + 0, + 0, + 108, + 107, + 1, + 0, + 0, + 0, + 109, + 7, + 1, + 0, + 0, + 0, + 110, + 112, + 5, + 16, + 0, + 0, + 111, + 113, + 3, + 10, + 5, + 0, + 112, + 111, + 1, + 0, + 0, + 0, + 112, + 113, + 1, + 0, + 0, + 0, + 113, + 9, + 1, + 0, + 0, + 0, + 114, + 115, + 6, + 5, + -1, + 0, + 115, + 116, + 7, + 1, + 0, + 0, + 116, + 123, + 3, + 6, + 3, + 0, + 117, + 118, + 7, + 1, + 0, + 0, + 118, + 119, + 5, + 3, + 0, + 0, + 119, + 120, + 3, + 4, + 2, + 0, + 120, + 121, + 5, + 4, + 0, + 0, + 121, + 123, + 1, + 0, + 0, + 0, + 122, + 114, + 1, + 0, + 0, + 0, + 122, + 117, + 1, + 0, + 0, + 0, + 123, + 132, + 1, + 0, + 0, + 0, + 124, + 125, + 10, + 4, + 0, + 0, + 125, + 126, + 7, + 0, + 0, + 0, + 126, + 131, + 3, + 12, + 6, + 0, + 127, + 128, + 10, + 3, + 0, + 0, + 128, + 129, + 7, + 1, + 0, + 0, + 129, + 131, + 3, + 12, + 6, + 0, + 130, + 124, + 1, + 0, + 0, + 0, + 130, + 127, + 1, + 0, + 0, + 0, + 131, + 134, + 1, + 0, + 0, + 0, + 132, + 130, + 1, + 0, + 0, + 0, + 132, + 133, + 1, + 0, + 0, + 0, + 133, + 11, + 1, + 0, + 0, + 0, + 134, + 132, + 1, + 0, + 0, + 0, + 135, + 136, + 6, + 6, + -1, + 0, + 136, + 137, + 5, + 3, + 0, + 0, + 137, + 138, + 3, + 4, + 2, + 0, + 138, + 139, + 5, + 4, + 0, + 0, + 139, + 142, + 1, + 0, + 0, + 0, + 140, + 142, + 3, + 6, + 3, + 0, + 141, + 135, + 1, + 0, + 0, + 0, + 141, + 140, + 1, + 0, + 0, + 0, + 142, + 148, + 1, + 0, + 0, + 0, + 143, + 144, + 10, + 3, + 0, + 0, + 144, + 145, + 7, + 0, + 0, + 0, + 145, + 147, + 3, + 12, + 6, + 4, + 146, + 143, + 1, + 0, + 0, + 0, + 147, + 150, + 1, + 0, + 0, + 0, + 148, + 146, + 1, + 0, + 0, + 0, + 148, + 149, + 1, + 0, + 0, + 0, + 149, + 13, + 1, + 0, + 0, + 0, + 150, + 148, + 1, + 0, + 0, + 0, + 11, + 85, + 90, + 101, + 103, + 108, + 112, + 122, + 130, + 132, + 141, + 148, ] -class ExprParser ( Parser ): +class ExprParser(Parser): grammarFileName = "Expr.g4" atn = ATNDeserializer().deserialize(serializedATN()) - decisionsToDFA = [ DFA(ds, i) for i, ds in enumerate(atn.decisionToState) ] + decisionsToDFA = [DFA(ds, i) for i, ds in enumerate(atn.decisionToState)] sharedContextCache = PredictionContextCache() - literalNames = [ "", "'.'", "'-'", "'('", "')'", "'/'", "'*'", - "'+'", "'sum'", "'sum_connections'", "'..'", "','", - "'['", "']'", "", "'max'", "'t'" ] + literalNames = [ + "", + "'.'", + "'-'", + "'('", + "')'", + "'/'", + "'*'", + "'+'", + "'sum'", + "'sum_connections'", + "'..'", + "','", + "'['", + "']'", + "", + "'max'", + "'t'", + ] - symbolicNames = [ "", "", "", "", - "", "", "", "", - "", "", "", "", - "", "", "NUMBER", "MAX", "TIME", - "IDENTIFIER", "COMPARISON", "WS" ] + symbolicNames = [ + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "NUMBER", + "MAX", + "TIME", + "IDENTIFIER", + "COMPARISON", + "WS", + ] RULE_portFieldExpr = 0 RULE_fullexpr = 1 @@ -91,47 +1436,55 @@ class ExprParser ( Parser ): RULE_shift_expr = 5 RULE_right_expr = 6 - ruleNames = [ "portFieldExpr", "fullexpr", "expr", "atom", "shift", - "shift_expr", "right_expr" ] + ruleNames = [ + "portFieldExpr", + "fullexpr", + "expr", + "atom", + "shift", + "shift_expr", + "right_expr", + ] EOF = Token.EOF - T__0=1 - T__1=2 - T__2=3 - T__3=4 - T__4=5 - T__5=6 - T__6=7 - T__7=8 - T__8=9 - T__9=10 - T__10=11 - T__11=12 - T__12=13 - NUMBER=14 - MAX=15 - TIME=16 - IDENTIFIER=17 - COMPARISON=18 - WS=19 - - def __init__(self, input:TokenStream, output:TextIO = sys.stdout): + T__0 = 1 + T__1 = 2 + T__2 = 3 + T__3 = 4 + T__4 = 5 + T__5 = 6 + T__6 = 7 + T__7 = 8 + T__8 = 9 + T__9 = 10 + T__10 = 11 + T__11 = 12 + T__12 = 13 + NUMBER = 14 + MAX = 15 + TIME = 16 + IDENTIFIER = 17 + COMPARISON = 18 + WS = 19 + + def __init__(self, input: TokenStream, output: TextIO = sys.stdout): super().__init__(input, output) self.checkVersion("4.13.2") - self._interp = ParserATNSimulator(self, self.atn, self.decisionsToDFA, self.sharedContextCache) + self._interp = ParserATNSimulator( + self, self.atn, self.decisionsToDFA, self.sharedContextCache + ) self._predicates = None - - - class PortFieldExprContext(ParserRuleContext): - __slots__ = 'parser' + __slots__ = "parser" - def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): + def __init__( + self, parser, parent: ParserRuleContext = None, invokingState: int = -1 + ): super().__init__(parent, invokingState) self.parser = parser - def IDENTIFIER(self, i:int=None): + def IDENTIFIER(self, i: int = None): if i is None: return self.getTokens(ExprParser.IDENTIFIER) else: @@ -140,17 +1493,13 @@ def IDENTIFIER(self, i:int=None): def getRuleIndex(self): return ExprParser.RULE_portFieldExpr - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitPortFieldExpr" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitPortFieldExpr"): return visitor.visitPortFieldExpr(self) else: return visitor.visitChildren(self) - - - def portFieldExpr(self): - localctx = ExprParser.PortFieldExprContext(self, self._ctx, self.state) self.enterRule(localctx, 0, self.RULE_portFieldExpr) try: @@ -169,17 +1518,17 @@ def portFieldExpr(self): self.exitRule() return localctx - class FullexprContext(ParserRuleContext): - __slots__ = 'parser' + __slots__ = "parser" - def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): + def __init__( + self, parser, parent: ParserRuleContext = None, invokingState: int = -1 + ): super().__init__(parent, invokingState) self.parser = parser def expr(self): - return self.getTypedRuleContext(ExprParser.ExprContext,0) - + return self.getTypedRuleContext(ExprParser.ExprContext, 0) def EOF(self): return self.getToken(ExprParser.EOF, 0) @@ -187,17 +1536,13 @@ def EOF(self): def getRuleIndex(self): return ExprParser.RULE_fullexpr - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitFullexpr" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitFullexpr"): return visitor.visitFullexpr(self) else: return visitor.visitChildren(self) - - - def fullexpr(self): - localctx = ExprParser.FullexprContext(self, self._ctx, self.state) self.enterRule(localctx, 2, self.RULE_fullexpr) try: @@ -214,347 +1559,333 @@ def fullexpr(self): self.exitRule() return localctx - class ExprContext(ParserRuleContext): - __slots__ = 'parser' + __slots__ = "parser" - def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): + def __init__( + self, parser, parent: ParserRuleContext = None, invokingState: int = -1 + ): super().__init__(parent, invokingState) self.parser = parser - def getRuleIndex(self): return ExprParser.RULE_expr - - def copyFrom(self, ctx:ParserRuleContext): + def copyFrom(self, ctx: ParserRuleContext): super().copyFrom(ctx) - class PortFieldSumContext(ExprContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) def portFieldExpr(self): - return self.getTypedRuleContext(ExprParser.PortFieldExprContext,0) + return self.getTypedRuleContext(ExprParser.PortFieldExprContext, 0) - - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitPortFieldSum" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitPortFieldSum"): return visitor.visitPortFieldSum(self) else: return visitor.visitChildren(self) - class NegationContext(ExprContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) def expr(self): - return self.getTypedRuleContext(ExprParser.ExprContext,0) - + return self.getTypedRuleContext(ExprParser.ExprContext, 0) - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitNegation" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitNegation"): return visitor.visitNegation(self) else: return visitor.visitChildren(self) - class UnsignedAtomContext(ExprContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) def atom(self): - return self.getTypedRuleContext(ExprParser.AtomContext,0) + return self.getTypedRuleContext(ExprParser.AtomContext, 0) - - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitUnsignedAtom" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitUnsignedAtom"): return visitor.visitUnsignedAtom(self) else: return visitor.visitChildren(self) - class ExpressionContext(ExprContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) def expr(self): - return self.getTypedRuleContext(ExprParser.ExprContext,0) - + return self.getTypedRuleContext(ExprParser.ExprContext, 0) - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitExpression" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitExpression"): return visitor.visitExpression(self) else: return visitor.visitChildren(self) - class ComparisonContext(ExprContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) - def expr(self, i:int=None): + def expr(self, i: int = None): if i is None: return self.getTypedRuleContexts(ExprParser.ExprContext) else: - return self.getTypedRuleContext(ExprParser.ExprContext,i) + return self.getTypedRuleContext(ExprParser.ExprContext, i) def COMPARISON(self): return self.getToken(ExprParser.COMPARISON, 0) - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitComparison" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitComparison"): return visitor.visitComparison(self) else: return visitor.visitChildren(self) - class AllTimeSumContext(ExprContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) def expr(self): - return self.getTypedRuleContext(ExprParser.ExprContext,0) - + return self.getTypedRuleContext(ExprParser.ExprContext, 0) - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitAllTimeSum" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitAllTimeSum"): return visitor.visitAllTimeSum(self) else: return visitor.visitChildren(self) - class TimeIndexExprContext(ExprContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) - def expr(self, i:int=None): + def expr(self, i: int = None): if i is None: return self.getTypedRuleContexts(ExprParser.ExprContext) else: - return self.getTypedRuleContext(ExprParser.ExprContext,i) + return self.getTypedRuleContext(ExprParser.ExprContext, i) - - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitTimeIndexExpr" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitTimeIndexExpr"): return visitor.visitTimeIndexExpr(self) else: return visitor.visitChildren(self) - class AddsubContext(ExprContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.ExprContext super().__init__(parser) - self.op = None # Token + self.op = None # Token self.copyFrom(ctx) - def expr(self, i:int=None): + def expr(self, i: int = None): if i is None: return self.getTypedRuleContexts(ExprParser.ExprContext) else: - return self.getTypedRuleContext(ExprParser.ExprContext,i) - + return self.getTypedRuleContext(ExprParser.ExprContext, i) - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitAddsub" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitAddsub"): return visitor.visitAddsub(self) else: return visitor.visitChildren(self) - class TimeShiftExprContext(ExprContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) def expr(self): - return self.getTypedRuleContext(ExprParser.ExprContext,0) + return self.getTypedRuleContext(ExprParser.ExprContext, 0) def shift(self): - return self.getTypedRuleContext(ExprParser.ShiftContext,0) + return self.getTypedRuleContext(ExprParser.ShiftContext, 0) - - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitTimeShiftExpr" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitTimeShiftExpr"): return visitor.visitTimeShiftExpr(self) else: return visitor.visitChildren(self) - class PortFieldContext(ExprContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) def portFieldExpr(self): - return self.getTypedRuleContext(ExprParser.PortFieldExprContext,0) - + return self.getTypedRuleContext(ExprParser.PortFieldExprContext, 0) - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitPortField" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitPortField"): return visitor.visitPortField(self) else: return visitor.visitChildren(self) - class MuldivContext(ExprContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.ExprContext super().__init__(parser) - self.op = None # Token + self.op = None # Token self.copyFrom(ctx) - def expr(self, i:int=None): + def expr(self, i: int = None): if i is None: return self.getTypedRuleContexts(ExprParser.ExprContext) else: - return self.getTypedRuleContext(ExprParser.ExprContext,i) + return self.getTypedRuleContext(ExprParser.ExprContext, i) - - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitMuldiv" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitMuldiv"): return visitor.visitMuldiv(self) else: return visitor.visitChildren(self) - class TimeSumContext(ExprContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.ExprContext super().__init__(parser) - self.from_ = None # ShiftContext - self.to = None # ShiftContext + self.from_ = None # ShiftContext + self.to = None # ShiftContext self.copyFrom(ctx) def expr(self): - return self.getTypedRuleContext(ExprParser.ExprContext,0) + return self.getTypedRuleContext(ExprParser.ExprContext, 0) - def shift(self, i:int=None): + def shift(self, i: int = None): if i is None: return self.getTypedRuleContexts(ExprParser.ShiftContext) else: - return self.getTypedRuleContext(ExprParser.ShiftContext,i) - + return self.getTypedRuleContext(ExprParser.ShiftContext, i) - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitTimeSum" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitTimeSum"): return visitor.visitTimeSum(self) else: return visitor.visitChildren(self) - class MaxExprContext(ExprContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) def MAX(self): return self.getToken(ExprParser.MAX, 0) - def expr(self, i:int=None): + + def expr(self, i: int = None): if i is None: return self.getTypedRuleContexts(ExprParser.ExprContext) else: - return self.getTypedRuleContext(ExprParser.ExprContext,i) - + return self.getTypedRuleContext(ExprParser.ExprContext, i) - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitMaxExpr" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitMaxExpr"): return visitor.visitMaxExpr(self) else: return visitor.visitChildren(self) - class TimeIndexContext(ExprContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) def IDENTIFIER(self): return self.getToken(ExprParser.IDENTIFIER, 0) - def expr(self): - return self.getTypedRuleContext(ExprParser.ExprContext,0) + def expr(self): + return self.getTypedRuleContext(ExprParser.ExprContext, 0) - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitTimeIndex" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitTimeIndex"): return visitor.visitTimeIndex(self) else: return visitor.visitChildren(self) - class TimeShiftContext(ExprContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) def IDENTIFIER(self): return self.getToken(ExprParser.IDENTIFIER, 0) - def shift(self): - return self.getTypedRuleContext(ExprParser.ShiftContext,0) + def shift(self): + return self.getTypedRuleContext(ExprParser.ShiftContext, 0) - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitTimeShift" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitTimeShift"): return visitor.visitTimeShift(self) else: return visitor.visitChildren(self) - class FunctionContext(ExprContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.ExprContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.ExprContext super().__init__(parser) self.copyFrom(ctx) def IDENTIFIER(self): return self.getToken(ExprParser.IDENTIFIER, 0) - def expr(self): - return self.getTypedRuleContext(ExprParser.ExprContext,0) + def expr(self): + return self.getTypedRuleContext(ExprParser.ExprContext, 0) - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitFunction" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitFunction"): return visitor.visitFunction(self) else: return visitor.visitChildren(self) - - - def expr(self, _p:int=0): + def expr(self, _p: int = 0): _parentctx = self._ctx _parentState = self.state localctx = ExprParser.ExprContext(self, self._ctx, _parentState) _prevctx = localctx _startState = 4 self.enterRecursionRule(localctx, 4, self.RULE_expr, _p) - self._la = 0 # Token type + self._la = 0 # Token type try: self.enterOuterAlt(localctx, 1) self.state = 90 self._errHandler.sync(self) - la_ = self._interp.adaptivePredict(self._input,1,self._ctx) + la_ = self._interp.adaptivePredict(self._input, 1, self._ctx) if la_ == 1: localctx = ExprParser.UnsignedAtomContext(self, localctx) self._ctx = localctx @@ -735,7 +2066,7 @@ def expr(self, _p:int=0): self.state = 85 self._errHandler.sync(self) _la = self._input.LA(1) - while _la==11: + while _la == 11: self.state = 81 self.match(ExprParser.T__10) self.state = 82 @@ -748,30 +2079,36 @@ def expr(self, _p:int=0): self.match(ExprParser.T__3) pass - self._ctx.stop = self._input.LT(-1) self.state = 103 self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input,3,self._ctx) - while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER: - if _alt==1: + _alt = self._interp.adaptivePredict(self._input, 3, self._ctx) + while _alt != 2 and _alt != ATN.INVALID_ALT_NUMBER: + if _alt == 1: if self._parseListeners is not None: self.triggerExitRuleEvent() _prevctx = localctx self.state = 101 self._errHandler.sync(self) - la_ = self._interp.adaptivePredict(self._input,2,self._ctx) + la_ = self._interp.adaptivePredict(self._input, 2, self._ctx) if la_ == 1: - localctx = ExprParser.MuldivContext(self, ExprParser.ExprContext(self, _parentctx, _parentState)) - self.pushNewRecursionContext(localctx, _startState, self.RULE_expr) + localctx = ExprParser.MuldivContext( + self, ExprParser.ExprContext(self, _parentctx, _parentState) + ) + self.pushNewRecursionContext( + localctx, _startState, self.RULE_expr + ) self.state = 92 if not self.precpred(self._ctx, 12): from antlr4.error.Errors import FailedPredicateException - raise FailedPredicateException(self, "self.precpred(self._ctx, 12)") + + raise FailedPredicateException( + self, "self.precpred(self._ctx, 12)" + ) self.state = 93 localctx.op = self._input.LT(1) _la = self._input.LA(1) - if not(_la==5 or _la==6): + if not (_la == 5 or _la == 6): localctx.op = self._errHandler.recoverInline(self) else: self._errHandler.reportMatch(self) @@ -781,16 +2118,23 @@ def expr(self, _p:int=0): pass elif la_ == 2: - localctx = ExprParser.AddsubContext(self, ExprParser.ExprContext(self, _parentctx, _parentState)) - self.pushNewRecursionContext(localctx, _startState, self.RULE_expr) + localctx = ExprParser.AddsubContext( + self, ExprParser.ExprContext(self, _parentctx, _parentState) + ) + self.pushNewRecursionContext( + localctx, _startState, self.RULE_expr + ) self.state = 95 if not self.precpred(self._ctx, 11): from antlr4.error.Errors import FailedPredicateException - raise FailedPredicateException(self, "self.precpred(self._ctx, 11)") + + raise FailedPredicateException( + self, "self.precpred(self._ctx, 11)" + ) self.state = 96 localctx.op = self._input.LT(1) _la = self._input.LA(1) - if not(_la==2 or _la==7): + if not (_la == 2 or _la == 7): localctx.op = self._errHandler.recoverInline(self) else: self._errHandler.reportMatch(self) @@ -800,22 +2144,28 @@ def expr(self, _p:int=0): pass elif la_ == 3: - localctx = ExprParser.ComparisonContext(self, ExprParser.ExprContext(self, _parentctx, _parentState)) - self.pushNewRecursionContext(localctx, _startState, self.RULE_expr) + localctx = ExprParser.ComparisonContext( + self, ExprParser.ExprContext(self, _parentctx, _parentState) + ) + self.pushNewRecursionContext( + localctx, _startState, self.RULE_expr + ) self.state = 98 if not self.precpred(self._ctx, 10): from antlr4.error.Errors import FailedPredicateException - raise FailedPredicateException(self, "self.precpred(self._ctx, 10)") + + raise FailedPredicateException( + self, "self.precpred(self._ctx, 10)" + ) self.state = 99 self.match(ExprParser.COMPARISON) self.state = 100 self.expr(11) pass - self.state = 105 self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input,3,self._ctx) + _alt = self._interp.adaptivePredict(self._input, 3, self._ctx) except RecognitionException as re: localctx.exception = re @@ -825,59 +2175,54 @@ def expr(self, _p:int=0): self.unrollRecursionContexts(_parentctx) return localctx - class AtomContext(ParserRuleContext): - __slots__ = 'parser' + __slots__ = "parser" - def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): + def __init__( + self, parser, parent: ParserRuleContext = None, invokingState: int = -1 + ): super().__init__(parent, invokingState) self.parser = parser - def getRuleIndex(self): return ExprParser.RULE_atom - - def copyFrom(self, ctx:ParserRuleContext): + def copyFrom(self, ctx: ParserRuleContext): super().copyFrom(ctx) - - class NumberContext(AtomContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.AtomContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.AtomContext super().__init__(parser) self.copyFrom(ctx) def NUMBER(self): return self.getToken(ExprParser.NUMBER, 0) - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitNumber" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitNumber"): return visitor.visitNumber(self) else: return visitor.visitChildren(self) - class IdentifierContext(AtomContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.AtomContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.AtomContext super().__init__(parser) self.copyFrom(ctx) def IDENTIFIER(self): return self.getToken(ExprParser.IDENTIFIER, 0) - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitIdentifier" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitIdentifier"): return visitor.visitIdentifier(self) else: return visitor.visitChildren(self) - - def atom(self): - localctx = ExprParser.AtomContext(self, self._ctx, self.state) self.enterRule(localctx, 6, self.RULE_atom) try: @@ -907,11 +2252,12 @@ def atom(self): self.exitRule() return localctx - class ShiftContext(ParserRuleContext): - __slots__ = 'parser' + __slots__ = "parser" - def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): + def __init__( + self, parser, parent: ParserRuleContext = None, invokingState: int = -1 + ): super().__init__(parent, invokingState) self.parser = parser @@ -919,26 +2265,21 @@ def TIME(self): return self.getToken(ExprParser.TIME, 0) def shift_expr(self): - return self.getTypedRuleContext(ExprParser.Shift_exprContext,0) - + return self.getTypedRuleContext(ExprParser.Shift_exprContext, 0) def getRuleIndex(self): return ExprParser.RULE_shift - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitShift" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitShift"): return visitor.visitShift(self) else: return visitor.visitChildren(self) - - - def shift(self): - localctx = ExprParser.ShiftContext(self, self._ctx, self.state) self.enterRule(localctx, 8, self.RULE_shift) - self._la = 0 # Token type + self._la = 0 # Token type try: self.enterOuterAlt(localctx, 1) self.state = 110 @@ -946,11 +2287,10 @@ def shift(self): self.state = 112 self._errHandler.sync(self) _la = self._input.LA(1) - if _la==2 or _la==7: + if _la == 2 or _la == 7: self.state = 111 self.shift_expr(0) - except RecognitionException as re: localctx.exception = re self._errHandler.reportError(self, re) @@ -959,115 +2299,108 @@ def shift(self): self.exitRule() return localctx - class Shift_exprContext(ParserRuleContext): - __slots__ = 'parser' + __slots__ = "parser" - def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): + def __init__( + self, parser, parent: ParserRuleContext = None, invokingState: int = -1 + ): super().__init__(parent, invokingState) self.parser = parser - def getRuleIndex(self): return ExprParser.RULE_shift_expr - - def copyFrom(self, ctx:ParserRuleContext): + def copyFrom(self, ctx: ParserRuleContext): super().copyFrom(ctx) - class SignedAtomContext(Shift_exprContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.Shift_exprContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.Shift_exprContext super().__init__(parser) - self.op = None # Token + self.op = None # Token self.copyFrom(ctx) def atom(self): - return self.getTypedRuleContext(ExprParser.AtomContext,0) + return self.getTypedRuleContext(ExprParser.AtomContext, 0) - - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitSignedAtom" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitSignedAtom"): return visitor.visitSignedAtom(self) else: return visitor.visitChildren(self) - class SignedExpressionContext(Shift_exprContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.Shift_exprContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.Shift_exprContext super().__init__(parser) - self.op = None # Token + self.op = None # Token self.copyFrom(ctx) def expr(self): - return self.getTypedRuleContext(ExprParser.ExprContext,0) - + return self.getTypedRuleContext(ExprParser.ExprContext, 0) - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitSignedExpression" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitSignedExpression"): return visitor.visitSignedExpression(self) else: return visitor.visitChildren(self) - class ShiftMuldivContext(Shift_exprContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.Shift_exprContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.Shift_exprContext super().__init__(parser) - self.op = None # Token + self.op = None # Token self.copyFrom(ctx) def shift_expr(self): - return self.getTypedRuleContext(ExprParser.Shift_exprContext,0) + return self.getTypedRuleContext(ExprParser.Shift_exprContext, 0) def right_expr(self): - return self.getTypedRuleContext(ExprParser.Right_exprContext,0) - + return self.getTypedRuleContext(ExprParser.Right_exprContext, 0) - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitShiftMuldiv" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitShiftMuldiv"): return visitor.visitShiftMuldiv(self) else: return visitor.visitChildren(self) - class ShiftAddsubContext(Shift_exprContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.Shift_exprContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.Shift_exprContext super().__init__(parser) - self.op = None # Token + self.op = None # Token self.copyFrom(ctx) def shift_expr(self): - return self.getTypedRuleContext(ExprParser.Shift_exprContext,0) + return self.getTypedRuleContext(ExprParser.Shift_exprContext, 0) def right_expr(self): - return self.getTypedRuleContext(ExprParser.Right_exprContext,0) + return self.getTypedRuleContext(ExprParser.Right_exprContext, 0) - - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitShiftAddsub" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitShiftAddsub"): return visitor.visitShiftAddsub(self) else: return visitor.visitChildren(self) - - - def shift_expr(self, _p:int=0): + def shift_expr(self, _p: int = 0): _parentctx = self._ctx _parentState = self.state localctx = ExprParser.Shift_exprContext(self, self._ctx, _parentState) _prevctx = localctx _startState = 10 self.enterRecursionRule(localctx, 10, self.RULE_shift_expr, _p) - self._la = 0 # Token type + self._la = 0 # Token type try: self.enterOuterAlt(localctx, 1) self.state = 122 self._errHandler.sync(self) - la_ = self._interp.adaptivePredict(self._input,6,self._ctx) + la_ = self._interp.adaptivePredict(self._input, 6, self._ctx) if la_ == 1: localctx = ExprParser.SignedAtomContext(self, localctx) self._ctx = localctx @@ -1076,7 +2409,7 @@ def shift_expr(self, _p:int=0): self.state = 115 localctx.op = self._input.LT(1) _la = self._input.LA(1) - if not(_la==2 or _la==7): + if not (_la == 2 or _la == 7): localctx.op = self._errHandler.recoverInline(self) else: self._errHandler.reportMatch(self) @@ -1092,7 +2425,7 @@ def shift_expr(self, _p:int=0): self.state = 117 localctx.op = self._input.LT(1) _la = self._input.LA(1) - if not(_la==2 or _la==7): + if not (_la == 2 or _la == 7): localctx.op = self._errHandler.recoverInline(self) else: self._errHandler.reportMatch(self) @@ -1105,30 +2438,39 @@ def shift_expr(self, _p:int=0): self.match(ExprParser.T__3) pass - self._ctx.stop = self._input.LT(-1) self.state = 132 self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input,8,self._ctx) - while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER: - if _alt==1: + _alt = self._interp.adaptivePredict(self._input, 8, self._ctx) + while _alt != 2 and _alt != ATN.INVALID_ALT_NUMBER: + if _alt == 1: if self._parseListeners is not None: self.triggerExitRuleEvent() _prevctx = localctx self.state = 130 self._errHandler.sync(self) - la_ = self._interp.adaptivePredict(self._input,7,self._ctx) + la_ = self._interp.adaptivePredict(self._input, 7, self._ctx) if la_ == 1: - localctx = ExprParser.ShiftMuldivContext(self, ExprParser.Shift_exprContext(self, _parentctx, _parentState)) - self.pushNewRecursionContext(localctx, _startState, self.RULE_shift_expr) + localctx = ExprParser.ShiftMuldivContext( + self, + ExprParser.Shift_exprContext( + self, _parentctx, _parentState + ), + ) + self.pushNewRecursionContext( + localctx, _startState, self.RULE_shift_expr + ) self.state = 124 if not self.precpred(self._ctx, 4): from antlr4.error.Errors import FailedPredicateException - raise FailedPredicateException(self, "self.precpred(self._ctx, 4)") + + raise FailedPredicateException( + self, "self.precpred(self._ctx, 4)" + ) self.state = 125 localctx.op = self._input.LT(1) _la = self._input.LA(1) - if not(_la==5 or _la==6): + if not (_la == 5 or _la == 6): localctx.op = self._errHandler.recoverInline(self) else: self._errHandler.reportMatch(self) @@ -1138,16 +2480,26 @@ def shift_expr(self, _p:int=0): pass elif la_ == 2: - localctx = ExprParser.ShiftAddsubContext(self, ExprParser.Shift_exprContext(self, _parentctx, _parentState)) - self.pushNewRecursionContext(localctx, _startState, self.RULE_shift_expr) + localctx = ExprParser.ShiftAddsubContext( + self, + ExprParser.Shift_exprContext( + self, _parentctx, _parentState + ), + ) + self.pushNewRecursionContext( + localctx, _startState, self.RULE_shift_expr + ) self.state = 127 if not self.precpred(self._ctx, 3): from antlr4.error.Errors import FailedPredicateException - raise FailedPredicateException(self, "self.precpred(self._ctx, 3)") + + raise FailedPredicateException( + self, "self.precpred(self._ctx, 3)" + ) self.state = 128 localctx.op = self._input.LT(1) _la = self._input.LA(1) - if not(_la==2 or _la==7): + if not (_la == 2 or _la == 7): localctx.op = self._errHandler.recoverInline(self) else: self._errHandler.reportMatch(self) @@ -1156,10 +2508,9 @@ def shift_expr(self, _p:int=0): self.right_expr(0) pass - self.state = 134 self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input,8,self._ctx) + _alt = self._interp.adaptivePredict(self._input, 8, self._ctx) except RecognitionException as re: localctx.exception = re @@ -1169,87 +2520,81 @@ def shift_expr(self, _p:int=0): self.unrollRecursionContexts(_parentctx) return localctx - class Right_exprContext(ParserRuleContext): - __slots__ = 'parser' + __slots__ = "parser" - def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): + def __init__( + self, parser, parent: ParserRuleContext = None, invokingState: int = -1 + ): super().__init__(parent, invokingState) self.parser = parser - def getRuleIndex(self): return ExprParser.RULE_right_expr - - def copyFrom(self, ctx:ParserRuleContext): + def copyFrom(self, ctx: ParserRuleContext): super().copyFrom(ctx) - class RightExpressionContext(Right_exprContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.Right_exprContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.Right_exprContext super().__init__(parser) self.copyFrom(ctx) def expr(self): - return self.getTypedRuleContext(ExprParser.ExprContext,0) + return self.getTypedRuleContext(ExprParser.ExprContext, 0) - - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitRightExpression" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitRightExpression"): return visitor.visitRightExpression(self) else: return visitor.visitChildren(self) - class RightMuldivContext(Right_exprContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.Right_exprContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.Right_exprContext super().__init__(parser) - self.op = None # Token + self.op = None # Token self.copyFrom(ctx) - def right_expr(self, i:int=None): + def right_expr(self, i: int = None): if i is None: return self.getTypedRuleContexts(ExprParser.Right_exprContext) else: - return self.getTypedRuleContext(ExprParser.Right_exprContext,i) - + return self.getTypedRuleContext(ExprParser.Right_exprContext, i) - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitRightMuldiv" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitRightMuldiv"): return visitor.visitRightMuldiv(self) else: return visitor.visitChildren(self) - class RightAtomContext(Right_exprContext): - - def __init__(self, parser, ctx:ParserRuleContext): # actually a ExprParser.Right_exprContext + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.Right_exprContext super().__init__(parser) self.copyFrom(ctx) def atom(self): - return self.getTypedRuleContext(ExprParser.AtomContext,0) + return self.getTypedRuleContext(ExprParser.AtomContext, 0) - - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitRightAtom" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitRightAtom"): return visitor.visitRightAtom(self) else: return visitor.visitChildren(self) - - - def right_expr(self, _p:int=0): + def right_expr(self, _p: int = 0): _parentctx = self._ctx _parentState = self.state localctx = ExprParser.Right_exprContext(self, self._ctx, _parentState) _prevctx = localctx _startState = 12 self.enterRecursionRule(localctx, 12, self.RULE_right_expr, _p) - self._la = 0 # Token type + self._la = 0 # Token type try: self.enterOuterAlt(localctx, 1) self.state = 141 @@ -1280,31 +2625,39 @@ def right_expr(self, _p:int=0): self._ctx.stop = self._input.LT(-1) self.state = 148 self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input,10,self._ctx) - while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER: - if _alt==1: + _alt = self._interp.adaptivePredict(self._input, 10, self._ctx) + while _alt != 2 and _alt != ATN.INVALID_ALT_NUMBER: + if _alt == 1: if self._parseListeners is not None: self.triggerExitRuleEvent() _prevctx = localctx - localctx = ExprParser.RightMuldivContext(self, ExprParser.Right_exprContext(self, _parentctx, _parentState)) - self.pushNewRecursionContext(localctx, _startState, self.RULE_right_expr) + localctx = ExprParser.RightMuldivContext( + self, + ExprParser.Right_exprContext(self, _parentctx, _parentState), + ) + self.pushNewRecursionContext( + localctx, _startState, self.RULE_right_expr + ) self.state = 143 if not self.precpred(self._ctx, 3): from antlr4.error.Errors import FailedPredicateException - raise FailedPredicateException(self, "self.precpred(self._ctx, 3)") + + raise FailedPredicateException( + self, "self.precpred(self._ctx, 3)" + ) self.state = 144 localctx.op = self._input.LT(1) _la = self._input.LA(1) - if not(_la==5 or _la==6): + if not (_la == 5 or _la == 6): localctx.op = self._errHandler.recoverInline(self) else: self._errHandler.reportMatch(self) self.consume() self.state = 145 - self.right_expr(4) + self.right_expr(4) self.state = 150 self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input,10,self._ctx) + _alt = self._interp.adaptivePredict(self._input, 10, self._ctx) except RecognitionException as re: localctx.exception = re @@ -1314,9 +2667,7 @@ def right_expr(self, _p:int=0): self.unrollRecursionContexts(_parentctx) return localctx - - - def sempred(self, localctx:RuleContext, ruleIndex:int, predIndex:int): + def sempred(self, localctx: RuleContext, ruleIndex: int, predIndex: int): if self._predicates == None: self._predicates = dict() self._predicates[2] = self.expr_sempred @@ -1328,33 +2679,23 @@ def sempred(self, localctx:RuleContext, ruleIndex:int, predIndex:int): else: return pred(localctx, predIndex) - def expr_sempred(self, localctx:ExprContext, predIndex:int): - if predIndex == 0: - return self.precpred(self._ctx, 12) - - - if predIndex == 1: - return self.precpred(self._ctx, 11) - - - if predIndex == 2: - return self.precpred(self._ctx, 10) - - - def shift_expr_sempred(self, localctx:Shift_exprContext, predIndex:int): - if predIndex == 3: - return self.precpred(self._ctx, 4) - - - if predIndex == 4: - return self.precpred(self._ctx, 3) - + def expr_sempred(self, localctx: ExprContext, predIndex: int): + if predIndex == 0: + return self.precpred(self._ctx, 12) - def right_expr_sempred(self, localctx:Right_exprContext, predIndex:int): - if predIndex == 5: - return self.precpred(self._ctx, 3) - + if predIndex == 1: + return self.precpred(self._ctx, 11) + if predIndex == 2: + return self.precpred(self._ctx, 10) + def shift_expr_sempred(self, localctx: Shift_exprContext, predIndex: int): + if predIndex == 3: + return self.precpred(self._ctx, 4) + if predIndex == 4: + return self.precpred(self._ctx, 3) + def right_expr_sempred(self, localctx: Right_exprContext, predIndex: int): + if predIndex == 5: + return self.precpred(self._ctx, 3) diff --git a/src/gems/expression/parsing/antlr/ExprVisitor.py b/src/gems/expression/parsing/antlr/ExprVisitor.py index 7e9dfe69..c79c9be7 100644 --- a/src/gems/expression/parsing/antlr/ExprVisitor.py +++ b/src/gems/expression/parsing/antlr/ExprVisitor.py @@ -1,5 +1,6 @@ # Generated from Expr.g4 by ANTLR 4.13.2 from antlr4 import * + if "." in __name__: from .ExprParser import ExprParser else: @@ -7,147 +8,119 @@ # This class defines a complete generic visitor for a parse tree produced by ExprParser. -class ExprVisitor(ParseTreeVisitor): +class ExprVisitor(ParseTreeVisitor): # Visit a parse tree produced by ExprParser#portFieldExpr. - def visitPortFieldExpr(self, ctx:ExprParser.PortFieldExprContext): + def visitPortFieldExpr(self, ctx: ExprParser.PortFieldExprContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#fullexpr. - def visitFullexpr(self, ctx:ExprParser.FullexprContext): + def visitFullexpr(self, ctx: ExprParser.FullexprContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#portFieldSum. - def visitPortFieldSum(self, ctx:ExprParser.PortFieldSumContext): + def visitPortFieldSum(self, ctx: ExprParser.PortFieldSumContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#negation. - def visitNegation(self, ctx:ExprParser.NegationContext): + def visitNegation(self, ctx: ExprParser.NegationContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#unsignedAtom. - def visitUnsignedAtom(self, ctx:ExprParser.UnsignedAtomContext): + def visitUnsignedAtom(self, ctx: ExprParser.UnsignedAtomContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#expression. - def visitExpression(self, ctx:ExprParser.ExpressionContext): + def visitExpression(self, ctx: ExprParser.ExpressionContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#comparison. - def visitComparison(self, ctx:ExprParser.ComparisonContext): + def visitComparison(self, ctx: ExprParser.ComparisonContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#allTimeSum. - def visitAllTimeSum(self, ctx:ExprParser.AllTimeSumContext): + def visitAllTimeSum(self, ctx: ExprParser.AllTimeSumContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#timeIndexExpr. - def visitTimeIndexExpr(self, ctx:ExprParser.TimeIndexExprContext): + def visitTimeIndexExpr(self, ctx: ExprParser.TimeIndexExprContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#addsub. - def visitAddsub(self, ctx:ExprParser.AddsubContext): + def visitAddsub(self, ctx: ExprParser.AddsubContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#timeShiftExpr. - def visitTimeShiftExpr(self, ctx:ExprParser.TimeShiftExprContext): + def visitTimeShiftExpr(self, ctx: ExprParser.TimeShiftExprContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#portField. - def visitPortField(self, ctx:ExprParser.PortFieldContext): + def visitPortField(self, ctx: ExprParser.PortFieldContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#muldiv. - def visitMuldiv(self, ctx:ExprParser.MuldivContext): + def visitMuldiv(self, ctx: ExprParser.MuldivContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#timeSum. - def visitTimeSum(self, ctx:ExprParser.TimeSumContext): + def visitTimeSum(self, ctx: ExprParser.TimeSumContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#maxExpr. - def visitMaxExpr(self, ctx:ExprParser.MaxExprContext): + def visitMaxExpr(self, ctx: ExprParser.MaxExprContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#timeIndex. - def visitTimeIndex(self, ctx:ExprParser.TimeIndexContext): + def visitTimeIndex(self, ctx: ExprParser.TimeIndexContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#timeShift. - def visitTimeShift(self, ctx:ExprParser.TimeShiftContext): + def visitTimeShift(self, ctx: ExprParser.TimeShiftContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#function. - def visitFunction(self, ctx:ExprParser.FunctionContext): + def visitFunction(self, ctx: ExprParser.FunctionContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#number. - def visitNumber(self, ctx:ExprParser.NumberContext): + def visitNumber(self, ctx: ExprParser.NumberContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#identifier. - def visitIdentifier(self, ctx:ExprParser.IdentifierContext): + def visitIdentifier(self, ctx: ExprParser.IdentifierContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#shift. - def visitShift(self, ctx:ExprParser.ShiftContext): + def visitShift(self, ctx: ExprParser.ShiftContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#signedAtom. - def visitSignedAtom(self, ctx:ExprParser.SignedAtomContext): + def visitSignedAtom(self, ctx: ExprParser.SignedAtomContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#signedExpression. - def visitSignedExpression(self, ctx:ExprParser.SignedExpressionContext): + def visitSignedExpression(self, ctx: ExprParser.SignedExpressionContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#shiftMuldiv. - def visitShiftMuldiv(self, ctx:ExprParser.ShiftMuldivContext): + def visitShiftMuldiv(self, ctx: ExprParser.ShiftMuldivContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#shiftAddsub. - def visitShiftAddsub(self, ctx:ExprParser.ShiftAddsubContext): + def visitShiftAddsub(self, ctx: ExprParser.ShiftAddsubContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#rightExpression. - def visitRightExpression(self, ctx:ExprParser.RightExpressionContext): + def visitRightExpression(self, ctx: ExprParser.RightExpressionContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#rightMuldiv. - def visitRightMuldiv(self, ctx:ExprParser.RightMuldivContext): + def visitRightMuldiv(self, ctx: ExprParser.RightMuldivContext): return self.visitChildren(ctx) - # Visit a parse tree produced by ExprParser#rightAtom. - def visitRightAtom(self, ctx:ExprParser.RightAtomContext): + def visitRightAtom(self, ctx: ExprParser.RightAtomContext): return self.visitChildren(ctx) - -del ExprParser \ No newline at end of file +del ExprParser