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 2015/10/04 21:17:07 UTC
[03/16] incubator-freemarker git commit: <@ and @ is now allowed in
String literals that contain ${exp},
and will be part of the literal as is. Earlier it was a syntactical error.
<@ and </@ is now allowed in String literals that contain ${exp}, and will be part of the literal as is. Earlier it was a syntactical error.
Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/6ac1b86a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/6ac1b86a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/6ac1b86a
Branch: refs/heads/2.3
Commit: 6ac1b86a48ab9826e5061e497df22ea289b0c17b
Parents: a361243
Author: ddekany <dd...@apache.org>
Authored: Thu Oct 1 12:46:50 2015 +0200
Committer: ddekany <dd...@apache.org>
Committed: Thu Oct 1 12:46:50 2015 +0200
----------------------------------------------------------------------
src/main/javacc/FTL.jj | 33 +++++++++++++-------
src/manual/book.xml | 8 +++++
.../core/StringLiteralInterpolationTest.java | 14 +++++++++
3 files changed, 44 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/6ac1b86a/src/main/javacc/FTL.jj
----------------------------------------------------------------------
diff --git a/src/main/javacc/FTL.jj b/src/main/javacc/FTL.jj
index e234e90..f65f4c5 100644
--- a/src/main/javacc/FTL.jj
+++ b/src/main/javacc/FTL.jj
@@ -731,6 +731,11 @@ TOKEN_MGR_DECLS:
}
private void unifiedCall(Token tok) {
+ if (onlyTextOutput) {
+ tok.kind = STATIC_TEXT_NON_WS;
+ return;
+ }
+
char firstChar = tok.image.charAt(0);
if (autodetectTagSyntax && !directiveSyntaxEstablished) {
squBracTagSyntax = (firstChar == '[');
@@ -748,6 +753,11 @@ TOKEN_MGR_DECLS:
}
private void unifiedCallEnd(Token tok) {
+ if (onlyTextOutput) {
+ tok.kind = STATIC_TEXT_NON_WS;
+ return;
+ }
+
char firstChar = tok.image.charAt(0);
if (squBracTagSyntax && firstChar == '<') {
tok.kind = STATIC_TEXT_NON_WS;
@@ -2225,19 +2235,20 @@ StringLiteral StringLiteral(boolean interpolate) :
t = <RAW_STRING> { raw = true; }
)
{
- String s = t.image;
+ String s;
// Get rid of the quotes.
- s = s.substring(1, s.length() -1);
if (raw) {
- s = s.substring(1);
- } else try {
- s = StringUtil.FTLStringLiteralDec(s);
- } catch (ParseException pe) {
- pe.lineNumber = t.beginLine;
- pe.columnNumber = t.beginColumn;
- pe.endLineNumber = t.endLine;
- pe.endColumnNumber = t.endColumn;
- throw pe;
+ s = t.image.substring(2, t.image.length() -1);
+ } else {
+ try {
+ s = StringUtil.FTLStringLiteralDec(t.image.substring(1, t.image.length() -1));
+ } catch (ParseException pe) {
+ pe.lineNumber = t.beginLine;
+ pe.columnNumber = t.beginColumn;
+ pe.endLineNumber = t.endLine;
+ pe.endColumnNumber = t.endColumn;
+ throw pe;
+ }
}
StringLiteral result = new StringLiteral(s);
result.setLocation(template, t, t);
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/6ac1b86a/src/manual/book.xml
----------------------------------------------------------------------
diff --git a/src/manual/book.xml b/src/manual/book.xml
index b8bc656..6decbd9 100644
--- a/src/manual/book.xml
+++ b/src/manual/book.xml
@@ -25810,6 +25810,14 @@ TemplateModel x = env.getVariable("x"); // get variable x</programlisting>
keeping the exact class can be important in some
applications.</para>
</listitem>
+
+ <listitem>
+ <para><literal><@</literal> and <literal></@</literal> is
+ now allowed in String literals that contain
+ <literal>${<replaceable>exp</replaceable>}</literal>, and will
+ be part of the literal as is. Earlier it was a syntactical
+ error.</para>
+ </listitem>
</itemizedlist>
</section>
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/6ac1b86a/src/test/java/freemarker/core/StringLiteralInterpolationTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/freemarker/core/StringLiteralInterpolationTest.java b/src/test/java/freemarker/core/StringLiteralInterpolationTest.java
index 6abe579..e6d86e4 100644
--- a/src/test/java/freemarker/core/StringLiteralInterpolationTest.java
+++ b/src/test/java/freemarker/core/StringLiteralInterpolationTest.java
@@ -34,6 +34,20 @@ public class StringLiteralInterpolationTest extends TemplateTest {
assertOutput("<#assign x = 1>${'${x} ${x}'}", "1 1");
assertOutput("<#assign x = 1>${'$\\{x}'}", "${x}");
assertOutput("<#assign x = 1>${'$\\{x} $\\{x}'}", "${x} ${x}");
+ assertOutput("<#assign x = 1>${'<#-- not a comment -->${x}'}", "<#-- not a comment -->1");
+ assertOutput("<#assign x = 1>${'<#-- not a comment -->$\\{x}'}", "<#-- not a comment -->${x}");
+ assertOutput("<#assign x = 1>${'<@x/>${x}'}", "<@x/>1");
+ assertOutput("<#assign x = 1>${'<@x/>$\\{x}'}", "<@x/>${x}");
+ assertOutput("<#assign x = 1>${'<@ ${x}<@'}", "<@ 1<@");
+ assertOutput("<#assign x = 1>${'<@ $\\{x}<@'}", "<@ ${x}<@");
+ assertOutput("<#assign x = 1>${'</...@x>${x}'}", "</...@x>1");
+ assertOutput("<#assign x = 1>${'</...@x>$\\{x}'}", "</...@x>${x}");
+ assertOutput("<#assign x = 1>${'</@ ${x}</@'}", "</@ 1</@");
+ assertOutput("<#assign x = 1>${'</@ $\\{x}</@'}", "</@ ${x}</@");
+ assertOutput("<#assign x = 1>${'[@ ${x}'}", "[@ 1");
+ assertOutput("<#assign x = 1>${'[@ $\\{x}'}", "[@ ${x}");
+ assertOutput("<#assign x = 1>${'<#assign x = 2> ${x}'}", "<#assign x = 2> 1");
+ assertOutput("<#assign x = 1>${'<#assign x = 2> $\\{x}'}", "<#assign x = 2> ${x}");
}
/**