freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ddek...@apache.org
Subject [2/2] incubator-freemarker git commit: Removed the following operator aliases: `=` for comparison (it can only be used for assignment now); use `==` instead. `&` for logical "and"; use `&&` instead. `|` for logical "or"; use `||` instead.
Date Mon, 17 Jul 2017 13:16:05 GMT
Removed the following operator aliases: `=` for comparison (it can only be used for assignment
now); use `==` instead. `&` for logical "and"; use `&&` instead. `|` for logical
"or"; use `||` instead.


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

Branch: refs/heads/3
Commit: d0f34dcc1e6b7ed802012a12c1168b467618f3b9
Parents: e5f21cf
Author: ddekany <ddekany@apache.org>
Authored: Mon Jul 17 15:14:56 2017 +0200
Committer: ddekany <ddekany@apache.org>
Committed: Mon Jul 17 15:15:46 2017 +0200

----------------------------------------------------------------------
 FM3-CHANGE-LOG.txt                              |  4 +++
 .../core/FM2ASTToFM3SourceConverter.java        |  8 ++---
 .../converter/FM2ToFM3ConverterTest.java        |  9 +++---
 .../freemarker/core/RemovedFM2SyntaxTest.java   | 34 ++++++++++++++++++++
 .../templates/sequence-builtins.ftl             |  2 +-
 .../freemarker/core/ASTDirAssignment.java       |  2 +-
 .../freemarker/core/ASTExpComparison.java       |  2 +-
 freemarker-core/src/main/javacc/FTL.jj          | 34 +++++++++-----------
 8 files changed, 65 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d0f34dcc/FM3-CHANGE-LOG.txt
----------------------------------------------------------------------
diff --git a/FM3-CHANGE-LOG.txt b/FM3-CHANGE-LOG.txt
index 51caf23..70300ce 100644
--- a/FM3-CHANGE-LOG.txt
+++ b/FM3-CHANGE-LOG.txt
@@ -56,6 +56,10 @@ Node: Changes already mentioned above aren't repeated here!
   - <#comment>...</#comment> (deprecated by <#-- ... -->)
   - <#transform ...>...</#transform> (deprecated by <@...>...</@...>)
   - <#foreach x in xs>...</#foreach> (deprecated by <#list xs as x>...</#list>)
+- Removed the following operator aliases:
+  - `=` for comparison (it can only be used for assignment now). Use `==` instead.
+  - `&` for logical "and". Use `&&` instead.
+  - `|` for logical "or". Use `||` instead.
 - Removed long deprecated `#{}` interpolations. They are treated as plain static text now.
   Converter note: The template converter tool translates these to `${}` interpolations. For
example `#{x}` is simply
   translated to `${b}`, while `#{x; m1M3}` is translated to `${x?string('0.0##')}`). The
