You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@freemarker.apache.org by dd...@apache.org on 2017/10/26 17:47:02 UTC
[1/2] incubator-freemarker git commit: Some FTL.jj cleanup
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 <dd...@apache.org>
Authored: Thu Oct 26 19:41:48 2017 +0200
Committer: ddekany <dd...@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;
[2/2] incubator-freemarker git commit: (Removed some unnecessary
parentheses sometimes added in canonical forms.)
Posted by dd...@apache.org.
(Removed some unnecessary parentheses sometimes added in canonical forms.)
Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/792ccde6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/792ccde6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/792ccde6
Branch: refs/heads/2.3-gae
Commit: 792ccde6da90dc3b9bc8925b8bfb80a34fe8cbff
Parents: a0fb4ad
Author: ddekany <dd...@apache.org>
Authored: Thu Oct 26 19:43:02 2017 +0200
Committer: ddekany <dd...@apache.org>
Committed: Thu Oct 26 19:45:27 2017 +0200
----------------------------------------------------------------------
src/main/java/freemarker/core/MessageUtil.java | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/792ccde6/src/main/java/freemarker/core/MessageUtil.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/MessageUtil.java b/src/main/java/freemarker/core/MessageUtil.java
index ebdefb4..418ad26 100644
--- a/src/main/java/freemarker/core/MessageUtil.java
+++ b/src/main/java/freemarker/core/MessageUtil.java
@@ -178,7 +178,9 @@ class MessageUtil {
&& !(argExp instanceof Dot)
&& !(argExp instanceof DynamicKeyName)
&& !(argExp instanceof MethodCall)
- && !(argExp instanceof BuiltIn);
+ && !(argExp instanceof BuiltIn)
+ && !(argExp instanceof ExistsExpression)
+ && !(argExp instanceof ParentheticalExpression);
if (needParen) sb.append('(');
sb.append(argExp.getCanonicalForm());
if (needParen) sb.append(')');