Repository: incubator-freemarker
Updated Branches:
  refs/heads/3 6e61c1d60 -> 0d21cbb77


Forward ported from 2.3-gae: Some more cleanup in FTL.jj


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

Branch: refs/heads/3
Commit: 348e73dc61f90af24ebe01e31b1db83a1b966517
Parents: 6e61c1d
Author: ddekany <ddek...@apache.org>
Authored: Mon Mar 19 00:25:26 2018 +0100
Committer: ddekany <ddek...@apache.org>
Committed: Mon Mar 19 00:25:26 2018 +0100

----------------------------------------------------------------------
 .../core/InterpolationSyntaxTest.java           |  1 +
 freemarker-core/src/main/javacc/FTL.jj          | 35 +++++++++++---------
 2 files changed, 21 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/348e73dc/freemarker-core-test/src/test/java/org/apache/freemarker/core/InterpolationSyntaxTest.java
----------------------------------------------------------------------
diff --git 
a/freemarker-core-test/src/test/java/org/apache/freemarker/core/InterpolationSyntaxTest.java
 
b/freemarker-core-test/src/test/java/org/apache/freemarker/core/InterpolationSyntaxTest.java
index e6b0eeb..4d7d0cc 100644
--- 
a/freemarker-core-test/src/test/java/org/apache/freemarker/core/InterpolationSyntaxTest.java
+++ 
b/freemarker-core-test/src/test/java/org/apache/freemarker/core/InterpolationSyntaxTest.java
@@ -90,6 +90,7 @@ public class InterpolationSyntaxTest extends TemplateTest {
         
         assertErrorContains("[=", "end of file");
         assertErrorContains("[=1", "unclosed \"[\"");
+        assertErrorContains("[=1}", "\"}\"", "open");
         
         assertOutput("[='[\\=1]']", "[=1]");
         assertOutput("[='[\\=1][=2]']", "12"); // Usual legacy interpolation 
escaping glitch...

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/348e73dc/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 8da0768..76b32f5 100644
--- a/freemarker-core/src/main/javacc/FTL.jj
+++ b/freemarker-core/src/main/javacc/FTL.jj
@@ -527,7 +527,7 @@ TOKEN_MGR_DECLS:
      * Keeps track of how deeply nested we have the hash literals. This is 
necessary since we need to be able to
      * distinguish the } used to close a hash literal and the one used to 
close a ${
      */
-    private int hashLiteralNesting;
+    private int curlyBracketNesting;
     private int parenthesisNesting;
     private int bracketNesting;
     private boolean inFTLHeader;
@@ -632,22 +632,21 @@ TOKEN_MGR_DECLS:
         SwitchTo(FM_EXPRESSION);
     }
 
-    /**
-     * @param tok
-     *         Assumed to be an '}', or something that is the closing pair of 
another "mirror image" character.
-     */
-    private void endInterpolation(Token tok) {
+    private void endInterpolation(Token closingTk) {
         if (postInterpolationLexState == -1) {
-            char c = tok.image.charAt(0);
-            throw new TokenMgrError(
-                    "You can't have an \"" + c + "\" here, as there's nothing 
open that it could close.",
-                    TokenMgrError.LEXICAL_ERROR,
-                    tok.beginLine, tok.beginColumn,
-                    tok.endLine, tok.endColumn);
+            throw newUnexpectedClosingTokenException(closingTk);
         }
         SwitchTo(postInterpolationLexState);
         postInterpolationLexState = -1;
     }
+    
+    private TokenMgrError newUnexpectedClosingTokenException(Token closingTk) {
+            return new TokenMgrError(
+                    "You can't have an \"" + closingTk.image + "\" here, as 
there's nothing open that it could close.",
+                    TokenMgrError.LEXICAL_ERROR,
+                    closingTk.beginLine, closingTk.beginColumn,
+                    closingTk.endLine, closingTk.endColumn);
+    }
 
     private void eatNewline() {
         int charsRead = 0;
@@ -953,6 +952,7 @@ TOKEN:
     // Find related: [interpolation prefixes]
     <DOLLAR_INTERPOLATION_OPENING : "${"> { startInterpolation(matchedToken); }
     |
+    // Find related: [interpolation prefixes]
     <SQUARE_BRACKET_INTERPOLATION_OPENING : "[="> { 
startInterpolation(matchedToken); }
 }
 
@@ -1121,13 +1121,18 @@ TOKEN:
     |
     <OPENING_CURLY_BRACKET : "{">
     {
-        ++hashLiteralNesting;
+        ++curlyBracketNesting;
     }
     |
     <CLOSING_CURLY_BRACKET : "}">
     {
-        if (hashLiteralNesting == 0) endInterpolation(matchedToken);
-        else --hashLiteralNesting;
+        if (curlyBracketNesting > 0) {
+            --curlyBracketNesting;
+        } else if (interpolationSyntax != InterpolationSyntax.SQUARE_BRACKET) {
+            endInterpolation(matchedToken);
+        } else {
+            throw newUnexpectedClosingTokenException(matchedToken);
+        }
     }
     |
     <IN : "in">

Reply via email to