From ab5f8a701dccef8224183a2ebd038967375f550f Mon Sep 17 00:00:00 2001 From: ChouaneLouis Date: Fri, 17 May 2024 15:32:31 +0200 Subject: [PATCH] fixed parsing of time shift yaml add unittests for new parsing change functional test --- grammar/Expr.g4 | 15 +- .../expression/parsing/antlr/Expr.interp | 5 +- .../expression/parsing/antlr/Expr.tokens | 6 +- .../expression/parsing/antlr/ExprLexer.interp | 4 +- .../expression/parsing/antlr/ExprLexer.py | 8 +- .../expression/parsing/antlr/ExprLexer.tokens | 6 +- .../expression/parsing/antlr/ExprParser.py | 1474 ++++++++++++----- .../expression/parsing/antlr/ExprVisitor.py | 28 + .../expression/parsing/antlr/__init__.py | 0 .../expression/parsing/parse_expression.py | 84 +- tests/functional/libs/lib.yml | 6 +- tests/functional/test_andromede_yml.py | 5 +- .../parsing/test_expression_parsing.py | 12 + 13 files changed, 1215 insertions(+), 438 deletions(-) delete mode 100644 src/andromede/expression/parsing/antlr/__init__.py diff --git a/grammar/Expr.g4 b/grammar/Expr.g4 index d0d16424..b9d57973 100644 --- a/grammar/Expr.g4 +++ b/grammar/Expr.g4 @@ -17,9 +17,20 @@ grammar Expr; /* To match the whole input */ fullexpr: expr EOF; -shift: TIME (op=('+' | '-') expr)?; +shift: TIME shift_expr?; + +shift_expr + : op=('+' | '-') NUMBER # signedNumber + | shift_expr op=('+' | '-') expr # shiftAddsub + | op=('+' | '-') IDENTIFIER # signedIdentifier + | op=('+' | '-') IDENTIFIER '.' IDENTIFIER # signedPortField + | shift_expr op=('/' | '*') expr # shiftMuldiv + | op=('+' | '-') '(' expr ')' # signedExpression + | op=('+' | '-') IDENTIFIER '(' expr ')' # signedFunction + ; -expr: '-' expr # negation +expr + : '-' expr # negation | expr op=('/' | '*') expr # muldiv | expr op=('+' | '-') expr # addsub | expr COMPARISON expr # comparison diff --git a/src/andromede/expression/parsing/antlr/Expr.interp b/src/andromede/expression/parsing/antlr/Expr.interp index bed35193..141ce4da 100644 --- a/src/andromede/expression/parsing/antlr/Expr.interp +++ b/src/andromede/expression/parsing/antlr/Expr.interp @@ -2,9 +2,9 @@ token literal names: null '+' '-' +'.' '/' '*' -'.' '(' ')' ',' @@ -43,8 +43,9 @@ WS rule names: fullexpr shift +shift_expr expr atn: -[4, 1, 18, 86, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 3, 1, 13, 8, 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, 5, 2, 37, 8, 2, 10, 2, 12, 2, 40, 9, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 5, 2, 49, 8, 2, 10, 2, 12, 2, 52, 9, 2, 1, 2, 1, 2, 1, 2, 1, 2, 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, 70, 8, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 5, 2, 81, 8, 2, 10, 2, 12, 2, 84, 9, 2, 1, 2, 0, 1, 4, 3, 0, 2, 4, 0, 2, 1, 0, 1, 2, 1, 0, 3, 4, 97, 0, 6, 1, 0, 0, 0, 2, 9, 1, 0, 0, 0, 4, 69, 1, 0, 0, 0, 6, 7, 3, 4, 2, 0, 7, 8, 5, 0, 0, 1, 8, 1, 1, 0, 0, 0, 9, 12, 5, 11, 0, 0, 10, 11, 7, 0, 0, 0, 11, 13, 3, 4, 2, 0, 12, 10, 1, 0, 0, 0, 12, 13, 1, 0, 0, 0, 13, 3, 1, 0, 0, 0, 14, 15, 6, 2, -1, 0, 15, 16, 5, 2, 0, 0, 16, 70, 3, 4, 2, 13, 17, 70, 5, 12, 0, 0, 18, 19, 5, 12, 0, 0, 19, 20, 5, 5, 0, 0, 20, 70, 5, 12, 0, 0, 21, 70, 5, 10, 0, 0, 22, 23, 5, 6, 0, 0, 23, 24, 3, 4, 2, 0, 24, 25, 5, 7, 0, 0, 25, 70, 1, 0, 0, 0, 26, 27, 5, 12, 0, 0, 27, 28, 5, 6, 0, 0, 28, 29, 3, 4, 2, 0, 29, 30, 5, 7, 0, 0, 30, 70, 1, 0, 0, 0, 31, 32, 5, 12, 0, 0, 32, 33, 5, 16, 0, 0, 33, 38, 3, 2, 1, 0, 34, 35, 5, 8, 0, 0, 35, 37, 3, 2, 1, 0, 36, 34, 1, 0, 0, 0, 37, 40, 1, 0, 0, 0, 38, 36, 1, 0, 0, 0, 38, 39, 1, 0, 0, 0, 39, 41, 1, 0, 0, 0, 40, 38, 1, 0, 0, 0, 41, 42, 5, 17, 0, 0, 42, 70, 1, 0, 0, 0, 43, 44, 5, 12, 0, 0, 44, 45, 5, 16, 0, 0, 45, 50, 3, 4, 2, 0, 46, 47, 5, 8, 0, 0, 47, 49, 3, 4, 2, 0, 48, 46, 1, 0, 0, 0, 49, 52, 1, 0, 0, 0, 50, 48, 1, 0, 0, 0, 50, 51, 1, 0, 0, 0, 51, 53, 1, 0, 0, 0, 52, 50, 1, 0, 0, 0, 53, 54, 5, 17, 0, 0, 54, 70, 1, 0, 0, 0, 55, 56, 5, 12, 0, 0, 56, 57, 5, 16, 0, 0, 57, 58, 3, 2, 1, 0, 58, 59, 5, 9, 0, 0, 59, 60, 3, 2, 1, 0, 60, 61, 5, 17, 0, 0, 61, 70, 1, 0, 0, 0, 62, 63, 5, 12, 0, 0, 63, 64, 5, 16, 0, 0, 64, 65, 3, 4, 2, 0, 65, 66, 5, 9, 0, 0, 66, 67, 3, 4, 2, 0, 67, 68, 5, 17, 0, 0, 68, 70, 1, 0, 0, 0, 69, 14, 1, 0, 0, 0, 69, 17, 1, 0, 0, 0, 69, 18, 1, 0, 0, 0, 69, 21, 1, 0, 0, 0, 69, 22, 1, 0, 0, 0, 69, 26, 1, 0, 0, 0, 69, 31, 1, 0, 0, 0, 69, 43, 1, 0, 0, 0, 69, 55, 1, 0, 0, 0, 69, 62, 1, 0, 0, 0, 70, 82, 1, 0, 0, 0, 71, 72, 10, 12, 0, 0, 72, 73, 7, 1, 0, 0, 73, 81, 3, 4, 2, 13, 74, 75, 10, 11, 0, 0, 75, 76, 7, 0, 0, 0, 76, 81, 3, 4, 2, 12, 77, 78, 10, 10, 0, 0, 78, 79, 5, 13, 0, 0, 79, 81, 3, 4, 2, 11, 80, 71, 1, 0, 0, 0, 80, 74, 1, 0, 0, 0, 80, 77, 1, 0, 0, 0, 81, 84, 1, 0, 0, 0, 82, 80, 1, 0, 0, 0, 82, 83, 1, 0, 0, 0, 83, 5, 1, 0, 0, 0, 84, 82, 1, 0, 0, 0, 6, 12, 38, 50, 69, 80, 82] \ No newline at end of file +[4, 1, 18, 120, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 3, 1, 14, 8, 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, 3, 2, 36, 8, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 5, 2, 44, 8, 2, 10, 2, 12, 2, 47, 9, 2, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 5, 3, 71, 8, 3, 10, 3, 12, 3, 74, 9, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 5, 3, 83, 8, 3, 10, 3, 12, 3, 86, 9, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 3, 3, 104, 8, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 5, 3, 115, 8, 3, 10, 3, 12, 3, 118, 9, 3, 1, 3, 0, 2, 4, 6, 4, 0, 2, 4, 6, 0, 2, 1, 0, 1, 2, 1, 0, 4, 5, 136, 0, 8, 1, 0, 0, 0, 2, 11, 1, 0, 0, 0, 4, 35, 1, 0, 0, 0, 6, 103, 1, 0, 0, 0, 8, 9, 3, 6, 3, 0, 9, 10, 5, 0, 0, 1, 10, 1, 1, 0, 0, 0, 11, 13, 5, 11, 0, 0, 12, 14, 3, 4, 2, 0, 13, 12, 1, 0, 0, 0, 13, 14, 1, 0, 0, 0, 14, 3, 1, 0, 0, 0, 15, 16, 6, 2, -1, 0, 16, 17, 7, 0, 0, 0, 17, 36, 5, 10, 0, 0, 18, 19, 7, 0, 0, 0, 19, 36, 5, 12, 0, 0, 20, 21, 7, 0, 0, 0, 21, 22, 5, 12, 0, 0, 22, 23, 5, 3, 0, 0, 23, 36, 5, 12, 0, 0, 24, 25, 7, 0, 0, 0, 25, 26, 5, 6, 0, 0, 26, 27, 3, 6, 3, 0, 27, 28, 5, 7, 0, 0, 28, 36, 1, 0, 0, 0, 29, 30, 7, 0, 0, 0, 30, 31, 5, 12, 0, 0, 31, 32, 5, 6, 0, 0, 32, 33, 3, 6, 3, 0, 33, 34, 5, 7, 0, 0, 34, 36, 1, 0, 0, 0, 35, 15, 1, 0, 0, 0, 35, 18, 1, 0, 0, 0, 35, 20, 1, 0, 0, 0, 35, 24, 1, 0, 0, 0, 35, 29, 1, 0, 0, 0, 36, 45, 1, 0, 0, 0, 37, 38, 10, 6, 0, 0, 38, 39, 7, 0, 0, 0, 39, 44, 3, 6, 3, 0, 40, 41, 10, 3, 0, 0, 41, 42, 7, 1, 0, 0, 42, 44, 3, 6, 3, 0, 43, 37, 1, 0, 0, 0, 43, 40, 1, 0, 0, 0, 44, 47, 1, 0, 0, 0, 45, 43, 1, 0, 0, 0, 45, 46, 1, 0, 0, 0, 46, 5, 1, 0, 0, 0, 47, 45, 1, 0, 0, 0, 48, 49, 6, 3, -1, 0, 49, 50, 5, 2, 0, 0, 50, 104, 3, 6, 3, 13, 51, 104, 5, 12, 0, 0, 52, 53, 5, 12, 0, 0, 53, 54, 5, 3, 0, 0, 54, 104, 5, 12, 0, 0, 55, 104, 5, 10, 0, 0, 56, 57, 5, 6, 0, 0, 57, 58, 3, 6, 3, 0, 58, 59, 5, 7, 0, 0, 59, 104, 1, 0, 0, 0, 60, 61, 5, 12, 0, 0, 61, 62, 5, 6, 0, 0, 62, 63, 3, 6, 3, 0, 63, 64, 5, 7, 0, 0, 64, 104, 1, 0, 0, 0, 65, 66, 5, 12, 0, 0, 66, 67, 5, 16, 0, 0, 67, 72, 3, 2, 1, 0, 68, 69, 5, 8, 0, 0, 69, 71, 3, 2, 1, 0, 70, 68, 1, 0, 0, 0, 71, 74, 1, 0, 0, 0, 72, 70, 1, 0, 0, 0, 72, 73, 1, 0, 0, 0, 73, 75, 1, 0, 0, 0, 74, 72, 1, 0, 0, 0, 75, 76, 5, 17, 0, 0, 76, 104, 1, 0, 0, 0, 77, 78, 5, 12, 0, 0, 78, 79, 5, 16, 0, 0, 79, 84, 3, 6, 3, 0, 80, 81, 5, 8, 0, 0, 81, 83, 3, 6, 3, 0, 82, 80, 1, 0, 0, 0, 83, 86, 1, 0, 0, 0, 84, 82, 1, 0, 0, 0, 84, 85, 1, 0, 0, 0, 85, 87, 1, 0, 0, 0, 86, 84, 1, 0, 0, 0, 87, 88, 5, 17, 0, 0, 88, 104, 1, 0, 0, 0, 89, 90, 5, 12, 0, 0, 90, 91, 5, 16, 0, 0, 91, 92, 3, 2, 1, 0, 92, 93, 5, 9, 0, 0, 93, 94, 3, 2, 1, 0, 94, 95, 5, 17, 0, 0, 95, 104, 1, 0, 0, 0, 96, 97, 5, 12, 0, 0, 97, 98, 5, 16, 0, 0, 98, 99, 3, 6, 3, 0, 99, 100, 5, 9, 0, 0, 100, 101, 3, 6, 3, 0, 101, 102, 5, 17, 0, 0, 102, 104, 1, 0, 0, 0, 103, 48, 1, 0, 0, 0, 103, 51, 1, 0, 0, 0, 103, 52, 1, 0, 0, 0, 103, 55, 1, 0, 0, 0, 103, 56, 1, 0, 0, 0, 103, 60, 1, 0, 0, 0, 103, 65, 1, 0, 0, 0, 103, 77, 1, 0, 0, 0, 103, 89, 1, 0, 0, 0, 103, 96, 1, 0, 0, 0, 104, 116, 1, 0, 0, 0, 105, 106, 10, 12, 0, 0, 106, 107, 7, 1, 0, 0, 107, 115, 3, 6, 3, 13, 108, 109, 10, 11, 0, 0, 109, 110, 7, 0, 0, 0, 110, 115, 3, 6, 3, 12, 111, 112, 10, 10, 0, 0, 112, 113, 5, 13, 0, 0, 113, 115, 3, 6, 3, 11, 114, 105, 1, 0, 0, 0, 114, 108, 1, 0, 0, 0, 114, 111, 1, 0, 0, 0, 115, 118, 1, 0, 0, 0, 116, 114, 1, 0, 0, 0, 116, 117, 1, 0, 0, 0, 117, 7, 1, 0, 0, 0, 118, 116, 1, 0, 0, 0, 9, 13, 35, 43, 45, 72, 84, 103, 114, 116] \ No newline at end of file diff --git a/src/andromede/expression/parsing/antlr/Expr.tokens b/src/andromede/expression/parsing/antlr/Expr.tokens index 29d96df5..0184f9e8 100644 --- a/src/andromede/expression/parsing/antlr/Expr.tokens +++ b/src/andromede/expression/parsing/antlr/Expr.tokens @@ -18,9 +18,9 @@ RBRACKET=17 WS=18 '+'=1 '-'=2 -'/'=3 -'*'=4 -'.'=5 +'.'=3 +'/'=4 +'*'=5 '('=6 ')'=7 ','=8 diff --git a/src/andromede/expression/parsing/antlr/ExprLexer.interp b/src/andromede/expression/parsing/antlr/ExprLexer.interp index e98cab1e..ef5d4fe6 100644 --- a/src/andromede/expression/parsing/antlr/ExprLexer.interp +++ b/src/andromede/expression/parsing/antlr/ExprLexer.interp @@ -2,9 +2,9 @@ token literal names: null '+' '-' +'.' '/' '*' -'.' '(' ')' ',' @@ -71,4 +71,4 @@ mode names: DEFAULT_MODE atn: -[4, 0, 18, 111, 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, 8, 1, 8, 1, 8, 1, 9, 1, 9, 1, 10, 1, 10, 1, 11, 1, 11, 3, 11, 69, 8, 11, 1, 12, 4, 12, 72, 8, 12, 11, 12, 12, 12, 73, 1, 12, 1, 12, 4, 12, 78, 8, 12, 11, 12, 12, 12, 79, 3, 12, 82, 8, 12, 1, 13, 1, 13, 1, 14, 1, 14, 5, 14, 88, 8, 14, 10, 14, 12, 14, 91, 9, 14, 1, 15, 1, 15, 1, 15, 1, 15, 1, 15, 3, 15, 98, 8, 15, 1, 16, 1, 16, 1, 17, 1, 17, 1, 18, 1, 18, 1, 19, 1, 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, 0, 21, 0, 23, 0, 25, 10, 27, 11, 29, 12, 31, 13, 33, 14, 35, 15, 37, 16, 39, 17, 41, 18, 1, 0, 5, 1, 0, 48, 57, 3, 0, 65, 90, 95, 95, 97, 122, 2, 0, 43, 43, 45, 45, 2, 0, 42, 42, 47, 47, 3, 0, 9, 10, 13, 13, 32, 32, 114, 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, 25, 1, 0, 0, 0, 0, 27, 1, 0, 0, 0, 0, 29, 1, 0, 0, 0, 0, 31, 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, 59, 1, 0, 0, 0, 19, 62, 1, 0, 0, 0, 21, 64, 1, 0, 0, 0, 23, 68, 1, 0, 0, 0, 25, 71, 1, 0, 0, 0, 27, 83, 1, 0, 0, 0, 29, 85, 1, 0, 0, 0, 31, 97, 1, 0, 0, 0, 33, 99, 1, 0, 0, 0, 35, 101, 1, 0, 0, 0, 37, 103, 1, 0, 0, 0, 39, 105, 1, 0, 0, 0, 41, 107, 1, 0, 0, 0, 43, 44, 5, 43, 0, 0, 44, 2, 1, 0, 0, 0, 45, 46, 5, 45, 0, 0, 46, 4, 1, 0, 0, 0, 47, 48, 5, 47, 0, 0, 48, 6, 1, 0, 0, 0, 49, 50, 5, 42, 0, 0, 50, 8, 1, 0, 0, 0, 51, 52, 5, 46, 0, 0, 52, 10, 1, 0, 0, 0, 53, 54, 5, 40, 0, 0, 54, 12, 1, 0, 0, 0, 55, 56, 5, 41, 0, 0, 56, 14, 1, 0, 0, 0, 57, 58, 5, 44, 0, 0, 58, 16, 1, 0, 0, 0, 59, 60, 5, 46, 0, 0, 60, 61, 5, 46, 0, 0, 61, 18, 1, 0, 0, 0, 62, 63, 7, 0, 0, 0, 63, 20, 1, 0, 0, 0, 64, 65, 7, 1, 0, 0, 65, 22, 1, 0, 0, 0, 66, 69, 3, 21, 10, 0, 67, 69, 3, 19, 9, 0, 68, 66, 1, 0, 0, 0, 68, 67, 1, 0, 0, 0, 69, 24, 1, 0, 0, 0, 70, 72, 3, 19, 9, 0, 71, 70, 1, 0, 0, 0, 72, 73, 1, 0, 0, 0, 73, 71, 1, 0, 0, 0, 73, 74, 1, 0, 0, 0, 74, 81, 1, 0, 0, 0, 75, 77, 5, 46, 0, 0, 76, 78, 3, 19, 9, 0, 77, 76, 1, 0, 0, 0, 78, 79, 1, 0, 0, 0, 79, 77, 1, 0, 0, 0, 79, 80, 1, 0, 0, 0, 80, 82, 1, 0, 0, 0, 81, 75, 1, 0, 0, 0, 81, 82, 1, 0, 0, 0, 82, 26, 1, 0, 0, 0, 83, 84, 5, 116, 0, 0, 84, 28, 1, 0, 0, 0, 85, 89, 3, 21, 10, 0, 86, 88, 3, 23, 11, 0, 87, 86, 1, 0, 0, 0, 88, 91, 1, 0, 0, 0, 89, 87, 1, 0, 0, 0, 89, 90, 1, 0, 0, 0, 90, 30, 1, 0, 0, 0, 91, 89, 1, 0, 0, 0, 92, 98, 5, 61, 0, 0, 93, 94, 5, 62, 0, 0, 94, 98, 5, 61, 0, 0, 95, 96, 5, 60, 0, 0, 96, 98, 5, 61, 0, 0, 97, 92, 1, 0, 0, 0, 97, 93, 1, 0, 0, 0, 97, 95, 1, 0, 0, 0, 98, 32, 1, 0, 0, 0, 99, 100, 7, 2, 0, 0, 100, 34, 1, 0, 0, 0, 101, 102, 7, 3, 0, 0, 102, 36, 1, 0, 0, 0, 103, 104, 5, 91, 0, 0, 104, 38, 1, 0, 0, 0, 105, 106, 5, 93, 0, 0, 106, 40, 1, 0, 0, 0, 107, 108, 7, 4, 0, 0, 108, 109, 1, 0, 0, 0, 109, 110, 6, 20, 0, 0, 110, 42, 1, 0, 0, 0, 7, 0, 68, 73, 79, 81, 89, 97, 1, 6, 0, 0] \ No newline at end of file +[4, 0, 18, 111, 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, 8, 1, 8, 1, 8, 1, 9, 1, 9, 1, 10, 1, 10, 1, 11, 1, 11, 3, 11, 69, 8, 11, 1, 12, 4, 12, 72, 8, 12, 11, 12, 12, 12, 73, 1, 12, 1, 12, 4, 12, 78, 8, 12, 11, 12, 12, 12, 79, 3, 12, 82, 8, 12, 1, 13, 1, 13, 1, 14, 1, 14, 5, 14, 88, 8, 14, 10, 14, 12, 14, 91, 9, 14, 1, 15, 1, 15, 1, 15, 1, 15, 1, 15, 3, 15, 98, 8, 15, 1, 16, 1, 16, 1, 17, 1, 17, 1, 18, 1, 18, 1, 19, 1, 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, 0, 21, 0, 23, 0, 25, 10, 27, 11, 29, 12, 31, 13, 33, 14, 35, 15, 37, 16, 39, 17, 41, 18, 1, 0, 5, 1, 0, 48, 57, 3, 0, 65, 90, 95, 95, 97, 122, 2, 0, 43, 43, 45, 45, 2, 0, 42, 42, 47, 47, 3, 0, 9, 10, 13, 13, 32, 32, 114, 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, 25, 1, 0, 0, 0, 0, 27, 1, 0, 0, 0, 0, 29, 1, 0, 0, 0, 0, 31, 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, 59, 1, 0, 0, 0, 19, 62, 1, 0, 0, 0, 21, 64, 1, 0, 0, 0, 23, 68, 1, 0, 0, 0, 25, 71, 1, 0, 0, 0, 27, 83, 1, 0, 0, 0, 29, 85, 1, 0, 0, 0, 31, 97, 1, 0, 0, 0, 33, 99, 1, 0, 0, 0, 35, 101, 1, 0, 0, 0, 37, 103, 1, 0, 0, 0, 39, 105, 1, 0, 0, 0, 41, 107, 1, 0, 0, 0, 43, 44, 5, 43, 0, 0, 44, 2, 1, 0, 0, 0, 45, 46, 5, 45, 0, 0, 46, 4, 1, 0, 0, 0, 47, 48, 5, 46, 0, 0, 48, 6, 1, 0, 0, 0, 49, 50, 5, 47, 0, 0, 50, 8, 1, 0, 0, 0, 51, 52, 5, 42, 0, 0, 52, 10, 1, 0, 0, 0, 53, 54, 5, 40, 0, 0, 54, 12, 1, 0, 0, 0, 55, 56, 5, 41, 0, 0, 56, 14, 1, 0, 0, 0, 57, 58, 5, 44, 0, 0, 58, 16, 1, 0, 0, 0, 59, 60, 5, 46, 0, 0, 60, 61, 5, 46, 0, 0, 61, 18, 1, 0, 0, 0, 62, 63, 7, 0, 0, 0, 63, 20, 1, 0, 0, 0, 64, 65, 7, 1, 0, 0, 65, 22, 1, 0, 0, 0, 66, 69, 3, 21, 10, 0, 67, 69, 3, 19, 9, 0, 68, 66, 1, 0, 0, 0, 68, 67, 1, 0, 0, 0, 69, 24, 1, 0, 0, 0, 70, 72, 3, 19, 9, 0, 71, 70, 1, 0, 0, 0, 72, 73, 1, 0, 0, 0, 73, 71, 1, 0, 0, 0, 73, 74, 1, 0, 0, 0, 74, 81, 1, 0, 0, 0, 75, 77, 5, 46, 0, 0, 76, 78, 3, 19, 9, 0, 77, 76, 1, 0, 0, 0, 78, 79, 1, 0, 0, 0, 79, 77, 1, 0, 0, 0, 79, 80, 1, 0, 0, 0, 80, 82, 1, 0, 0, 0, 81, 75, 1, 0, 0, 0, 81, 82, 1, 0, 0, 0, 82, 26, 1, 0, 0, 0, 83, 84, 5, 116, 0, 0, 84, 28, 1, 0, 0, 0, 85, 89, 3, 21, 10, 0, 86, 88, 3, 23, 11, 0, 87, 86, 1, 0, 0, 0, 88, 91, 1, 0, 0, 0, 89, 87, 1, 0, 0, 0, 89, 90, 1, 0, 0, 0, 90, 30, 1, 0, 0, 0, 91, 89, 1, 0, 0, 0, 92, 98, 5, 61, 0, 0, 93, 94, 5, 62, 0, 0, 94, 98, 5, 61, 0, 0, 95, 96, 5, 60, 0, 0, 96, 98, 5, 61, 0, 0, 97, 92, 1, 0, 0, 0, 97, 93, 1, 0, 0, 0, 97, 95, 1, 0, 0, 0, 98, 32, 1, 0, 0, 0, 99, 100, 7, 2, 0, 0, 100, 34, 1, 0, 0, 0, 101, 102, 7, 3, 0, 0, 102, 36, 1, 0, 0, 0, 103, 104, 5, 91, 0, 0, 104, 38, 1, 0, 0, 0, 105, 106, 5, 93, 0, 0, 106, 40, 1, 0, 0, 0, 107, 108, 7, 4, 0, 0, 108, 109, 1, 0, 0, 0, 109, 110, 6, 20, 0, 0, 110, 42, 1, 0, 0, 0, 7, 0, 68, 73, 79, 81, 89, 97, 1, 6, 0, 0] \ No newline at end of file diff --git a/src/andromede/expression/parsing/antlr/ExprLexer.py b/src/andromede/expression/parsing/antlr/ExprLexer.py index 7d750dc2..c0769945 100644 --- a/src/andromede/expression/parsing/antlr/ExprLexer.py +++ b/src/andromede/expression/parsing/antlr/ExprLexer.py @@ -589,7 +589,7 @@ def serializedATN(): 47, 48, 5, - 47, + 46, 0, 0, 48, @@ -601,7 +601,7 @@ def serializedATN(): 49, 50, 5, - 42, + 47, 0, 0, 50, @@ -613,7 +613,7 @@ def serializedATN(): 51, 52, 5, - 46, + 42, 0, 0, 52, @@ -1059,9 +1059,9 @@ class ExprLexer(Lexer): "", "'+'", "'-'", + "'.'", "'/'", "'*'", - "'.'", "'('", "')'", "','", diff --git a/src/andromede/expression/parsing/antlr/ExprLexer.tokens b/src/andromede/expression/parsing/antlr/ExprLexer.tokens index 29d96df5..0184f9e8 100644 --- a/src/andromede/expression/parsing/antlr/ExprLexer.tokens +++ b/src/andromede/expression/parsing/antlr/ExprLexer.tokens @@ -18,9 +18,9 @@ RBRACKET=17 WS=18 '+'=1 '-'=2 -'/'=3 -'*'=4 -'.'=5 +'.'=3 +'/'=4 +'*'=5 '('=6 ')'=7 ','=8 diff --git a/src/andromede/expression/parsing/antlr/ExprParser.py b/src/andromede/expression/parsing/antlr/ExprParser.py index a8c87cab..ce3cfe32 100644 --- a/src/andromede/expression/parsing/antlr/ExprParser.py +++ b/src/andromede/expression/parsing/antlr/ExprParser.py @@ -16,7 +16,7 @@ def serializedATN(): 4, 1, 18, - 86, + 120, 2, 0, 7, @@ -29,6 +29,10 @@ def serializedATN(): 2, 7, 2, + 2, + 3, + 7, + 3, 1, 0, 1, @@ -39,11 +43,9 @@ def serializedATN(): 1, 1, 1, - 1, - 1, 3, 1, - 13, + 14, 8, 1, 1, @@ -86,124 +88,195 @@ def serializedATN(): 2, 1, 2, + 3, + 2, + 36, + 8, + 2, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 2, 1, 2, 1, 2, 5, 2, - 37, + 44, 8, 2, 10, 2, 12, 2, - 40, + 47, 9, 2, 1, - 2, + 3, 1, - 2, + 3, 1, - 2, + 3, 1, - 2, + 3, 1, - 2, + 3, 1, - 2, + 3, 1, - 2, + 3, + 1, + 3, + 1, + 3, + 1, + 3, + 1, + 3, + 1, + 3, + 1, + 3, + 1, + 3, + 1, + 3, + 1, + 3, + 1, + 3, + 1, + 3, + 1, + 3, + 1, + 3, + 1, + 3, + 1, + 3, 5, - 2, - 49, + 3, + 71, 8, - 2, + 3, 10, - 2, + 3, 12, - 2, - 52, + 3, + 74, 9, - 2, + 3, 1, - 2, + 3, 1, - 2, + 3, 1, - 2, + 3, 1, - 2, + 3, 1, - 2, + 3, 1, - 2, + 3, 1, - 2, + 3, + 5, + 3, + 83, + 8, + 3, + 10, + 3, + 12, + 3, + 86, + 9, + 3, 1, - 2, + 3, 1, - 2, + 3, 1, - 2, + 3, 1, - 2, + 3, 1, - 2, + 3, 1, - 2, + 3, 1, - 2, + 3, 1, - 2, + 3, 1, - 2, 3, - 2, - 70, + 1, + 3, + 1, + 3, + 1, + 3, + 1, + 3, + 1, + 3, + 1, + 3, + 1, + 3, + 3, + 3, + 104, 8, - 2, + 3, 1, - 2, + 3, 1, - 2, + 3, 1, - 2, + 3, 1, - 2, + 3, 1, - 2, + 3, 1, - 2, + 3, 1, - 2, + 3, 1, - 2, + 3, 1, - 2, + 3, 5, - 2, - 81, + 3, + 115, 8, - 2, + 3, 10, - 2, + 3, 12, - 2, - 84, + 3, + 118, 9, - 2, + 3, 1, - 2, + 3, 0, - 1, + 2, + 4, + 6, 4, - 3, 0, 2, 4, + 6, 0, 2, 1, @@ -212,598 +285,835 @@ def serializedATN(): 2, 1, 0, - 3, 4, - 97, + 5, + 136, 0, - 6, + 8, 1, 0, 0, 0, 2, + 11, + 1, + 0, + 0, + 0, + 4, + 35, + 1, + 0, + 0, + 0, + 6, + 103, + 1, + 0, + 0, + 0, + 8, 9, + 3, + 6, + 3, + 0, + 9, + 10, + 5, + 0, + 0, + 1, + 10, + 1, + 1, + 0, + 0, + 0, + 11, + 13, + 5, + 11, + 0, + 0, + 12, + 14, + 3, + 4, + 2, + 0, + 13, + 12, + 1, + 0, + 0, + 0, + 13, + 14, + 1, + 0, + 0, + 0, + 14, + 3, + 1, + 0, + 0, + 0, + 15, + 16, + 6, + 2, + -1, + 0, + 16, + 17, + 7, + 0, + 0, + 0, + 17, + 36, + 5, + 10, + 0, + 0, + 18, + 19, + 7, + 0, + 0, + 0, + 19, + 36, + 5, + 12, + 0, + 0, + 20, + 21, + 7, + 0, + 0, + 0, + 21, + 22, + 5, + 12, + 0, + 0, + 22, + 23, + 5, + 3, + 0, + 0, + 23, + 36, + 5, + 12, + 0, + 0, + 24, + 25, + 7, + 0, + 0, + 0, + 25, + 26, + 5, + 6, + 0, + 0, + 26, + 27, + 3, + 6, + 3, + 0, + 27, + 28, + 5, + 7, + 0, + 0, + 28, + 36, + 1, + 0, + 0, + 0, + 29, + 30, + 7, + 0, + 0, + 0, + 30, + 31, + 5, + 12, + 0, + 0, + 31, + 32, + 5, + 6, + 0, + 0, + 32, + 33, + 3, + 6, + 3, + 0, + 33, + 34, + 5, + 7, + 0, + 0, + 34, + 36, + 1, + 0, + 0, + 0, + 35, + 15, + 1, + 0, + 0, + 0, + 35, + 18, + 1, + 0, + 0, + 0, + 35, + 20, + 1, + 0, + 0, + 0, + 35, + 24, + 1, + 0, + 0, + 0, + 35, + 29, 1, 0, 0, 0, - 4, - 69, + 36, + 45, + 1, + 0, + 0, + 0, + 37, + 38, + 10, + 6, + 0, + 0, + 38, + 39, + 7, + 0, + 0, + 0, + 39, + 44, + 3, + 6, + 3, + 0, + 40, + 41, + 10, + 3, + 0, + 0, + 41, + 42, + 7, 1, 0, 0, - 0, + 42, + 44, + 3, 6, - 7, 3, - 4, - 2, 0, - 7, - 8, - 5, + 43, + 37, + 1, 0, 0, - 1, - 8, - 1, + 0, + 43, + 40, 1, 0, 0, 0, - 9, - 12, - 5, - 11, + 44, + 47, + 1, 0, 0, - 10, - 11, - 7, 0, + 45, + 43, + 1, 0, 0, - 11, - 13, - 3, - 4, - 2, 0, - 12, - 10, + 45, + 46, 1, 0, 0, 0, - 12, - 13, + 46, + 5, 1, 0, 0, 0, - 13, - 3, + 47, + 45, 1, 0, 0, 0, - 14, - 15, + 48, + 49, 6, - 2, + 3, -1, 0, - 15, - 16, + 49, + 50, 5, 2, 0, 0, - 16, - 70, + 50, + 104, + 3, + 6, 3, - 4, - 2, 13, - 17, - 70, + 51, + 104, 5, 12, 0, 0, - 18, - 19, + 52, + 53, 5, 12, 0, 0, - 19, - 20, - 5, + 53, + 54, 5, + 3, 0, 0, - 20, - 70, + 54, + 104, 5, 12, 0, 0, - 21, - 70, + 55, + 104, 5, 10, 0, 0, - 22, - 23, + 56, + 57, 5, 6, 0, 0, - 23, - 24, + 57, + 58, + 3, + 6, 3, - 4, - 2, 0, - 24, - 25, + 58, + 59, 5, 7, 0, 0, - 25, - 70, + 59, + 104, 1, 0, 0, 0, - 26, - 27, + 60, + 61, 5, 12, 0, 0, - 27, - 28, + 61, + 62, 5, 6, 0, 0, - 28, - 29, + 62, + 63, + 3, + 6, 3, - 4, - 2, 0, - 29, - 30, + 63, + 64, 5, 7, 0, 0, - 30, - 70, + 64, + 104, 1, 0, 0, 0, - 31, - 32, + 65, + 66, 5, 12, 0, 0, - 32, - 33, + 66, + 67, 5, 16, 0, 0, - 33, - 38, + 67, + 72, 3, 2, 1, 0, - 34, - 35, + 68, + 69, 5, 8, 0, 0, - 35, - 37, + 69, + 71, 3, 2, 1, 0, - 36, - 34, + 70, + 68, 1, 0, 0, 0, - 37, - 40, + 71, + 74, 1, 0, 0, 0, - 38, - 36, + 72, + 70, 1, 0, 0, 0, - 38, - 39, + 72, + 73, 1, 0, 0, 0, - 39, - 41, + 73, + 75, 1, 0, 0, 0, - 40, - 38, + 74, + 72, 1, 0, 0, 0, - 41, - 42, + 75, + 76, 5, 17, 0, 0, - 42, - 70, + 76, + 104, 1, 0, 0, 0, - 43, - 44, + 77, + 78, 5, 12, 0, 0, - 44, - 45, + 78, + 79, 5, 16, 0, 0, - 45, - 50, + 79, + 84, + 3, + 6, 3, - 4, - 2, 0, - 46, - 47, + 80, + 81, 5, 8, 0, 0, - 47, - 49, + 81, + 83, + 3, + 6, 3, - 4, - 2, 0, - 48, - 46, + 82, + 80, 1, 0, 0, 0, - 49, - 52, + 83, + 86, 1, 0, 0, 0, - 50, - 48, + 84, + 82, 1, 0, 0, 0, - 50, - 51, + 84, + 85, 1, 0, 0, 0, - 51, - 53, + 85, + 87, 1, 0, 0, 0, - 52, - 50, + 86, + 84, 1, 0, 0, 0, - 53, - 54, + 87, + 88, 5, 17, 0, 0, - 54, - 70, + 88, + 104, 1, 0, 0, 0, - 55, - 56, + 89, + 90, 5, 12, 0, 0, - 56, - 57, + 90, + 91, 5, 16, 0, 0, - 57, - 58, + 91, + 92, 3, 2, 1, 0, - 58, - 59, + 92, + 93, 5, 9, 0, 0, - 59, - 60, + 93, + 94, 3, 2, 1, 0, - 60, - 61, + 94, + 95, 5, 17, 0, 0, - 61, - 70, + 95, + 104, 1, 0, 0, 0, - 62, - 63, + 96, + 97, 5, 12, 0, 0, - 63, - 64, + 97, + 98, 5, 16, 0, 0, - 64, - 65, + 98, + 99, + 3, + 6, 3, - 4, - 2, 0, - 65, - 66, + 99, + 100, 5, 9, 0, 0, - 66, - 67, + 100, + 101, + 3, + 6, 3, - 4, - 2, 0, - 67, - 68, + 101, + 102, 5, 17, 0, 0, - 68, - 70, + 102, + 104, 1, 0, 0, 0, - 69, - 14, + 103, + 48, 1, 0, 0, 0, - 69, - 17, + 103, + 51, 1, 0, 0, 0, - 69, - 18, + 103, + 52, 1, 0, 0, 0, - 69, - 21, + 103, + 55, 1, 0, 0, 0, - 69, - 22, + 103, + 56, 1, 0, 0, 0, - 69, - 26, + 103, + 60, 1, 0, 0, 0, - 69, - 31, + 103, + 65, 1, 0, 0, 0, - 69, - 43, + 103, + 77, 1, 0, 0, 0, - 69, - 55, + 103, + 89, 1, 0, 0, 0, - 69, - 62, + 103, + 96, 1, 0, 0, 0, - 70, - 82, + 104, + 116, 1, 0, 0, 0, - 71, - 72, + 105, + 106, 10, 12, 0, 0, - 72, - 73, + 106, + 107, 7, 1, 0, 0, - 73, - 81, + 107, + 115, + 3, + 6, 3, - 4, - 2, 13, - 74, - 75, + 108, + 109, 10, 11, 0, 0, - 75, - 76, + 109, + 110, 7, 0, 0, 0, - 76, - 81, + 110, + 115, + 3, + 6, 3, - 4, - 2, 12, - 77, - 78, + 111, + 112, 10, 10, 0, 0, - 78, - 79, + 112, + 113, 5, 13, 0, 0, - 79, - 81, + 113, + 115, + 3, + 6, 3, - 4, - 2, 11, - 80, - 71, + 114, + 105, 1, 0, 0, 0, - 80, - 74, + 114, + 108, 1, 0, 0, 0, - 80, - 77, + 114, + 111, 1, 0, 0, 0, - 81, - 84, + 115, + 118, 1, 0, 0, 0, - 82, - 80, + 116, + 114, 1, 0, 0, 0, - 82, - 83, + 116, + 117, 1, 0, 0, 0, - 83, - 5, + 117, + 7, 1, 0, 0, 0, - 84, - 82, + 118, + 116, 1, 0, 0, 0, - 6, - 12, - 38, - 50, - 69, - 80, - 82, + 9, + 13, + 35, + 43, + 45, + 72, + 84, + 103, + 114, + 116, ] @@ -820,9 +1130,9 @@ class ExprParser(Parser): "", "'+'", "'-'", + "'.'", "'/'", "'*'", - "'.'", "'('", "')'", "','", @@ -861,9 +1171,10 @@ class ExprParser(Parser): RULE_fullexpr = 0 RULE_shift = 1 - RULE_expr = 2 + RULE_shift_expr = 2 + RULE_expr = 3 - ruleNames = ["fullexpr", "shift", "expr"] + ruleNames = ["fullexpr", "shift", "shift_expr", "expr"] EOF = Token.EOF T__0 = 1 @@ -893,85 +1204,331 @@ def __init__(self, input: TokenStream, output: TextIO = sys.stdout): ) self._predicates = None - class FullexprContext(ParserRuleContext): - __slots__ = "parser" + class FullexprContext(ParserRuleContext): + __slots__ = "parser" + + 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) + + def EOF(self): + return self.getToken(ExprParser.EOF, 0) + + def getRuleIndex(self): + return ExprParser.RULE_fullexpr + + 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, 0, self.RULE_fullexpr) + try: + self.enterOuterAlt(localctx, 1) + self.state = 8 + self.expr(0) + self.state = 9 + self.match(ExprParser.EOF) + except RecognitionException as re: + localctx.exception = re + self._errHandler.reportError(self, re) + self._errHandler.recover(self, re) + finally: + self.exitRule() + return localctx + + class ShiftContext(ParserRuleContext): + __slots__ = "parser" + + def __init__( + self, parser, parent: ParserRuleContext = None, invokingState: int = -1 + ): + super().__init__(parent, invokingState) + self.parser = parser + + def TIME(self): + return self.getToken(ExprParser.TIME, 0) + + def shift_expr(self): + return self.getTypedRuleContext(ExprParser.Shift_exprContext, 0) + + def getRuleIndex(self): + return ExprParser.RULE_shift + + 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, 2, self.RULE_shift) + self._la = 0 # Token type + try: + self.enterOuterAlt(localctx, 1) + self.state = 11 + self.match(ExprParser.TIME) + self.state = 13 + self._errHandler.sync(self) + _la = self._input.LA(1) + if _la == 1 or _la == 2: + self.state = 12 + self.shift_expr(0) + + except RecognitionException as re: + localctx.exception = re + self._errHandler.reportError(self, re) + self._errHandler.recover(self, re) + finally: + self.exitRule() + return localctx + + class Shift_exprContext(ParserRuleContext): + __slots__ = "parser" + + 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): + super().copyFrom(ctx) + + class SignedIdentifierContext(Shift_exprContext): + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.Shift_exprContext + super().__init__(parser) + self.op = None # Token + self.copyFrom(ctx) + + def IDENTIFIER(self): + return self.getToken(ExprParser.IDENTIFIER, 0) + + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitSignedIdentifier"): + return visitor.visitSignedIdentifier(self) + else: + return visitor.visitChildren(self) + + class SignedExpressionContext(Shift_exprContext): + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.Shift_exprContext + super().__init__(parser) + self.op = None # Token + self.copyFrom(ctx) + + def expr(self): + return self.getTypedRuleContext(ExprParser.ExprContext, 0) + + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitSignedExpression"): + return visitor.visitSignedExpression(self) + else: + return visitor.visitChildren(self) + + class SignedPortFieldContext(Shift_exprContext): + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.Shift_exprContext + super().__init__(parser) + self.op = None # Token + self.copyFrom(ctx) + + def IDENTIFIER(self, i: int = None): + if i is None: + return self.getTokens(ExprParser.IDENTIFIER) + else: + return self.getToken(ExprParser.IDENTIFIER, i) + + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitSignedPortField"): + return visitor.visitSignedPortField(self) + else: + return visitor.visitChildren(self) + + class SignedNumberContext(Shift_exprContext): + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.Shift_exprContext + super().__init__(parser) + self.op = None # Token + self.copyFrom(ctx) + + def NUMBER(self): + return self.getToken(ExprParser.NUMBER, 0) + + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitSignedNumber"): + return visitor.visitSignedNumber(self) + else: + return visitor.visitChildren(self) + class SignedFunctionContext(Shift_exprContext): def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.Shift_exprContext + super().__init__(parser) + self.op = None # Token + self.copyFrom(ctx) + + def IDENTIFIER(self): + return self.getToken(ExprParser.IDENTIFIER, 0) def expr(self): return self.getTypedRuleContext(ExprParser.ExprContext, 0) - def EOF(self): - return self.getToken(ExprParser.EOF, 0) - - def getRuleIndex(self): - return ExprParser.RULE_fullexpr - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitFullexpr"): - return visitor.visitFullexpr(self) + if hasattr(visitor, "visitSignedFunction"): + return visitor.visitSignedFunction(self) else: return visitor.visitChildren(self) - def fullexpr(self): - localctx = ExprParser.FullexprContext(self, self._ctx, self.state) - self.enterRule(localctx, 0, self.RULE_fullexpr) - try: - self.enterOuterAlt(localctx, 1) - self.state = 6 - self.expr(0) - self.state = 7 - self.match(ExprParser.EOF) - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx + class ShiftAddsubContext(Shift_exprContext): + def __init__( + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.Shift_exprContext + super().__init__(parser) + self.op = None # Token + self.copyFrom(ctx) - class ShiftContext(ParserRuleContext): - __slots__ = "parser" + def shift_expr(self): + return self.getTypedRuleContext(ExprParser.Shift_exprContext, 0) + + def expr(self): + return self.getTypedRuleContext(ExprParser.ExprContext, 0) + + def accept(self, visitor: ParseTreeVisitor): + if hasattr(visitor, "visitShiftAddsub"): + return visitor.visitShiftAddsub(self) + else: + return visitor.visitChildren(self) + class ShiftMuldivContext(Shift_exprContext): def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser + self, parser, ctx: ParserRuleContext + ): # actually a ExprParser.Shift_exprContext + super().__init__(parser) self.op = None # Token + self.copyFrom(ctx) - def TIME(self): - return self.getToken(ExprParser.TIME, 0) + def shift_expr(self): + return self.getTypedRuleContext(ExprParser.Shift_exprContext, 0) def expr(self): return self.getTypedRuleContext(ExprParser.ExprContext, 0) - def getRuleIndex(self): - return ExprParser.RULE_shift - def accept(self, visitor: ParseTreeVisitor): - if hasattr(visitor, "visitShift"): - return visitor.visitShift(self) + if hasattr(visitor, "visitShiftMuldiv"): + return visitor.visitShiftMuldiv(self) else: return visitor.visitChildren(self) - def shift(self): - localctx = ExprParser.ShiftContext(self, self._ctx, self.state) - self.enterRule(localctx, 2, self.RULE_shift) + def shift_expr(self, _p: int = 0): + _parentctx = self._ctx + _parentState = self.state + localctx = ExprParser.Shift_exprContext(self, self._ctx, _parentState) + _prevctx = localctx + _startState = 4 + self.enterRecursionRule(localctx, 4, self.RULE_shift_expr, _p) self._la = 0 # Token type try: self.enterOuterAlt(localctx, 1) - self.state = 9 - self.match(ExprParser.TIME) - self.state = 12 + self.state = 35 self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 1 or _la == 2: - self.state = 10 + la_ = self._interp.adaptivePredict(self._input, 1, self._ctx) + if la_ == 1: + localctx = ExprParser.SignedNumberContext(self, localctx) + self._ctx = localctx + _prevctx = localctx + + self.state = 16 + localctx.op = self._input.LT(1) + _la = self._input.LA(1) + if not (_la == 1 or _la == 2): + localctx.op = self._errHandler.recoverInline(self) + else: + self._errHandler.reportMatch(self) + self.consume() + self.state = 17 + self.match(ExprParser.NUMBER) + pass + + elif la_ == 2: + localctx = ExprParser.SignedIdentifierContext(self, localctx) + self._ctx = localctx + _prevctx = localctx + self.state = 18 + localctx.op = self._input.LT(1) + _la = self._input.LA(1) + if not (_la == 1 or _la == 2): + localctx.op = self._errHandler.recoverInline(self) + else: + self._errHandler.reportMatch(self) + self.consume() + self.state = 19 + self.match(ExprParser.IDENTIFIER) + pass + + elif la_ == 3: + localctx = ExprParser.SignedPortFieldContext(self, localctx) + self._ctx = localctx + _prevctx = localctx + self.state = 20 + localctx.op = self._input.LT(1) + _la = self._input.LA(1) + if not (_la == 1 or _la == 2): + localctx.op = self._errHandler.recoverInline(self) + else: + self._errHandler.reportMatch(self) + self.consume() + self.state = 21 + self.match(ExprParser.IDENTIFIER) + self.state = 22 + self.match(ExprParser.T__2) + self.state = 23 + self.match(ExprParser.IDENTIFIER) + pass + + elif la_ == 4: + localctx = ExprParser.SignedExpressionContext(self, localctx) + self._ctx = localctx + _prevctx = localctx + self.state = 24 + localctx.op = self._input.LT(1) + _la = self._input.LA(1) + if not (_la == 1 or _la == 2): + localctx.op = self._errHandler.recoverInline(self) + else: + self._errHandler.reportMatch(self) + self.consume() + self.state = 25 + self.match(ExprParser.T__5) + self.state = 26 + self.expr(0) + self.state = 27 + self.match(ExprParser.T__6) + pass + + elif la_ == 5: + localctx = ExprParser.SignedFunctionContext(self, localctx) + self._ctx = localctx + _prevctx = localctx + self.state = 29 localctx.op = self._input.LT(1) _la = self._input.LA(1) if not (_la == 1 or _la == 2): @@ -979,15 +1536,96 @@ def shift(self): else: self._errHandler.reportMatch(self) self.consume() - self.state = 11 + self.state = 30 + self.match(ExprParser.IDENTIFIER) + self.state = 31 + self.match(ExprParser.T__5) + self.state = 32 self.expr(0) + self.state = 33 + self.match(ExprParser.T__6) + pass + + self._ctx.stop = self._input.LT(-1) + self.state = 45 + 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: + if self._parseListeners is not None: + self.triggerExitRuleEvent() + _prevctx = localctx + self.state = 43 + self._errHandler.sync(self) + la_ = self._interp.adaptivePredict(self._input, 2, self._ctx) + if la_ == 1: + localctx = ExprParser.ShiftAddsubContext( + self, + ExprParser.Shift_exprContext( + self, _parentctx, _parentState + ), + ) + self.pushNewRecursionContext( + localctx, _startState, self.RULE_shift_expr + ) + self.state = 37 + if not self.precpred(self._ctx, 6): + from antlr4.error.Errors import FailedPredicateException + + raise FailedPredicateException( + self, "self.precpred(self._ctx, 6)" + ) + self.state = 38 + localctx.op = self._input.LT(1) + _la = self._input.LA(1) + if not (_la == 1 or _la == 2): + localctx.op = self._errHandler.recoverInline(self) + else: + self._errHandler.reportMatch(self) + self.consume() + self.state = 39 + self.expr(0) + pass + + elif la_ == 2: + localctx = ExprParser.ShiftMuldivContext( + self, + ExprParser.Shift_exprContext( + self, _parentctx, _parentState + ), + ) + self.pushNewRecursionContext( + localctx, _startState, self.RULE_shift_expr + ) + self.state = 40 + if not self.precpred(self._ctx, 3): + from antlr4.error.Errors import FailedPredicateException + + raise FailedPredicateException( + self, "self.precpred(self._ctx, 3)" + ) + self.state = 41 + localctx.op = self._input.LT(1) + _la = self._input.LA(1) + if not (_la == 4 or _la == 5): + localctx.op = self._errHandler.recoverInline(self) + else: + self._errHandler.reportMatch(self) + self.consume() + self.state = 42 + self.expr(0) + pass + + self.state = 47 + self._errHandler.sync(self) + _alt = self._interp.adaptivePredict(self._input, 3, self._ctx) except RecognitionException as re: localctx.exception = re self._errHandler.reportError(self, re) self._errHandler.recover(self, re) finally: - self.exitRule() + self.unrollRecursionContexts(_parentctx) return localctx class ExprContext(ParserRuleContext): @@ -1288,22 +1926,22 @@ def expr(self, _p: int = 0): _parentState = self.state localctx = ExprParser.ExprContext(self, self._ctx, _parentState) _prevctx = localctx - _startState = 4 - self.enterRecursionRule(localctx, 4, self.RULE_expr, _p) + _startState = 6 + self.enterRecursionRule(localctx, 6, self.RULE_expr, _p) self._la = 0 # Token type try: self.enterOuterAlt(localctx, 1) - self.state = 69 + self.state = 103 self._errHandler.sync(self) - la_ = self._interp.adaptivePredict(self._input, 3, self._ctx) + la_ = self._interp.adaptivePredict(self._input, 6, self._ctx) if la_ == 1: localctx = ExprParser.NegationContext(self, localctx) self._ctx = localctx _prevctx = localctx - self.state = 15 + self.state = 49 self.match(ExprParser.T__1) - self.state = 16 + self.state = 50 self.expr(13) pass @@ -1311,7 +1949,7 @@ def expr(self, _p: int = 0): localctx = ExprParser.IdentifierContext(self, localctx) self._ctx = localctx _prevctx = localctx - self.state = 17 + self.state = 51 self.match(ExprParser.IDENTIFIER) pass @@ -1319,11 +1957,11 @@ def expr(self, _p: int = 0): localctx = ExprParser.PortFieldContext(self, localctx) self._ctx = localctx _prevctx = localctx - self.state = 18 + self.state = 52 self.match(ExprParser.IDENTIFIER) - self.state = 19 - self.match(ExprParser.T__4) - self.state = 20 + self.state = 53 + self.match(ExprParser.T__2) + self.state = 54 self.match(ExprParser.IDENTIFIER) pass @@ -1331,7 +1969,7 @@ def expr(self, _p: int = 0): localctx = ExprParser.NumberContext(self, localctx) self._ctx = localctx _prevctx = localctx - self.state = 21 + self.state = 55 self.match(ExprParser.NUMBER) pass @@ -1339,11 +1977,11 @@ def expr(self, _p: int = 0): localctx = ExprParser.ExpressionContext(self, localctx) self._ctx = localctx _prevctx = localctx - self.state = 22 + self.state = 56 self.match(ExprParser.T__5) - self.state = 23 + self.state = 57 self.expr(0) - self.state = 24 + self.state = 58 self.match(ExprParser.T__6) pass @@ -1351,13 +1989,13 @@ def expr(self, _p: int = 0): localctx = ExprParser.FunctionContext(self, localctx) self._ctx = localctx _prevctx = localctx - self.state = 26 + self.state = 60 self.match(ExprParser.IDENTIFIER) - self.state = 27 + self.state = 61 self.match(ExprParser.T__5) - self.state = 28 + self.state = 62 self.expr(0) - self.state = 29 + self.state = 63 self.match(ExprParser.T__6) pass @@ -1365,25 +2003,25 @@ def expr(self, _p: int = 0): localctx = ExprParser.TimeShiftContext(self, localctx) self._ctx = localctx _prevctx = localctx - self.state = 31 + self.state = 65 self.match(ExprParser.IDENTIFIER) - self.state = 32 + self.state = 66 self.match(ExprParser.LBRACKET) - self.state = 33 + self.state = 67 self.shift() - self.state = 38 + self.state = 72 self._errHandler.sync(self) _la = self._input.LA(1) while _la == 8: - self.state = 34 + self.state = 68 self.match(ExprParser.T__7) - self.state = 35 + self.state = 69 self.shift() - self.state = 40 + self.state = 74 self._errHandler.sync(self) _la = self._input.LA(1) - self.state = 41 + self.state = 75 self.match(ExprParser.RBRACKET) pass @@ -1391,25 +2029,25 @@ def expr(self, _p: int = 0): localctx = ExprParser.TimeIndexContext(self, localctx) self._ctx = localctx _prevctx = localctx - self.state = 43 + self.state = 77 self.match(ExprParser.IDENTIFIER) - self.state = 44 + self.state = 78 self.match(ExprParser.LBRACKET) - self.state = 45 + self.state = 79 self.expr(0) - self.state = 50 + self.state = 84 self._errHandler.sync(self) _la = self._input.LA(1) while _la == 8: - self.state = 46 + self.state = 80 self.match(ExprParser.T__7) - self.state = 47 + self.state = 81 self.expr(0) - self.state = 52 + self.state = 86 self._errHandler.sync(self) _la = self._input.LA(1) - self.state = 53 + self.state = 87 self.match(ExprParser.RBRACKET) pass @@ -1417,17 +2055,17 @@ def expr(self, _p: int = 0): localctx = ExprParser.TimeShiftRangeContext(self, localctx) self._ctx = localctx _prevctx = localctx - self.state = 55 + self.state = 89 self.match(ExprParser.IDENTIFIER) - self.state = 56 + self.state = 90 self.match(ExprParser.LBRACKET) - self.state = 57 + self.state = 91 localctx.shift1 = self.shift() - self.state = 58 + self.state = 92 self.match(ExprParser.T__8) - self.state = 59 + self.state = 93 localctx.shift2 = self.shift() - self.state = 60 + self.state = 94 self.match(ExprParser.RBRACKET) pass @@ -1435,32 +2073,32 @@ def expr(self, _p: int = 0): localctx = ExprParser.TimeRangeContext(self, localctx) self._ctx = localctx _prevctx = localctx - self.state = 62 + self.state = 96 self.match(ExprParser.IDENTIFIER) - self.state = 63 + self.state = 97 self.match(ExprParser.LBRACKET) - self.state = 64 + self.state = 98 self.expr(0) - self.state = 65 + self.state = 99 self.match(ExprParser.T__8) - self.state = 66 + self.state = 100 self.expr(0) - self.state = 67 + self.state = 101 self.match(ExprParser.RBRACKET) pass self._ctx.stop = self._input.LT(-1) - self.state = 82 + self.state = 116 self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input, 5, self._ctx) + _alt = self._interp.adaptivePredict(self._input, 8, self._ctx) while _alt != 2 and _alt != ATN.INVALID_ALT_NUMBER: if _alt == 1: if self._parseListeners is not None: self.triggerExitRuleEvent() _prevctx = localctx - self.state = 80 + self.state = 114 self._errHandler.sync(self) - la_ = self._interp.adaptivePredict(self._input, 4, self._ctx) + la_ = self._interp.adaptivePredict(self._input, 7, self._ctx) if la_ == 1: localctx = ExprParser.MuldivContext( self, ExprParser.ExprContext(self, _parentctx, _parentState) @@ -1468,22 +2106,22 @@ def expr(self, _p: int = 0): self.pushNewRecursionContext( localctx, _startState, self.RULE_expr ) - self.state = 71 + self.state = 105 if not self.precpred(self._ctx, 12): from antlr4.error.Errors import FailedPredicateException raise FailedPredicateException( self, "self.precpred(self._ctx, 12)" ) - self.state = 72 + self.state = 106 localctx.op = self._input.LT(1) _la = self._input.LA(1) - if not (_la == 3 or _la == 4): + if not (_la == 4 or _la == 5): localctx.op = self._errHandler.recoverInline(self) else: self._errHandler.reportMatch(self) self.consume() - self.state = 73 + self.state = 107 self.expr(13) pass @@ -1494,14 +2132,14 @@ def expr(self, _p: int = 0): self.pushNewRecursionContext( localctx, _startState, self.RULE_expr ) - self.state = 74 + self.state = 108 if not self.precpred(self._ctx, 11): from antlr4.error.Errors import FailedPredicateException raise FailedPredicateException( self, "self.precpred(self._ctx, 11)" ) - self.state = 75 + self.state = 109 localctx.op = self._input.LT(1) _la = self._input.LA(1) if not (_la == 1 or _la == 2): @@ -1509,7 +2147,7 @@ def expr(self, _p: int = 0): else: self._errHandler.reportMatch(self) self.consume() - self.state = 76 + self.state = 110 self.expr(12) pass @@ -1520,22 +2158,22 @@ def expr(self, _p: int = 0): self.pushNewRecursionContext( localctx, _startState, self.RULE_expr ) - self.state = 77 + self.state = 111 if not self.precpred(self._ctx, 10): from antlr4.error.Errors import FailedPredicateException raise FailedPredicateException( self, "self.precpred(self._ctx, 10)" ) - self.state = 78 + self.state = 112 self.match(ExprParser.COMPARISON) - self.state = 79 + self.state = 113 self.expr(11) pass - self.state = 84 + self.state = 118 self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input, 5, self._ctx) + _alt = self._interp.adaptivePredict(self._input, 8, self._ctx) except RecognitionException as re: localctx.exception = re @@ -1548,19 +2186,27 @@ def expr(self, _p: int = 0): def sempred(self, localctx: RuleContext, ruleIndex: int, predIndex: int): if self._predicates == None: self._predicates = dict() - self._predicates[2] = self.expr_sempred + self._predicates[2] = self.shift_expr_sempred + self._predicates[3] = self.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): + def shift_expr_sempred(self, localctx: Shift_exprContext, predIndex: int): if predIndex == 0: - return self.precpred(self._ctx, 12) + return self.precpred(self._ctx, 6) if predIndex == 1: - return self.precpred(self._ctx, 11) + return self.precpred(self._ctx, 3) + def expr_sempred(self, localctx: ExprContext, predIndex: int): if predIndex == 2: + return self.precpred(self._ctx, 12) + + if predIndex == 3: + return self.precpred(self._ctx, 11) + + if predIndex == 4: return self.precpred(self._ctx, 10) diff --git a/src/andromede/expression/parsing/antlr/ExprVisitor.py b/src/andromede/expression/parsing/antlr/ExprVisitor.py index e7871aa9..6bae5e30 100644 --- a/src/andromede/expression/parsing/antlr/ExprVisitor.py +++ b/src/andromede/expression/parsing/antlr/ExprVisitor.py @@ -18,6 +18,34 @@ def visitFullexpr(self, ctx: ExprParser.FullexprContext): def visitShift(self, ctx: ExprParser.ShiftContext): return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#signedIdentifier. + def visitSignedIdentifier(self, ctx: ExprParser.SignedIdentifierContext): + return self.visitChildren(ctx) + + # Visit a parse tree produced by ExprParser#signedExpression. + def visitSignedExpression(self, ctx: ExprParser.SignedExpressionContext): + return self.visitChildren(ctx) + + # Visit a parse tree produced by ExprParser#signedPortField. + def visitSignedPortField(self, ctx: ExprParser.SignedPortFieldContext): + return self.visitChildren(ctx) + + # Visit a parse tree produced by ExprParser#signedNumber. + def visitSignedNumber(self, ctx: ExprParser.SignedNumberContext): + return self.visitChildren(ctx) + + # Visit a parse tree produced by ExprParser#signedFunction. + def visitSignedFunction(self, ctx: ExprParser.SignedFunctionContext): + return self.visitChildren(ctx) + + # Visit a parse tree produced by ExprParser#shiftAddsub. + def visitShiftAddsub(self, ctx: ExprParser.ShiftAddsubContext): + return self.visitChildren(ctx) + + # Visit a parse tree produced by ExprParser#shiftMuldiv. + def visitShiftMuldiv(self, ctx: ExprParser.ShiftMuldivContext): + return self.visitChildren(ctx) + # Visit a parse tree produced by ExprParser#identifier. def visitIdentifier(self, ctx: ExprParser.IdentifierContext): return self.visitChildren(ctx) diff --git a/src/andromede/expression/parsing/antlr/__init__.py b/src/andromede/expression/parsing/antlr/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/andromede/expression/parsing/parse_expression.py b/src/andromede/expression/parsing/parse_expression.py index aa968a10..5c453c15 100644 --- a/src/andromede/expression/parsing/parse_expression.py +++ b/src/andromede/expression/parsing/parse_expression.py @@ -158,13 +158,89 @@ def visitFunction(self, ctx: ExprParser.FunctionContext) -> ExpressionNode: # Visit a parse tree produced by ExprParser#shift. def visitShift(self, ctx: ExprParser.ShiftContext) -> ExpressionNode: - if ctx.expr() is None: # type: ignore + if ctx.shift_expr() is None: # type: ignore return literal(0) - shift = ctx.expr().accept(self) # type: ignore - if ctx.op.text == "-": # type: ignore - return -shift + shift = ctx.shift_expr().accept(self) # type: ignore return shift + # Visit a parse tree produced by ExprParser#signedNumber. + def visitSignedNumber(self, ctx: ExprParser.SignedNumberContext) -> ExpressionNode: + if ctx.op.text == "-": # type: ignore + return -literal(float(ctx.NUMBER().getText())) # type: ignore + else: + return literal(float(ctx.NUMBER().getText())) # type: ignore + + # Visit a parse tree produced by ExprParser#shiftAddsub. + def visitShiftAddsub(self, ctx: ExprParser.ShiftAddsubContext) -> ExpressionNode: + left = ctx.shift_expr().accept(self) # type: ignore + right = ctx.expr().accept(self) # type: ignore + op = ctx.op.text # type: ignore + if op == "+": + return left + right + elif op == "-": + return left - right + raise ValueError(f"Invalid operator {op}") + + # Visit a parse tree produced by ExprParser#signedIdentifier. + def visitSignedIdentifier( + self, ctx: ExprParser.SignedIdentifierContext + ) -> ExpressionNode: + if ctx.op.text == "-": # type: ignore + return -self._convert_identifier(ctx.IDENTIFIER().getText()) # type: ignore + else: + return self._convert_identifier(ctx.IDENTIFIER().getText()) # type: ignore + + # Visit a parse tree produced by ExprParser#signedPortField. + def visitSignedPortField( + self, ctx: ExprParser.SignedPortFieldContext + ) -> ExpressionNode: + op = ctx.op.text # type: ignore + if op == "-": + return -PortFieldNode( + port_name=ctx.IDENTIFIER(0).getText(), # type: ignore + field_name=ctx.IDENTIFIER(1).getText(), # type: ignore + ) + else: + return PortFieldNode( + port_name=ctx.IDENTIFIER(0).getText(), # type: ignore + field_name=ctx.IDENTIFIER(1).getText(), # type: ignore + ) + + # Visit a parse tree produced by ExprParser#shiftMuldiv. + def visitShiftMuldiv(self, ctx: ExprParser.ShiftMuldivContext) -> ExpressionNode: + left = ctx.shift_expr().accept(self) # type: ignore + right = ctx.expr().accept(self) # type: ignore + op = ctx.op.text # type: ignore + if op == "*": + return left * right + elif op == "/": + return left / right + raise ValueError(f"Invalid operator {op}") + + # Visit a parse tree produced by ExprParser#signedExpression. + def visitSignedExpression( + self, ctx: ExprParser.SignedExpressionContext + ) -> ExpressionNode: + if ctx.op.text == "-": # type: ignore + return -ctx.expr().accept(self) # type: ignore + else: + return ctx.expr().accept(self) # type: ignore + + # Visit a parse tree produced by ExprParser#signedFunction. + def visitSignedFunction( + self, ctx: ExprParser.SignedFunctionContext + ) -> ExpressionNode: + function_name: str = ctx.IDENTIFIER().getText() # type: ignore + operand: ExpressionNode = ctx.expr().accept(self) # type: ignore + op = ctx.op.text # type: ignore + fn = _FUNCTIONS.get(function_name, None) + if fn is None: + raise ValueError(f"Encountered invalid function name {function_name}") + if ctx.op.text == "-": # type: ignore + return -fn(operand) + else: + return fn(operand) + _FUNCTIONS = { "sum": ExpressionNode.sum, diff --git a/tests/functional/libs/lib.yml b/tests/functional/libs/lib.yml index b27a7d2b..27a8b47e 100644 --- a/tests/functional/libs/lib.yml +++ b/tests/functional/libs/lib.yml @@ -180,9 +180,9 @@ library: - name: min production expression: production >= nb_units_on * p_min - name: on units variation - expression: nb_units_on = nb_units_on[-1] + nb_starting - nb_stoping + expression: nb_units_on = nb_units_on[t-1] + nb_starting - nb_stoping - name: starting time - expression: sum(nb_starting[-d_min_up + 1 .. 0]) <= nb_units_on + expression: sum(nb_starting[t-d_min_up + 1 .. t]) <= nb_units_on - name: stoping time - expression: sum(nb_stoping[-d_min_down + 1 .. 0]) <= nb_units_max - nb_units_on + expression: sum(nb_stoping[t-d_min_down + 1 .. t]) <= nb_units_max - nb_units_on objective: expec(sum(cost * production)) \ No newline at end of file diff --git a/tests/functional/test_andromede_yml.py b/tests/functional/test_andromede_yml.py index 8d915e6f..c959f0f4 100644 --- a/tests/functional/test_andromede_yml.py +++ b/tests/functional/test_andromede_yml.py @@ -417,7 +417,7 @@ def test_min_up_down_times_2(lib) -> None: database.add_data("G", "p_min", ConstantData(100)) database.add_data("G", "cost", ConstantData(100)) database.add_data("G", "d_min_up", ConstantData(2)) - database.add_data("G", "d_min_down", ConstantData(2)) + database.add_data("G", "d_min_down", ConstantData(1)) database.add_data("G", "nb_units_max", ConstantData(1)) database.add_data("G", "nb_failures", ConstantData(0)) @@ -476,5 +476,8 @@ def test_min_up_down_times_2(lib) -> None: ) status = problem.solver.Solve() + print(problem.solver.ExportModelAsMpsFormat(fixed_format=False, obfuscated=False)) + print(OutputValues(problem).component("G").var("nb_units_on").value) + assert status == problem.solver.OPTIMAL assert problem.solver.Objective().Value() == pytest.approx(61000) diff --git a/tests/unittests/expressions/parsing/test_expression_parsing.py b/tests/unittests/expressions/parsing/test_expression_parsing.py index 5aab206d..f64e424a 100644 --- a/tests/unittests/expressions/parsing/test_expression_parsing.py +++ b/tests/unittests/expressions/parsing/test_expression_parsing.py @@ -57,6 +57,18 @@ "x[t-1, t+4]", var("x").shift([-literal(1), literal(4)]), ), + ( + {"x"}, + {}, + "x[t-1+1]", + var("x").shift(-literal(1) + literal(1)), + ), + ( + {"x"}, + {"d"}, + "x[t-d+1]", + var("x").shift(-param("d") + literal(1)), + ), ( {"x"}, {},