freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ddek...@apache.org
Subject [1/2] incubator-freemarker git commit: Some FTL.jj cleanup
Date Thu, 26 Oct 2017 17:47:02 GMT
Repository: incubator-freemarker
Updated Branches:
  refs/heads/2.3-gae d32c81faf -> 792ccde6d


Some FTL.jj cleanup


Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/a0fb4ada
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/a0fb4ada
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/a0fb4ada

Branch: refs/heads/2.3-gae
Commit: a0fb4ada81a2cb02679eef3f2ba5812b28b19663
Parents: d32c81f
Author: ddekany <ddekany@apache.org>
Authored: Thu Oct 26 19:41:48 2017 +0200
Committer: ddekany <ddekany@apache.org>
Committed: Thu Oct 26 19:41:48 2017 +0200

----------------------------------------------------------------------
 src/main/javacc/FTL.jj | 82 +++++++++++++++++++++------------------------
 1 file changed, 38 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/a0fb4ada/src/main/javacc/FTL.jj
----------------------------------------------------------------------
diff --git a/src/main/javacc/FTL.jj b/src/main/javacc/FTL.jj
index ddbf78f..0d07789 100644
--- a/src/main/javacc/FTL.jj
+++ b/src/main/javacc/FTL.jj
@@ -1594,11 +1594,39 @@ Expression Expression() :
 }
 
 /**
+ * Deals with the operators that have the highest precedence. Also deals with `exp!default`
and `exp!`, due to parser
+ * tricks needed because of the last.
+ */
+Expression HighestPrecedenceExpression() :
+{
+    Expression exp;
+}
+{
+    exp = AtomicExpression()
+    (
+        exp = DotVariable(exp)
+        |
+        exp = DynamicKey(exp)
+        |
+        exp = MethodArgs(exp)
+        |
+        exp = BuiltIn(exp)
+        |
+        exp = DefaultTo(exp)
+        |
+        exp = Exists(exp)
+    )*
+    {
+        return exp;
+    }
+}
+
+/**
  * Lowest level expression, a literal, a variable,
  * or a possibly more complex expression bounded
  * by parentheses.
  */
-Expression PrimaryExpression() :
+Expression AtomicExpression() :
 {
     Expression exp;
 }
@@ -1620,10 +1648,6 @@ Expression PrimaryExpression() :
         |   
         exp = BuiltinVariable()
     )
-    (
-        LOOKAHEAD(<DOT> | <OPEN_BRACKET> |<OPEN_PAREN> | <BUILT_IN>
| <EXCLAM> | <TERMINATING_EXCLAM> | <EXISTS>)
-        exp = AddSubExpression(exp)
-    )*
     {
         return exp;
     }
@@ -1646,11 +1670,9 @@ Expression Parenthesis() :
 }
 
 /**
- * A primary expression preceded by zero or
- * more unary operators. (The only unary operator we
- * currently have is the NOT.)
+ * A primary expression preceded by zero or more unary prefix operators.
  */
-Expression UnaryExpression() :
+Expression UnaryPrefixExpression() :
 {
     Expression exp, result;
     boolean haveNot = false;
@@ -1662,7 +1684,7 @@ Expression UnaryExpression() :
         |
         result = NotExpression()
         |
-        result = PrimaryExpression()
+        result = HighestPrecedenceExpression()
     )
     {
         return result;
@@ -1679,7 +1701,7 @@ Expression NotExpression() :
     (
         t = <EXCLAM> { nots.add(t); }
     )+
-    exp = PrimaryExpression()
+    exp = HighestPrecedenceExpression()
     {
         for (int i = 0; i < nots.size(); i++) {
             result = new NotExpression(exp);
@@ -1703,7 +1725,7 @@ Expression UnaryPlusMinusExpression() :
         |
         t = <MINUS> { isMinus = true; }
     )
-    exp = PrimaryExpression()
+    exp = HighestPrecedenceExpression()
     {
         result = new UnaryPlusMinusExpression(exp, isMinus);  
         result.setLocation(template, t, exp);
@@ -1748,8 +1770,8 @@ Expression AdditiveExpression() :
 }
 
 /**
- * A unary expression followed by zero or more
- * unary expressions with operators in between.
+ * A unary prefix expression followed by zero or more
+ * unary prefix expressions with operators in between.
  */
 Expression MultiplicativeExpression() :
 {
@@ -1757,7 +1779,7 @@ Expression MultiplicativeExpression() :
     int operation = ArithmeticExpression.TYPE_MULTIPLICATION;
 }
 {
-    lhs = UnaryExpression() { result = lhs; }
+    lhs = UnaryPrefixExpression() { result = lhs; }
     (
         LOOKAHEAD(<TIMES>|<DIVIDE>|<PERCENT>)
         (
@@ -1769,7 +1791,7 @@ Expression MultiplicativeExpression() :
                 <PERCENT> {operation = ArithmeticExpression.TYPE_MODULO; }
             )
         )
-        rhs = UnaryExpression()
+        rhs = UnaryPrefixExpression()
         {
             numberLiteralOnly(lhs);
             numberLiteralOnly(rhs);
@@ -2043,34 +2065,6 @@ BuiltinVariable BuiltinVariable() :
     }
 }
 
-/**
- * Production that builds up an expression
- * using the dot or dynamic key name
- * or the args list if this is a method invocation.
- */
-Expression AddSubExpression(Expression exp) :
-{
-    Expression result = null;
-}
-{
-    (
-        result = DotVariable(exp)
-        |
-        result = DynamicKey(exp)
-        |
-        result = MethodArgs(exp)
-        |
-        result = BuiltIn(exp)
-        |
-        result = DefaultTo(exp)
-        |
-        result = Exists(exp)
-    )
-    {
-        return result;
-    }
-}
-
 Expression DefaultTo(Expression exp) :
 {
     Expression rhs = null;


Mime
View raw message