You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ra...@apache.org on 2018/05/31 13:14:06 UTC

[sling-org-apache-sling-scripting-sightly-compiler] branch issue/SLING-7681 updated: SLING-7700 - [HTL] Implement operator precedence for binary operations

This is an automated email from the ASF dual-hosted git repository.

radu pushed a commit to branch issue/SLING-7681
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler.git


The following commit(s) were added to refs/heads/issue/SLING-7681 by this push:
     new f04e0f3  SLING-7700 - [HTL] Implement operator precedence for binary operations
f04e0f3 is described below

commit f04e0f3bfa976c486814d4b55fd7bd383a2ed829
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Thu May 31 15:11:19 2018 +0200

    SLING-7700 - [HTL] Implement operator precedence for binary operations
---
 .../impl/parser/expr/generated/SightlyLexer.g4        |  2 +-
 .../impl/parser/expr/generated/SightlyParser.g4       | 19 +++++++++++--------
 2 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/src/main/antlr4/org/apache/sling/scripting/sightly/impl/parser/expr/generated/SightlyLexer.g4 b/src/main/antlr4/org/apache/sling/scripting/sightly/impl/parser/expr/generated/SightlyLexer.g4
index de8c1fc..255fb2a 100644
--- a/src/main/antlr4/org/apache/sling/scripting/sightly/impl/parser/expr/generated/SightlyLexer.g4
+++ b/src/main/antlr4/org/apache/sling/scripting/sightly/impl/parser/expr/generated/SightlyLexer.g4
@@ -115,7 +115,7 @@ HEX_DIGIT : ('0'..'9'|'a'..'f'|'A'..'F') ;
 
 fragment
 ESC_SEQ
-    :   '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\')
+    :   '\\' ('b'|'t'|'n'|'f'|'r'|'"'|'\''|'\\')
     |   UNICODE_ESC
     ;
 
diff --git a/src/main/antlr4/org/apache/sling/scripting/sightly/impl/parser/expr/generated/SightlyParser.g4 b/src/main/antlr4/org/apache/sling/scripting/sightly/impl/parser/expr/generated/SightlyParser.g4
index 2470086..e605fca 100644
--- a/src/main/antlr4/org/apache/sling/scripting/sightly/impl/parser/expr/generated/SightlyParser.g4
+++ b/src/main/antlr4/org/apache/sling/scripting/sightly/impl/parser/expr/generated/SightlyParser.g4
@@ -72,18 +72,21 @@ option returns [String name, ExpressionNode value]
 
 
 exprNode returns [ExpressionNode node]
-    :   condition=binaryOp TERNARY_Q_OP thenBranch=binaryOp TERNARY_BRANCHES_OP elseBranch=binaryOp
+    :   condition=orBinaryOp TERNARY_Q_OP thenBranch=orBinaryOp TERNARY_BRANCHES_OP elseBranch=orBinaryOp
         {$node = new TernaryOperator($condition.node, $thenBranch.node, $elseBranch.node);}
-    |   binaryOp {$node = $binaryOp.node;}
+    |   orBinaryOp {$node = $orBinaryOp.node;}
     ;
 
-binaryOp returns [ExpressionNode node] //is there any priority precedence between AND & OR ?
-    :   left=comparisonTerm { $node = $left.node; }
-        (operator right=comparisonTerm { $node = new BinaryOperation($operator.op, $node, $right.node); })*
+orBinaryOp returns [ExpressionNode node]
+    : left=andBinaryOp { $node = $left.node; } (OR_OP right=andBinaryOp { $node = new BinaryOperation(BinaryOperator.OR, $node, $right.node);})*
     ;
-    
-operator returns [BinaryOperator op]
-    :    AND_OP { $op = BinaryOperator.AND; } | OR_OP { $op = BinaryOperator.OR; } | IN_OP { $op = BinaryOperator.IN; }
+
+andBinaryOp returns [ExpressionNode node]
+    : left=inBinaryOp { $node = $left.node; } (AND_OP right=inBinaryOp{ $node = new BinaryOperation(BinaryOperator.AND, $node, $right.node);})*
+    ;
+
+inBinaryOp returns [ExpressionNode node]
+    : left=comparisonTerm { $node = $left.node; } (IN_OP right=comparisonTerm { $node = new BinaryOperation(BinaryOperator.IN, $node, $right.node); })*
     ;
 
 comparisonTerm returns [ExpressionNode node]

-- 
To stop receiving notification emails like this one, please contact
radu@apache.org.