output should remain the same.

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d0f34dcc/freemarker-converter/src/main/java/freemarker/core/FM2ASTToFM3SourceConverter.java
----------------------------------------------------------------------
diff --git a/freemarker-converter/src/main/java/freemarker/core/FM2ASTToFM3SourceConverter.java
b/freemarker-converter/src/main/java/freemarker/core/FM2ASTToFM3SourceConverter.java
index 0161cb8..3117ec2 100644
--- a/freemarker-converter/src/main/java/freemarker/core/FM2ASTToFM3SourceConverter.java
+++ b/freemarker-converter/src/main/java/freemarker/core/FM2ASTToFM3SourceConverter.java
@@ -1431,7 +1431,7 @@ public class FM2ASTToFM3SourceConverter {
         COMPARATOR_OP_MAP = new HashMap<String, String>();
         // For now we leave FM2 ops as is, but later in many cases they will be replaced.
         COMPARATOR_OP_MAP.put("==", "==");
-        COMPARATOR_OP_MAP.put("=", "=");
+        COMPARATOR_OP_MAP.put("=", "==");
         COMPARATOR_OP_MAP.put("!=", "!=");
         COMPARATOR_OP_MAP.put("<", "<");
         COMPARATOR_OP_MAP.put("lt", "lt");
@@ -1459,9 +1459,8 @@ public class FM2ASTToFM3SourceConverter {
 
     static {
         AND_OP_MAP = new HashMap<String, String>();
-        // For now we leave FM2 ops as is, but later in many cases they will be replaced.
         AND_OP_MAP.put("&&", "&&");
-        AND_OP_MAP.put("&", "&");
+        AND_OP_MAP.put("&", "&&");
         AND_OP_MAP.put("\\and", "\\and");
         AND_OP_MAP.put("&amp;&amp;", "&amp;&amp;");
     }
@@ -1474,9 +1473,8 @@ public class FM2ASTToFM3SourceConverter {
 
     static {
         OR_OP_MAP = new HashMap<String, String>();
-        // For now we leave FM2 ops as is, but later in many cases they will be replaced.
         OR_OP_MAP.put("||", "||");
-        OR_OP_MAP.put("|", "|");
+        OR_OP_MAP.put("|", "||");
     }
 
     private void printExpOr(OrExpression node) throws ConverterException {

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d0f34dcc/freemarker-converter/src/test/java/org/freemarker/converter/FM2ToFM3ConverterTest.java
----------------------------------------------------------------------
diff --git a/freemarker-converter/src/test/java/org/freemarker/converter/FM2ToFM3ConverterTest.java
b/freemarker-converter/src/test/java/org/freemarker/converter/FM2ToFM3ConverterTest.java
index 5d79962..5915476 100644
--- a/freemarker-converter/src/test/java/org/freemarker/converter/FM2ToFM3ConverterTest.java
+++ b/freemarker-converter/src/test/java/org/freemarker/converter/FM2ToFM3ConverterTest.java
@@ -128,16 +128,17 @@ public class FM2ToFM3ConverterTest extends ConverterTest {
                 + "${(a<#--7-->><#--8-->b)}${(a<#--9-->>=<#--A-->b)}"
                 + "${a<#--B-->==<#--C-->b}${a<#--D-->!=<#--E-->b}");
         // "Same" for now, will be different later.
-        assertConvertedSame("${a = b}${a == b}");
+        assertConverted("${a == b}${a == b}", "${a = b}${a == b}");
         assertConvertedSame("${a &lt; b}${a lt b}${a \\lt b}");
         assertConvertedSame("${a &lt;= b}${a lte b}${a \\lte b}");
         assertConvertedSame("${a &gt; b}${a gt b}${a \\gt b}");
         assertConvertedSame("${a &gt;= b}${a gte b}${a \\gte b}");
 
         // [FM3] Add \and and &amp;&amp; tests when 2.3.27 is released
-        assertConvertedSame("${a && b}${a & b}${a || b}${a | b}");
-        assertConvertedSame("${a<#--1-->&&<#--2-->b}${a<#--3-->&<#--4-->b}"
-                + "${a<#--5-->||<#--6-->b}${a<#--7-->|<#--8-->b}");
+        assertConverted("${a && b}${a && b}${a || b}${a || b}", "${a &&
b}${a & b}${a || b}${a | b}");
+        assertConverted(
+                "${a<#--1-->&&<#--2-->b}${a<#--3-->&&<#--4-->b}${a<#--5-->||<#--6-->b}${a<#--7-->||<#--8-->b}",
+                "${a<#--1-->&&<#--2-->b}${a<#--3-->&<#--4-->b}${a<#--5-->||<#--6-->b}${a<#--7-->|<#--8-->b}");
 
         assertConvertedSame("${!a}${! foo}${! <#--1--> bar}${!!c}");
 

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d0f34dcc/freemarker-core-test/src/test/java/org/apache/freemarker/core/RemovedFM2SyntaxTest.java
----------------------------------------------------------------------
diff --git a/freemarker-core-test/src/test/java/org/apache/freemarker/core/RemovedFM2SyntaxTest.java
b/freemarker-core-test/src/test/java/org/apache/freemarker/core/RemovedFM2SyntaxTest.java
new file mode 100644
index 0000000..89b981c
--- /dev/null
+++ b/freemarker-core-test/src/test/java/org/apache/freemarker/core/RemovedFM2SyntaxTest.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.freemarker.core;
+
+import org.apache.freemarker.test.TemplateTest;
+import org.junit.Test;
+
+public class RemovedFM2SyntaxTest extends TemplateTest {
+
+    @Test
+    public void testRemovedOperators() {
+       assertErrorContains("<#if a & b></#if>", ParseException.class);
+       assertErrorContains("<#if a | b></#if>", ParseException.class);
+       assertErrorContains("<#if a = b></#if>", ParseException.class);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d0f34dcc/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/sequence-builtins.ftl
----------------------------------------------------------------------
diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/sequence-builtins.ftl
b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/sequence-builtins.ftl
index ffda546..b86feb9 100644
--- a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/sequence-builtins.ftl
+++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/sequence-builtins.ftl
@@ -322,7 +322,7 @@ Chunk
 
 <#macro printTable ls columns fill>
   columns = ${columns}, fill = ${fill}:<#lt>
-  <#if fill='NULL'>
+  <#if fill=='NULL'>
     <#local rows = ls?chunk(columns)>
   <#else>
     <#local rows = ls?chunk(columns, fill)>

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d0f34dcc/freemarker-core/src/main/java/org/apache/freemarker/core/ASTDirAssignment.java
----------------------------------------------------------------------
diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/ASTDirAssignment.java
b/freemarker-core/src/main/java/org/apache/freemarker/core/ASTDirAssignment.java
index f25e9fe..db548cf 100644
--- a/freemarker-core/src/main/java/org/apache/freemarker/core/ASTDirAssignment.java
+++ b/freemarker-core/src/main/java/org/apache/freemarker/core/ASTDirAssignment.java
@@ -63,7 +63,7 @@ final class ASTDirAssignment extends ASTDirective {
         
         this.variableName = variableName;
         
-        if (operator == FMParserConstants.EQUALS) {
+        if (operator == FMParserConstants.ASSIGNMENT_EQUALS) {
             operatorType = OPERATOR_TYPE_EQUALS;
         } else {
             switch (operator) {

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d0f34dcc/freemarker-core/src/main/java/org/apache/freemarker/core/ASTExpComparison.java
----------------------------------------------------------------------
diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/ASTExpComparison.java
b/freemarker-core/src/main/java/org/apache/freemarker/core/ASTExpComparison.java
index 138b69e..7629a94 100644
--- a/freemarker-core/src/main/java/org/apache/freemarker/core/ASTExpComparison.java
+++ b/freemarker-core/src/main/java/org/apache/freemarker/core/ASTExpComparison.java
@@ -36,7 +36,7 @@ final class ASTExpComparison extends ASTExpBoolean {
         this.right = right;
         opString = opString.intern();
         this.opString = opString;
-        if (opString == "==" || opString == "=") {
+        if (opString == "==") {
             operation = _EvalUtil.CMP_OP_EQUALS;
         } else if (opString == "!=") {
             operation = _EvalUtil.CMP_OP_NOT_EQUALS;

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d0f34dcc/freemarker-core/src/main/javacc/FTL.jj
----------------------------------------------------------------------
diff --git a/freemarker-core/src/main/javacc/FTL.jj b/freemarker-core/src/main/javacc/FTL.jj
index 37a66ae..22aaf2a 100644
--- a/freemarker-core/src/main/javacc/FTL.jj
+++ b/freemarker-core/src/main/javacc/FTL.jj
@@ -966,9 +966,9 @@ TOKEN:
     |
     <EXISTS : "??">
     |
-    <EQUALS : "=">
+    <ASSIGNMENT_EQUALS : "=">
     |
-    <DOUBLE_EQUALS : "==">
+    <COMPARISON_EQUALS : "==">
     |
     <NOT_EQUALS : "!=">
     |
@@ -1008,9 +1008,9 @@ TOKEN:
     |
     <PERCENT : "%">
     |
-    <AND : "&" | "&&" | "&amp;&amp;" | "\\and">
+    <AND : "&&" | "&amp;&amp;" | "\\and">
     |
-    <OR : "|" | "||">
+    <OR : "||">
     |
     <EXCLAM : "!">
     |
@@ -1527,13 +1527,11 @@ ASTExpression EqualityExpression() :
 {
     lhs = RelationalExpression() { result = lhs; }
     [
-        LOOKAHEAD(<NOT_EQUALS>|<EQUALS>|<DOUBLE_EQUALS>)
+        LOOKAHEAD(<NOT_EQUALS>|<COMPARISON_EQUALS>)
         (
             t = <NOT_EQUALS> 
             |
-            t = <EQUALS> 
-            |
-            t = <DOUBLE_EQUALS>
+            t = <COMPARISON_EQUALS>
         )
         rhs = RelationalExpression()
         {
@@ -2628,7 +2626,7 @@ ASTElement Assign() :
     	(
             (
 	    	    (
-			        (<EQUALS>|<PLUS_EQUALS>|<MINUS_EQUALS>|<TIMES_EQUALS>|<DIV_EQUALS>|<MOD_EQUALS>)
+			        (<ASSIGNMENT_EQUALS>|<PLUS_EQUALS>|<MINUS_EQUALS>|<TIMES_EQUALS>|<DIV_EQUALS>|<MOD_EQUALS>)
 			        {
 			           equalsOp = token;
 			        }
@@ -2656,7 +2654,7 @@ ASTElement Assign() :
 	            LOOKAHEAD(
 	               [<COMMA>]
 	               (<ID>|<STRING_LITERAL>)
-	               (<EQUALS>|<PLUS_EQUALS>|<MINUS_EQUALS>|<TIMES_EQUALS>|<DIV_EQUALS>|<MOD_EQUALS>
+	               (<ASSIGNMENT_EQUALS>|<PLUS_EQUALS>|<MINUS_EQUALS>|<TIMES_EQUALS>|<DIV_EQUALS>|<MOD_EQUALS>
 	                       |<PLUS_PLUS>|<MINUS_MINUS>)
 	            )
 	            [<COMMA>]
@@ -2668,7 +2666,7 @@ ASTElement Assign() :
 	            }
 	            (
 	                (
-	                    (<EQUALS>|<PLUS_EQUALS>|<MINUS_EQUALS>|<TIMES_EQUALS>|<DIV_EQUALS>|<MOD_EQUALS>)
+	                    (<ASSIGNMENT_EQUALS>|<PLUS_EQUALS>|<MINUS_EQUALS>|<TIMES_EQUALS>|<DIV_EQUALS>|<MOD_EQUALS>)
 	                    {
 	                       equalsOp = token;
 	                    }
@@ -2777,7 +2775,7 @@ ASTDirInclude Include() :
     [<SEMICOLON>]
     (
         att = <ID>
-        <EQUALS>
+        <ASSIGNMENT_EQUALS>
         exp = ASTExpression()
         {
             String attString = att.image;
@@ -2865,7 +2863,7 @@ ASTDirMacro Macro() :
             <ELLIPSIS> { isCatchAll = true; }
         ]
         [
-            <EQUALS>
+            <ASSIGNMENT_EQUALS>
             defValue = ASTExpression()
             {
                 defNames.add(arg.image);
@@ -2969,7 +2967,7 @@ ASTElement UnifiedMacroTransform() :
     }
     [<TERMINATING_WHITESPACE>]
     (
-        LOOKAHEAD(<ID><EQUALS>)
+        LOOKAHEAD(<ID><ASSIGNMENT_EQUALS>)
         namedArgs = NamedArgs()
         |
         positionalArgs = PositionalArgs()
@@ -3051,7 +3049,7 @@ HashMap NamedArgs() :
 {
     (
         t = <ID>
-        <EQUALS>
+        <ASSIGNMENT_EQUALS>
         {
             token_source.SwitchTo(token_source.NAMED_PARAMETER_EXPRESSION);
             token_source.inInvocation = true;
@@ -3411,7 +3409,7 @@ ASTDirSetting Setting() :
 {
     start = <SETTING>
     key = <ID>
-    <EQUALS>
+    <ASSIGNMENT_EQUALS>
     value = ASTExpression()
     end = LooseDirectiveEnd()
     {
@@ -3750,7 +3748,7 @@ void HeaderElement() :
             <FTL_HEADER>
             (
                 key = <ID>
-                <EQUALS>
+                <ASSIGNMENT_EQUALS>
                 exp = ASTExpression()
                 {
                     String ks = key.image;
@@ -3946,7 +3944,7 @@ Map ParamList() :
 {
     (
         id = ASTExpVariable()
-        <EQUALS>
+        <ASSIGNMENT_EQUALS>
         exp = ASTExpression() { result.put(id.toString(), exp); }
         [<COMMA>]
     )+


Mime
View raw message