From 90986a0bf09d0f51c9b760e76a56fbcb3a74a794 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 18 Mar 2026 21:45:34 +0000 Subject: [PATCH 01/12] Add floor, ceil, max, and min math operators to GemsPy expression AST These operators are needed to parse and evaluate GEMS model expressions from antares_legacy_models.yml, which uses ceil(p/q), max(0, expr), and min(a, b) in variable bounds and constraint expressions for thermal unit commitment models. Changes: - Add FloorNode, CeilNode (unary) and MaxNode, MinNode (binary) AST nodes - Add floor()/ceil() methods on ExpressionNode; maximum()/minimum() factory fns - Extend Expr.g4 grammar with binaryFunction rule; regenerate ANTLR files - Update all visitors: abstract ExpressionVisitor, CopyVisitor, PrinterVisitor, EvaluationVisitor, ExpressionDegreeVisitor, TimeScenarioIndexingVisitor, EqualityVisitor - Register floor/ceil in _FUNCTIONS and max/min in new _BINARY_FUNCTIONS dict - Add tests for parsing, evaluation, and printing of the new operators https://claude.ai/code/session_01VUYEHTGsxtBYVEVm5c7ysC --- grammar/Expr.g4 | 1 + src/gems/expression/__init__.py | 6 + src/gems/expression/copy.py | 16 + src/gems/expression/degree.py | 16 + src/gems/expression/equality.py | 24 + src/gems/expression/evaluate.py | 17 + src/gems/expression/expression.py | 34 + src/gems/expression/indexing.py | 16 + src/gems/expression/parsing/antlr/Expr.interp | 2 +- .../expression/parsing/antlr/ExprLexer.py | 1245 +-------- .../expression/parsing/antlr/ExprParser.py | 2253 ++++------------- .../expression/parsing/antlr/ExprVisitor.py | 93 +- .../expression/parsing/parse_expression.py | 19 + src/gems/expression/print.py | 16 + src/gems/expression/visitor.py | 28 + .../parsing/test_expression_parsing.py | 38 +- .../expressions/visitor/test_evaluation.py | 13 + .../expressions/visitor/test_printer.py | 14 + 18 files changed, 914 insertions(+), 2937 deletions(-) diff --git a/grammar/Expr.g4 b/grammar/Expr.g4 index 73e4d0ba..92928f38 100644 --- a/grammar/Expr.g4 +++ b/grammar/Expr.g4 @@ -29,6 +29,7 @@ expr | 'sum_connections' '(' portFieldExpr ')' # portFieldSum | 'sum' '(' from=shift '..' to=shift ',' expr ')' # timeSum | IDENTIFIER '(' expr ')' # function + | IDENTIFIER '(' expr ',' expr ')' # binaryFunction | IDENTIFIER '[' shift ']' # timeShift | IDENTIFIER '[' expr ']' # timeIndex | '(' expr ')' '[' shift ']' # timeShiftExpr diff --git a/src/gems/expression/__init__.py b/src/gems/expression/__init__.py index 3d949b6e..1eafc790 100644 --- a/src/gems/expression/__init__.py +++ b/src/gems/expression/__init__.py @@ -20,16 +20,22 @@ ) from .expression import ( AdditionNode, + CeilNode, Comparator, ComparisonNode, DivisionNode, ExpressionNode, + FloorNode, LiteralNode, + MaxNode, + MinNode, MultiplicationNode, NegationNode, ParameterNode, VariableNode, literal, + maximum, + minimum, param, sum_expressions, var, diff --git a/src/gems/expression/copy.py b/src/gems/expression/copy.py index eea34d74..108b98ac 100644 --- a/src/gems/expression/copy.py +++ b/src/gems/expression/copy.py @@ -15,11 +15,15 @@ from .expression import ( AllTimeSumNode, + CeilNode, ComparisonNode, ComponentParameterNode, ComponentVariableNode, ExpressionNode, + FloorNode, LiteralNode, + MaxNode, + MinNode, ParameterNode, PortFieldAggregatorNode, PortFieldNode, @@ -95,6 +99,18 @@ def port_field(self, node: PortFieldNode) -> ExpressionNode: def port_field_aggregator(self, node: PortFieldAggregatorNode) -> ExpressionNode: return PortFieldAggregatorNode(visit(node.operand, self), node.aggregator) + def floor(self, node: FloorNode) -> ExpressionNode: + return FloorNode(visit(node.operand, self)) + + def ceil(self, node: CeilNode) -> ExpressionNode: + return CeilNode(visit(node.operand, self)) + + def maximum(self, node: MaxNode) -> ExpressionNode: + return MaxNode(visit(node.left, self), visit(node.right, self)) + + def minimum(self, node: MinNode) -> ExpressionNode: + return MinNode(visit(node.left, self), visit(node.right, self)) + def copy_expression(expression: ExpressionNode) -> ExpressionNode: return visit(expression, CopyVisitor()) diff --git a/src/gems/expression/degree.py b/src/gems/expression/degree.py index d9051818..587fae44 100644 --- a/src/gems/expression/degree.py +++ b/src/gems/expression/degree.py @@ -13,8 +13,12 @@ import gems.expression.scenario_operator from gems.expression.expression import ( AllTimeSumNode, + CeilNode, ComponentParameterNode, ComponentVariableNode, + FloorNode, + MaxNode, + MinNode, PortFieldAggregatorNode, PortFieldNode, ProblemParameterNode, @@ -108,6 +112,18 @@ def port_field(self, node: PortFieldNode) -> int: def port_field_aggregator(self, node: PortFieldAggregatorNode) -> int: return visit(node.operand, self) + def floor(self, node: FloorNode) -> int: + return visit(node.operand, self) + + def ceil(self, node: CeilNode) -> int: + return visit(node.operand, self) + + def maximum(self, node: MaxNode) -> int: + return max(visit(node.left, self), visit(node.right, self)) + + def minimum(self, node: MinNode) -> int: + return max(visit(node.left, self), visit(node.right, self)) + 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 d5a543ff..0517269e 100644 --- a/src/gems/expression/equality.py +++ b/src/gems/expression/equality.py @@ -28,8 +28,12 @@ from gems.expression.expression import ( AllTimeSumNode, BinaryOperatorNode, + CeilNode, ComponentParameterNode, ComponentVariableNode, + FloorNode, + MaxNode, + MinNode, PortFieldAggregatorNode, PortFieldNode, ProblemParameterNode, @@ -111,6 +115,14 @@ def visit(self, left: ExpressionNode, right: ExpressionNode) -> bool: right, PortFieldAggregatorNode ): return self.port_field_aggregator(left, right) + if isinstance(left, FloorNode) and isinstance(right, FloorNode): + return self.floor(left, right) + if isinstance(left, CeilNode) and isinstance(right, CeilNode): + return self.ceil(left, right) + if isinstance(left, MaxNode) and isinstance(right, MaxNode): + return self.maximum(left, right) + if isinstance(left, MinNode) and isinstance(right, MinNode): + return self.minimum(left, right) raise NotImplementedError(f"Equality not implemented for {left.__class__}") def literal(self, left: LiteralNode, right: LiteralNode) -> bool: @@ -215,6 +227,18 @@ def port_field_aggregator( left.operand, right.operand ) + def floor(self, left: FloorNode, right: FloorNode) -> bool: + return self.visit(left.operand, right.operand) + + def ceil(self, left: CeilNode, right: CeilNode) -> bool: + return self.visit(left.operand, right.operand) + + def maximum(self, left: MaxNode, right: MaxNode) -> bool: + return self._visit_operands(left, right) + + def minimum(self, left: MinNode, right: MinNode) -> bool: + return self._visit_operands(left, right) + def expressions_equal( left: ExpressionNode, right: ExpressionNode, abs_tol: float = 0, rel_tol: float = 0 diff --git a/src/gems/expression/evaluate.py b/src/gems/expression/evaluate.py index 398db7da..4d3c3770 100644 --- a/src/gems/expression/evaluate.py +++ b/src/gems/expression/evaluate.py @@ -10,14 +10,19 @@ # # This file is part of the Antares project. +import math from abc import ABC, abstractmethod from dataclasses import dataclass, field from typing import Dict from gems.expression.expression import ( AllTimeSumNode, + CeilNode, ComponentParameterNode, ComponentVariableNode, + FloorNode, + MaxNode, + MinNode, PortFieldAggregatorNode, PortFieldNode, ProblemParameterNode, @@ -139,6 +144,18 @@ def port_field(self, node: PortFieldNode) -> float: def port_field_aggregator(self, node: PortFieldAggregatorNode) -> float: raise NotImplementedError() + def floor(self, node: FloorNode) -> float: + return float(math.floor(visit(node.operand, self))) + + def ceil(self, node: CeilNode) -> float: + return float(math.ceil(visit(node.operand, self))) + + def maximum(self, node: MaxNode) -> float: + return max(visit(node.left, self), visit(node.right, self)) + + def minimum(self, node: MinNode) -> float: + return min(visit(node.left, self), visit(node.right, self)) + 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 44bfcfc9..ee639cb0 100644 --- a/src/gems/expression/expression.py +++ b/src/gems/expression/expression.py @@ -117,6 +117,12 @@ def shift(self, shift: AnyExpression) -> "ExpressionNode": def eval(self, time: AnyExpression) -> "ExpressionNode": return TimeEvalNode(self, _wrap_in_node(time)) + def floor(self) -> "ExpressionNode": + return FloorNode(self) + + def ceil(self) -> "ExpressionNode": + return CeilNode(self) + def expec(self) -> "ExpressionNode": return _apply_if_node(self, lambda x: ScenarioOperatorNode(x, "Expectation")) @@ -368,6 +374,16 @@ class NegationNode(UnaryOperatorNode): pass +@dataclass(frozen=True, eq=False) +class FloorNode(UnaryOperatorNode): + pass + + +@dataclass(frozen=True, eq=False) +class CeilNode(UnaryOperatorNode): + pass + + @dataclass(frozen=True, eq=False) class BinaryOperatorNode(ExpressionNode): left: ExpressionNode @@ -400,6 +416,24 @@ class DivisionNode(BinaryOperatorNode): pass +@dataclass(frozen=True, eq=False) +class MaxNode(BinaryOperatorNode): + pass + + +@dataclass(frozen=True, eq=False) +class MinNode(BinaryOperatorNode): + pass + + +def maximum(left: "ExpressionNode", right: "ExpressionNode") -> "MaxNode": + return MaxNode(left, right) + + +def minimum(left: "ExpressionNode", right: "ExpressionNode") -> "MinNode": + return MinNode(left, right) + + @dataclass(frozen=True, eq=False) class TimeShiftNode(UnaryOperatorNode): time_shift: ExpressionNode diff --git a/src/gems/expression/indexing.py b/src/gems/expression/indexing.py index 022aa936..7d7f1f0b 100644 --- a/src/gems/expression/indexing.py +++ b/src/gems/expression/indexing.py @@ -19,12 +19,16 @@ from .expression import ( AdditionNode, AllTimeSumNode, + CeilNode, ComparisonNode, ComponentParameterNode, ComponentVariableNode, DivisionNode, ExpressionNode, + FloorNode, LiteralNode, + MaxNode, + MinNode, MultiplicationNode, NegationNode, ParameterNode, @@ -159,6 +163,18 @@ def port_field_aggregator(self, node: PortFieldAggregatorNode) -> IndexingStruct "Port fields aggregators must be resolved before computing indexing structure." ) + def floor(self, node: FloorNode) -> IndexingStructure: + return visit(node.operand, self) + + def ceil(self, node: CeilNode) -> IndexingStructure: + return visit(node.operand, self) + + def maximum(self, node: MaxNode) -> IndexingStructure: + return self._combine([node.left, node.right]) + + def minimum(self, node: MinNode) -> IndexingStructure: + return self._combine([node.left, node.right]) + def compute_indexation( expression: ExpressionNode, provider: IndexingStructureProvider diff --git a/src/gems/expression/parsing/antlr/Expr.interp b/src/gems/expression/parsing/antlr/Expr.interp index 94f1370f..4cd49648 100644 --- a/src/gems/expression/parsing/antlr/Expr.interp +++ b/src/gems/expression/parsing/antlr/Expr.interp @@ -51,4 +51,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, 18, 147, 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, 1, 2, 1, 2, 3, 2, 86, 8, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 5, 2, 97, 8, 2, 10, 2, 12, 2, 100, 9, 2, 1, 3, 1, 3, 3, 3, 104, 8, 3, 1, 4, 1, 4, 3, 4, 108, 8, 4, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 3, 5, 118, 8, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 5, 5, 126, 8, 5, 10, 5, 12, 5, 129, 9, 5, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 3, 6, 137, 8, 6, 1, 6, 1, 6, 1, 6, 5, 6, 142, 8, 6, 10, 6, 12, 6, 145, 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, 161, 0, 14, 1, 0, 0, 0, 2, 18, 1, 0, 0, 0, 4, 85, 1, 0, 0, 0, 6, 103, 1, 0, 0, 0, 8, 105, 1, 0, 0, 0, 10, 117, 1, 0, 0, 0, 12, 136, 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, 86, 3, 6, 3, 0, 23, 86, 3, 0, 0, 0, 24, 25, 5, 2, 0, 0, 25, 86, 3, 4, 2, 14, 26, 27, 5, 3, 0, 0, 27, 28, 3, 4, 2, 0, 28, 29, 5, 4, 0, 0, 29, 86, 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, 86, 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, 86, 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, 86, 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, 86, 1, 0, 0, 0, 54, 55, 5, 16, 0, 0, 55, 56, 5, 3, 0, 0, 56, 57, 3, 4, 2, 0, 57, 58, 5, 11, 0, 0, 58, 59, 3, 4, 2, 0, 59, 60, 5, 4, 0, 0, 60, 86, 1, 0, 0, 0, 61, 62, 5, 16, 0, 0, 62, 63, 5, 12, 0, 0, 63, 64, 3, 8, 4, 0, 64, 65, 5, 13, 0, 0, 65, 86, 1, 0, 0, 0, 66, 67, 5, 16, 0, 0, 67, 68, 5, 12, 0, 0, 68, 69, 3, 4, 2, 0, 69, 70, 5, 13, 0, 0, 70, 86, 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, 8, 4, 0, 76, 77, 5, 13, 0, 0, 77, 86, 1, 0, 0, 0, 78, 79, 5, 3, 0, 0, 79, 80, 3, 4, 2, 0, 80, 81, 5, 4, 0, 0, 81, 82, 5, 12, 0, 0, 82, 83, 3, 4, 2, 0, 83, 84, 5, 13, 0, 0, 84, 86, 1, 0, 0, 0, 85, 21, 1, 0, 0, 0, 85, 23, 1, 0, 0, 0, 85, 24, 1, 0, 0, 0, 85, 26, 1, 0, 0, 0, 85, 30, 1, 0, 0, 0, 85, 35, 1, 0, 0, 0, 85, 40, 1, 0, 0, 0, 85, 49, 1, 0, 0, 0, 85, 54, 1, 0, 0, 0, 85, 61, 1, 0, 0, 0, 85, 66, 1, 0, 0, 0, 85, 71, 1, 0, 0, 0, 85, 78, 1, 0, 0, 0, 86, 98, 1, 0, 0, 0, 87, 88, 10, 12, 0, 0, 88, 89, 7, 0, 0, 0, 89, 97, 3, 4, 2, 13, 90, 91, 10, 11, 0, 0, 91, 92, 7, 1, 0, 0, 92, 97, 3, 4, 2, 12, 93, 94, 10, 10, 0, 0, 94, 95, 5, 17, 0, 0, 95, 97, 3, 4, 2, 11, 96, 87, 1, 0, 0, 0, 96, 90, 1, 0, 0, 0, 96, 93, 1, 0, 0, 0, 97, 100, 1, 0, 0, 0, 98, 96, 1, 0, 0, 0, 98, 99, 1, 0, 0, 0, 99, 5, 1, 0, 0, 0, 100, 98, 1, 0, 0, 0, 101, 104, 5, 14, 0, 0, 102, 104, 5, 16, 0, 0, 103, 101, 1, 0, 0, 0, 103, 102, 1, 0, 0, 0, 104, 7, 1, 0, 0, 0, 105, 107, 5, 15, 0, 0, 106, 108, 3, 10, 5, 0, 107, 106, 1, 0, 0, 0, 107, 108, 1, 0, 0, 0, 108, 9, 1, 0, 0, 0, 109, 110, 6, 5, -1, 0, 110, 111, 7, 1, 0, 0, 111, 118, 3, 6, 3, 0, 112, 113, 7, 1, 0, 0, 113, 114, 5, 3, 0, 0, 114, 115, 3, 4, 2, 0, 115, 116, 5, 4, 0, 0, 116, 118, 1, 0, 0, 0, 117, 109, 1, 0, 0, 0, 117, 112, 1, 0, 0, 0, 118, 127, 1, 0, 0, 0, 119, 120, 10, 4, 0, 0, 120, 121, 7, 0, 0, 0, 121, 126, 3, 12, 6, 0, 122, 123, 10, 3, 0, 0, 123, 124, 7, 1, 0, 0, 124, 126, 3, 12, 6, 0, 125, 119, 1, 0, 0, 0, 125, 122, 1, 0, 0, 0, 126, 129, 1, 0, 0, 0, 127, 125, 1, 0, 0, 0, 127, 128, 1, 0, 0, 0, 128, 11, 1, 0, 0, 0, 129, 127, 1, 0, 0, 0, 130, 131, 6, 6, -1, 0, 131, 132, 5, 3, 0, 0, 132, 133, 3, 4, 2, 0, 133, 134, 5, 4, 0, 0, 134, 137, 1, 0, 0, 0, 135, 137, 3, 6, 3, 0, 136, 130, 1, 0, 0, 0, 136, 135, 1, 0, 0, 0, 137, 143, 1, 0, 0, 0, 138, 139, 10, 3, 0, 0, 139, 140, 7, 0, 0, 0, 140, 142, 3, 12, 6, 4, 141, 138, 1, 0, 0, 0, 142, 145, 1, 0, 0, 0, 143, 141, 1, 0, 0, 0, 143, 144, 1, 0, 0, 0, 144, 13, 1, 0, 0, 0, 145, 143, 1, 0, 0, 0, 10, 85, 96, 98, 103, 107, 117, 125, 127, 136, 143] \ 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..0b61c62c 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 - +# Generated from /home/user/GemsPy/grammar/Expr.g4 by ANTLR 4.13.2 from antlr4 import * - +from io import StringIO +import sys if sys.version_info[1] > 5: from typing import TextIO else: @@ -12,1141 +10,56 @@ 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,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 ] - 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 @@ -1167,61 +80,29 @@ class ExprLexer(Lexer): COMPARISON = 17 WS = 18 - 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'", + "'..'", "','", "'['", "']'", "'t'" ] - symbolicNames = ["", "NUMBER", "TIME", "IDENTIFIER", "COMPARISON", "WS"] + symbolicNames = [ "", + "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", - "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" ] 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 859d23dc..7fb04f5e 100644 --- a/src/gems/expression/parsing/antlr/ExprParser.py +++ b/src/gems/expression/parsing/antlr/ExprParser.py @@ -1,1320 +1,85 @@ -# Generated from Expr.g4 by ANTLR 4.13.2 +# Generated from /home/user/GemsPy/grammar/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,18,147,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,1,2,1,2,3,2,86,8,2,1,2,1,2,1,2,1,2,1,2,1,2, + 1,2,1,2,1,2,5,2,97,8,2,10,2,12,2,100,9,2,1,3,1,3,3,3,104,8,3,1,4, + 1,4,3,4,108,8,4,1,5,1,5,1,5,1,5,1,5,1,5,1,5,1,5,3,5,118,8,5,1,5, + 1,5,1,5,1,5,1,5,1,5,5,5,126,8,5,10,5,12,5,129,9,5,1,6,1,6,1,6,1, + 6,1,6,1,6,3,6,137,8,6,1,6,1,6,1,6,5,6,142,8,6,10,6,12,6,145,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,161,0, + 14,1,0,0,0,2,18,1,0,0,0,4,85,1,0,0,0,6,103,1,0,0,0,8,105,1,0,0,0, + 10,117,1,0,0,0,12,136,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,86,3,6,3,0,23,86,3,0,0,0,24,25,5,2,0,0,25,86,3,4, + 2,14,26,27,5,3,0,0,27,28,3,4,2,0,28,29,5,4,0,0,29,86,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,86,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,86, + 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,86,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, + 86,1,0,0,0,54,55,5,16,0,0,55,56,5,3,0,0,56,57,3,4,2,0,57,58,5,11, + 0,0,58,59,3,4,2,0,59,60,5,4,0,0,60,86,1,0,0,0,61,62,5,16,0,0,62, + 63,5,12,0,0,63,64,3,8,4,0,64,65,5,13,0,0,65,86,1,0,0,0,66,67,5,16, + 0,0,67,68,5,12,0,0,68,69,3,4,2,0,69,70,5,13,0,0,70,86,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,8, + 4,0,76,77,5,13,0,0,77,86,1,0,0,0,78,79,5,3,0,0,79,80,3,4,2,0,80, + 81,5,4,0,0,81,82,5,12,0,0,82,83,3,4,2,0,83,84,5,13,0,0,84,86,1,0, + 0,0,85,21,1,0,0,0,85,23,1,0,0,0,85,24,1,0,0,0,85,26,1,0,0,0,85,30, + 1,0,0,0,85,35,1,0,0,0,85,40,1,0,0,0,85,49,1,0,0,0,85,54,1,0,0,0, + 85,61,1,0,0,0,85,66,1,0,0,0,85,71,1,0,0,0,85,78,1,0,0,0,86,98,1, + 0,0,0,87,88,10,12,0,0,88,89,7,0,0,0,89,97,3,4,2,13,90,91,10,11,0, + 0,91,92,7,1,0,0,92,97,3,4,2,12,93,94,10,10,0,0,94,95,5,17,0,0,95, + 97,3,4,2,11,96,87,1,0,0,0,96,90,1,0,0,0,96,93,1,0,0,0,97,100,1,0, + 0,0,98,96,1,0,0,0,98,99,1,0,0,0,99,5,1,0,0,0,100,98,1,0,0,0,101, + 104,5,14,0,0,102,104,5,16,0,0,103,101,1,0,0,0,103,102,1,0,0,0,104, + 7,1,0,0,0,105,107,5,15,0,0,106,108,3,10,5,0,107,106,1,0,0,0,107, + 108,1,0,0,0,108,9,1,0,0,0,109,110,6,5,-1,0,110,111,7,1,0,0,111,118, + 3,6,3,0,112,113,7,1,0,0,113,114,5,3,0,0,114,115,3,4,2,0,115,116, + 5,4,0,0,116,118,1,0,0,0,117,109,1,0,0,0,117,112,1,0,0,0,118,127, + 1,0,0,0,119,120,10,4,0,0,120,121,7,0,0,0,121,126,3,12,6,0,122,123, + 10,3,0,0,123,124,7,1,0,0,124,126,3,12,6,0,125,119,1,0,0,0,125,122, + 1,0,0,0,126,129,1,0,0,0,127,125,1,0,0,0,127,128,1,0,0,0,128,11,1, + 0,0,0,129,127,1,0,0,0,130,131,6,6,-1,0,131,132,5,3,0,0,132,133,3, + 4,2,0,133,134,5,4,0,0,134,137,1,0,0,0,135,137,3,6,3,0,136,130,1, + 0,0,0,136,135,1,0,0,0,137,143,1,0,0,0,138,139,10,3,0,0,139,140,7, + 0,0,0,140,142,3,12,6,4,141,138,1,0,0,0,142,145,1,0,0,0,143,141,1, + 0,0,0,143,144,1,0,0,0,144,13,1,0,0,0,145,143,1,0,0,0,10,85,96,98, + 103,107,117,125,127,136,143 ] +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'", "'..'", "','", + "'['", "']'", "", "'t'" ] - symbolicNames = [ - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "NUMBER", - "TIME", - "IDENTIFIER", - "COMPARISON", - "WS", - ] + symbolicNames = [ "", "", "", "", + "", "", "", "", + "", "", "", "", + "", "", "NUMBER", "TIME", "IDENTIFIER", + "COMPARISON", "WS" ] RULE_portFieldExpr = 0 RULE_fullexpr = 1 @@ -1324,54 +89,46 @@ 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 + TIME=15 + IDENTIFIER=16 + COMPARISON=17 + WS=18 + + 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 +137,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 +166,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 +184,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 +211,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 BinaryFunctionContext(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, 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, "visitBinaryFunction" ): + return visitor.visitBinaryFunction(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 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 = 85 self._errHandler.sync(self) - la_ = self._interp.adaptivePredict(self._input, 0, self._ctx) + la_ = self._interp.adaptivePredict(self._input,0,self._ctx) if la_ == 1: localctx = ExprParser.UnsignedAtomContext(self, localctx) self._ctx = localctx @@ -1775,7 +576,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: @@ -1855,53 +656,53 @@ def expr(self, _p: int = 0): pass elif la_ == 9: - localctx = ExprParser.TimeShiftContext(self, localctx) + localctx = ExprParser.BinaryFunctionContext(self, localctx) self._ctx = localctx _prevctx = localctx self.state = 54 self.match(ExprParser.IDENTIFIER) self.state = 55 - self.match(ExprParser.T__11) + self.match(ExprParser.T__2) self.state = 56 - self.shift() + self.expr(0) self.state = 57 - self.match(ExprParser.T__12) + self.match(ExprParser.T__10) + self.state = 58 + self.expr(0) + self.state = 59 + self.match(ExprParser.T__3) pass elif la_ == 10: - localctx = ExprParser.TimeIndexContext(self, localctx) + localctx = ExprParser.TimeShiftContext(self, localctx) self._ctx = localctx _prevctx = localctx - self.state = 59 - self.match(ExprParser.IDENTIFIER) - self.state = 60 - self.match(ExprParser.T__11) self.state = 61 - self.expr(0) + self.match(ExprParser.IDENTIFIER) self.state = 62 + self.match(ExprParser.T__11) + self.state = 63 + self.shift() + self.state = 64 self.match(ExprParser.T__12) pass elif la_ == 11: - localctx = ExprParser.TimeShiftExprContext(self, localctx) + localctx = ExprParser.TimeIndexContext(self, localctx) self._ctx = localctx _prevctx = localctx - self.state = 64 - self.match(ExprParser.T__2) - self.state = 65 - self.expr(0) self.state = 66 - self.match(ExprParser.T__3) + self.match(ExprParser.IDENTIFIER) self.state = 67 self.match(ExprParser.T__11) self.state = 68 - self.shift() + self.expr(0) self.state = 69 self.match(ExprParser.T__12) pass elif la_ == 12: - localctx = ExprParser.TimeIndexExprContext(self, localctx) + localctx = ExprParser.TimeShiftExprContext(self, localctx) self._ctx = localctx _prevctx = localctx self.state = 71 @@ -1913,98 +714,97 @@ def expr(self, _p: int = 0): self.state = 74 self.match(ExprParser.T__11) self.state = 75 - self.expr(0) + self.shift() self.state = 76 self.match(ExprParser.T__12) pass + elif la_ == 13: + localctx = ExprParser.TimeIndexExprContext(self, localctx) + self._ctx = localctx + _prevctx = localctx + self.state = 78 + self.match(ExprParser.T__2) + self.state = 79 + self.expr(0) + self.state = 80 + self.match(ExprParser.T__3) + self.state = 81 + self.match(ExprParser.T__11) + self.state = 82 + self.expr(0) + self.state = 83 + self.match(ExprParser.T__12) + pass + + self._ctx.stop = self._input.LT(-1) - self.state = 91 + self.state = 98 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,2,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 = 96 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.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 = 87 + 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 = 88 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 = 89 + 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 = 90 + 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 = 91 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 = 92 + 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 = 93 + 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 = 94 self.match(ExprParser.COMPARISON) - self.state = 88 - self.expr(10) + self.state = 95 + self.expr(11) pass - self.state = 93 + + self.state = 100 self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input, 2, self._ctx) + _alt = self._interp.adaptivePredict(self._input,2,self._ctx) except RecognitionException as re: localctx.exception = re @@ -2014,70 +814,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 = 103 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 = 101 self.match(ExprParser.NUMBER) pass elif token in [16]: localctx = ExprParser.IdentifierContext(self, localctx) self.enterOuterAlt(localctx, 2) - self.state = 95 + self.state = 102 self.match(ExprParser.IDENTIFIER) pass else: @@ -2091,12 +896,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 +908,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 = 105 self.match(ExprParser.TIME) - self.state = 100 + self.state = 107 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 = 106 self.shift_expr(0) + except RecognitionException as re: localctx.exception = re self._errHandler.reportError(self, re) @@ -2138,122 +948,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 = 117 self._errHandler.sync(self) - la_ = self._interp.adaptivePredict(self._input, 5, self._ctx) + la_ = self._interp.adaptivePredict(self._input,5,self._ctx) if la_ == 1: localctx = ExprParser.SignedAtomContext(self, localctx) self._ctx = localctx _prevctx = localctx - self.state = 103 + self.state = 110 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 = 111 self.atom() pass @@ -2261,95 +1078,77 @@ def shift_expr(self, _p: int = 0): localctx = ExprParser.SignedExpressionContext(self, localctx) self._ctx = localctx _prevctx = localctx - self.state = 105 + self.state = 112 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 = 113 self.match(ExprParser.T__2) - self.state = 107 + self.state = 114 self.expr(0) - self.state = 108 + self.state = 115 self.match(ExprParser.T__3) pass + self._ctx.stop = self._input.LT(-1) - self.state = 120 + self.state = 127 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,7,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 = 125 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.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 = 119 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 = 120 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 = 121 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 = 122 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 = 123 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 = 124 self.right_expr(0) pass - self.state = 122 + + self.state = 129 self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input, 7, self._ctx) + _alt = self._interp.adaptivePredict(self._input,7,self._ctx) except RecognitionException as re: localctx.exception = re @@ -2359,84 +1158,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 = 136 self._errHandler.sync(self) token = self._input.LA(1) if token in [3]: @@ -2444,59 +1249,51 @@ def right_expr(self, _p: int = 0): self._ctx = localctx _prevctx = localctx - self.state = 124 + self.state = 131 self.match(ExprParser.T__2) - self.state = 125 + self.state = 132 self.expr(0) - self.state = 126 + self.state = 133 self.match(ExprParser.T__3) pass elif token in [14, 16]: localctx = ExprParser.RightAtomContext(self, localctx) self._ctx = localctx _prevctx = localctx - self.state = 128 + self.state = 135 self.atom() pass else: raise NoViableAltException(self) self._ctx.stop = self._input.LT(-1) - self.state = 136 + self.state = 143 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,9,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 = 138 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 = 139 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 = 140 + self.right_expr(4) + self.state = 145 self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input, 9, self._ctx) + _alt = self._interp.adaptivePredict(self._input,9,self._ctx) except RecognitionException as re: localctx.exception = re @@ -2506,7 +1303,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 +1317,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..9126829d 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 +# Generated from /home/user/GemsPy/grammar/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#binaryFunction. + def visitBinaryFunction(self, ctx:ExprParser.BinaryFunctionContext): + 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#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..942f737c 100644 --- a/src/gems/expression/parsing/parse_expression.py +++ b/src/gems/expression/parsing/parse_expression.py @@ -22,6 +22,8 @@ ComparisonNode, PortFieldAggregatorNode, PortFieldNode, + maximum, + minimum, ) from gems.expression.parsing.antlr.ExprLexer import ExprLexer from gems.expression.parsing.antlr.ExprParser import ExprParser @@ -166,6 +168,16 @@ def visitFunction(self, ctx: ExprParser.FunctionContext) -> ExpressionNode: raise ValueError(f"Encountered invalid function name {function_name}") return fn(operand) + # Visit a parse tree produced by ExprParser#binaryFunction. + def visitBinaryFunction(self, ctx: ExprParser.BinaryFunctionContext) -> ExpressionNode: + function_name: str = ctx.IDENTIFIER().getText() # type: ignore + left: ExpressionNode = ctx.expr(0).accept(self) # type: ignore + right: ExpressionNode = ctx.expr(1).accept(self) # type: ignore + fn = _BINARY_FUNCTIONS.get(function_name, None) + if fn is None: + raise ValueError(f"Encountered invalid binary function name {function_name}") + return fn(left, right) + # Visit a parse tree produced by ExprParser#shift. def visitShift(self, ctx: ExprParser.ShiftContext) -> ExpressionNode: if ctx.shift_expr() is None: # type: ignore @@ -235,6 +247,13 @@ def visitRightAtom(self, ctx: ExprParser.RightAtomContext) -> ExpressionNode: _FUNCTIONS = { "expec": ExpressionNode.expec, + "floor": ExpressionNode.floor, + "ceil": ExpressionNode.ceil, +} + +_BINARY_FUNCTIONS = { + "max": maximum, + "min": minimum, } diff --git a/src/gems/expression/print.py b/src/gems/expression/print.py index 50308d87..36583f86 100644 --- a/src/gems/expression/print.py +++ b/src/gems/expression/print.py @@ -15,9 +15,13 @@ from gems.expression.expression import ( AllTimeSumNode, + CeilNode, ComponentParameterNode, ComponentVariableNode, ExpressionNode, + FloorNode, + MaxNode, + MinNode, PortFieldAggregatorNode, PortFieldNode, ProblemParameterNode, @@ -130,6 +134,18 @@ def port_field(self, node: PortFieldNode) -> str: def port_field_aggregator(self, node: PortFieldAggregatorNode) -> str: return f"({visit(node.operand, self)}.{node.aggregator})" + def floor(self, node: FloorNode) -> str: + return f"floor({visit(node.operand, self)})" + + def ceil(self, node: CeilNode) -> str: + return f"ceil({visit(node.operand, self)})" + + def maximum(self, node: MaxNode) -> str: + return f"max({visit(node.left, self)}, {visit(node.right, self)})" + + def minimum(self, node: MinNode) -> str: + return f"min({visit(node.left, self)}, {visit(node.right, self)})" + 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..b0179d59 100644 --- a/src/gems/expression/visitor.py +++ b/src/gems/expression/visitor.py @@ -20,12 +20,16 @@ from gems.expression.expression import ( AdditionNode, AllTimeSumNode, + CeilNode, ComparisonNode, ComponentParameterNode, ComponentVariableNode, DivisionNode, ExpressionNode, + FloorNode, LiteralNode, + MaxNode, + MinNode, MultiplicationNode, NegationNode, ParameterNode, @@ -128,6 +132,22 @@ def port_field(self, node: PortFieldNode) -> T: def port_field_aggregator(self, node: PortFieldAggregatorNode) -> T: ... + @abstractmethod + def floor(self, node: FloorNode) -> T: + ... + + @abstractmethod + def ceil(self, node: CeilNode) -> T: + ... + + @abstractmethod + def maximum(self, node: MaxNode) -> T: + ... + + @abstractmethod + def minimum(self, node: MinNode) -> T: + ... + def visit(root: ExpressionNode, visitor: ExpressionVisitor[T]) -> T: """ @@ -171,6 +191,14 @@ 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, FloorNode): + return visitor.floor(root) + elif isinstance(root, CeilNode): + return visitor.ceil(root) + elif isinstance(root, MaxNode): + return visitor.maximum(root) + elif isinstance(root, MinNode): + return visitor.minimum(root) raise ValueError(f"Unknown expression node type {root.__class__}") diff --git a/tests/unittests/expressions/parsing/test_expression_parsing.py b/tests/unittests/expressions/parsing/test_expression_parsing.py index d6558d7f..5998116f 100644 --- a/tests/unittests/expressions/parsing/test_expression_parsing.py +++ b/tests/unittests/expressions/parsing/test_expression_parsing.py @@ -15,7 +15,7 @@ from gems.expression import ExpressionNode, literal, param, print_expr, var from gems.expression.equality import expressions_equal -from gems.expression.expression import port_field +from gems.expression.expression import maximum, minimum, port_field from gems.expression.parsing.parse_expression import ( AntaresParseException, ModelIdentifiers, @@ -119,6 +119,42 @@ "expec(sum(cost * generation))", (param("cost") * var("generation")).time_sum().expec(), ), + ( + {}, + {"p"}, + "floor(p)", + param("p").floor(), + ), + ( + {}, + {"p"}, + "ceil(p)", + param("p").ceil(), + ), + ( + {}, + {"a", "b"}, + "max(a, b)", + maximum(param("a"), param("b")), + ), + ( + {}, + {"a", "b"}, + "min(a, b)", + minimum(param("a"), param("b")), + ), + ( + {}, + {"p", "q"}, + "ceil(p/q)", + (param("p") / param("q")).ceil(), + ), + ( + {}, + {"p", "q"}, + "max(0, ceil(p/q))", + maximum(literal(0), (param("p") / param("q")).ceil()), + ), ], ) def test_parsing_visitor( diff --git a/tests/unittests/expressions/visitor/test_evaluation.py b/tests/unittests/expressions/visitor/test_evaluation.py index 62e25183..756e4e5b 100644 --- a/tests/unittests/expressions/visitor/test_evaluation.py +++ b/tests/unittests/expressions/visitor/test_evaluation.py @@ -111,3 +111,16 @@ def test_sum_expressions() -> None: assert expressions_equal( sum_expressions([literal(1), var("x"), param("p")]), 1 + (var("x") + param("p")) ) + + +def test_floor_ceil_max_min() -> None: + from gems.expression.expression import maximum, minimum + + context = EvaluationContext(parameters={"p": 2.7, "q": 1.3}) + + assert visit(param("p").floor(), EvaluationVisitor(context)) == 2.0 + assert visit(param("p").ceil(), EvaluationVisitor(context)) == 3.0 + assert visit(maximum(param("p"), param("q")), EvaluationVisitor(context)) == pytest.approx(2.7) + assert visit(minimum(param("p"), param("q")), EvaluationVisitor(context)) == pytest.approx(1.3) + assert visit(maximum(literal(0), param("q")), EvaluationVisitor(context)) == pytest.approx(1.3) + assert visit(maximum(literal(0), -param("p")), EvaluationVisitor(context)) == 0.0 diff --git a/tests/unittests/expressions/visitor/test_printer.py b/tests/unittests/expressions/visitor/test_printer.py index a41250af..777f283d 100644 --- a/tests/unittests/expressions/visitor/test_printer.py +++ b/tests/unittests/expressions/visitor/test_printer.py @@ -19,3 +19,17 @@ def test_comparison() -> None: expr: ExpressionNode = (5 * x + 3) >= p - 2 assert visit(expr, PrinterVisitor()) == "((5.0 * x) + 3.0) >= (p - 2.0)" + + +def test_floor_ceil_max_min_printer() -> None: + from gems.expression.expression import maximum, minimum + + p = param("p") + q = param("q") + + assert visit(p.floor(), PrinterVisitor()) == "floor(p)" + assert visit(p.ceil(), PrinterVisitor()) == "ceil(p)" + assert visit(maximum(p, q), PrinterVisitor()) == "max(p, q)" + assert visit(minimum(p, q), PrinterVisitor()) == "min(p, q)" + assert visit((p / q).ceil(), PrinterVisitor()) == "ceil((p / q))" + assert visit(maximum(param("a"), (p / q).ceil()), PrinterVisitor()) == "max(a, ceil((p / q)))" From 8dcc2cfdfe21f929cf39bf7264429ae811789581 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 18 Mar 2026 21:51:02 +0000 Subject: [PATCH 02/12] Apply black formatting to all modified files https://claude.ai/code/session_01VUYEHTGsxtBYVEVm5c7ysC --- src/gems/expression/evaluate.py | 12 +- src/gems/expression/evaluate_parameters.py | 6 +- src/gems/expression/expression.py | 1 + src/gems/expression/indexing.py | 12 +- .../expression/parsing/antlr/ExprLexer.py | 1237 +++++++++- .../expression/parsing/antlr/ExprParser.py | 2114 ++++++++++++++--- .../expression/parsing/antlr/ExprVisitor.py | 88 +- .../expression/parsing/parse_expression.py | 8 +- src/gems/expression/visitor.py | 70 +- .../expressions/visitor/test_evaluation.py | 12 +- .../expressions/visitor/test_printer.py | 5 +- 11 files changed, 2981 insertions(+), 584 deletions(-) diff --git a/src/gems/expression/evaluate.py b/src/gems/expression/evaluate.py index 4d3c3770..1dd32bf6 100644 --- a/src/gems/expression/evaluate.py +++ b/src/gems/expression/evaluate.py @@ -51,20 +51,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) 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 ee639cb0..94405f0c 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 diff --git a/src/gems/expression/indexing.py b/src/gems/expression/indexing.py index 7d7f1f0b..030f4dad 100644 --- a/src/gems/expression/indexing.py +++ b/src/gems/expression/indexing.py @@ -47,24 +47,20 @@ 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/parsing/antlr/ExprLexer.py b/src/gems/expression/parsing/antlr/ExprLexer.py index 0b61c62c..793fc2c9 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,56 +11,1142 @@ 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, + 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, ] + 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 @@ -80,29 +1167,61 @@ class ExprLexer(Lexer): COMPARISON = 17 WS = 18 - channelNames = [ u"DEFAULT_TOKEN_CHANNEL", u"HIDDEN" ] + channelNames = ["DEFAULT_TOKEN_CHANNEL", "HIDDEN"] - modeNames = [ "DEFAULT_MODE" ] + modeNames = ["DEFAULT_MODE"] - literalNames = [ "", - "'.'", "'-'", "'('", "')'", "'/'", "'*'", "'+'", "'sum'", "'sum_connections'", - "'..'", "','", "'['", "']'", "'t'" ] + literalNames = [ + "", + "'.'", + "'-'", + "'('", + "')'", + "'/'", + "'*'", + "'+'", + "'sum'", + "'sum_connections'", + "'..'", + "','", + "'['", + "']'", + "'t'", + ] - symbolicNames = [ "", - "NUMBER", "TIME", "IDENTIFIER", "COMPARISON", "WS" ] + symbolicNames = ["", "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", "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", + ] 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 7fb04f5e..a09db512 100644 --- a/src/gems/expression/parsing/antlr/ExprParser.py +++ b/src/gems/expression/parsing/antlr/ExprParser.py @@ -3,83 +3,1380 @@ 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,147,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,1,2,1,2,3,2,86,8,2,1,2,1,2,1,2,1,2,1,2,1,2, - 1,2,1,2,1,2,5,2,97,8,2,10,2,12,2,100,9,2,1,3,1,3,3,3,104,8,3,1,4, - 1,4,3,4,108,8,4,1,5,1,5,1,5,1,5,1,5,1,5,1,5,1,5,3,5,118,8,5,1,5, - 1,5,1,5,1,5,1,5,1,5,5,5,126,8,5,10,5,12,5,129,9,5,1,6,1,6,1,6,1, - 6,1,6,1,6,3,6,137,8,6,1,6,1,6,1,6,5,6,142,8,6,10,6,12,6,145,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,161,0, - 14,1,0,0,0,2,18,1,0,0,0,4,85,1,0,0,0,6,103,1,0,0,0,8,105,1,0,0,0, - 10,117,1,0,0,0,12,136,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,86,3,6,3,0,23,86,3,0,0,0,24,25,5,2,0,0,25,86,3,4, - 2,14,26,27,5,3,0,0,27,28,3,4,2,0,28,29,5,4,0,0,29,86,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,86,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,86, - 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,86,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, - 86,1,0,0,0,54,55,5,16,0,0,55,56,5,3,0,0,56,57,3,4,2,0,57,58,5,11, - 0,0,58,59,3,4,2,0,59,60,5,4,0,0,60,86,1,0,0,0,61,62,5,16,0,0,62, - 63,5,12,0,0,63,64,3,8,4,0,64,65,5,13,0,0,65,86,1,0,0,0,66,67,5,16, - 0,0,67,68,5,12,0,0,68,69,3,4,2,0,69,70,5,13,0,0,70,86,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,8, - 4,0,76,77,5,13,0,0,77,86,1,0,0,0,78,79,5,3,0,0,79,80,3,4,2,0,80, - 81,5,4,0,0,81,82,5,12,0,0,82,83,3,4,2,0,83,84,5,13,0,0,84,86,1,0, - 0,0,85,21,1,0,0,0,85,23,1,0,0,0,85,24,1,0,0,0,85,26,1,0,0,0,85,30, - 1,0,0,0,85,35,1,0,0,0,85,40,1,0,0,0,85,49,1,0,0,0,85,54,1,0,0,0, - 85,61,1,0,0,0,85,66,1,0,0,0,85,71,1,0,0,0,85,78,1,0,0,0,86,98,1, - 0,0,0,87,88,10,12,0,0,88,89,7,0,0,0,89,97,3,4,2,13,90,91,10,11,0, - 0,91,92,7,1,0,0,92,97,3,4,2,12,93,94,10,10,0,0,94,95,5,17,0,0,95, - 97,3,4,2,11,96,87,1,0,0,0,96,90,1,0,0,0,96,93,1,0,0,0,97,100,1,0, - 0,0,98,96,1,0,0,0,98,99,1,0,0,0,99,5,1,0,0,0,100,98,1,0,0,0,101, - 104,5,14,0,0,102,104,5,16,0,0,103,101,1,0,0,0,103,102,1,0,0,0,104, - 7,1,0,0,0,105,107,5,15,0,0,106,108,3,10,5,0,107,106,1,0,0,0,107, - 108,1,0,0,0,108,9,1,0,0,0,109,110,6,5,-1,0,110,111,7,1,0,0,111,118, - 3,6,3,0,112,113,7,1,0,0,113,114,5,3,0,0,114,115,3,4,2,0,115,116, - 5,4,0,0,116,118,1,0,0,0,117,109,1,0,0,0,117,112,1,0,0,0,118,127, - 1,0,0,0,119,120,10,4,0,0,120,121,7,0,0,0,121,126,3,12,6,0,122,123, - 10,3,0,0,123,124,7,1,0,0,124,126,3,12,6,0,125,119,1,0,0,0,125,122, - 1,0,0,0,126,129,1,0,0,0,127,125,1,0,0,0,127,128,1,0,0,0,128,11,1, - 0,0,0,129,127,1,0,0,0,130,131,6,6,-1,0,131,132,5,3,0,0,132,133,3, - 4,2,0,133,134,5,4,0,0,134,137,1,0,0,0,135,137,3,6,3,0,136,130,1, - 0,0,0,136,135,1,0,0,0,137,143,1,0,0,0,138,139,10,3,0,0,139,140,7, - 0,0,0,140,142,3,12,6,4,141,138,1,0,0,0,142,145,1,0,0,0,143,141,1, - 0,0,0,143,144,1,0,0,0,144,13,1,0,0,0,145,143,1,0,0,0,10,85,96,98, - 103,107,117,125,127,136,143 + 4, + 1, + 18, + 147, + 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, + 1, + 2, + 1, + 2, + 3, + 2, + 86, + 8, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 5, + 2, + 97, + 8, + 2, + 10, + 2, + 12, + 2, + 100, + 9, + 2, + 1, + 3, + 1, + 3, + 3, + 3, + 104, + 8, + 3, + 1, + 4, + 1, + 4, + 3, + 4, + 108, + 8, + 4, + 1, + 5, + 1, + 5, + 1, + 5, + 1, + 5, + 1, + 5, + 1, + 5, + 1, + 5, + 1, + 5, + 3, + 5, + 118, + 8, + 5, + 1, + 5, + 1, + 5, + 1, + 5, + 1, + 5, + 1, + 5, + 1, + 5, + 5, + 5, + 126, + 8, + 5, + 10, + 5, + 12, + 5, + 129, + 9, + 5, + 1, + 6, + 1, + 6, + 1, + 6, + 1, + 6, + 1, + 6, + 1, + 6, + 3, + 6, + 137, + 8, + 6, + 1, + 6, + 1, + 6, + 1, + 6, + 5, + 6, + 142, + 8, + 6, + 10, + 6, + 12, + 6, + 145, + 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, + 161, + 0, + 14, + 1, + 0, + 0, + 0, + 2, + 18, + 1, + 0, + 0, + 0, + 4, + 85, + 1, + 0, + 0, + 0, + 6, + 103, + 1, + 0, + 0, + 0, + 8, + 105, + 1, + 0, + 0, + 0, + 10, + 117, + 1, + 0, + 0, + 0, + 12, + 136, + 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, + 86, + 3, + 6, + 3, + 0, + 23, + 86, + 3, + 0, + 0, + 0, + 24, + 25, + 5, + 2, + 0, + 0, + 25, + 86, + 3, + 4, + 2, + 14, + 26, + 27, + 5, + 3, + 0, + 0, + 27, + 28, + 3, + 4, + 2, + 0, + 28, + 29, + 5, + 4, + 0, + 0, + 29, + 86, + 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, + 86, + 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, + 86, + 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, + 86, + 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, + 86, + 1, + 0, + 0, + 0, + 54, + 55, + 5, + 16, + 0, + 0, + 55, + 56, + 5, + 3, + 0, + 0, + 56, + 57, + 3, + 4, + 2, + 0, + 57, + 58, + 5, + 11, + 0, + 0, + 58, + 59, + 3, + 4, + 2, + 0, + 59, + 60, + 5, + 4, + 0, + 0, + 60, + 86, + 1, + 0, + 0, + 0, + 61, + 62, + 5, + 16, + 0, + 0, + 62, + 63, + 5, + 12, + 0, + 0, + 63, + 64, + 3, + 8, + 4, + 0, + 64, + 65, + 5, + 13, + 0, + 0, + 65, + 86, + 1, + 0, + 0, + 0, + 66, + 67, + 5, + 16, + 0, + 0, + 67, + 68, + 5, + 12, + 0, + 0, + 68, + 69, + 3, + 4, + 2, + 0, + 69, + 70, + 5, + 13, + 0, + 0, + 70, + 86, + 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, + 8, + 4, + 0, + 76, + 77, + 5, + 13, + 0, + 0, + 77, + 86, + 1, + 0, + 0, + 0, + 78, + 79, + 5, + 3, + 0, + 0, + 79, + 80, + 3, + 4, + 2, + 0, + 80, + 81, + 5, + 4, + 0, + 0, + 81, + 82, + 5, + 12, + 0, + 0, + 82, + 83, + 3, + 4, + 2, + 0, + 83, + 84, + 5, + 13, + 0, + 0, + 84, + 86, + 1, + 0, + 0, + 0, + 85, + 21, + 1, + 0, + 0, + 0, + 85, + 23, + 1, + 0, + 0, + 0, + 85, + 24, + 1, + 0, + 0, + 0, + 85, + 26, + 1, + 0, + 0, + 0, + 85, + 30, + 1, + 0, + 0, + 0, + 85, + 35, + 1, + 0, + 0, + 0, + 85, + 40, + 1, + 0, + 0, + 0, + 85, + 49, + 1, + 0, + 0, + 0, + 85, + 54, + 1, + 0, + 0, + 0, + 85, + 61, + 1, + 0, + 0, + 0, + 85, + 66, + 1, + 0, + 0, + 0, + 85, + 71, + 1, + 0, + 0, + 0, + 85, + 78, + 1, + 0, + 0, + 0, + 86, + 98, + 1, + 0, + 0, + 0, + 87, + 88, + 10, + 12, + 0, + 0, + 88, + 89, + 7, + 0, + 0, + 0, + 89, + 97, + 3, + 4, + 2, + 13, + 90, + 91, + 10, + 11, + 0, + 0, + 91, + 92, + 7, + 1, + 0, + 0, + 92, + 97, + 3, + 4, + 2, + 12, + 93, + 94, + 10, + 10, + 0, + 0, + 94, + 95, + 5, + 17, + 0, + 0, + 95, + 97, + 3, + 4, + 2, + 11, + 96, + 87, + 1, + 0, + 0, + 0, + 96, + 90, + 1, + 0, + 0, + 0, + 96, + 93, + 1, + 0, + 0, + 0, + 97, + 100, + 1, + 0, + 0, + 0, + 98, + 96, + 1, + 0, + 0, + 0, + 98, + 99, + 1, + 0, + 0, + 0, + 99, + 5, + 1, + 0, + 0, + 0, + 100, + 98, + 1, + 0, + 0, + 0, + 101, + 104, + 5, + 14, + 0, + 0, + 102, + 104, + 5, + 16, + 0, + 0, + 103, + 101, + 1, + 0, + 0, + 0, + 103, + 102, + 1, + 0, + 0, + 0, + 104, + 7, + 1, + 0, + 0, + 0, + 105, + 107, + 5, + 15, + 0, + 0, + 106, + 108, + 3, + 10, + 5, + 0, + 107, + 106, + 1, + 0, + 0, + 0, + 107, + 108, + 1, + 0, + 0, + 0, + 108, + 9, + 1, + 0, + 0, + 0, + 109, + 110, + 6, + 5, + -1, + 0, + 110, + 111, + 7, + 1, + 0, + 0, + 111, + 118, + 3, + 6, + 3, + 0, + 112, + 113, + 7, + 1, + 0, + 0, + 113, + 114, + 5, + 3, + 0, + 0, + 114, + 115, + 3, + 4, + 2, + 0, + 115, + 116, + 5, + 4, + 0, + 0, + 116, + 118, + 1, + 0, + 0, + 0, + 117, + 109, + 1, + 0, + 0, + 0, + 117, + 112, + 1, + 0, + 0, + 0, + 118, + 127, + 1, + 0, + 0, + 0, + 119, + 120, + 10, + 4, + 0, + 0, + 120, + 121, + 7, + 0, + 0, + 0, + 121, + 126, + 3, + 12, + 6, + 0, + 122, + 123, + 10, + 3, + 0, + 0, + 123, + 124, + 7, + 1, + 0, + 0, + 124, + 126, + 3, + 12, + 6, + 0, + 125, + 119, + 1, + 0, + 0, + 0, + 125, + 122, + 1, + 0, + 0, + 0, + 126, + 129, + 1, + 0, + 0, + 0, + 127, + 125, + 1, + 0, + 0, + 0, + 127, + 128, + 1, + 0, + 0, + 0, + 128, + 11, + 1, + 0, + 0, + 0, + 129, + 127, + 1, + 0, + 0, + 0, + 130, + 131, + 6, + 6, + -1, + 0, + 131, + 132, + 5, + 3, + 0, + 0, + 132, + 133, + 3, + 4, + 2, + 0, + 133, + 134, + 5, + 4, + 0, + 0, + 134, + 137, + 1, + 0, + 0, + 0, + 135, + 137, + 3, + 6, + 3, + 0, + 136, + 130, + 1, + 0, + 0, + 0, + 136, + 135, + 1, + 0, + 0, + 0, + 137, + 143, + 1, + 0, + 0, + 0, + 138, + 139, + 10, + 3, + 0, + 0, + 139, + 140, + 7, + 0, + 0, + 0, + 140, + 142, + 3, + 12, + 6, + 4, + 141, + 138, + 1, + 0, + 0, + 0, + 142, + 145, + 1, + 0, + 0, + 0, + 143, + 141, + 1, + 0, + 0, + 0, + 143, + 144, + 1, + 0, + 0, + 0, + 144, + 13, + 1, + 0, + 0, + 0, + 145, + 143, + 1, + 0, + 0, + 0, + 10, + 85, + 96, + 98, + 103, + 107, + 117, + 125, + 127, + 136, + 143, ] -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'", + "'..'", + "','", + "'['", + "']'", + "", + "'t'", + ] - symbolicNames = [ "", "", "", "", - "", "", "", "", - "", "", "", "", - "", "", "NUMBER", "TIME", "IDENTIFIER", - "COMPARISON", "WS" ] + symbolicNames = [ + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "NUMBER", + "TIME", + "IDENTIFIER", + "COMPARISON", + "WS", + ] RULE_portFieldExpr = 0 RULE_fullexpr = 1 @@ -89,46 +1386,54 @@ 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 + TIME = 15 + IDENTIFIER = 16 + COMPARISON = 17 + WS = 18 + + 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: @@ -137,15 +1442,12 @@ 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) @@ -166,17 +1468,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) @@ -184,15 +1486,12 @@ 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) @@ -211,347 +1510,349 @@ 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 BinaryFunctionContext(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, 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, "visitBinaryFunction" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitBinaryFunction"): return visitor.visitBinaryFunction(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 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 = 85 self._errHandler.sync(self) - la_ = self._interp.adaptivePredict(self._input,0,self._ctx) + la_ = self._interp.adaptivePredict(self._input, 0, self._ctx) if la_ == 1: localctx = ExprParser.UnsignedAtomContext(self, localctx) self._ctx = localctx @@ -737,30 +2038,36 @@ def expr(self, _p:int=0): self.match(ExprParser.T__12) pass - self._ctx.stop = self._input.LT(-1) self.state = 98 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, 2, 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 = 96 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.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 = 87 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 = 88 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) @@ -770,16 +2077,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 = 90 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 = 91 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) @@ -789,22 +2103,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 = 93 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 = 94 self.match(ExprParser.COMPARISON) self.state = 95 self.expr(11) pass - self.state = 100 self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input,2,self._ctx) + _alt = self._interp.adaptivePredict(self._input, 2, self._ctx) except RecognitionException as re: localctx.exception = re @@ -814,57 +2134,55 @@ 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) @@ -896,11 +2214,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 @@ -908,26 +2227,22 @@ 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 = 105 @@ -935,11 +2250,10 @@ def shift(self): self.state = 107 self._errHandler.sync(self) _la = self._input.LA(1) - if _la==2 or _la==7: + if _la == 2 or _la == 7: self.state = 106 self.shift_expr(0) - except RecognitionException as re: localctx.exception = re self._errHandler.reportError(self, re) @@ -948,115 +2262,112 @@ 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 = 117 self._errHandler.sync(self) - la_ = self._interp.adaptivePredict(self._input,5,self._ctx) + la_ = self._interp.adaptivePredict(self._input, 5, self._ctx) if la_ == 1: localctx = ExprParser.SignedAtomContext(self, localctx) self._ctx = localctx @@ -1065,7 +2376,7 @@ def shift_expr(self, _p:int=0): self.state = 110 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) @@ -1081,7 +2392,7 @@ def shift_expr(self, _p:int=0): self.state = 112 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) @@ -1094,30 +2405,39 @@ def shift_expr(self, _p:int=0): self.match(ExprParser.T__3) pass - self._ctx.stop = self._input.LT(-1) self.state = 127 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, 7, 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 = 125 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.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 = 119 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 = 120 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) @@ -1127,16 +2447,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 = 122 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 = 123 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) @@ -1145,10 +2475,9 @@ def shift_expr(self, _p:int=0): self.right_expr(0) pass - self.state = 129 self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input,7,self._ctx) + _alt = self._interp.adaptivePredict(self._input, 7, self._ctx) except RecognitionException as re: localctx.exception = re @@ -1158,87 +2487,84 @@ 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 = 136 @@ -1269,31 +2595,39 @@ def right_expr(self, _p:int=0): self._ctx.stop = self._input.LT(-1) self.state = 143 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, 9, 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 = 138 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 = 139 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 = 140 - self.right_expr(4) + self.right_expr(4) self.state = 145 self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input,9,self._ctx) + _alt = self._interp.adaptivePredict(self._input, 9, self._ctx) except RecognitionException as re: localctx.exception = re @@ -1303,9 +2637,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 @@ -1317,33 +2649,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 9126829d..871f42d9 100644 --- a/src/gems/expression/parsing/antlr/ExprVisitor.py +++ b/src/gems/expression/parsing/antlr/ExprVisitor.py @@ -1,5 +1,6 @@ # Generated from /home/user/GemsPy/grammar/Expr.g4 by ANTLR 4.13.2 from antlr4 import * + if "." in __name__: from .ExprParser import ExprParser else: @@ -7,147 +8,120 @@ # 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#binaryFunction. - def visitBinaryFunction(self, ctx:ExprParser.BinaryFunctionContext): + def visitBinaryFunction(self, ctx: ExprParser.BinaryFunctionContext): 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#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 942f737c..6d4243f4 100644 --- a/src/gems/expression/parsing/parse_expression.py +++ b/src/gems/expression/parsing/parse_expression.py @@ -169,13 +169,17 @@ def visitFunction(self, ctx: ExprParser.FunctionContext) -> ExpressionNode: return fn(operand) # Visit a parse tree produced by ExprParser#binaryFunction. - def visitBinaryFunction(self, ctx: ExprParser.BinaryFunctionContext) -> ExpressionNode: + def visitBinaryFunction( + self, ctx: ExprParser.BinaryFunctionContext + ) -> ExpressionNode: function_name: str = ctx.IDENTIFIER().getText() # type: ignore left: ExpressionNode = ctx.expr(0).accept(self) # type: ignore right: ExpressionNode = ctx.expr(1).accept(self) # type: ignore fn = _BINARY_FUNCTIONS.get(function_name, None) if fn is None: - raise ValueError(f"Encountered invalid binary function name {function_name}") + raise ValueError( + f"Encountered invalid binary function name {function_name}" + ) return fn(left, right) # Visit a parse tree produced by ExprParser#shift. diff --git a/src/gems/expression/visitor.py b/src/gems/expression/visitor.py index b0179d59..c4e1da58 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 @@ -57,96 +58,73 @@ 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 floor(self, node: FloorNode) -> T: - ... + def floor(self, node: FloorNode) -> T: ... @abstractmethod - def ceil(self, node: CeilNode) -> T: - ... + def ceil(self, node: CeilNode) -> T: ... @abstractmethod - def maximum(self, node: MaxNode) -> T: - ... + def maximum(self, node: MaxNode) -> T: ... @abstractmethod - def minimum(self, node: MinNode) -> T: - ... + def minimum(self, node: MinNode) -> T: ... def visit(root: ExpressionNode, visitor: ExpressionVisitor[T]) -> T: diff --git a/tests/unittests/expressions/visitor/test_evaluation.py b/tests/unittests/expressions/visitor/test_evaluation.py index 756e4e5b..5566619c 100644 --- a/tests/unittests/expressions/visitor/test_evaluation.py +++ b/tests/unittests/expressions/visitor/test_evaluation.py @@ -120,7 +120,13 @@ def test_floor_ceil_max_min() -> None: assert visit(param("p").floor(), EvaluationVisitor(context)) == 2.0 assert visit(param("p").ceil(), EvaluationVisitor(context)) == 3.0 - assert visit(maximum(param("p"), param("q")), EvaluationVisitor(context)) == pytest.approx(2.7) - assert visit(minimum(param("p"), param("q")), EvaluationVisitor(context)) == pytest.approx(1.3) - assert visit(maximum(literal(0), param("q")), EvaluationVisitor(context)) == pytest.approx(1.3) + assert visit( + maximum(param("p"), param("q")), EvaluationVisitor(context) + ) == pytest.approx(2.7) + assert visit( + minimum(param("p"), param("q")), EvaluationVisitor(context) + ) == pytest.approx(1.3) + assert visit( + maximum(literal(0), param("q")), EvaluationVisitor(context) + ) == pytest.approx(1.3) assert visit(maximum(literal(0), -param("p")), EvaluationVisitor(context)) == 0.0 diff --git a/tests/unittests/expressions/visitor/test_printer.py b/tests/unittests/expressions/visitor/test_printer.py index 777f283d..f9cc82b1 100644 --- a/tests/unittests/expressions/visitor/test_printer.py +++ b/tests/unittests/expressions/visitor/test_printer.py @@ -32,4 +32,7 @@ def test_floor_ceil_max_min_printer() -> None: assert visit(maximum(p, q), PrinterVisitor()) == "max(p, q)" assert visit(minimum(p, q), PrinterVisitor()) == "min(p, q)" assert visit((p / q).ceil(), PrinterVisitor()) == "ceil((p / q))" - assert visit(maximum(param("a"), (p / q).ceil()), PrinterVisitor()) == "max(a, ceil((p / q)))" + assert ( + visit(maximum(param("a"), (p / q).ceil()), PrinterVisitor()) + == "max(a, ceil((p / q)))" + ) From ed8251d7e4b02c4c6aa4449a735330142c077c35 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 18 Mar 2026 21:55:31 +0000 Subject: [PATCH 03/12] Apply black formatting to pre-existing unformatted files https://claude.ai/code/session_01VUYEHTGsxtBYVEVm5c7ysC --- src/gems/model/common.py | 1 + src/gems/model/model.py | 15 +++++++----- src/gems/simulation/linear_expression.py | 2 +- src/gems/simulation/optimization.py | 8 +++---- src/gems/simulation/output_values.py | 1 + src/gems/simulation/strategy.py | 9 +++---- src/gems/study/network.py | 1 + src/gems/utils.py | 1 + tests/e2e/functional/libs/standard.py | 1 + .../test_libs_python_system_python.py | 1 + tests/e2e/integration/libs/standard.py | 1 + .../poc-various-models/libs/standard.py | 1 + .../test_electrolyzer_n_inputs.py | 24 +++++++++---------- .../test_electrolyzer_n_inputs_yaml.py | 24 +++++++++---------- .../poc-various-models/test_quota_co2.py | 6 ++--- .../poc-various-models/test_quota_co2_yaml.py | 6 ++--- .../test_objective_contribution.py | 3 ++- tests/unittests/system/libs/standard.py | 1 + 18 files changed, 57 insertions(+), 49 deletions(-) diff --git a/src/gems/model/common.py b/src/gems/model/common.py index e295c1aa..b4342735 100644 --- a/src/gems/model/common.py +++ b/src/gems/model/common.py @@ -13,6 +13,7 @@ """ Module for common classes used in models. """ + from enum import Enum diff --git a/src/gems/model/model.py b/src/gems/model/model.py index a49e934d..bd5c8b5c 100644 --- a/src/gems/model/model.py +++ b/src/gems/model/model.py @@ -15,6 +15,7 @@ A model allows to define the behaviour for components, by defining parameters, variables, and equations. """ + import itertools from dataclasses import dataclass, field, replace from typing import Any, Dict, Iterable, Optional @@ -179,9 +180,9 @@ def model( return Model( id=id, constraints={c.name: c for c in constraints} if constraints else {}, - binding_constraints={c.name: c for c in binding_constraints} - if binding_constraints - else {}, + binding_constraints=( + {c.name: c for c in binding_constraints} if binding_constraints else {} + ), parameters={p.name: p for p in parameters} if parameters else {}, variables={v.name: v for v in variables} if variables else {}, objective_contributions=objective_contributions, @@ -189,8 +190,10 @@ def model( objective_operational_contribution=objective_operational_contribution, inter_block_dyn=inter_block_dyn, ports=existing_port_names, - port_fields_definitions={d.port_field: d for d in port_fields_definitions} - if port_fields_definitions - else {}, + port_fields_definitions=( + {d.port_field: d for d in port_fields_definitions} + if port_fields_definitions + else {} + ), extra_outputs=extra_outputs, ) diff --git a/src/gems/simulation/linear_expression.py b/src/gems/simulation/linear_expression.py index 1f882e64..a0584c07 100644 --- a/src/gems/simulation/linear_expression.py +++ b/src/gems/simulation/linear_expression.py @@ -14,6 +14,7 @@ Specific modelling for "instantiated" linear expressions, with only variables and literal coefficients. """ + import dataclasses from dataclasses import dataclass from typing import Callable, Dict, List, Optional, TypeVar, Union @@ -118,7 +119,6 @@ def apply(self, other: "TimeExpansion") -> "TimeExpansion": @dataclass(frozen=True) class TermKey: - """ Utility class to provide key for a term that contains all term information except coefficient """ diff --git a/src/gems/simulation/optimization.py b/src/gems/simulation/optimization.py index 1d43b1de..2a8786fc 100644 --- a/src/gems/simulation/optimization.py +++ b/src/gems/simulation/optimization.py @@ -889,11 +889,9 @@ def fusion_problems( root_var = root_vars[var.name()] root_var.SetLb(var.lb()) root_var.SetUb(var.ub()) - root_master.context._solver_variables[ - var.name() - ].is_in_objective = context._solver_variables[ - var.name() - ].is_in_objective + root_master.context._solver_variables[var.name()].is_in_objective = ( + context._solver_variables[var.name()].is_in_objective + ) for cstr in master.solver.constraints(): coeff = cstr.GetCoefficient(var) diff --git a/src/gems/simulation/output_values.py b/src/gems/simulation/output_values.py index a0bbc5f7..e8d4eed7 100644 --- a/src/gems/simulation/output_values.py +++ b/src/gems/simulation/output_values.py @@ -7,6 +7,7 @@ """ Utility classes to obtain solver results. """ + import math from dataclasses import dataclass, field from typing import Any, Dict, Mapping, Optional, Set, TypeVar diff --git a/src/gems/simulation/strategy.py b/src/gems/simulation/strategy.py index 467dd32a..46b2096d 100644 --- a/src/gems/simulation/strategy.py +++ b/src/gems/simulation/strategy.py @@ -37,14 +37,12 @@ def get_constraints(self, model: Model) -> Generator[Constraint, None, None]: yield constraint @abstractmethod - def _keep_from_context(self, context: ProblemContext) -> bool: - ... + def _keep_from_context(self, context: ProblemContext) -> bool: ... @abstractmethod def get_objectives( self, model: Model - ) -> Generator[Optional[ExpressionNode], None, None]: - ... + ) -> Generator[Optional[ExpressionNode], None, None]: ... class MergedProblemStrategy(ModelSelectionStrategy): @@ -96,8 +94,7 @@ def __call__(self, expr: ExpressionNode) -> ExpressionNode: return self._modify_expression(expr) @abstractmethod - def _modify_expression(self, expr: ExpressionNode) -> ExpressionNode: - ... + def _modify_expression(self, expr: ExpressionNode) -> ExpressionNode: ... class UniformRisk(RiskManagementStrategy): diff --git a/src/gems/study/network.py b/src/gems/study/network.py index 0ac27ccc..53a53687 100644 --- a/src/gems/study/network.py +++ b/src/gems/study/network.py @@ -14,6 +14,7 @@ The network module defines the data model for an instance of network, including nodes, links, and components (model instantations). """ + import itertools from dataclasses import dataclass, field, replace from typing import Any, Dict, Iterable, List, cast diff --git a/src/gems/utils.py b/src/gems/utils.py index 23c1ebaa..7964fd24 100644 --- a/src/gems/utils.py +++ b/src/gems/utils.py @@ -13,6 +13,7 @@ """ Module for technical utilities. """ + import json import pathlib from typing import Any, Callable, Dict, Optional, TypeVar diff --git a/tests/e2e/functional/libs/standard.py b/tests/e2e/functional/libs/standard.py index bd30e958..a8f6cd7f 100644 --- a/tests/e2e/functional/libs/standard.py +++ b/tests/e2e/functional/libs/standard.py @@ -13,6 +13,7 @@ """ The standard module contains the definition of standard models. """ + from gems.expression import literal, param, var from gems.expression.expression import port_field from gems.expression.indexing_structure import IndexingStructure diff --git a/tests/e2e/functional/test_libs_python_system_python.py b/tests/e2e/functional/test_libs_python_system_python.py index aea1abff..01a7bebe 100644 --- a/tests/e2e/functional/test_libs_python_system_python.py +++ b/tests/e2e/functional/test_libs_python_system_python.py @@ -33,6 +33,7 @@ - Description: Short-term storage behavior over different horizons and efficiencies. - Names: `test_short_test_horizon_10`, `test_short_test_horizon_5`. """ + import pandas as pd import pytest diff --git a/tests/e2e/integration/libs/standard.py b/tests/e2e/integration/libs/standard.py index bd30e958..a8f6cd7f 100644 --- a/tests/e2e/integration/libs/standard.py +++ b/tests/e2e/integration/libs/standard.py @@ -13,6 +13,7 @@ """ The standard module contains the definition of standard models. """ + from gems.expression import literal, param, var from gems.expression.expression import port_field from gems.expression.indexing_structure import IndexingStructure diff --git a/tests/e2e/models/poc-various-models/libs/standard.py b/tests/e2e/models/poc-various-models/libs/standard.py index bd30e958..a8f6cd7f 100644 --- a/tests/e2e/models/poc-various-models/libs/standard.py +++ b/tests/e2e/models/poc-various-models/libs/standard.py @@ -13,6 +13,7 @@ """ The standard module contains the definition of standard models. """ + from gems.expression import literal, param, var from gems.expression.expression import port_field from gems.expression.indexing_structure import IndexingStructure diff --git a/tests/e2e/models/poc-various-models/test_electrolyzer_n_inputs.py b/tests/e2e/models/poc-various-models/test_electrolyzer_n_inputs.py index 0d8d7505..1663ff40 100644 --- a/tests/e2e/models/poc-various-models/test_electrolyzer_n_inputs.py +++ b/tests/e2e/models/poc-various-models/test_electrolyzer_n_inputs.py @@ -129,9 +129,9 @@ def test_electrolyzer_n_inputs_1() -> None: print(ep2_gen) print(gp_gen) - assert math.isclose(ep1_gen, 70) # type:ignore - assert math.isclose(ep2_gen, 42) # type:ignore - assert math.isclose(gp_gen, 30) # type:ignore + assert math.isclose(ep1_gen, 70) # type: ignore + assert math.isclose(ep2_gen, 42) # type: ignore + assert math.isclose(gp_gen, 30) # type: ignore assert status == problem.solver.OPTIMAL assert math.isclose(problem.solver.Objective().Value(), 1990) @@ -218,9 +218,9 @@ def test_electrolyzer_n_inputs_2() -> None: print(ep2_gen) print(gp_gen) - assert math.isclose(ep1_gen, 70) # type:ignore - assert math.isclose(ep2_gen, 42) # type:ignore - assert math.isclose(gp_gen, 30) # type:ignore + assert math.isclose(ep1_gen, 70) # type: ignore + assert math.isclose(ep2_gen, 42) # type: ignore + assert math.isclose(gp_gen, 30) # type: ignore assert status == problem.solver.OPTIMAL assert math.isclose(problem.solver.Objective().Value(), 1990) @@ -313,9 +313,9 @@ def test_electrolyzer_n_inputs_3() -> None: ep2_gen = output.component("ep2").var("generation").value gp_gen = output.component("gp").var("generation").value - assert math.isclose(ep1_gen, 70) # type:ignore - assert math.isclose(ep2_gen, 30) # type:ignore - assert math.isclose(gp_gen, 30) # type:ignore + assert math.isclose(ep1_gen, 70) # type: ignore + assert math.isclose(ep2_gen, 30) # type: ignore + assert math.isclose(gp_gen, 30) # type: ignore assert status == problem.solver.OPTIMAL assert math.isclose(problem.solver.Objective().Value(), 1750) @@ -401,9 +401,9 @@ def test_electrolyzer_n_inputs_4() -> None: ep2_gen = output.component("ep2").var("generation").value gp_gen = output.component("gp").var("generation").value - assert math.isclose(ep1_gen, 70) # type:ignore - assert math.isclose(ep2_gen, 30) # type:ignore - assert math.isclose(gp_gen, 30) # type:ignore + assert math.isclose(ep1_gen, 70) # type: ignore + assert math.isclose(ep2_gen, 30) # type: ignore + assert math.isclose(gp_gen, 30) # type: ignore assert status == problem.solver.OPTIMAL assert math.isclose(problem.solver.Objective().Value(), 1750) diff --git a/tests/e2e/models/poc-various-models/test_electrolyzer_n_inputs_yaml.py b/tests/e2e/models/poc-various-models/test_electrolyzer_n_inputs_yaml.py index 2e007571..78bfc5a0 100644 --- a/tests/e2e/models/poc-various-models/test_electrolyzer_n_inputs_yaml.py +++ b/tests/e2e/models/poc-various-models/test_electrolyzer_n_inputs_yaml.py @@ -135,9 +135,9 @@ def test_electrolyzer_n_inputs_1( print(ep2_gen) print(gp_gen) - assert math.isclose(ep1_gen, 70) # type:ignore - assert math.isclose(ep2_gen, 42) # type:ignore - assert math.isclose(gp_gen, 30) # type:ignore + assert math.isclose(ep1_gen, 70) # type: ignore + assert math.isclose(ep2_gen, 42) # type: ignore + assert math.isclose(gp_gen, 30) # type: ignore assert status == problem.solver.OPTIMAL assert math.isclose(problem.solver.Objective().Value(), 1990) @@ -235,9 +235,9 @@ def test_electrolyzer_n_inputs_2( print(ep2_gen) print(gp_gen) - assert math.isclose(ep1_gen, 70) # type:ignore - assert math.isclose(ep2_gen, 42) # type:ignore - assert math.isclose(gp_gen, 30) # type:ignore + assert math.isclose(ep1_gen, 70) # type: ignore + assert math.isclose(ep2_gen, 42) # type: ignore + assert math.isclose(gp_gen, 30) # type: ignore assert status == problem.solver.OPTIMAL assert math.isclose(problem.solver.Objective().Value(), 1990) @@ -342,9 +342,9 @@ def test_electrolyzer_n_inputs_3( ep2_gen = output.component("ep2").var("generation").value gp_gen = output.component("gp").var("generation").value - assert math.isclose(ep1_gen, 70) # type:ignore - assert math.isclose(ep2_gen, 30) # type:ignore - assert math.isclose(gp_gen, 30) # type:ignore + assert math.isclose(ep1_gen, 70) # type: ignore + assert math.isclose(ep2_gen, 30) # type: ignore + assert math.isclose(gp_gen, 30) # type: ignore assert status == problem.solver.OPTIMAL assert math.isclose(problem.solver.Objective().Value(), 1750) @@ -443,9 +443,9 @@ def test_electrolyzer_n_inputs_4( ep2_gen = output.component("ep2").var("generation").value gp_gen = output.component("gp").var("generation").value - assert math.isclose(ep1_gen, 70) # type:ignore - assert math.isclose(ep2_gen, 30) # type:ignore - assert math.isclose(gp_gen, 30) # type:ignore + assert math.isclose(ep1_gen, 70) # type: ignore + assert math.isclose(ep2_gen, 30) # type: ignore + assert math.isclose(gp_gen, 30) # type: ignore assert status == problem.solver.OPTIMAL assert math.isclose(problem.solver.Objective().Value(), 1750) diff --git a/tests/e2e/models/poc-various-models/test_quota_co2.py b/tests/e2e/models/poc-various-models/test_quota_co2.py index 2bd504ee..ee3bc445 100644 --- a/tests/e2e/models/poc-various-models/test_quota_co2.py +++ b/tests/e2e/models/poc-various-models/test_quota_co2.py @@ -85,6 +85,6 @@ def test_quota_co2() -> None: assert status == problem.solver.OPTIMAL assert math.isclose(problem.solver.Objective().Value(), 5500) - assert math.isclose(oil1_p, 50) # type:ignore - assert math.isclose(coal1_p, 50) # type:ignore - assert math.isclose(l12_flow, -50) # type:ignore + assert math.isclose(oil1_p, 50) # type: ignore + assert math.isclose(coal1_p, 50) # type: ignore + assert math.isclose(l12_flow, -50) # type: ignore diff --git a/tests/e2e/models/poc-various-models/test_quota_co2_yaml.py b/tests/e2e/models/poc-various-models/test_quota_co2_yaml.py index e0163cc7..812a75cc 100644 --- a/tests/e2e/models/poc-various-models/test_quota_co2_yaml.py +++ b/tests/e2e/models/poc-various-models/test_quota_co2_yaml.py @@ -91,6 +91,6 @@ def test_quota_co2( assert status == problem.solver.OPTIMAL assert math.isclose(problem.solver.Objective().Value(), 5500) - assert math.isclose(oil1_p, 50) # type:ignore - assert math.isclose(coal1_p, 50) # type:ignore - assert math.isclose(l12_flow, -50) # type:ignore + assert math.isclose(oil1_p, 50) # type: ignore + assert math.isclose(coal1_p, 50) # type: ignore + assert math.isclose(l12_flow, -50) # type: ignore diff --git a/tests/unittests/lib_parsing/test_objective_contribution.py b/tests/unittests/lib_parsing/test_objective_contribution.py index 49908930..18b48991 100644 --- a/tests/unittests/lib_parsing/test_objective_contribution.py +++ b/tests/unittests/lib_parsing/test_objective_contribution.py @@ -2,6 +2,7 @@ # SPDX-License-Identifier: MPL-2.0 """Tests for objective creation logic and coefficient accumulation.""" + from typing import Any, Dict, Optional from unittest.mock import Mock, patch @@ -97,7 +98,7 @@ def name(self) -> str: def _setup_mock_optimization_environment( - linear_expressions: Dict[Any, LinearExpression] + linear_expressions: Dict[Any, LinearExpression], ) -> Any: """Sets up a mock context and problem with real OR-Tools solver objects.""" diff --git a/tests/unittests/system/libs/standard.py b/tests/unittests/system/libs/standard.py index bd30e958..a8f6cd7f 100644 --- a/tests/unittests/system/libs/standard.py +++ b/tests/unittests/system/libs/standard.py @@ -13,6 +13,7 @@ """ The standard module contains the definition of standard models. """ + from gems.expression import literal, param, var from gems.expression.expression import port_field from gems.expression.indexing_structure import IndexingStructure From 95b09cc8eade972261667e792b9c8dbc44f3ea33 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 18 Mar 2026 22:02:35 +0000 Subject: [PATCH 04/12] Fix missing visitor methods in _PortFieldExpressionChecker and LinearExpressionBuilder Add ceil, floor, maximum, minimum implementations to all ExpressionVisitor subclasses that were missing them after the new math operators were added. https://claude.ai/code/session_01VUYEHTGsxtBYVEVm5c7ysC --- src/gems/model/port.py | 16 ++++++++++++++++ src/gems/simulation/linearize.py | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/gems/model/port.py b/src/gems/model/port.py index cb07319b..9eaaed09 100644 --- a/src/gems/model/port.py +++ b/src/gems/model/port.py @@ -28,8 +28,12 @@ from gems.expression.expression import ( AllTimeSumNode, BinaryOperatorNode, + CeilNode, ComponentParameterNode, ComponentVariableNode, + FloorNode, + MaxNode, + MinNode, PortFieldAggregatorNode, PortFieldNode, ProblemParameterNode, @@ -165,6 +169,18 @@ def scenario_operator(self, node: ScenarioOperatorNode) -> None: def port_field(self, node: PortFieldNode) -> None: raise ValueError("Port definition cannot reference another port field.") + def floor(self, node: FloorNode) -> None: + visit(node.operand, self) + + def ceil(self, node: CeilNode) -> None: + visit(node.operand, self) + + def maximum(self, node: MaxNode) -> None: + self._visit_binary_op(node) + + def minimum(self, node: MinNode) -> None: + self._visit_binary_op(node) + def port_field_aggregator(self, node: PortFieldAggregatorNode) -> None: raise ValueError("Port definition cannot contain port field aggregation.") diff --git a/src/gems/simulation/linearize.py b/src/gems/simulation/linearize.py index 7e8dbf15..0d3c9e71 100644 --- a/src/gems/simulation/linearize.py +++ b/src/gems/simulation/linearize.py @@ -23,12 +23,16 @@ ) from gems.expression.expression import ( AllTimeSumNode, + CeilNode, ComparisonNode, ComponentParameterNode, ComponentVariableNode, CurrentScenarioIndex, ExpressionNode, + FloorNode, LiteralNode, + MaxNode, + MinNode, NoScenarioIndex, NoTimeIndex, OneScenarioIndex, @@ -200,6 +204,18 @@ def _get_scenario(self, scenario_index: ScenarioIndex) -> Optional[int]: def literal(self, node: LiteralNode) -> LinearExpressionData: return LinearExpressionData([], node.value) + def floor(self, node: FloorNode) -> LinearExpressionData: + raise ValueError("Linear expression cannot contain a floor operator.") + + def ceil(self, node: CeilNode) -> LinearExpressionData: + raise ValueError("Linear expression cannot contain a ceil operator.") + + def maximum(self, node: MaxNode) -> LinearExpressionData: + raise ValueError("Linear expression cannot contain a max operator.") + + def minimum(self, node: MinNode) -> LinearExpressionData: + raise ValueError("Linear expression cannot contain a min operator.") + def comparison(self, node: ComparisonNode) -> LinearExpressionData: raise ValueError("Linear expression cannot contain a comparison operator.") From 92070f6a1b6471d004de607c26781b91af0c775d Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 18 Mar 2026 22:02:58 +0000 Subject: [PATCH 05/12] Add gemspy.egg-info to .gitignore https://claude.ai/code/session_01VUYEHTGsxtBYVEVm5c7ysC --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 1edab6c2..59318f35 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ bin outputs build src/gems.egg-info/ +src/gemspy.egg-info/ From 2ae3e64ced82d028261cb39c36f91ca45dc2e89a Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 18 Mar 2026 22:07:14 +0000 Subject: [PATCH 06/12] Fix black formatting using version 23.7.0 to match CI https://claude.ai/code/session_01VUYEHTGsxtBYVEVm5c7ysC --- src/gems/expression/evaluate.py | 12 ++-- src/gems/expression/evaluate_parameters.py | 6 +- src/gems/expression/indexing.py | 12 ++-- .../expression/parsing/antlr/ExprLexer.py | 1 - .../expression/parsing/antlr/ExprParser.py | 30 -------- .../expression/parsing/antlr/ExprVisitor.py | 1 - src/gems/expression/visitor.py | 69 ++++++++++++------- src/gems/simulation/optimization.py | 8 ++- src/gems/simulation/strategy.py | 9 ++- 9 files changed, 77 insertions(+), 71 deletions(-) diff --git a/src/gems/expression/evaluate.py b/src/gems/expression/evaluate.py index 1dd32bf6..4d3c3770 100644 --- a/src/gems/expression/evaluate.py +++ b/src/gems/expression/evaluate.py @@ -51,16 +51,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 030f4dad..7d7f1f0b 100644 --- a/src/gems/expression/indexing.py +++ b/src/gems/expression/indexing.py @@ -47,20 +47,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/parsing/antlr/ExprLexer.py b/src/gems/expression/parsing/antlr/ExprLexer.py index 793fc2c9..261c7170 100644 --- a/src/gems/expression/parsing/antlr/ExprLexer.py +++ b/src/gems/expression/parsing/antlr/ExprLexer.py @@ -1143,7 +1143,6 @@ def serializedATN(): class ExprLexer(Lexer): - atn = ATNDeserializer().deserialize(serializedATN()) decisionsToDFA = [DFA(ds, i) for i, ds in enumerate(atn.decisionToState)] diff --git a/src/gems/expression/parsing/antlr/ExprParser.py b/src/gems/expression/parsing/antlr/ExprParser.py index a09db512..8d66b7c6 100644 --- a/src/gems/expression/parsing/antlr/ExprParser.py +++ b/src/gems/expression/parsing/antlr/ExprParser.py @@ -1328,7 +1328,6 @@ def serializedATN(): class ExprParser(Parser): - grammarFileName = "Expr.g4" atn = ATNDeserializer().deserialize(serializedATN()) @@ -1449,7 +1448,6 @@ def accept(self, visitor: ParseTreeVisitor): return visitor.visitChildren(self) def portFieldExpr(self): - localctx = ExprParser.PortFieldExprContext(self, self._ctx, self.state) self.enterRule(localctx, 0, self.RULE_portFieldExpr) try: @@ -1493,7 +1491,6 @@ def accept(self, visitor: ParseTreeVisitor): return visitor.visitChildren(self) def fullexpr(self): - localctx = ExprParser.FullexprContext(self, self._ctx, self.state) self.enterRule(localctx, 2, self.RULE_fullexpr) try: @@ -1526,7 +1523,6 @@ def copyFrom(self, ctx: ParserRuleContext): super().copyFrom(ctx) class PortFieldSumContext(ExprContext): - def __init__( self, parser, ctx: ParserRuleContext ): # actually a ExprParser.ExprContext @@ -1543,7 +1539,6 @@ def accept(self, visitor: ParseTreeVisitor): return visitor.visitChildren(self) class BinaryFunctionContext(ExprContext): - def __init__( self, parser, ctx: ParserRuleContext ): # actually a ExprParser.ExprContext @@ -1566,7 +1561,6 @@ def accept(self, visitor: ParseTreeVisitor): return visitor.visitChildren(self) class NegationContext(ExprContext): - def __init__( self, parser, ctx: ParserRuleContext ): # actually a ExprParser.ExprContext @@ -1583,7 +1577,6 @@ def accept(self, visitor: ParseTreeVisitor): return visitor.visitChildren(self) class UnsignedAtomContext(ExprContext): - def __init__( self, parser, ctx: ParserRuleContext ): # actually a ExprParser.ExprContext @@ -1600,7 +1593,6 @@ def accept(self, visitor: ParseTreeVisitor): return visitor.visitChildren(self) class ExpressionContext(ExprContext): - def __init__( self, parser, ctx: ParserRuleContext ): # actually a ExprParser.ExprContext @@ -1617,7 +1609,6 @@ def accept(self, visitor: ParseTreeVisitor): return visitor.visitChildren(self) class ComparisonContext(ExprContext): - def __init__( self, parser, ctx: ParserRuleContext ): # actually a ExprParser.ExprContext @@ -1640,7 +1631,6 @@ def accept(self, visitor: ParseTreeVisitor): return visitor.visitChildren(self) class AllTimeSumContext(ExprContext): - def __init__( self, parser, ctx: ParserRuleContext ): # actually a ExprParser.ExprContext @@ -1657,7 +1647,6 @@ def accept(self, visitor: ParseTreeVisitor): return visitor.visitChildren(self) class TimeIndexExprContext(ExprContext): - def __init__( self, parser, ctx: ParserRuleContext ): # actually a ExprParser.ExprContext @@ -1677,7 +1666,6 @@ def accept(self, visitor: ParseTreeVisitor): return visitor.visitChildren(self) class AddsubContext(ExprContext): - def __init__( self, parser, ctx: ParserRuleContext ): # actually a ExprParser.ExprContext @@ -1698,7 +1686,6 @@ def accept(self, visitor: ParseTreeVisitor): return visitor.visitChildren(self) class TimeShiftExprContext(ExprContext): - def __init__( self, parser, ctx: ParserRuleContext ): # actually a ExprParser.ExprContext @@ -1718,7 +1705,6 @@ def accept(self, visitor: ParseTreeVisitor): return visitor.visitChildren(self) class PortFieldContext(ExprContext): - def __init__( self, parser, ctx: ParserRuleContext ): # actually a ExprParser.ExprContext @@ -1735,7 +1721,6 @@ def accept(self, visitor: ParseTreeVisitor): return visitor.visitChildren(self) class MuldivContext(ExprContext): - def __init__( self, parser, ctx: ParserRuleContext ): # actually a ExprParser.ExprContext @@ -1756,7 +1741,6 @@ def accept(self, visitor: ParseTreeVisitor): return visitor.visitChildren(self) class TimeSumContext(ExprContext): - def __init__( self, parser, ctx: ParserRuleContext ): # actually a ExprParser.ExprContext @@ -1781,7 +1765,6 @@ def accept(self, visitor: ParseTreeVisitor): return visitor.visitChildren(self) class TimeIndexContext(ExprContext): - def __init__( self, parser, ctx: ParserRuleContext ): # actually a ExprParser.ExprContext @@ -1801,7 +1784,6 @@ def accept(self, visitor: ParseTreeVisitor): return visitor.visitChildren(self) class TimeShiftContext(ExprContext): - def __init__( self, parser, ctx: ParserRuleContext ): # actually a ExprParser.ExprContext @@ -1821,7 +1803,6 @@ def accept(self, visitor: ParseTreeVisitor): return visitor.visitChildren(self) class FunctionContext(ExprContext): - def __init__( self, parser, ctx: ParserRuleContext ): # actually a ExprParser.ExprContext @@ -2150,7 +2131,6 @@ def copyFrom(self, ctx: ParserRuleContext): super().copyFrom(ctx) class NumberContext(AtomContext): - def __init__( self, parser, ctx: ParserRuleContext ): # actually a ExprParser.AtomContext @@ -2167,7 +2147,6 @@ def accept(self, visitor: ParseTreeVisitor): return visitor.visitChildren(self) class IdentifierContext(AtomContext): - def __init__( self, parser, ctx: ParserRuleContext ): # actually a ExprParser.AtomContext @@ -2184,7 +2163,6 @@ def accept(self, visitor: ParseTreeVisitor): return visitor.visitChildren(self) def atom(self): - localctx = ExprParser.AtomContext(self, self._ctx, self.state) self.enterRule(localctx, 6, self.RULE_atom) try: @@ -2239,7 +2217,6 @@ def accept(self, visitor: ParseTreeVisitor): 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 @@ -2278,7 +2255,6 @@ def copyFrom(self, ctx: ParserRuleContext): super().copyFrom(ctx) class SignedAtomContext(Shift_exprContext): - def __init__( self, parser, ctx: ParserRuleContext ): # actually a ExprParser.Shift_exprContext @@ -2296,7 +2272,6 @@ def accept(self, visitor: ParseTreeVisitor): return visitor.visitChildren(self) class SignedExpressionContext(Shift_exprContext): - def __init__( self, parser, ctx: ParserRuleContext ): # actually a ExprParser.Shift_exprContext @@ -2314,7 +2289,6 @@ def accept(self, visitor: ParseTreeVisitor): return visitor.visitChildren(self) class ShiftMuldivContext(Shift_exprContext): - def __init__( self, parser, ctx: ParserRuleContext ): # actually a ExprParser.Shift_exprContext @@ -2335,7 +2309,6 @@ def accept(self, visitor: ParseTreeVisitor): return visitor.visitChildren(self) class ShiftAddsubContext(Shift_exprContext): - def __init__( self, parser, ctx: ParserRuleContext ): # actually a ExprParser.Shift_exprContext @@ -2503,7 +2476,6 @@ def copyFrom(self, ctx: ParserRuleContext): super().copyFrom(ctx) class RightExpressionContext(Right_exprContext): - def __init__( self, parser, ctx: ParserRuleContext ): # actually a ExprParser.Right_exprContext @@ -2520,7 +2492,6 @@ def accept(self, visitor: ParseTreeVisitor): return visitor.visitChildren(self) class RightMuldivContext(Right_exprContext): - def __init__( self, parser, ctx: ParserRuleContext ): # actually a ExprParser.Right_exprContext @@ -2541,7 +2512,6 @@ def accept(self, visitor: ParseTreeVisitor): return visitor.visitChildren(self) class RightAtomContext(Right_exprContext): - def __init__( self, parser, ctx: ParserRuleContext ): # actually a ExprParser.Right_exprContext diff --git a/src/gems/expression/parsing/antlr/ExprVisitor.py b/src/gems/expression/parsing/antlr/ExprVisitor.py index 871f42d9..68a41ab8 100644 --- a/src/gems/expression/parsing/antlr/ExprVisitor.py +++ b/src/gems/expression/parsing/antlr/ExprVisitor.py @@ -10,7 +10,6 @@ class ExprVisitor(ParseTreeVisitor): - # Visit a parse tree produced by ExprParser#portFieldExpr. def visitPortFieldExpr(self, ctx: ExprParser.PortFieldExprContext): return self.visitChildren(ctx) diff --git a/src/gems/expression/visitor.py b/src/gems/expression/visitor.py index c4e1da58..dc5ad42c 100644 --- a/src/gems/expression/visitor.py +++ b/src/gems/expression/visitor.py @@ -58,73 +58,96 @@ 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 floor(self, node: FloorNode) -> T: ... + def floor(self, node: FloorNode) -> T: + ... @abstractmethod - def ceil(self, node: CeilNode) -> T: ... + def ceil(self, node: CeilNode) -> T: + ... @abstractmethod - def maximum(self, node: MaxNode) -> T: ... + def maximum(self, node: MaxNode) -> T: + ... @abstractmethod - def minimum(self, node: MinNode) -> T: ... + def minimum(self, node: MinNode) -> T: + ... def visit(root: ExpressionNode, visitor: ExpressionVisitor[T]) -> T: diff --git a/src/gems/simulation/optimization.py b/src/gems/simulation/optimization.py index 2a8786fc..1d43b1de 100644 --- a/src/gems/simulation/optimization.py +++ b/src/gems/simulation/optimization.py @@ -889,9 +889,11 @@ def fusion_problems( root_var = root_vars[var.name()] root_var.SetLb(var.lb()) root_var.SetUb(var.ub()) - root_master.context._solver_variables[var.name()].is_in_objective = ( - context._solver_variables[var.name()].is_in_objective - ) + root_master.context._solver_variables[ + var.name() + ].is_in_objective = context._solver_variables[ + var.name() + ].is_in_objective for cstr in master.solver.constraints(): coeff = cstr.GetCoefficient(var) diff --git a/src/gems/simulation/strategy.py b/src/gems/simulation/strategy.py index 46b2096d..467dd32a 100644 --- a/src/gems/simulation/strategy.py +++ b/src/gems/simulation/strategy.py @@ -37,12 +37,14 @@ def get_constraints(self, model: Model) -> Generator[Constraint, None, None]: yield constraint @abstractmethod - def _keep_from_context(self, context: ProblemContext) -> bool: ... + def _keep_from_context(self, context: ProblemContext) -> bool: + ... @abstractmethod def get_objectives( self, model: Model - ) -> Generator[Optional[ExpressionNode], None, None]: ... + ) -> Generator[Optional[ExpressionNode], None, None]: + ... class MergedProblemStrategy(ModelSelectionStrategy): @@ -94,7 +96,8 @@ def __call__(self, expr: ExpressionNode) -> ExpressionNode: return self._modify_expression(expr) @abstractmethod - def _modify_expression(self, expr: ExpressionNode) -> ExpressionNode: ... + def _modify_expression(self, expr: ExpressionNode) -> ExpressionNode: + ... class UniformRisk(RiskManagementStrategy): From e791c3ce405da7fb35b8faa2bd9c9bac12a13617 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 18 Mar 2026 22:20:30 +0000 Subject: [PATCH 07/12] Fix degree of floor/ceil/max/min: return inf for non-constant operands floor(x), ceil(x), max(x,y), min(x,y) are not polynomials when their operands involve variables, so their degree is mathematically undefined (infinity) rather than equal to the operand degree. Also widens ExpressionDegreeVisitor and compute_degree from int to int | float to accommodate math.inf. https://claude.ai/code/session_01VUYEHTGsxtBYVEVm5c7ysC --- src/gems/expression/degree.py | 28 +++++++++------ .../expressions/visitor/test_degree.py | 35 ++++++++++++++++++- 2 files changed, 52 insertions(+), 11 deletions(-) diff --git a/src/gems/expression/degree.py b/src/gems/expression/degree.py index 587fae44..b1546e29 100644 --- a/src/gems/expression/degree.py +++ b/src/gems/expression/degree.py @@ -10,6 +10,8 @@ # # This file is part of the Antares project. +import math + import gems.expression.scenario_operator from gems.expression.expression import ( AllTimeSumNode, @@ -43,7 +45,7 @@ from .visitor import ExpressionVisitor, T, visit -class ExpressionDegreeVisitor(ExpressionVisitor[int]): +class ExpressionDegreeVisitor(ExpressionVisitor[int | float]): """ Computes degree of expression with respect to variables. """ @@ -112,20 +114,26 @@ def port_field(self, node: PortFieldNode) -> int: def port_field_aggregator(self, node: PortFieldAggregatorNode) -> int: return visit(node.operand, self) - def floor(self, node: FloorNode) -> int: - return visit(node.operand, self) + def floor(self, node: FloorNode) -> int | float: + d = visit(node.operand, self) + return 0 if d == 0 else math.inf - def ceil(self, node: CeilNode) -> int: - return visit(node.operand, self) + def ceil(self, node: CeilNode) -> int | float: + d = visit(node.operand, self) + return 0 if d == 0 else math.inf - def maximum(self, node: MaxNode) -> int: - return max(visit(node.left, self), visit(node.right, self)) + def maximum(self, node: MaxNode) -> int | float: + d_l = visit(node.left, self) + d_r = visit(node.right, self) + return 0 if d_l == 0 and d_r == 0 else math.inf - def minimum(self, node: MinNode) -> int: - return max(visit(node.left, self), visit(node.right, self)) + def minimum(self, node: MinNode) -> int | float: + d_l = visit(node.left, self) + d_r = visit(node.right, self) + return 0 if d_l == 0 and d_r == 0 else math.inf -def compute_degree(expression: ExpressionNode) -> int: +def compute_degree(expression: ExpressionNode) -> int | float: return visit(expression, ExpressionDegreeVisitor()) diff --git a/tests/unittests/expressions/visitor/test_degree.py b/tests/unittests/expressions/visitor/test_degree.py index 72996d64..0df558c1 100644 --- a/tests/unittests/expressions/visitor/test_degree.py +++ b/tests/unittests/expressions/visitor/test_degree.py @@ -10,9 +10,20 @@ # # This file is part of the Antares project. +import math + import pytest -from gems.expression import ExpressionDegreeVisitor, LiteralNode, param, var, visit +from gems.expression import ( + ExpressionDegreeVisitor, + LiteralNode, + maximum, + minimum, + param, + var, + visit, +) +from gems.expression.expression import CeilNode, FloorNode def test_degree() -> None: @@ -26,6 +37,28 @@ def test_degree() -> None: assert visit(expr, ExpressionDegreeVisitor()) == 2 +def test_floor_ceil_degree() -> None: + x = var("x") + p = param("p") + + assert visit(FloorNode(p), ExpressionDegreeVisitor()) == 0 + assert visit(CeilNode(p), ExpressionDegreeVisitor()) == 0 + assert visit(FloorNode(x), ExpressionDegreeVisitor()) == math.inf + assert visit(CeilNode(x), ExpressionDegreeVisitor()) == math.inf + + +def test_max_min_degree() -> None: + x = var("x") + p = param("p") + q = param("q") + + assert visit(maximum(p, q), ExpressionDegreeVisitor()) == 0 + assert visit(minimum(p, q), ExpressionDegreeVisitor()) == 0 + assert visit(maximum(x, p), ExpressionDegreeVisitor()) == math.inf + assert visit(minimum(p, x), ExpressionDegreeVisitor()) == math.inf + assert visit(maximum(x, x), ExpressionDegreeVisitor()) == math.inf + + @pytest.mark.xfail(reason="Degree simplification not implemented") def test_degree_computation_should_take_into_account_simplifications() -> None: x = var("x") From 7384c02c0b9d7f77d6ff749b134141d2a2431218 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 18 Mar 2026 22:25:16 +0000 Subject: [PATCH 08/12] Add equality tests for floor, ceil, max, min nodes https://claude.ai/code/session_01VUYEHTGsxtBYVEVm5c7ysC --- .../unittests/expressions/visitor/test_equality.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/unittests/expressions/visitor/test_equality.py b/tests/unittests/expressions/visitor/test_equality.py index bcdec8ff..b2efd0fb 100644 --- a/tests/unittests/expressions/visitor/test_equality.py +++ b/tests/unittests/expressions/visitor/test_equality.py @@ -14,6 +14,7 @@ from gems.expression import ExpressionNode, copy_expression, literal, param, var from gems.expression.equality import expressions_equal +from gems.expression.expression import maximum, minimum @pytest.mark.parametrize( @@ -30,6 +31,10 @@ var("x").time_sum(), var("x") + 5 <= 2, var("x").expec(), + var("x").floor(), + var("x").ceil(), + maximum(var("x"), param("p")), + minimum(var("x"), param("p")), ], ) def test_equals(expr: ExpressionNode) -> None: @@ -52,6 +57,14 @@ def test_equals(expr: ExpressionNode) -> None: var("x").time_sum(1, 10), ), (var("x").expec(), var("y").expec()), + # floor / ceil + (var("x").floor(), var("y").floor()), + (var("x").ceil(), var("y").ceil()), + (var("x").floor(), var("x").ceil()), # different node type + # max / min + (maximum(var("x"), param("p")), maximum(var("y"), param("p"))), + (minimum(var("x"), param("p")), minimum(var("x"), param("q"))), + (maximum(var("x"), param("p")), minimum(var("x"), param("p"))), # Max vs Min ], ) def test_not_equals(lhs: ExpressionNode, rhs: ExpressionNode) -> None: From 590e302b67a0fae4d971c968b08b3eacf09d3a4e Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 18 Mar 2026 22:28:34 +0000 Subject: [PATCH 09/12] Fix mypy errors: widen all degree visitor method return types to int | float When ExpressionDegreeVisitor is parameterized as ExpressionVisitor[int | float], visit() returns int | float everywhere, so all methods that call visit() and were annotated -> int now need -> int | float. https://claude.ai/code/session_01VUYEHTGsxtBYVEVm5c7ysC --- src/gems/expression/degree.py | 38 +++++++++++++++++------------------ 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/gems/expression/degree.py b/src/gems/expression/degree.py index b1546e29..0be2c5fe 100644 --- a/src/gems/expression/degree.py +++ b/src/gems/expression/degree.py @@ -50,68 +50,68 @@ class ExpressionDegreeVisitor(ExpressionVisitor[int | float]): Computes degree of expression with respect to variables. """ - def literal(self, node: LiteralNode) -> int: + def literal(self, node: LiteralNode) -> int | float: return 0 - def negation(self, node: NegationNode) -> int: + def negation(self, node: NegationNode) -> int | float: return visit(node.operand, self) # TODO: Take into account simplification that can occur with literal coefficient for add, sub, mult, div - def addition(self, node: AdditionNode) -> int: + def addition(self, node: AdditionNode) -> int | float: degrees = [visit(o, self) for o in node.operands] return max(degrees) - def multiplication(self, node: MultiplicationNode) -> int: + def multiplication(self, node: MultiplicationNode) -> int | float: return visit(node.left, self) + visit(node.right, self) - def division(self, node: DivisionNode) -> int: + def division(self, node: DivisionNode) -> int | float: right_degree = visit(node.right, self) if right_degree != 0: raise ValueError("Degree computation not implemented for divisions.") return visit(node.left, self) - def comparison(self, node: ComparisonNode) -> int: + def comparison(self, node: ComparisonNode) -> int | float: return max(visit(node.left, self), visit(node.right, self)) - def variable(self, node: VariableNode) -> int: + def variable(self, node: VariableNode) -> int | float: return 1 - def parameter(self, node: ParameterNode) -> int: + def parameter(self, node: ParameterNode) -> int | float: return 0 - def comp_variable(self, node: ComponentVariableNode) -> int: + def comp_variable(self, node: ComponentVariableNode) -> int | float: return 1 - def comp_parameter(self, node: ComponentParameterNode) -> int: + def comp_parameter(self, node: ComponentParameterNode) -> int | float: return 0 - def pb_variable(self, node: ProblemVariableNode) -> int: + def pb_variable(self, node: ProblemVariableNode) -> int | float: return 1 - def pb_parameter(self, node: ProblemParameterNode) -> int: + def pb_parameter(self, node: ProblemParameterNode) -> int | float: return 0 - def time_shift(self, node: TimeShiftNode) -> int: + def time_shift(self, node: TimeShiftNode) -> int | float: return visit(node.operand, self) - def time_eval(self, node: TimeEvalNode) -> int: + def time_eval(self, node: TimeEvalNode) -> int | float: return visit(node.operand, self) - def time_sum(self, node: TimeSumNode) -> int: + def time_sum(self, node: TimeSumNode) -> int | float: return visit(node.operand, self) - def all_time_sum(self, node: AllTimeSumNode) -> int: + def all_time_sum(self, node: AllTimeSumNode) -> int | float: return visit(node.operand, self) - def scenario_operator(self, node: ScenarioOperatorNode) -> int: + def scenario_operator(self, node: ScenarioOperatorNode) -> int | float: 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) - def port_field(self, node: PortFieldNode) -> int: + def port_field(self, node: PortFieldNode) -> int | float: return 1 - def port_field_aggregator(self, node: PortFieldAggregatorNode) -> int: + def port_field_aggregator(self, node: PortFieldAggregatorNode) -> int | float: return visit(node.operand, self) def floor(self, node: FloorNode) -> int | float: From ba54411ede7405370c7a9bf622c4df8692a2018e Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 20 Mar 2026 16:00:27 +0000 Subject: [PATCH 10/12] feat(expressions): make max/min operators variadic with unified argList grammar rule Replace the separate binaryFunction grammar rule with a unified function rule using argList, allowing max/min to accept an arbitrary number of operands. Changes: - grammar/Expr.g4: add argList rule, merge function/binaryFunction into single IDENTIFIER '(' argList? ')' # function rule - Regenerate ANTLR parser files from updated grammar - expression.py: change MaxNode/MinNode from BinaryOperatorNode to variadic nodes with operands: List[ExpressionNode]; update maximum()/minimum() helpers to accept *args - parse_expression.py: merge visitBinaryFunction into visitFunction using argList context; remove separate _BINARY_FUNCTIONS dict - All visitor implementations updated to use node.operands instead of node.left/node.right (evaluate, print, degree, copy, equality, indexing, port) - Tests: add variadic test cases (3+ operands) for parsing, degree, evaluation, and printer https://claude.ai/code/session_01LLG7eSxsw3XGULyah6ZiB3 --- grammar/Expr.g4 | 5 +- src/gems/expression/copy.py | 4 +- src/gems/expression/degree.py | 8 +- src/gems/expression/equality.py | 8 +- src/gems/expression/evaluate.py | 4 +- src/gems/expression/expression.py | 16 +- src/gems/expression/indexing.py | 4 +- src/gems/expression/parsing/antlr/Expr.interp | 3 +- .../expression/parsing/antlr/ExprLexer.py | 1240 +-------- .../expression/parsing/antlr/ExprParser.py | 2471 ++++------------- .../expression/parsing/antlr/ExprVisitor.py | 95 +- .../expression/parsing/parse_expression.py | 41 +- src/gems/expression/print.py | 4 +- src/gems/model/port.py | 6 +- .../parsing/test_expression_parsing.py | 12 + .../expressions/visitor/test_degree.py | 5 + .../expressions/visitor/test_evaluation.py | 7 + .../expressions/visitor/test_printer.py | 3 + 18 files changed, 801 insertions(+), 3135 deletions(-) diff --git a/grammar/Expr.g4 b/grammar/Expr.g4 index 92928f38..f990402f 100644 --- a/grammar/Expr.g4 +++ b/grammar/Expr.g4 @@ -28,14 +28,15 @@ expr | 'sum' '(' expr ')' # allTimeSum | 'sum_connections' '(' portFieldExpr ')' # portFieldSum | 'sum' '(' from=shift '..' to=shift ',' expr ')' # timeSum - | IDENTIFIER '(' expr ')' # function - | IDENTIFIER '(' expr ',' expr ')' # binaryFunction + | IDENTIFIER '(' argList? ')' # function | IDENTIFIER '[' shift ']' # timeShift | IDENTIFIER '[' expr ']' # timeIndex | '(' expr ')' '[' shift ']' # timeShiftExpr | '(' expr ')' '[' expr ']' # timeIndexExpr ; +argList : expr (',' expr)* ; + atom : NUMBER # number | IDENTIFIER # identifier diff --git a/src/gems/expression/copy.py b/src/gems/expression/copy.py index 108b98ac..a5276ccd 100644 --- a/src/gems/expression/copy.py +++ b/src/gems/expression/copy.py @@ -106,10 +106,10 @@ def ceil(self, node: CeilNode) -> ExpressionNode: return CeilNode(visit(node.operand, self)) def maximum(self, node: MaxNode) -> ExpressionNode: - return MaxNode(visit(node.left, self), visit(node.right, self)) + return MaxNode([visit(op, self) for op in node.operands]) def minimum(self, node: MinNode) -> ExpressionNode: - return MinNode(visit(node.left, self), visit(node.right, self)) + return MinNode([visit(op, self) for op in node.operands]) def copy_expression(expression: ExpressionNode) -> ExpressionNode: diff --git a/src/gems/expression/degree.py b/src/gems/expression/degree.py index 0be2c5fe..220650c1 100644 --- a/src/gems/expression/degree.py +++ b/src/gems/expression/degree.py @@ -123,14 +123,10 @@ def ceil(self, node: CeilNode) -> int | float: return 0 if d == 0 else math.inf def maximum(self, node: MaxNode) -> int | float: - d_l = visit(node.left, self) - d_r = visit(node.right, self) - return 0 if d_l == 0 and d_r == 0 else math.inf + return 0 if all(visit(op, self) == 0 for op in node.operands) else math.inf def minimum(self, node: MinNode) -> int | float: - d_l = visit(node.left, self) - d_r = visit(node.right, self) - return 0 if d_l == 0 and d_r == 0 else math.inf + return 0 if all(visit(op, self) == 0 for op in node.operands) else math.inf def compute_degree(expression: ExpressionNode) -> int | float: diff --git a/src/gems/expression/equality.py b/src/gems/expression/equality.py index 0517269e..b96ddaa0 100644 --- a/src/gems/expression/equality.py +++ b/src/gems/expression/equality.py @@ -234,10 +234,14 @@ def ceil(self, left: CeilNode, right: CeilNode) -> bool: return self.visit(left.operand, right.operand) def maximum(self, left: MaxNode, right: MaxNode) -> bool: - return self._visit_operands(left, right) + return len(left.operands) == len(right.operands) and all( + self.visit(l, r) for l, r in zip(left.operands, right.operands) + ) def minimum(self, left: MinNode, right: MinNode) -> bool: - return self._visit_operands(left, right) + return len(left.operands) == len(right.operands) and all( + self.visit(l, r) for l, r in zip(left.operands, right.operands) + ) def expressions_equal( diff --git a/src/gems/expression/evaluate.py b/src/gems/expression/evaluate.py index 4d3c3770..2c850eff 100644 --- a/src/gems/expression/evaluate.py +++ b/src/gems/expression/evaluate.py @@ -151,10 +151,10 @@ def ceil(self, node: CeilNode) -> float: return float(math.ceil(visit(node.operand, self))) def maximum(self, node: MaxNode) -> float: - return max(visit(node.left, self), visit(node.right, self)) + return max(visit(op, self) for op in node.operands) def minimum(self, node: MinNode) -> float: - return min(visit(node.left, self), visit(node.right, self)) + return min(visit(op, self) for op in node.operands) def evaluate(expression: ExpressionNode, value_provider: ValueProvider) -> float: diff --git a/src/gems/expression/expression.py b/src/gems/expression/expression.py index 94405f0c..68dcee3d 100644 --- a/src/gems/expression/expression.py +++ b/src/gems/expression/expression.py @@ -418,21 +418,21 @@ class DivisionNode(BinaryOperatorNode): @dataclass(frozen=True, eq=False) -class MaxNode(BinaryOperatorNode): - pass +class MaxNode(ExpressionNode): + operands: List[ExpressionNode] @dataclass(frozen=True, eq=False) -class MinNode(BinaryOperatorNode): - pass +class MinNode(ExpressionNode): + operands: List[ExpressionNode] -def maximum(left: "ExpressionNode", right: "ExpressionNode") -> "MaxNode": - return MaxNode(left, right) +def maximum(*operands: "ExpressionNode") -> "MaxNode": + return MaxNode(list(operands)) -def minimum(left: "ExpressionNode", right: "ExpressionNode") -> "MinNode": - return MinNode(left, right) +def minimum(*operands: "ExpressionNode") -> "MinNode": + return MinNode(list(operands)) @dataclass(frozen=True, eq=False) diff --git a/src/gems/expression/indexing.py b/src/gems/expression/indexing.py index 7d7f1f0b..c7858204 100644 --- a/src/gems/expression/indexing.py +++ b/src/gems/expression/indexing.py @@ -170,10 +170,10 @@ def ceil(self, node: CeilNode) -> IndexingStructure: return visit(node.operand, self) def maximum(self, node: MaxNode) -> IndexingStructure: - return self._combine([node.left, node.right]) + return self._combine(node.operands) def minimum(self, node: MinNode) -> IndexingStructure: - return self._combine([node.left, node.right]) + 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 4cd49648..d2035f0c 100644 --- a/src/gems/expression/parsing/antlr/Expr.interp +++ b/src/gems/expression/parsing/antlr/Expr.interp @@ -44,6 +44,7 @@ rule names: portFieldExpr fullexpr expr +argList atom shift shift_expr @@ -51,4 +52,4 @@ right_expr atn: -[4, 1, 18, 147, 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, 1, 2, 1, 2, 3, 2, 86, 8, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 5, 2, 97, 8, 2, 10, 2, 12, 2, 100, 9, 2, 1, 3, 1, 3, 3, 3, 104, 8, 3, 1, 4, 1, 4, 3, 4, 108, 8, 4, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 3, 5, 118, 8, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 5, 5, 126, 8, 5, 10, 5, 12, 5, 129, 9, 5, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 3, 6, 137, 8, 6, 1, 6, 1, 6, 1, 6, 5, 6, 142, 8, 6, 10, 6, 12, 6, 145, 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, 161, 0, 14, 1, 0, 0, 0, 2, 18, 1, 0, 0, 0, 4, 85, 1, 0, 0, 0, 6, 103, 1, 0, 0, 0, 8, 105, 1, 0, 0, 0, 10, 117, 1, 0, 0, 0, 12, 136, 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, 86, 3, 6, 3, 0, 23, 86, 3, 0, 0, 0, 24, 25, 5, 2, 0, 0, 25, 86, 3, 4, 2, 14, 26, 27, 5, 3, 0, 0, 27, 28, 3, 4, 2, 0, 28, 29, 5, 4, 0, 0, 29, 86, 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, 86, 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, 86, 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, 86, 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, 86, 1, 0, 0, 0, 54, 55, 5, 16, 0, 0, 55, 56, 5, 3, 0, 0, 56, 57, 3, 4, 2, 0, 57, 58, 5, 11, 0, 0, 58, 59, 3, 4, 2, 0, 59, 60, 5, 4, 0, 0, 60, 86, 1, 0, 0, 0, 61, 62, 5, 16, 0, 0, 62, 63, 5, 12, 0, 0, 63, 64, 3, 8, 4, 0, 64, 65, 5, 13, 0, 0, 65, 86, 1, 0, 0, 0, 66, 67, 5, 16, 0, 0, 67, 68, 5, 12, 0, 0, 68, 69, 3, 4, 2, 0, 69, 70, 5, 13, 0, 0, 70, 86, 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, 8, 4, 0, 76, 77, 5, 13, 0, 0, 77, 86, 1, 0, 0, 0, 78, 79, 5, 3, 0, 0, 79, 80, 3, 4, 2, 0, 80, 81, 5, 4, 0, 0, 81, 82, 5, 12, 0, 0, 82, 83, 3, 4, 2, 0, 83, 84, 5, 13, 0, 0, 84, 86, 1, 0, 0, 0, 85, 21, 1, 0, 0, 0, 85, 23, 1, 0, 0, 0, 85, 24, 1, 0, 0, 0, 85, 26, 1, 0, 0, 0, 85, 30, 1, 0, 0, 0, 85, 35, 1, 0, 0, 0, 85, 40, 1, 0, 0, 0, 85, 49, 1, 0, 0, 0, 85, 54, 1, 0, 0, 0, 85, 61, 1, 0, 0, 0, 85, 66, 1, 0, 0, 0, 85, 71, 1, 0, 0, 0, 85, 78, 1, 0, 0, 0, 86, 98, 1, 0, 0, 0, 87, 88, 10, 12, 0, 0, 88, 89, 7, 0, 0, 0, 89, 97, 3, 4, 2, 13, 90, 91, 10, 11, 0, 0, 91, 92, 7, 1, 0, 0, 92, 97, 3, 4, 2, 12, 93, 94, 10, 10, 0, 0, 94, 95, 5, 17, 0, 0, 95, 97, 3, 4, 2, 11, 96, 87, 1, 0, 0, 0, 96, 90, 1, 0, 0, 0, 96, 93, 1, 0, 0, 0, 97, 100, 1, 0, 0, 0, 98, 96, 1, 0, 0, 0, 98, 99, 1, 0, 0, 0, 99, 5, 1, 0, 0, 0, 100, 98, 1, 0, 0, 0, 101, 104, 5, 14, 0, 0, 102, 104, 5, 16, 0, 0, 103, 101, 1, 0, 0, 0, 103, 102, 1, 0, 0, 0, 104, 7, 1, 0, 0, 0, 105, 107, 5, 15, 0, 0, 106, 108, 3, 10, 5, 0, 107, 106, 1, 0, 0, 0, 107, 108, 1, 0, 0, 0, 108, 9, 1, 0, 0, 0, 109, 110, 6, 5, -1, 0, 110, 111, 7, 1, 0, 0, 111, 118, 3, 6, 3, 0, 112, 113, 7, 1, 0, 0, 113, 114, 5, 3, 0, 0, 114, 115, 3, 4, 2, 0, 115, 116, 5, 4, 0, 0, 116, 118, 1, 0, 0, 0, 117, 109, 1, 0, 0, 0, 117, 112, 1, 0, 0, 0, 118, 127, 1, 0, 0, 0, 119, 120, 10, 4, 0, 0, 120, 121, 7, 0, 0, 0, 121, 126, 3, 12, 6, 0, 122, 123, 10, 3, 0, 0, 123, 124, 7, 1, 0, 0, 124, 126, 3, 12, 6, 0, 125, 119, 1, 0, 0, 0, 125, 122, 1, 0, 0, 0, 126, 129, 1, 0, 0, 0, 127, 125, 1, 0, 0, 0, 127, 128, 1, 0, 0, 0, 128, 11, 1, 0, 0, 0, 129, 127, 1, 0, 0, 0, 130, 131, 6, 6, -1, 0, 131, 132, 5, 3, 0, 0, 132, 133, 3, 4, 2, 0, 133, 134, 5, 4, 0, 0, 134, 137, 1, 0, 0, 0, 135, 137, 3, 6, 3, 0, 136, 130, 1, 0, 0, 0, 136, 135, 1, 0, 0, 0, 137, 143, 1, 0, 0, 0, 138, 139, 10, 3, 0, 0, 139, 140, 7, 0, 0, 0, 140, 142, 3, 12, 6, 4, 141, 138, 1, 0, 0, 0, 142, 145, 1, 0, 0, 0, 143, 141, 1, 0, 0, 0, 143, 144, 1, 0, 0, 0, 144, 13, 1, 0, 0, 0, 145, 143, 1, 0, 0, 0, 10, 85, 96, 98, 103, 107, 117, 125, 127, 136, 143] \ No newline at end of file +[4, 1, 18, 151, 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, 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, 3, 2, 55, 8, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 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, 82, 8, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 5, 2, 93, 8, 2, 10, 2, 12, 2, 96, 9, 2, 1, 3, 1, 3, 1, 3, 5, 3, 101, 8, 3, 10, 3, 12, 3, 104, 9, 3, 1, 4, 1, 4, 3, 4, 108, 8, 4, 1, 5, 1, 5, 3, 5, 112, 8, 5, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 3, 6, 122, 8, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 5, 6, 130, 8, 6, 10, 6, 12, 6, 133, 9, 6, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 3, 7, 141, 8, 7, 1, 7, 1, 7, 1, 7, 5, 7, 146, 8, 7, 10, 7, 12, 7, 149, 9, 7, 1, 7, 0, 3, 4, 12, 14, 8, 0, 2, 4, 6, 8, 10, 12, 14, 0, 2, 1, 0, 5, 6, 2, 0, 2, 2, 7, 7, 165, 0, 16, 1, 0, 0, 0, 2, 20, 1, 0, 0, 0, 4, 81, 1, 0, 0, 0, 6, 97, 1, 0, 0, 0, 8, 107, 1, 0, 0, 0, 10, 109, 1, 0, 0, 0, 12, 121, 1, 0, 0, 0, 14, 140, 1, 0, 0, 0, 16, 17, 5, 16, 0, 0, 17, 18, 5, 1, 0, 0, 18, 19, 5, 16, 0, 0, 19, 1, 1, 0, 0, 0, 20, 21, 3, 4, 2, 0, 21, 22, 5, 0, 0, 1, 22, 3, 1, 0, 0, 0, 23, 24, 6, 2, -1, 0, 24, 82, 3, 8, 4, 0, 25, 82, 3, 0, 0, 0, 26, 27, 5, 2, 0, 0, 27, 82, 3, 4, 2, 13, 28, 29, 5, 3, 0, 0, 29, 30, 3, 4, 2, 0, 30, 31, 5, 4, 0, 0, 31, 82, 1, 0, 0, 0, 32, 33, 5, 8, 0, 0, 33, 34, 5, 3, 0, 0, 34, 35, 3, 4, 2, 0, 35, 36, 5, 4, 0, 0, 36, 82, 1, 0, 0, 0, 37, 38, 5, 9, 0, 0, 38, 39, 5, 3, 0, 0, 39, 40, 3, 0, 0, 0, 40, 41, 5, 4, 0, 0, 41, 82, 1, 0, 0, 0, 42, 43, 5, 8, 0, 0, 43, 44, 5, 3, 0, 0, 44, 45, 3, 10, 5, 0, 45, 46, 5, 10, 0, 0, 46, 47, 3, 10, 5, 0, 47, 48, 5, 11, 0, 0, 48, 49, 3, 4, 2, 0, 49, 50, 5, 4, 0, 0, 50, 82, 1, 0, 0, 0, 51, 52, 5, 16, 0, 0, 52, 54, 5, 3, 0, 0, 53, 55, 3, 6, 3, 0, 54, 53, 1, 0, 0, 0, 54, 55, 1, 0, 0, 0, 55, 56, 1, 0, 0, 0, 56, 82, 5, 4, 0, 0, 57, 58, 5, 16, 0, 0, 58, 59, 5, 12, 0, 0, 59, 60, 3, 10, 5, 0, 60, 61, 5, 13, 0, 0, 61, 82, 1, 0, 0, 0, 62, 63, 5, 16, 0, 0, 63, 64, 5, 12, 0, 0, 64, 65, 3, 4, 2, 0, 65, 66, 5, 13, 0, 0, 66, 82, 1, 0, 0, 0, 67, 68, 5, 3, 0, 0, 68, 69, 3, 4, 2, 0, 69, 70, 5, 4, 0, 0, 70, 71, 5, 12, 0, 0, 71, 72, 3, 10, 5, 0, 72, 73, 5, 13, 0, 0, 73, 82, 1, 0, 0, 0, 74, 75, 5, 3, 0, 0, 75, 76, 3, 4, 2, 0, 76, 77, 5, 4, 0, 0, 77, 78, 5, 12, 0, 0, 78, 79, 3, 4, 2, 0, 79, 80, 5, 13, 0, 0, 80, 82, 1, 0, 0, 0, 81, 23, 1, 0, 0, 0, 81, 25, 1, 0, 0, 0, 81, 26, 1, 0, 0, 0, 81, 28, 1, 0, 0, 0, 81, 32, 1, 0, 0, 0, 81, 37, 1, 0, 0, 0, 81, 42, 1, 0, 0, 0, 81, 51, 1, 0, 0, 0, 81, 57, 1, 0, 0, 0, 81, 62, 1, 0, 0, 0, 81, 67, 1, 0, 0, 0, 81, 74, 1, 0, 0, 0, 82, 94, 1, 0, 0, 0, 83, 84, 10, 11, 0, 0, 84, 85, 7, 0, 0, 0, 85, 93, 3, 4, 2, 12, 86, 87, 10, 10, 0, 0, 87, 88, 7, 1, 0, 0, 88, 93, 3, 4, 2, 11, 89, 90, 10, 9, 0, 0, 90, 91, 5, 17, 0, 0, 91, 93, 3, 4, 2, 10, 92, 83, 1, 0, 0, 0, 92, 86, 1, 0, 0, 0, 92, 89, 1, 0, 0, 0, 93, 96, 1, 0, 0, 0, 94, 92, 1, 0, 0, 0, 94, 95, 1, 0, 0, 0, 95, 5, 1, 0, 0, 0, 96, 94, 1, 0, 0, 0, 97, 102, 3, 4, 2, 0, 98, 99, 5, 11, 0, 0, 99, 101, 3, 4, 2, 0, 100, 98, 1, 0, 0, 0, 101, 104, 1, 0, 0, 0, 102, 100, 1, 0, 0, 0, 102, 103, 1, 0, 0, 0, 103, 7, 1, 0, 0, 0, 104, 102, 1, 0, 0, 0, 105, 108, 5, 14, 0, 0, 106, 108, 5, 16, 0, 0, 107, 105, 1, 0, 0, 0, 107, 106, 1, 0, 0, 0, 108, 9, 1, 0, 0, 0, 109, 111, 5, 15, 0, 0, 110, 112, 3, 12, 6, 0, 111, 110, 1, 0, 0, 0, 111, 112, 1, 0, 0, 0, 112, 11, 1, 0, 0, 0, 113, 114, 6, 6, -1, 0, 114, 115, 7, 1, 0, 0, 115, 122, 3, 8, 4, 0, 116, 117, 7, 1, 0, 0, 117, 118, 5, 3, 0, 0, 118, 119, 3, 4, 2, 0, 119, 120, 5, 4, 0, 0, 120, 122, 1, 0, 0, 0, 121, 113, 1, 0, 0, 0, 121, 116, 1, 0, 0, 0, 122, 131, 1, 0, 0, 0, 123, 124, 10, 4, 0, 0, 124, 125, 7, 0, 0, 0, 125, 130, 3, 14, 7, 0, 126, 127, 10, 3, 0, 0, 127, 128, 7, 1, 0, 0, 128, 130, 3, 14, 7, 0, 129, 123, 1, 0, 0, 0, 129, 126, 1, 0, 0, 0, 130, 133, 1, 0, 0, 0, 131, 129, 1, 0, 0, 0, 131, 132, 1, 0, 0, 0, 132, 13, 1, 0, 0, 0, 133, 131, 1, 0, 0, 0, 134, 135, 6, 7, -1, 0, 135, 136, 5, 3, 0, 0, 136, 137, 3, 4, 2, 0, 137, 138, 5, 4, 0, 0, 138, 141, 1, 0, 0, 0, 139, 141, 3, 8, 4, 0, 140, 134, 1, 0, 0, 0, 140, 139, 1, 0, 0, 0, 141, 147, 1, 0, 0, 0, 142, 143, 10, 3, 0, 0, 143, 144, 7, 0, 0, 0, 144, 146, 3, 14, 7, 4, 145, 142, 1, 0, 0, 0, 146, 149, 1, 0, 0, 0, 147, 145, 1, 0, 0, 0, 147, 148, 1, 0, 0, 0, 148, 15, 1, 0, 0, 0, 149, 147, 1, 0, 0, 0, 12, 54, 81, 92, 94, 102, 107, 111, 121, 129, 131, 140, 147] \ 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 261c7170..71a27deb 100644 --- a/src/gems/expression/parsing/antlr/ExprLexer.py +++ b/src/gems/expression/parsing/antlr/ExprLexer.py @@ -1,8 +1,7 @@ -# Generated from /home/user/GemsPy/grammar/Expr.g4 by ANTLR 4.13.2 +# Generated from Expr.g4 by ANTLR 4.13.2 from antlr4 import * from io import StringIO import sys - if sys.version_info[1] > 5: from typing import TextIO else: @@ -11,1141 +10,56 @@ 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,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 ] - 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 @@ -1166,61 +80,29 @@ class ExprLexer(Lexer): COMPARISON = 17 WS = 18 - 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'", + "'..'", "','", "'['", "']'", "'t'" ] - symbolicNames = ["", "NUMBER", "TIME", "IDENTIFIER", "COMPARISON", "WS"] + symbolicNames = [ "", + "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", - "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" ] 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 8d66b7c6..c3908e61 100644 --- a/src/gems/expression/parsing/antlr/ExprParser.py +++ b/src/gems/expression/parsing/antlr/ExprParser.py @@ -1,1438 +1,137 @@ -# Generated from /home/user/GemsPy/grammar/Expr.g4 by ANTLR 4.13.2 +# Generated from Expr.g4 by ANTLR 4.13.2 # encoding: utf-8 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, - 147, - 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, - 1, - 2, - 1, - 2, - 3, - 2, - 86, - 8, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 5, - 2, - 97, - 8, - 2, - 10, - 2, - 12, - 2, - 100, - 9, - 2, - 1, - 3, - 1, - 3, - 3, - 3, - 104, - 8, - 3, - 1, - 4, - 1, - 4, - 3, - 4, - 108, - 8, - 4, - 1, - 5, - 1, - 5, - 1, - 5, - 1, - 5, - 1, - 5, - 1, - 5, - 1, - 5, - 1, - 5, - 3, - 5, - 118, - 8, - 5, - 1, - 5, - 1, - 5, - 1, - 5, - 1, - 5, - 1, - 5, - 1, - 5, - 5, - 5, - 126, - 8, - 5, - 10, - 5, - 12, - 5, - 129, - 9, - 5, - 1, - 6, - 1, - 6, - 1, - 6, - 1, - 6, - 1, - 6, - 1, - 6, - 3, - 6, - 137, - 8, - 6, - 1, - 6, - 1, - 6, - 1, - 6, - 5, - 6, - 142, - 8, - 6, - 10, - 6, - 12, - 6, - 145, - 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, - 161, - 0, - 14, - 1, - 0, - 0, - 0, - 2, - 18, - 1, - 0, - 0, - 0, - 4, - 85, - 1, - 0, - 0, - 0, - 6, - 103, - 1, - 0, - 0, - 0, - 8, - 105, - 1, - 0, - 0, - 0, - 10, - 117, - 1, - 0, - 0, - 0, - 12, - 136, - 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, - 86, - 3, - 6, - 3, - 0, - 23, - 86, - 3, - 0, - 0, - 0, - 24, - 25, - 5, - 2, - 0, - 0, - 25, - 86, - 3, - 4, - 2, - 14, - 26, - 27, - 5, - 3, - 0, - 0, - 27, - 28, - 3, - 4, - 2, - 0, - 28, - 29, - 5, - 4, - 0, - 0, - 29, - 86, - 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, - 86, - 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, - 86, - 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, - 86, - 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, - 86, - 1, - 0, - 0, - 0, - 54, - 55, - 5, - 16, - 0, - 0, - 55, - 56, - 5, - 3, - 0, - 0, - 56, - 57, - 3, - 4, - 2, - 0, - 57, - 58, - 5, - 11, - 0, - 0, - 58, - 59, - 3, - 4, - 2, - 0, - 59, - 60, - 5, - 4, - 0, - 0, - 60, - 86, - 1, - 0, - 0, - 0, - 61, - 62, - 5, - 16, - 0, - 0, - 62, - 63, - 5, - 12, - 0, - 0, - 63, - 64, - 3, - 8, - 4, - 0, - 64, - 65, - 5, - 13, - 0, - 0, - 65, - 86, - 1, - 0, - 0, - 0, - 66, - 67, - 5, - 16, - 0, - 0, - 67, - 68, - 5, - 12, - 0, - 0, - 68, - 69, - 3, - 4, - 2, - 0, - 69, - 70, - 5, - 13, - 0, - 0, - 70, - 86, - 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, - 8, - 4, - 0, - 76, - 77, - 5, - 13, - 0, - 0, - 77, - 86, - 1, - 0, - 0, - 0, - 78, - 79, - 5, - 3, - 0, - 0, - 79, - 80, - 3, - 4, - 2, - 0, - 80, - 81, - 5, - 4, - 0, - 0, - 81, - 82, - 5, - 12, - 0, - 0, - 82, - 83, - 3, - 4, - 2, - 0, - 83, - 84, - 5, - 13, - 0, - 0, - 84, - 86, - 1, - 0, - 0, - 0, - 85, - 21, - 1, - 0, - 0, - 0, - 85, - 23, - 1, - 0, - 0, - 0, - 85, - 24, - 1, - 0, - 0, - 0, - 85, - 26, - 1, - 0, - 0, - 0, - 85, - 30, - 1, - 0, - 0, - 0, - 85, - 35, - 1, - 0, - 0, - 0, - 85, - 40, - 1, - 0, - 0, - 0, - 85, - 49, - 1, - 0, - 0, - 0, - 85, - 54, - 1, - 0, - 0, - 0, - 85, - 61, - 1, - 0, - 0, - 0, - 85, - 66, - 1, - 0, - 0, - 0, - 85, - 71, - 1, - 0, - 0, - 0, - 85, - 78, - 1, - 0, - 0, - 0, - 86, - 98, - 1, - 0, - 0, - 0, - 87, - 88, - 10, - 12, - 0, - 0, - 88, - 89, - 7, - 0, - 0, - 0, - 89, - 97, - 3, - 4, - 2, - 13, - 90, - 91, - 10, - 11, - 0, - 0, - 91, - 92, - 7, - 1, - 0, - 0, - 92, - 97, - 3, - 4, - 2, - 12, - 93, - 94, - 10, - 10, - 0, - 0, - 94, - 95, - 5, - 17, - 0, - 0, - 95, - 97, - 3, - 4, - 2, - 11, - 96, - 87, - 1, - 0, - 0, - 0, - 96, - 90, - 1, - 0, - 0, - 0, - 96, - 93, - 1, - 0, - 0, - 0, - 97, - 100, - 1, - 0, - 0, - 0, - 98, - 96, - 1, - 0, - 0, - 0, - 98, - 99, - 1, - 0, - 0, - 0, - 99, - 5, - 1, - 0, - 0, - 0, - 100, - 98, - 1, - 0, - 0, - 0, - 101, - 104, - 5, - 14, - 0, - 0, - 102, - 104, - 5, - 16, - 0, - 0, - 103, - 101, - 1, - 0, - 0, - 0, - 103, - 102, - 1, - 0, - 0, - 0, - 104, - 7, - 1, - 0, - 0, - 0, - 105, - 107, - 5, - 15, - 0, - 0, - 106, - 108, - 3, - 10, - 5, - 0, - 107, - 106, - 1, - 0, - 0, - 0, - 107, - 108, - 1, - 0, - 0, - 0, - 108, - 9, - 1, - 0, - 0, - 0, - 109, - 110, - 6, - 5, - -1, - 0, - 110, - 111, - 7, - 1, - 0, - 0, - 111, - 118, - 3, - 6, - 3, - 0, - 112, - 113, - 7, - 1, - 0, - 0, - 113, - 114, - 5, - 3, - 0, - 0, - 114, - 115, - 3, - 4, - 2, - 0, - 115, - 116, - 5, - 4, - 0, - 0, - 116, - 118, - 1, - 0, - 0, - 0, - 117, - 109, - 1, - 0, - 0, - 0, - 117, - 112, - 1, - 0, - 0, - 0, - 118, - 127, - 1, - 0, - 0, - 0, - 119, - 120, - 10, - 4, - 0, - 0, - 120, - 121, - 7, - 0, - 0, - 0, - 121, - 126, - 3, - 12, - 6, - 0, - 122, - 123, - 10, - 3, - 0, - 0, - 123, - 124, - 7, - 1, - 0, - 0, - 124, - 126, - 3, - 12, - 6, - 0, - 125, - 119, - 1, - 0, - 0, - 0, - 125, - 122, - 1, - 0, - 0, - 0, - 126, - 129, - 1, - 0, - 0, - 0, - 127, - 125, - 1, - 0, - 0, - 0, - 127, - 128, - 1, - 0, - 0, - 0, - 128, - 11, - 1, - 0, - 0, - 0, - 129, - 127, - 1, - 0, - 0, - 0, - 130, - 131, - 6, - 6, - -1, - 0, - 131, - 132, - 5, - 3, - 0, - 0, - 132, - 133, - 3, - 4, - 2, - 0, - 133, - 134, - 5, - 4, - 0, - 0, - 134, - 137, - 1, - 0, - 0, - 0, - 135, - 137, - 3, - 6, - 3, - 0, - 136, - 130, - 1, - 0, - 0, - 0, - 136, - 135, - 1, - 0, - 0, - 0, - 137, - 143, - 1, - 0, - 0, - 0, - 138, - 139, - 10, - 3, - 0, - 0, - 139, - 140, - 7, - 0, - 0, - 0, - 140, - 142, - 3, - 12, - 6, - 4, - 141, - 138, - 1, - 0, - 0, - 0, - 142, - 145, - 1, - 0, - 0, - 0, - 143, - 141, - 1, - 0, - 0, - 0, - 143, - 144, - 1, - 0, - 0, - 0, - 144, - 13, - 1, - 0, - 0, - 0, - 145, - 143, - 1, - 0, - 0, - 0, - 10, - 85, - 96, - 98, - 103, - 107, - 117, - 125, - 127, - 136, - 143, + 4,1,18,151,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,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,3,2,55,8,2,1,2,1,2,1,2,1,2,1,2, + 1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,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,82,8,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,5, + 2,93,8,2,10,2,12,2,96,9,2,1,3,1,3,1,3,5,3,101,8,3,10,3,12,3,104, + 9,3,1,4,1,4,3,4,108,8,4,1,5,1,5,3,5,112,8,5,1,6,1,6,1,6,1,6,1,6, + 1,6,1,6,1,6,3,6,122,8,6,1,6,1,6,1,6,1,6,1,6,1,6,5,6,130,8,6,10,6, + 12,6,133,9,6,1,7,1,7,1,7,1,7,1,7,1,7,3,7,141,8,7,1,7,1,7,1,7,5,7, + 146,8,7,10,7,12,7,149,9,7,1,7,0,3,4,12,14,8,0,2,4,6,8,10,12,14,0, + 2,1,0,5,6,2,0,2,2,7,7,165,0,16,1,0,0,0,2,20,1,0,0,0,4,81,1,0,0,0, + 6,97,1,0,0,0,8,107,1,0,0,0,10,109,1,0,0,0,12,121,1,0,0,0,14,140, + 1,0,0,0,16,17,5,16,0,0,17,18,5,1,0,0,18,19,5,16,0,0,19,1,1,0,0,0, + 20,21,3,4,2,0,21,22,5,0,0,1,22,3,1,0,0,0,23,24,6,2,-1,0,24,82,3, + 8,4,0,25,82,3,0,0,0,26,27,5,2,0,0,27,82,3,4,2,13,28,29,5,3,0,0,29, + 30,3,4,2,0,30,31,5,4,0,0,31,82,1,0,0,0,32,33,5,8,0,0,33,34,5,3,0, + 0,34,35,3,4,2,0,35,36,5,4,0,0,36,82,1,0,0,0,37,38,5,9,0,0,38,39, + 5,3,0,0,39,40,3,0,0,0,40,41,5,4,0,0,41,82,1,0,0,0,42,43,5,8,0,0, + 43,44,5,3,0,0,44,45,3,10,5,0,45,46,5,10,0,0,46,47,3,10,5,0,47,48, + 5,11,0,0,48,49,3,4,2,0,49,50,5,4,0,0,50,82,1,0,0,0,51,52,5,16,0, + 0,52,54,5,3,0,0,53,55,3,6,3,0,54,53,1,0,0,0,54,55,1,0,0,0,55,56, + 1,0,0,0,56,82,5,4,0,0,57,58,5,16,0,0,58,59,5,12,0,0,59,60,3,10,5, + 0,60,61,5,13,0,0,61,82,1,0,0,0,62,63,5,16,0,0,63,64,5,12,0,0,64, + 65,3,4,2,0,65,66,5,13,0,0,66,82,1,0,0,0,67,68,5,3,0,0,68,69,3,4, + 2,0,69,70,5,4,0,0,70,71,5,12,0,0,71,72,3,10,5,0,72,73,5,13,0,0,73, + 82,1,0,0,0,74,75,5,3,0,0,75,76,3,4,2,0,76,77,5,4,0,0,77,78,5,12, + 0,0,78,79,3,4,2,0,79,80,5,13,0,0,80,82,1,0,0,0,81,23,1,0,0,0,81, + 25,1,0,0,0,81,26,1,0,0,0,81,28,1,0,0,0,81,32,1,0,0,0,81,37,1,0,0, + 0,81,42,1,0,0,0,81,51,1,0,0,0,81,57,1,0,0,0,81,62,1,0,0,0,81,67, + 1,0,0,0,81,74,1,0,0,0,82,94,1,0,0,0,83,84,10,11,0,0,84,85,7,0,0, + 0,85,93,3,4,2,12,86,87,10,10,0,0,87,88,7,1,0,0,88,93,3,4,2,11,89, + 90,10,9,0,0,90,91,5,17,0,0,91,93,3,4,2,10,92,83,1,0,0,0,92,86,1, + 0,0,0,92,89,1,0,0,0,93,96,1,0,0,0,94,92,1,0,0,0,94,95,1,0,0,0,95, + 5,1,0,0,0,96,94,1,0,0,0,97,102,3,4,2,0,98,99,5,11,0,0,99,101,3,4, + 2,0,100,98,1,0,0,0,101,104,1,0,0,0,102,100,1,0,0,0,102,103,1,0,0, + 0,103,7,1,0,0,0,104,102,1,0,0,0,105,108,5,14,0,0,106,108,5,16,0, + 0,107,105,1,0,0,0,107,106,1,0,0,0,108,9,1,0,0,0,109,111,5,15,0,0, + 110,112,3,12,6,0,111,110,1,0,0,0,111,112,1,0,0,0,112,11,1,0,0,0, + 113,114,6,6,-1,0,114,115,7,1,0,0,115,122,3,8,4,0,116,117,7,1,0,0, + 117,118,5,3,0,0,118,119,3,4,2,0,119,120,5,4,0,0,120,122,1,0,0,0, + 121,113,1,0,0,0,121,116,1,0,0,0,122,131,1,0,0,0,123,124,10,4,0,0, + 124,125,7,0,0,0,125,130,3,14,7,0,126,127,10,3,0,0,127,128,7,1,0, + 0,128,130,3,14,7,0,129,123,1,0,0,0,129,126,1,0,0,0,130,133,1,0,0, + 0,131,129,1,0,0,0,131,132,1,0,0,0,132,13,1,0,0,0,133,131,1,0,0,0, + 134,135,6,7,-1,0,135,136,5,3,0,0,136,137,3,4,2,0,137,138,5,4,0,0, + 138,141,1,0,0,0,139,141,3,8,4,0,140,134,1,0,0,0,140,139,1,0,0,0, + 141,147,1,0,0,0,142,143,10,3,0,0,143,144,7,0,0,0,144,146,3,14,7, + 4,145,142,1,0,0,0,146,149,1,0,0,0,147,145,1,0,0,0,147,148,1,0,0, + 0,148,15,1,0,0,0,149,147,1,0,0,0,12,54,81,92,94,102,107,111,121, + 129,131,140,147 ] +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'", "'..'", "','", + "'['", "']'", "", "'t'" ] - symbolicNames = [ - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "NUMBER", - "TIME", - "IDENTIFIER", - "COMPARISON", - "WS", - ] + symbolicNames = [ "", "", "", "", + "", "", "", "", + "", "", "", "", + "", "", "NUMBER", "TIME", "IDENTIFIER", + "COMPARISON", "WS" ] RULE_portFieldExpr = 0 RULE_fullexpr = 1 RULE_expr = 2 - RULE_atom = 3 - RULE_shift = 4 - RULE_shift_expr = 5 - RULE_right_expr = 6 - - ruleNames = [ - "portFieldExpr", - "fullexpr", - "expr", - "atom", - "shift", - "shift_expr", - "right_expr", - ] + RULE_argList = 3 + RULE_atom = 4 + RULE_shift = 5 + RULE_shift_expr = 6 + RULE_right_expr = 7 + + ruleNames = [ "portFieldExpr", "fullexpr", "expr", "argList", "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 + TIME=15 + IDENTIFIER=16 + COMPARISON=17 + WS=18 + + 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: @@ -1441,22 +140,26 @@ 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: self.enterOuterAlt(localctx, 1) - self.state = 14 + self.state = 16 self.match(ExprParser.IDENTIFIER) - self.state = 15 + self.state = 17 self.match(ExprParser.T__0) - self.state = 16 + self.state = 18 self.match(ExprParser.IDENTIFIER) except RecognitionException as re: localctx.exception = re @@ -1466,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) @@ -1484,20 +187,24 @@ 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: self.enterOuterAlt(localctx, 1) - self.state = 18 + self.state = 20 self.expr(0) - self.state = 19 + self.state = 21 self.match(ExprParser.EOF) except RecognitionException as re: localctx.exception = re @@ -1507,339 +214,331 @@ 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 BinaryFunctionContext(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, 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, "visitBinaryFunction"): - return visitor.visitBinaryFunction(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 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 argList(self): + return self.getTypedRuleContext(ExprParser.ArgListContext,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 = 85 + self.state = 81 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 _prevctx = localctx - self.state = 22 + self.state = 24 self.atom() pass @@ -1847,7 +546,7 @@ def expr(self, _p: int = 0): localctx = ExprParser.PortFieldContext(self, localctx) self._ctx = localctx _prevctx = localctx - self.state = 23 + self.state = 25 self.portFieldExpr() pass @@ -1855,21 +554,21 @@ def expr(self, _p: int = 0): localctx = ExprParser.NegationContext(self, localctx) self._ctx = localctx _prevctx = localctx - self.state = 24 + self.state = 26 self.match(ExprParser.T__1) - self.state = 25 - self.expr(14) + self.state = 27 + self.expr(13) pass elif la_ == 4: localctx = ExprParser.ExpressionContext(self, localctx) self._ctx = localctx _prevctx = localctx - self.state = 26 + self.state = 28 self.match(ExprParser.T__2) - self.state = 27 + self.state = 29 self.expr(0) - self.state = 28 + self.state = 30 self.match(ExprParser.T__3) pass @@ -1877,13 +576,13 @@ def expr(self, _p: int = 0): localctx = ExprParser.AllTimeSumContext(self, localctx) self._ctx = localctx _prevctx = localctx - self.state = 30 + self.state = 32 self.match(ExprParser.T__7) - self.state = 31 + self.state = 33 self.match(ExprParser.T__2) - self.state = 32 + self.state = 34 self.expr(0) - self.state = 33 + self.state = 35 self.match(ExprParser.T__3) pass @@ -1891,13 +590,13 @@ def expr(self, _p: int = 0): localctx = ExprParser.PortFieldSumContext(self, localctx) self._ctx = localctx _prevctx = localctx - self.state = 35 + self.state = 37 self.match(ExprParser.T__8) - self.state = 36 + self.state = 38 self.match(ExprParser.T__2) - self.state = 37 + self.state = 39 self.portFieldExpr() - self.state = 38 + self.state = 40 self.match(ExprParser.T__3) pass @@ -1905,21 +604,21 @@ def expr(self, _p: int = 0): localctx = ExprParser.TimeSumContext(self, localctx) self._ctx = localctx _prevctx = localctx - self.state = 40 + self.state = 42 self.match(ExprParser.T__7) - self.state = 41 + self.state = 43 self.match(ExprParser.T__2) - self.state = 42 + self.state = 44 localctx.from_ = self.shift() - self.state = 43 + self.state = 45 self.match(ExprParser.T__9) - self.state = 44 + self.state = 46 localctx.to = self.shift() - self.state = 45 + self.state = 47 self.match(ExprParser.T__10) - self.state = 46 + self.state = 48 self.expr(0) - self.state = 47 + self.state = 49 self.match(ExprParser.T__3) pass @@ -1927,185 +626,154 @@ def expr(self, _p: int = 0): localctx = ExprParser.FunctionContext(self, localctx) self._ctx = localctx _prevctx = localctx - self.state = 49 - self.match(ExprParser.IDENTIFIER) - self.state = 50 - self.match(ExprParser.T__2) self.state = 51 - self.expr(0) - self.state = 52 - self.match(ExprParser.T__3) - pass - - elif la_ == 9: - localctx = ExprParser.BinaryFunctionContext(self, localctx) - self._ctx = localctx - _prevctx = localctx - self.state = 54 self.match(ExprParser.IDENTIFIER) - self.state = 55 + self.state = 52 self.match(ExprParser.T__2) + self.state = 54 + self._errHandler.sync(self) + _la = self._input.LA(1) + if (((_la) & ~0x3f) == 0 and ((1 << _la) & 82700) != 0): + self.state = 53 + self.argList() + + self.state = 56 - self.expr(0) - self.state = 57 - self.match(ExprParser.T__10) - self.state = 58 - self.expr(0) - self.state = 59 self.match(ExprParser.T__3) pass - elif la_ == 10: + elif la_ == 9: localctx = ExprParser.TimeShiftContext(self, localctx) self._ctx = localctx _prevctx = localctx - self.state = 61 + self.state = 57 self.match(ExprParser.IDENTIFIER) - self.state = 62 + self.state = 58 self.match(ExprParser.T__11) - self.state = 63 + self.state = 59 self.shift() - self.state = 64 + self.state = 60 self.match(ExprParser.T__12) pass - elif la_ == 11: + elif la_ == 10: localctx = ExprParser.TimeIndexContext(self, localctx) self._ctx = localctx _prevctx = localctx - self.state = 66 + self.state = 62 self.match(ExprParser.IDENTIFIER) - self.state = 67 + self.state = 63 self.match(ExprParser.T__11) - self.state = 68 + self.state = 64 self.expr(0) - self.state = 69 + self.state = 65 self.match(ExprParser.T__12) pass - elif la_ == 12: + elif la_ == 11: localctx = ExprParser.TimeShiftExprContext(self, localctx) self._ctx = localctx _prevctx = localctx - self.state = 71 + self.state = 67 self.match(ExprParser.T__2) - self.state = 72 + self.state = 68 self.expr(0) - self.state = 73 + self.state = 69 self.match(ExprParser.T__3) - self.state = 74 + self.state = 70 self.match(ExprParser.T__11) - self.state = 75 + self.state = 71 self.shift() - self.state = 76 + self.state = 72 self.match(ExprParser.T__12) pass - elif la_ == 13: + elif la_ == 12: localctx = ExprParser.TimeIndexExprContext(self, localctx) self._ctx = localctx _prevctx = localctx - self.state = 78 + self.state = 74 self.match(ExprParser.T__2) - self.state = 79 + self.state = 75 self.expr(0) - self.state = 80 + self.state = 76 self.match(ExprParser.T__3) - self.state = 81 + self.state = 77 self.match(ExprParser.T__11) - self.state = 82 + self.state = 78 self.expr(0) - self.state = 83 + self.state = 79 self.match(ExprParser.T__12) pass + self._ctx.stop = self._input.LT(-1) - self.state = 98 + self.state = 94 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 = 96 + self.state = 92 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 = 87 - if not self.precpred(self._ctx, 12): + localctx = ExprParser.MuldivContext(self, ExprParser.ExprContext(self, _parentctx, _parentState)) + self.pushNewRecursionContext(localctx, _startState, self.RULE_expr) + self.state = 83 + if not self.precpred(self._ctx, 11): from antlr4.error.Errors import FailedPredicateException - - raise FailedPredicateException( - self, "self.precpred(self._ctx, 12)" - ) - self.state = 88 + raise FailedPredicateException(self, "self.precpred(self._ctx, 11)") + self.state = 84 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 = 89 - self.expr(13) + self.state = 85 + self.expr(12) pass elif la_ == 2: - localctx = ExprParser.AddsubContext( - self, ExprParser.ExprContext(self, _parentctx, _parentState) - ) - self.pushNewRecursionContext( - localctx, _startState, self.RULE_expr - ) - self.state = 90 - if not self.precpred(self._ctx, 11): + localctx = ExprParser.AddsubContext(self, ExprParser.ExprContext(self, _parentctx, _parentState)) + self.pushNewRecursionContext(localctx, _startState, self.RULE_expr) + self.state = 86 + if not self.precpred(self._ctx, 10): from antlr4.error.Errors import FailedPredicateException - - raise FailedPredicateException( - self, "self.precpred(self._ctx, 11)" - ) - self.state = 91 + raise FailedPredicateException(self, "self.precpred(self._ctx, 10)") + self.state = 87 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 = 92 - self.expr(12) + self.state = 88 + self.expr(11) pass elif la_ == 3: - localctx = ExprParser.ComparisonContext( - self, ExprParser.ExprContext(self, _parentctx, _parentState) - ) - self.pushNewRecursionContext( - localctx, _startState, self.RULE_expr - ) - self.state = 93 - if not self.precpred(self._ctx, 10): + localctx = ExprParser.ComparisonContext(self, ExprParser.ExprContext(self, _parentctx, _parentState)) + self.pushNewRecursionContext(localctx, _startState, self.RULE_expr) + self.state = 89 + if not self.precpred(self._ctx, 9): from antlr4.error.Errors import FailedPredicateException - - raise FailedPredicateException( - self, "self.precpred(self._ctx, 10)" - ) - self.state = 94 + raise FailedPredicateException(self, "self.precpred(self._ctx, 9)") + self.state = 90 self.match(ExprParser.COMPARISON) - self.state = 95 - self.expr(11) + self.state = 91 + self.expr(10) pass - self.state = 100 + + self.state = 96 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 @@ -2115,70 +783,131 @@ def expr(self, _p: int = 0): self.unrollRecursionContexts(_parentctx) return localctx + + class ArgListContext(ParserRuleContext): + __slots__ = 'parser' + + def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): + super().__init__(parent, invokingState) + self.parser = parser + + def expr(self, i:int=None): + if i is None: + return self.getTypedRuleContexts(ExprParser.ExprContext) + else: + return self.getTypedRuleContext(ExprParser.ExprContext,i) + + + def getRuleIndex(self): + return ExprParser.RULE_argList + + def accept(self, visitor:ParseTreeVisitor): + if hasattr( visitor, "visitArgList" ): + return visitor.visitArgList(self) + else: + return visitor.visitChildren(self) + + + + + def argList(self): + + localctx = ExprParser.ArgListContext(self, self._ctx, self.state) + self.enterRule(localctx, 6, self.RULE_argList) + self._la = 0 # Token type + try: + self.enterOuterAlt(localctx, 1) + self.state = 97 + self.expr(0) + self.state = 102 + self._errHandler.sync(self) + _la = self._input.LA(1) + while _la==11: + self.state = 98 + self.match(ExprParser.T__10) + self.state = 99 + self.expr(0) + self.state = 104 + self._errHandler.sync(self) + _la = self._input.LA(1) + + except RecognitionException as re: + localctx.exception = re + self._errHandler.reportError(self, re) + self._errHandler.recover(self, re) + finally: + self.exitRule() + 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) + self.enterRule(localctx, 8, self.RULE_atom) try: - self.state = 103 + self.state = 107 self._errHandler.sync(self) token = self._input.LA(1) if token in [14]: localctx = ExprParser.NumberContext(self, localctx) self.enterOuterAlt(localctx, 1) - self.state = 101 + self.state = 105 self.match(ExprParser.NUMBER) pass elif token in [16]: localctx = ExprParser.IdentifierContext(self, localctx) self.enterOuterAlt(localctx, 2) - self.state = 102 + self.state = 106 self.match(ExprParser.IDENTIFIER) pass else: @@ -2192,12 +921,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 @@ -2205,32 +933,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.enterRule(localctx, 10, self.RULE_shift) + self._la = 0 # Token type try: self.enterOuterAlt(localctx, 1) - self.state = 105 + self.state = 109 self.match(ExprParser.TIME) - self.state = 107 + self.state = 111 self._errHandler.sync(self) _la = self._input.LA(1) - if _la == 2 or _la == 7: - self.state = 106 + if _la==2 or _la==7: + self.state = 110 self.shift_expr(0) + except RecognitionException as re: localctx.exception = re self._errHandler.reportError(self, re) @@ -2239,122 +973,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 + _startState = 12 + self.enterRecursionRule(localctx, 12, self.RULE_shift_expr, _p) + self._la = 0 # Token type try: self.enterOuterAlt(localctx, 1) - self.state = 117 + self.state = 121 self._errHandler.sync(self) - la_ = self._interp.adaptivePredict(self._input, 5, self._ctx) + la_ = self._interp.adaptivePredict(self._input,7,self._ctx) if la_ == 1: localctx = ExprParser.SignedAtomContext(self, localctx) self._ctx = localctx _prevctx = localctx - self.state = 110 + self.state = 114 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 = 111 + self.state = 115 self.atom() pass @@ -2362,95 +1103,77 @@ def shift_expr(self, _p: int = 0): localctx = ExprParser.SignedExpressionContext(self, localctx) self._ctx = localctx _prevctx = localctx - self.state = 112 + self.state = 116 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 = 113 + self.state = 117 self.match(ExprParser.T__2) - self.state = 114 + self.state = 118 self.expr(0) - self.state = 115 + self.state = 119 self.match(ExprParser.T__3) pass + self._ctx.stop = self._input.LT(-1) - self.state = 127 + self.state = 131 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,9,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 = 125 + self.state = 129 self._errHandler.sync(self) - la_ = self._interp.adaptivePredict(self._input, 6, self._ctx) + la_ = self._interp.adaptivePredict(self._input,8,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 = 119 + localctx = ExprParser.ShiftMuldivContext(self, ExprParser.Shift_exprContext(self, _parentctx, _parentState)) + self.pushNewRecursionContext(localctx, _startState, self.RULE_shift_expr) + self.state = 123 if not self.precpred(self._ctx, 4): from antlr4.error.Errors import FailedPredicateException - - raise FailedPredicateException( - self, "self.precpred(self._ctx, 4)" - ) - self.state = 120 + raise FailedPredicateException(self, "self.precpred(self._ctx, 4)") + self.state = 124 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 = 121 + self.state = 125 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 = 122 + localctx = ExprParser.ShiftAddsubContext(self, ExprParser.Shift_exprContext(self, _parentctx, _parentState)) + self.pushNewRecursionContext(localctx, _startState, self.RULE_shift_expr) + self.state = 126 if not self.precpred(self._ctx, 3): from antlr4.error.Errors import FailedPredicateException - - raise FailedPredicateException( - self, "self.precpred(self._ctx, 3)" - ) - self.state = 123 + raise FailedPredicateException(self, "self.precpred(self._ctx, 3)") + self.state = 127 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 = 124 + self.state = 128 self.right_expr(0) pass - self.state = 129 + + self.state = 133 self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input, 7, self._ctx) + _alt = self._interp.adaptivePredict(self._input,9,self._ctx) except RecognitionException as re: localctx.exception = re @@ -2460,84 +1183,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 + _startState = 14 + self.enterRecursionRule(localctx, 14, self.RULE_right_expr, _p) + self._la = 0 # Token type try: self.enterOuterAlt(localctx, 1) - self.state = 136 + self.state = 140 self._errHandler.sync(self) token = self._input.LA(1) if token in [3]: @@ -2545,59 +1274,51 @@ def right_expr(self, _p: int = 0): self._ctx = localctx _prevctx = localctx - self.state = 131 + self.state = 135 self.match(ExprParser.T__2) - self.state = 132 + self.state = 136 self.expr(0) - self.state = 133 + self.state = 137 self.match(ExprParser.T__3) pass elif token in [14, 16]: localctx = ExprParser.RightAtomContext(self, localctx) self._ctx = localctx _prevctx = localctx - self.state = 135 + self.state = 139 self.atom() pass else: raise NoViableAltException(self) self._ctx.stop = self._input.LT(-1) - self.state = 143 + self.state = 147 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,11,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 = 138 + localctx = ExprParser.RightMuldivContext(self, ExprParser.Right_exprContext(self, _parentctx, _parentState)) + self.pushNewRecursionContext(localctx, _startState, self.RULE_right_expr) + self.state = 142 if not self.precpred(self._ctx, 3): from antlr4.error.Errors import FailedPredicateException - - raise FailedPredicateException( - self, "self.precpred(self._ctx, 3)" - ) - self.state = 139 + raise FailedPredicateException(self, "self.precpred(self._ctx, 3)") + self.state = 143 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 = 140 - self.right_expr(4) - self.state = 145 + self.state = 144 + self.right_expr(4) + self.state = 149 self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input, 9, self._ctx) + _alt = self._interp.adaptivePredict(self._input,11,self._ctx) except RecognitionException as re: localctx.exception = re @@ -2607,35 +1328,47 @@ 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 - self._predicates[5] = self.shift_expr_sempred - self._predicates[6] = self.right_expr_sempred + self._predicates[6] = self.shift_expr_sempred + self._predicates[7] = self.right_expr_sempred pred = self._predicates.get(ruleIndex, None) if pred is None: raise Exception("No predicate with index:" + str(ruleIndex)) 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, 11) + + + if predIndex == 1: + return self.precpred(self._ctx, 10) + + + 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) + - 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 68a41ab8..2c53bcd4 100644 --- a/src/gems/expression/parsing/antlr/ExprVisitor.py +++ b/src/gems/expression/parsing/antlr/ExprVisitor.py @@ -1,6 +1,5 @@ -# Generated from /home/user/GemsPy/grammar/Expr.g4 by ANTLR 4.13.2 +# 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#binaryFunction. - def visitBinaryFunction(self, ctx: ExprParser.BinaryFunctionContext): - 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#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#argList. + def visitArgList(self, ctx:ExprParser.ArgListContext): 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 6d4243f4..d090c872 100644 --- a/src/gems/expression/parsing/parse_expression.py +++ b/src/gems/expression/parsing/parse_expression.py @@ -162,25 +162,23 @@ def visitAllTimeSum(self, ctx: ExprParser.AllTimeSumContext) -> ExpressionNode: # Visit a parse tree produced by ExprParser#function. def visitFunction(self, ctx: ExprParser.FunctionContext) -> ExpressionNode: function_name: str = ctx.IDENTIFIER().getText() # type: ignore - operand: ExpressionNode = ctx.expr().accept(self) # type: ignore - fn = _FUNCTIONS.get(function_name, None) - if fn is None: - raise ValueError(f"Encountered invalid function name {function_name}") - return fn(operand) - - # Visit a parse tree produced by ExprParser#binaryFunction. - def visitBinaryFunction( - self, ctx: ExprParser.BinaryFunctionContext - ) -> ExpressionNode: - function_name: str = ctx.IDENTIFIER().getText() # type: ignore - left: ExpressionNode = ctx.expr(0).accept(self) # type: ignore - right: ExpressionNode = ctx.expr(1).accept(self) # type: ignore - fn = _BINARY_FUNCTIONS.get(function_name, None) - if fn is None: - raise ValueError( - f"Encountered invalid binary function name {function_name}" - ) - return fn(left, right) + arg_list = ctx.argList() # type: ignore + args: list[ExpressionNode] = ( + [expr.accept(self) for expr in arg_list.expr()] # type: ignore + if arg_list is not None + else [] + ) + if function_name in _FUNCTIONS: + if len(args) != 1: + raise ValueError( + f"Function {function_name} requires exactly 1 argument, got {len(args)}" + ) + return _FUNCTIONS[function_name](args[0]) + if function_name == "max": + return maximum(*args) + if function_name == "min": + return minimum(*args) + raise ValueError(f"Encountered invalid function name {function_name}") # Visit a parse tree produced by ExprParser#shift. def visitShift(self, ctx: ExprParser.ShiftContext) -> ExpressionNode: @@ -255,11 +253,6 @@ def visitRightAtom(self, ctx: ExprParser.RightAtomContext) -> ExpressionNode: "ceil": ExpressionNode.ceil, } -_BINARY_FUNCTIONS = { - "max": maximum, - "min": minimum, -} - class AntaresParseException(Exception): pass diff --git a/src/gems/expression/print.py b/src/gems/expression/print.py index 36583f86..d819185c 100644 --- a/src/gems/expression/print.py +++ b/src/gems/expression/print.py @@ -141,10 +141,10 @@ def ceil(self, node: CeilNode) -> str: return f"ceil({visit(node.operand, self)})" def maximum(self, node: MaxNode) -> str: - return f"max({visit(node.left, self)}, {visit(node.right, self)})" + return "max(" + ", ".join(visit(op, self) for op in node.operands) + ")" def minimum(self, node: MinNode) -> str: - return f"min({visit(node.left, self)}, {visit(node.right, self)})" + return "min(" + ", ".join(visit(op, self) for op in node.operands) + ")" def print_expr(expression: ExpressionNode) -> str: diff --git a/src/gems/model/port.py b/src/gems/model/port.py index 9eaaed09..a13bce35 100644 --- a/src/gems/model/port.py +++ b/src/gems/model/port.py @@ -176,10 +176,12 @@ def ceil(self, node: CeilNode) -> None: visit(node.operand, self) def maximum(self, node: MaxNode) -> None: - self._visit_binary_op(node) + for op in node.operands: + visit(op, self) def minimum(self, node: MinNode) -> None: - self._visit_binary_op(node) + for op in node.operands: + visit(op, self) def port_field_aggregator(self, node: PortFieldAggregatorNode) -> None: raise ValueError("Port definition cannot contain port field aggregation.") diff --git a/tests/unittests/expressions/parsing/test_expression_parsing.py b/tests/unittests/expressions/parsing/test_expression_parsing.py index 5998116f..7287bed3 100644 --- a/tests/unittests/expressions/parsing/test_expression_parsing.py +++ b/tests/unittests/expressions/parsing/test_expression_parsing.py @@ -155,6 +155,18 @@ "max(0, ceil(p/q))", maximum(literal(0), (param("p") / param("q")).ceil()), ), + ( + {}, + {"a", "b", "c"}, + "max(a, b, c)", + maximum(param("a"), param("b"), param("c")), + ), + ( + {}, + {"a", "b", "c"}, + "min(a, b, c)", + minimum(param("a"), param("b"), param("c")), + ), ], ) def test_parsing_visitor( diff --git a/tests/unittests/expressions/visitor/test_degree.py b/tests/unittests/expressions/visitor/test_degree.py index 0df558c1..e2b3b492 100644 --- a/tests/unittests/expressions/visitor/test_degree.py +++ b/tests/unittests/expressions/visitor/test_degree.py @@ -57,6 +57,11 @@ def test_max_min_degree() -> None: assert visit(maximum(x, p), ExpressionDegreeVisitor()) == math.inf assert visit(minimum(p, x), ExpressionDegreeVisitor()) == math.inf assert visit(maximum(x, x), ExpressionDegreeVisitor()) == math.inf + # variadic (3+ operands) + assert visit(maximum(p, q, param("r")), ExpressionDegreeVisitor()) == 0 + assert visit(minimum(p, q, param("r")), ExpressionDegreeVisitor()) == 0 + assert visit(maximum(p, q, x), ExpressionDegreeVisitor()) == math.inf + assert visit(minimum(p, x, q), ExpressionDegreeVisitor()) == math.inf @pytest.mark.xfail(reason="Degree simplification not implemented") diff --git a/tests/unittests/expressions/visitor/test_evaluation.py b/tests/unittests/expressions/visitor/test_evaluation.py index 5566619c..efd110ff 100644 --- a/tests/unittests/expressions/visitor/test_evaluation.py +++ b/tests/unittests/expressions/visitor/test_evaluation.py @@ -130,3 +130,10 @@ def test_floor_ceil_max_min() -> None: maximum(literal(0), param("q")), EvaluationVisitor(context) ) == pytest.approx(1.3) assert visit(maximum(literal(0), -param("p")), EvaluationVisitor(context)) == 0.0 + # variadic (3+ operands) + assert visit( + maximum(param("p"), param("q"), literal(5.0)), EvaluationVisitor(context) + ) == pytest.approx(5.0) + assert visit( + minimum(param("p"), param("q"), literal(5.0)), EvaluationVisitor(context) + ) == pytest.approx(1.3) diff --git a/tests/unittests/expressions/visitor/test_printer.py b/tests/unittests/expressions/visitor/test_printer.py index f9cc82b1..34510760 100644 --- a/tests/unittests/expressions/visitor/test_printer.py +++ b/tests/unittests/expressions/visitor/test_printer.py @@ -36,3 +36,6 @@ def test_floor_ceil_max_min_printer() -> None: visit(maximum(param("a"), (p / q).ceil()), PrinterVisitor()) == "max(a, ceil((p / q)))" ) + # variadic (3+ operands) + assert visit(maximum(p, q, param("r")), PrinterVisitor()) == "max(p, q, r)" + assert visit(minimum(p, q, param("r")), PrinterVisitor()) == "min(p, q, r)" From eb14e2b831ddcc282af905dec7824b3f808923dd Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 20 Mar 2026 16:06:41 +0000 Subject: [PATCH 11/12] fix(ci): fix import sort order in regenerated ANTLR files isort requires stdlib imports (sys, io) before third-party (antlr4) in the generated ExprLexer.py, ExprParser.py, and ExprVisitor.py. https://claude.ai/code/session_01LLG7eSxsw3XGULyah6ZiB3 --- src/gems/expression/parsing/antlr/ExprLexer.py | 6 ++++-- src/gems/expression/parsing/antlr/ExprParser.py | 6 ++++-- src/gems/expression/parsing/antlr/ExprVisitor.py | 1 + 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/gems/expression/parsing/antlr/ExprLexer.py b/src/gems/expression/parsing/antlr/ExprLexer.py index 71a27deb..e5f4e83e 100644 --- a/src/gems/expression/parsing/antlr/ExprLexer.py +++ b/src/gems/expression/parsing/antlr/ExprLexer.py @@ -1,7 +1,9 @@ # Generated from Expr.g4 by ANTLR 4.13.2 -from antlr4 import * -from io import StringIO import sys +from io import StringIO + +from antlr4 import * + if sys.version_info[1] > 5: from typing import TextIO else: diff --git a/src/gems/expression/parsing/antlr/ExprParser.py b/src/gems/expression/parsing/antlr/ExprParser.py index c3908e61..60bd86ce 100644 --- a/src/gems/expression/parsing/antlr/ExprParser.py +++ b/src/gems/expression/parsing/antlr/ExprParser.py @@ -1,8 +1,10 @@ # Generated from Expr.g4 by ANTLR 4.13.2 # encoding: utf-8 -from antlr4 import * -from io import StringIO import sys +from io import StringIO + +from antlr4 import * + if sys.version_info[1] > 5: from typing import TextIO else: diff --git a/src/gems/expression/parsing/antlr/ExprVisitor.py b/src/gems/expression/parsing/antlr/ExprVisitor.py index 2c53bcd4..aedf8651 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: From 5b18533f5ba8b8c8a6fef5febe6a0535b67a1874 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 20 Mar 2026 16:11:44 +0000 Subject: [PATCH 12/12] fix(ci): apply black formatting to regenerated ANTLR files Black reformats ExprLexer.py, ExprParser.py and ExprVisitor.py: spaces after colons in type hints, one-item-per-line lists, extra blank lines between class/function definitions. https://claude.ai/code/session_01LLG7eSxsw3XGULyah6ZiB3 --- .../expression/parsing/antlr/ExprLexer.py | 1237 +++++++++- .../expression/parsing/antlr/ExprParser.py | 2193 +++++++++++++---- .../expression/parsing/antlr/ExprVisitor.py | 88 +- 3 files changed, 2965 insertions(+), 553 deletions(-) diff --git a/src/gems/expression/parsing/antlr/ExprLexer.py b/src/gems/expression/parsing/antlr/ExprLexer.py index e5f4e83e..60c2d135 100644 --- a/src/gems/expression/parsing/antlr/ExprLexer.py +++ b/src/gems/expression/parsing/antlr/ExprLexer.py @@ -12,56 +12,1141 @@ 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, + 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, ] -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 @@ -82,29 +1167,61 @@ class ExprLexer(Lexer): COMPARISON = 17 WS = 18 - channelNames = [ u"DEFAULT_TOKEN_CHANNEL", u"HIDDEN" ] + channelNames = ["DEFAULT_TOKEN_CHANNEL", "HIDDEN"] - modeNames = [ "DEFAULT_MODE" ] + modeNames = ["DEFAULT_MODE"] - literalNames = [ "", - "'.'", "'-'", "'('", "')'", "'/'", "'*'", "'+'", "'sum'", "'sum_connections'", - "'..'", "','", "'['", "']'", "'t'" ] + literalNames = [ + "", + "'.'", + "'-'", + "'('", + "')'", + "'/'", + "'*'", + "'+'", + "'sum'", + "'sum_connections'", + "'..'", + "','", + "'['", + "']'", + "'t'", + ] - symbolicNames = [ "", - "NUMBER", "TIME", "IDENTIFIER", "COMPARISON", "WS" ] + symbolicNames = ["", "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", "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", + ] 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 60bd86ce..bdc68001 100644 --- a/src/gems/expression/parsing/antlr/ExprParser.py +++ b/src/gems/expression/parsing/antlr/ExprParser.py @@ -6,84 +6,1415 @@ from antlr4 import * 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,151,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,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,3,2,55,8,2,1,2,1,2,1,2,1,2,1,2, - 1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,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,82,8,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,5, - 2,93,8,2,10,2,12,2,96,9,2,1,3,1,3,1,3,5,3,101,8,3,10,3,12,3,104, - 9,3,1,4,1,4,3,4,108,8,4,1,5,1,5,3,5,112,8,5,1,6,1,6,1,6,1,6,1,6, - 1,6,1,6,1,6,3,6,122,8,6,1,6,1,6,1,6,1,6,1,6,1,6,5,6,130,8,6,10,6, - 12,6,133,9,6,1,7,1,7,1,7,1,7,1,7,1,7,3,7,141,8,7,1,7,1,7,1,7,5,7, - 146,8,7,10,7,12,7,149,9,7,1,7,0,3,4,12,14,8,0,2,4,6,8,10,12,14,0, - 2,1,0,5,6,2,0,2,2,7,7,165,0,16,1,0,0,0,2,20,1,0,0,0,4,81,1,0,0,0, - 6,97,1,0,0,0,8,107,1,0,0,0,10,109,1,0,0,0,12,121,1,0,0,0,14,140, - 1,0,0,0,16,17,5,16,0,0,17,18,5,1,0,0,18,19,5,16,0,0,19,1,1,0,0,0, - 20,21,3,4,2,0,21,22,5,0,0,1,22,3,1,0,0,0,23,24,6,2,-1,0,24,82,3, - 8,4,0,25,82,3,0,0,0,26,27,5,2,0,0,27,82,3,4,2,13,28,29,5,3,0,0,29, - 30,3,4,2,0,30,31,5,4,0,0,31,82,1,0,0,0,32,33,5,8,0,0,33,34,5,3,0, - 0,34,35,3,4,2,0,35,36,5,4,0,0,36,82,1,0,0,0,37,38,5,9,0,0,38,39, - 5,3,0,0,39,40,3,0,0,0,40,41,5,4,0,0,41,82,1,0,0,0,42,43,5,8,0,0, - 43,44,5,3,0,0,44,45,3,10,5,0,45,46,5,10,0,0,46,47,3,10,5,0,47,48, - 5,11,0,0,48,49,3,4,2,0,49,50,5,4,0,0,50,82,1,0,0,0,51,52,5,16,0, - 0,52,54,5,3,0,0,53,55,3,6,3,0,54,53,1,0,0,0,54,55,1,0,0,0,55,56, - 1,0,0,0,56,82,5,4,0,0,57,58,5,16,0,0,58,59,5,12,0,0,59,60,3,10,5, - 0,60,61,5,13,0,0,61,82,1,0,0,0,62,63,5,16,0,0,63,64,5,12,0,0,64, - 65,3,4,2,0,65,66,5,13,0,0,66,82,1,0,0,0,67,68,5,3,0,0,68,69,3,4, - 2,0,69,70,5,4,0,0,70,71,5,12,0,0,71,72,3,10,5,0,72,73,5,13,0,0,73, - 82,1,0,0,0,74,75,5,3,0,0,75,76,3,4,2,0,76,77,5,4,0,0,77,78,5,12, - 0,0,78,79,3,4,2,0,79,80,5,13,0,0,80,82,1,0,0,0,81,23,1,0,0,0,81, - 25,1,0,0,0,81,26,1,0,0,0,81,28,1,0,0,0,81,32,1,0,0,0,81,37,1,0,0, - 0,81,42,1,0,0,0,81,51,1,0,0,0,81,57,1,0,0,0,81,62,1,0,0,0,81,67, - 1,0,0,0,81,74,1,0,0,0,82,94,1,0,0,0,83,84,10,11,0,0,84,85,7,0,0, - 0,85,93,3,4,2,12,86,87,10,10,0,0,87,88,7,1,0,0,88,93,3,4,2,11,89, - 90,10,9,0,0,90,91,5,17,0,0,91,93,3,4,2,10,92,83,1,0,0,0,92,86,1, - 0,0,0,92,89,1,0,0,0,93,96,1,0,0,0,94,92,1,0,0,0,94,95,1,0,0,0,95, - 5,1,0,0,0,96,94,1,0,0,0,97,102,3,4,2,0,98,99,5,11,0,0,99,101,3,4, - 2,0,100,98,1,0,0,0,101,104,1,0,0,0,102,100,1,0,0,0,102,103,1,0,0, - 0,103,7,1,0,0,0,104,102,1,0,0,0,105,108,5,14,0,0,106,108,5,16,0, - 0,107,105,1,0,0,0,107,106,1,0,0,0,108,9,1,0,0,0,109,111,5,15,0,0, - 110,112,3,12,6,0,111,110,1,0,0,0,111,112,1,0,0,0,112,11,1,0,0,0, - 113,114,6,6,-1,0,114,115,7,1,0,0,115,122,3,8,4,0,116,117,7,1,0,0, - 117,118,5,3,0,0,118,119,3,4,2,0,119,120,5,4,0,0,120,122,1,0,0,0, - 121,113,1,0,0,0,121,116,1,0,0,0,122,131,1,0,0,0,123,124,10,4,0,0, - 124,125,7,0,0,0,125,130,3,14,7,0,126,127,10,3,0,0,127,128,7,1,0, - 0,128,130,3,14,7,0,129,123,1,0,0,0,129,126,1,0,0,0,130,133,1,0,0, - 0,131,129,1,0,0,0,131,132,1,0,0,0,132,13,1,0,0,0,133,131,1,0,0,0, - 134,135,6,7,-1,0,135,136,5,3,0,0,136,137,3,4,2,0,137,138,5,4,0,0, - 138,141,1,0,0,0,139,141,3,8,4,0,140,134,1,0,0,0,140,139,1,0,0,0, - 141,147,1,0,0,0,142,143,10,3,0,0,143,144,7,0,0,0,144,146,3,14,7, - 4,145,142,1,0,0,0,146,149,1,0,0,0,147,145,1,0,0,0,147,148,1,0,0, - 0,148,15,1,0,0,0,149,147,1,0,0,0,12,54,81,92,94,102,107,111,121, - 129,131,140,147 + 4, + 1, + 18, + 151, + 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, + 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, + 3, + 2, + 55, + 8, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 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, + 82, + 8, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 5, + 2, + 93, + 8, + 2, + 10, + 2, + 12, + 2, + 96, + 9, + 2, + 1, + 3, + 1, + 3, + 1, + 3, + 5, + 3, + 101, + 8, + 3, + 10, + 3, + 12, + 3, + 104, + 9, + 3, + 1, + 4, + 1, + 4, + 3, + 4, + 108, + 8, + 4, + 1, + 5, + 1, + 5, + 3, + 5, + 112, + 8, + 5, + 1, + 6, + 1, + 6, + 1, + 6, + 1, + 6, + 1, + 6, + 1, + 6, + 1, + 6, + 1, + 6, + 3, + 6, + 122, + 8, + 6, + 1, + 6, + 1, + 6, + 1, + 6, + 1, + 6, + 1, + 6, + 1, + 6, + 5, + 6, + 130, + 8, + 6, + 10, + 6, + 12, + 6, + 133, + 9, + 6, + 1, + 7, + 1, + 7, + 1, + 7, + 1, + 7, + 1, + 7, + 1, + 7, + 3, + 7, + 141, + 8, + 7, + 1, + 7, + 1, + 7, + 1, + 7, + 5, + 7, + 146, + 8, + 7, + 10, + 7, + 12, + 7, + 149, + 9, + 7, + 1, + 7, + 0, + 3, + 4, + 12, + 14, + 8, + 0, + 2, + 4, + 6, + 8, + 10, + 12, + 14, + 0, + 2, + 1, + 0, + 5, + 6, + 2, + 0, + 2, + 2, + 7, + 7, + 165, + 0, + 16, + 1, + 0, + 0, + 0, + 2, + 20, + 1, + 0, + 0, + 0, + 4, + 81, + 1, + 0, + 0, + 0, + 6, + 97, + 1, + 0, + 0, + 0, + 8, + 107, + 1, + 0, + 0, + 0, + 10, + 109, + 1, + 0, + 0, + 0, + 12, + 121, + 1, + 0, + 0, + 0, + 14, + 140, + 1, + 0, + 0, + 0, + 16, + 17, + 5, + 16, + 0, + 0, + 17, + 18, + 5, + 1, + 0, + 0, + 18, + 19, + 5, + 16, + 0, + 0, + 19, + 1, + 1, + 0, + 0, + 0, + 20, + 21, + 3, + 4, + 2, + 0, + 21, + 22, + 5, + 0, + 0, + 1, + 22, + 3, + 1, + 0, + 0, + 0, + 23, + 24, + 6, + 2, + -1, + 0, + 24, + 82, + 3, + 8, + 4, + 0, + 25, + 82, + 3, + 0, + 0, + 0, + 26, + 27, + 5, + 2, + 0, + 0, + 27, + 82, + 3, + 4, + 2, + 13, + 28, + 29, + 5, + 3, + 0, + 0, + 29, + 30, + 3, + 4, + 2, + 0, + 30, + 31, + 5, + 4, + 0, + 0, + 31, + 82, + 1, + 0, + 0, + 0, + 32, + 33, + 5, + 8, + 0, + 0, + 33, + 34, + 5, + 3, + 0, + 0, + 34, + 35, + 3, + 4, + 2, + 0, + 35, + 36, + 5, + 4, + 0, + 0, + 36, + 82, + 1, + 0, + 0, + 0, + 37, + 38, + 5, + 9, + 0, + 0, + 38, + 39, + 5, + 3, + 0, + 0, + 39, + 40, + 3, + 0, + 0, + 0, + 40, + 41, + 5, + 4, + 0, + 0, + 41, + 82, + 1, + 0, + 0, + 0, + 42, + 43, + 5, + 8, + 0, + 0, + 43, + 44, + 5, + 3, + 0, + 0, + 44, + 45, + 3, + 10, + 5, + 0, + 45, + 46, + 5, + 10, + 0, + 0, + 46, + 47, + 3, + 10, + 5, + 0, + 47, + 48, + 5, + 11, + 0, + 0, + 48, + 49, + 3, + 4, + 2, + 0, + 49, + 50, + 5, + 4, + 0, + 0, + 50, + 82, + 1, + 0, + 0, + 0, + 51, + 52, + 5, + 16, + 0, + 0, + 52, + 54, + 5, + 3, + 0, + 0, + 53, + 55, + 3, + 6, + 3, + 0, + 54, + 53, + 1, + 0, + 0, + 0, + 54, + 55, + 1, + 0, + 0, + 0, + 55, + 56, + 1, + 0, + 0, + 0, + 56, + 82, + 5, + 4, + 0, + 0, + 57, + 58, + 5, + 16, + 0, + 0, + 58, + 59, + 5, + 12, + 0, + 0, + 59, + 60, + 3, + 10, + 5, + 0, + 60, + 61, + 5, + 13, + 0, + 0, + 61, + 82, + 1, + 0, + 0, + 0, + 62, + 63, + 5, + 16, + 0, + 0, + 63, + 64, + 5, + 12, + 0, + 0, + 64, + 65, + 3, + 4, + 2, + 0, + 65, + 66, + 5, + 13, + 0, + 0, + 66, + 82, + 1, + 0, + 0, + 0, + 67, + 68, + 5, + 3, + 0, + 0, + 68, + 69, + 3, + 4, + 2, + 0, + 69, + 70, + 5, + 4, + 0, + 0, + 70, + 71, + 5, + 12, + 0, + 0, + 71, + 72, + 3, + 10, + 5, + 0, + 72, + 73, + 5, + 13, + 0, + 0, + 73, + 82, + 1, + 0, + 0, + 0, + 74, + 75, + 5, + 3, + 0, + 0, + 75, + 76, + 3, + 4, + 2, + 0, + 76, + 77, + 5, + 4, + 0, + 0, + 77, + 78, + 5, + 12, + 0, + 0, + 78, + 79, + 3, + 4, + 2, + 0, + 79, + 80, + 5, + 13, + 0, + 0, + 80, + 82, + 1, + 0, + 0, + 0, + 81, + 23, + 1, + 0, + 0, + 0, + 81, + 25, + 1, + 0, + 0, + 0, + 81, + 26, + 1, + 0, + 0, + 0, + 81, + 28, + 1, + 0, + 0, + 0, + 81, + 32, + 1, + 0, + 0, + 0, + 81, + 37, + 1, + 0, + 0, + 0, + 81, + 42, + 1, + 0, + 0, + 0, + 81, + 51, + 1, + 0, + 0, + 0, + 81, + 57, + 1, + 0, + 0, + 0, + 81, + 62, + 1, + 0, + 0, + 0, + 81, + 67, + 1, + 0, + 0, + 0, + 81, + 74, + 1, + 0, + 0, + 0, + 82, + 94, + 1, + 0, + 0, + 0, + 83, + 84, + 10, + 11, + 0, + 0, + 84, + 85, + 7, + 0, + 0, + 0, + 85, + 93, + 3, + 4, + 2, + 12, + 86, + 87, + 10, + 10, + 0, + 0, + 87, + 88, + 7, + 1, + 0, + 0, + 88, + 93, + 3, + 4, + 2, + 11, + 89, + 90, + 10, + 9, + 0, + 0, + 90, + 91, + 5, + 17, + 0, + 0, + 91, + 93, + 3, + 4, + 2, + 10, + 92, + 83, + 1, + 0, + 0, + 0, + 92, + 86, + 1, + 0, + 0, + 0, + 92, + 89, + 1, + 0, + 0, + 0, + 93, + 96, + 1, + 0, + 0, + 0, + 94, + 92, + 1, + 0, + 0, + 0, + 94, + 95, + 1, + 0, + 0, + 0, + 95, + 5, + 1, + 0, + 0, + 0, + 96, + 94, + 1, + 0, + 0, + 0, + 97, + 102, + 3, + 4, + 2, + 0, + 98, + 99, + 5, + 11, + 0, + 0, + 99, + 101, + 3, + 4, + 2, + 0, + 100, + 98, + 1, + 0, + 0, + 0, + 101, + 104, + 1, + 0, + 0, + 0, + 102, + 100, + 1, + 0, + 0, + 0, + 102, + 103, + 1, + 0, + 0, + 0, + 103, + 7, + 1, + 0, + 0, + 0, + 104, + 102, + 1, + 0, + 0, + 0, + 105, + 108, + 5, + 14, + 0, + 0, + 106, + 108, + 5, + 16, + 0, + 0, + 107, + 105, + 1, + 0, + 0, + 0, + 107, + 106, + 1, + 0, + 0, + 0, + 108, + 9, + 1, + 0, + 0, + 0, + 109, + 111, + 5, + 15, + 0, + 0, + 110, + 112, + 3, + 12, + 6, + 0, + 111, + 110, + 1, + 0, + 0, + 0, + 111, + 112, + 1, + 0, + 0, + 0, + 112, + 11, + 1, + 0, + 0, + 0, + 113, + 114, + 6, + 6, + -1, + 0, + 114, + 115, + 7, + 1, + 0, + 0, + 115, + 122, + 3, + 8, + 4, + 0, + 116, + 117, + 7, + 1, + 0, + 0, + 117, + 118, + 5, + 3, + 0, + 0, + 118, + 119, + 3, + 4, + 2, + 0, + 119, + 120, + 5, + 4, + 0, + 0, + 120, + 122, + 1, + 0, + 0, + 0, + 121, + 113, + 1, + 0, + 0, + 0, + 121, + 116, + 1, + 0, + 0, + 0, + 122, + 131, + 1, + 0, + 0, + 0, + 123, + 124, + 10, + 4, + 0, + 0, + 124, + 125, + 7, + 0, + 0, + 0, + 125, + 130, + 3, + 14, + 7, + 0, + 126, + 127, + 10, + 3, + 0, + 0, + 127, + 128, + 7, + 1, + 0, + 0, + 128, + 130, + 3, + 14, + 7, + 0, + 129, + 123, + 1, + 0, + 0, + 0, + 129, + 126, + 1, + 0, + 0, + 0, + 130, + 133, + 1, + 0, + 0, + 0, + 131, + 129, + 1, + 0, + 0, + 0, + 131, + 132, + 1, + 0, + 0, + 0, + 132, + 13, + 1, + 0, + 0, + 0, + 133, + 131, + 1, + 0, + 0, + 0, + 134, + 135, + 6, + 7, + -1, + 0, + 135, + 136, + 5, + 3, + 0, + 0, + 136, + 137, + 3, + 4, + 2, + 0, + 137, + 138, + 5, + 4, + 0, + 0, + 138, + 141, + 1, + 0, + 0, + 0, + 139, + 141, + 3, + 8, + 4, + 0, + 140, + 134, + 1, + 0, + 0, + 0, + 140, + 139, + 1, + 0, + 0, + 0, + 141, + 147, + 1, + 0, + 0, + 0, + 142, + 143, + 10, + 3, + 0, + 0, + 143, + 144, + 7, + 0, + 0, + 0, + 144, + 146, + 3, + 14, + 7, + 4, + 145, + 142, + 1, + 0, + 0, + 0, + 146, + 149, + 1, + 0, + 0, + 0, + 147, + 145, + 1, + 0, + 0, + 0, + 147, + 148, + 1, + 0, + 0, + 0, + 148, + 15, + 1, + 0, + 0, + 0, + 149, + 147, + 1, + 0, + 0, + 0, + 12, + 54, + 81, + 92, + 94, + 102, + 107, + 111, + 121, + 129, + 131, + 140, + 147, ] -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'", + "'..'", + "','", + "'['", + "']'", + "", + "'t'", + ] - symbolicNames = [ "", "", "", "", - "", "", "", "", - "", "", "", "", - "", "", "NUMBER", "TIME", "IDENTIFIER", - "COMPARISON", "WS" ] + symbolicNames = [ + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "NUMBER", + "TIME", + "IDENTIFIER", + "COMPARISON", + "WS", + ] RULE_portFieldExpr = 0 RULE_fullexpr = 1 @@ -94,46 +1425,55 @@ class ExprParser ( Parser ): RULE_shift_expr = 6 RULE_right_expr = 7 - ruleNames = [ "portFieldExpr", "fullexpr", "expr", "argList", "atom", - "shift", "shift_expr", "right_expr" ] + ruleNames = [ + "portFieldExpr", + "fullexpr", + "expr", + "argList", + "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 + TIME = 15 + IDENTIFIER = 16 + COMPARISON = 17 + WS = 18 + + 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: @@ -142,17 +1482,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: @@ -171,17 +1507,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) @@ -189,17 +1525,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: @@ -216,325 +1548,311 @@ 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 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 argList(self): - return self.getTypedRuleContext(ExprParser.ArgListContext,0) + def argList(self): + return self.getTypedRuleContext(ExprParser.ArgListContext, 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 = 81 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 @@ -635,11 +1953,10 @@ def expr(self, _p:int=0): self.state = 54 self._errHandler.sync(self) _la = self._input.LA(1) - if (((_la) & ~0x3f) == 0 and ((1 << _la) & 82700) != 0): + if ((_la) & ~0x3F) == 0 and ((1 << _la) & 82700) != 0: self.state = 53 self.argList() - self.state = 56 self.match(ExprParser.T__3) pass @@ -708,30 +2025,36 @@ def expr(self, _p:int=0): self.match(ExprParser.T__12) pass - self._ctx.stop = self._input.LT(-1) self.state = 94 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 = 92 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 = 83 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 = 84 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) @@ -741,16 +2064,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 = 86 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 = 87 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) @@ -760,22 +2090,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 = 89 if not self.precpred(self._ctx, 9): from antlr4.error.Errors import FailedPredicateException - raise FailedPredicateException(self, "self.precpred(self._ctx, 9)") + + raise FailedPredicateException( + self, "self.precpred(self._ctx, 9)" + ) self.state = 90 self.match(ExprParser.COMPARISON) self.state = 91 self.expr(10) pass - self.state = 96 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 @@ -785,38 +2121,34 @@ def expr(self, _p:int=0): self.unrollRecursionContexts(_parentctx) return localctx - class ArgListContext(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, 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 getRuleIndex(self): return ExprParser.RULE_argList - def accept(self, visitor:ParseTreeVisitor): - if hasattr( visitor, "visitArgList" ): + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitArgList"): return visitor.visitArgList(self) else: return visitor.visitChildren(self) - - - def argList(self): - localctx = ExprParser.ArgListContext(self, self._ctx, self.state) self.enterRule(localctx, 6, self.RULE_argList) - self._la = 0 # Token type + self._la = 0 # Token type try: self.enterOuterAlt(localctx, 1) self.state = 97 @@ -824,7 +2156,7 @@ def argList(self): self.state = 102 self._errHandler.sync(self) _la = self._input.LA(1) - while _la==11: + while _la == 11: self.state = 98 self.match(ExprParser.T__10) self.state = 99 @@ -841,59 +2173,54 @@ def argList(self): self.exitRule() 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, 8, self.RULE_atom) try: @@ -923,11 +2250,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 @@ -935,26 +2263,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, 10, self.RULE_shift) - self._la = 0 # Token type + self._la = 0 # Token type try: self.enterOuterAlt(localctx, 1) self.state = 109 @@ -962,11 +2285,10 @@ def shift(self): self.state = 111 self._errHandler.sync(self) _la = self._input.LA(1) - if _la==2 or _la==7: + if _la == 2 or _la == 7: self.state = 110 self.shift_expr(0) - except RecognitionException as re: localctx.exception = re self._errHandler.reportError(self, re) @@ -975,115 +2297,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 = 12 self.enterRecursionRule(localctx, 12, self.RULE_shift_expr, _p) - self._la = 0 # Token type + self._la = 0 # Token type try: self.enterOuterAlt(localctx, 1) self.state = 121 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.SignedAtomContext(self, localctx) self._ctx = localctx @@ -1092,7 +2407,7 @@ def shift_expr(self, _p:int=0): self.state = 114 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) @@ -1108,7 +2423,7 @@ def shift_expr(self, _p:int=0): self.state = 116 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) @@ -1121,30 +2436,39 @@ def shift_expr(self, _p:int=0): self.match(ExprParser.T__3) pass - self._ctx.stop = self._input.LT(-1) self.state = 131 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, 9, 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 = 129 self._errHandler.sync(self) - la_ = self._interp.adaptivePredict(self._input,8,self._ctx) + la_ = self._interp.adaptivePredict(self._input, 8, 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 = 123 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 = 124 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) @@ -1154,16 +2478,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 = 126 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 = 127 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) @@ -1172,10 +2506,9 @@ def shift_expr(self, _p:int=0): self.right_expr(0) pass - self.state = 133 self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input,9,self._ctx) + _alt = self._interp.adaptivePredict(self._input, 9, self._ctx) except RecognitionException as re: localctx.exception = re @@ -1185,87 +2518,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 = 14 self.enterRecursionRule(localctx, 14, self.RULE_right_expr, _p) - self._la = 0 # Token type + self._la = 0 # Token type try: self.enterOuterAlt(localctx, 1) self.state = 140 @@ -1296,31 +2623,39 @@ def right_expr(self, _p:int=0): self._ctx.stop = self._input.LT(-1) self.state = 147 self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input,11,self._ctx) - while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER: - if _alt==1: + _alt = self._interp.adaptivePredict(self._input, 11, 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 = 142 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 = 143 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 = 144 - self.right_expr(4) + self.right_expr(4) self.state = 149 self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input,11,self._ctx) + _alt = self._interp.adaptivePredict(self._input, 11, self._ctx) except RecognitionException as re: localctx.exception = re @@ -1330,9 +2665,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 @@ -1344,33 +2677,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, 11) - - - if predIndex == 1: - return self.precpred(self._ctx, 10) - - - 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 expr_sempred(self, localctx: ExprContext, predIndex: int): + if predIndex == 0: + 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 == 1: + return self.precpred(self._ctx, 10) + 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 aedf8651..3a4cf8d6 100644 --- a/src/gems/expression/parsing/antlr/ExprVisitor.py +++ b/src/gems/expression/parsing/antlr/ExprVisitor.py @@ -8,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#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#argList. - def visitArgList(self, ctx:ExprParser.ArgListContext): + def visitArgList(self, ctx: ExprParser.ArgListContext): 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