You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@velocity.apache.org by wg...@apache.org on 2007/08/24 07:41:09 UTC
svn commit: r569256 - in /velocity/engine/trunk/src:
java/org/apache/velocity/runtime/parser/ parser/
test/org/apache/velocity/test/
Author: wglass
Date: Thu Aug 23 22:41:08 2007
New Revision: 569256
URL: http://svn.apache.org/viewvc?rev=569256&view=rev
Log:
Single-line comments will cause multi-line comments to be ignored. Solves VELOCITY-561.
Added:
velocity/engine/trunk/src/test/org/apache/velocity/test/CommentsTestCase.java (with props)
Modified:
velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/Parser.java
velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/Parser.jj
velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/ParserTokenManager.java
velocity/engine/trunk/src/parser/Parser.jjt
Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/Parser.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/Parser.java?rev=569256&r1=569255&r2=569256&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/Parser.java (original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/Parser.java Thu Aug 23 22:41:08 2007
@@ -213,9 +213,8 @@
/**
* Check whether there is a left parenthesis with leading optional
* whitespaces. This method is used in the semantic look ahead of
- * Directive method. It requires lot of changes to implement the
- * required look ahead as a BNF production and the code will become
- * inefficient.
+ * Directive method. This is done in code instead of as a production
+ * for simplicity and efficiency.
*/
private boolean isLeftParenthesis()
{
@@ -2577,63 +2576,6 @@
finally { jj_save(11, xla); }
}
- final private boolean jj_3R_52() {
- if (jj_3R_65()) return true;
- return false;
- }
-
- final private boolean jj_3R_31() {
- Token xsp;
- xsp = jj_scanpos;
- if (jj_3_11()) {
- jj_scanpos = xsp;
- if (jj_3R_58()) return true;
- }
- return false;
- }
-
- final private boolean jj_3_11() {
- Token xsp;
- xsp = jj_scanpos;
- if (jj_scan_token(26)) jj_scanpos = xsp;
- if (jj_scan_token(LOGICAL_NOT)) return true;
- if (jj_3R_31()) return true;
- return false;
- }
-
- final private boolean jj_3R_58() {
- if (jj_3R_67()) return true;
- return false;
- }
-
- final private boolean jj_3R_51() {
- if (jj_3R_64()) return true;
- return false;
- }
-
- final private boolean jj_3R_85() {
- if (jj_scan_token(COMMA)) return true;
- if (jj_3R_25()) return true;
- if (jj_scan_token(COLON)) return true;
- if (jj_3R_25()) return true;
- return false;
- }
-
- final private boolean jj_3R_50() {
- if (jj_3R_63()) return true;
- return false;
- }
-
- final private boolean jj_3R_49() {
- if (jj_3R_61()) return true;
- return false;
- }
-
- final private boolean jj_3R_48() {
- if (jj_3R_36()) return true;
- return false;
- }
-
final private boolean jj_3R_47() {
if (jj_3R_60()) return true;
return false;
@@ -3203,6 +3145,63 @@
final private boolean jj_3R_53() {
if (jj_3R_66()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_52() {
+ if (jj_3R_65()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_31() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3_11()) {
+ jj_scanpos = xsp;
+ if (jj_3R_58()) return true;
+ }
+ return false;
+ }
+
+ final private boolean jj_3_11() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_scan_token(26)) jj_scanpos = xsp;
+ if (jj_scan_token(LOGICAL_NOT)) return true;
+ if (jj_3R_31()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_58() {
+ if (jj_3R_67()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_51() {
+ if (jj_3R_64()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_85() {
+ if (jj_scan_token(COMMA)) return true;
+ if (jj_3R_25()) return true;
+ if (jj_scan_token(COLON)) return true;
+ if (jj_3R_25()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_50() {
+ if (jj_3R_63()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_49() {
+ if (jj_3R_61()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_48() {
+ if (jj_3R_36()) return true;
return false;
}
Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/Parser.jj
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/Parser.jj?rev=569256&r1=569255&r2=569256&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/Parser.jj (original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/Parser.jj Thu Aug 23 22:41:08 2007
@@ -15,7 +15,7 @@
* "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.
+ * under the License.
*/
/*
@@ -23,14 +23,14 @@
* to always have to page past it... :)
*/
options
-{
+{
/**
* The parser must be non-static in order for the
* above option to work, otherwise the parser value
* is passed in as null, which isn't all the useful ;)
*/
- STATIC=false;
+ STATIC=false;
/**
* Declare that we are accepting unicode input and
@@ -269,9 +269,8 @@
/**
* Check whether there is a left parenthesis with leading optional
* whitespaces. This method is used in the semantic look ahead of
- * Directive method. It requires lot of changes to implement the
- * required look ahead as a BNF production and the code will become
- * inefficient.
+ * Directive method. This is done in code instead of as a production
+ * for simplicity and efficiency.
*/
private boolean isLeftParenthesis()
{
@@ -679,17 +678,23 @@
| <"#**" ~["#"]>
{
- input_stream.backup(1);
- inComment = true;
- stateStackPush();
- SwitchTo( IN_FORMAL_COMMENT);
+ if (!inComment)
+ {
+ input_stream.backup(1);
+ inComment = true;
+ stateStackPush();
+ SwitchTo( IN_FORMAL_COMMENT);
+ }
}
| "#*"
{
- inComment=true;
- stateStackPush();
- SwitchTo( IN_MULTI_LINE_COMMENT );
+ if (!inComment)
+ {
+ inComment=true;
+ stateStackPush();
+ SwitchTo( IN_MULTI_LINE_COMMENT );
+ }
}
| <HASH : "#" >
@@ -1678,7 +1683,7 @@
|
[ <WHITESPACE> ]
)
-
+
/** note: need both tokens as they are generated in different states **/
( <RIGHT_CURLEY> | <RCURLY> )/*@bgen(jjtree)*/
} catch (Throwable jjte000) {
Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/ParserTokenManager.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/ParserTokenManager.java?rev=569256&r1=569255&r2=569256&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/ParserTokenManager.java (original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/ParserTokenManager.java Thu Aug 23 22:41:08 2007
@@ -4200,10 +4200,13 @@
else
image.append(input_stream.GetSuffix(jjimageLen));
jjimageLen = 0;
- input_stream.backup(1);
- inComment = true;
- stateStackPush();
- SwitchTo( IN_FORMAL_COMMENT);
+ if (!inComment)
+ {
+ input_stream.backup(1);
+ inComment = true;
+ stateStackPush();
+ SwitchTo( IN_FORMAL_COMMENT);
+ }
break;
case 16 :
if (image == null)
@@ -4211,9 +4214,12 @@
else
image.append(input_stream.GetSuffix(jjimageLen));
jjimageLen = 0;
- inComment=true;
- stateStackPush();
- SwitchTo( IN_MULTI_LINE_COMMENT );
+ if (!inComment)
+ {
+ inComment=true;
+ stateStackPush();
+ SwitchTo( IN_MULTI_LINE_COMMENT );
+ }
break;
case 17 :
if (image == null)
Modified: velocity/engine/trunk/src/parser/Parser.jjt
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/parser/Parser.jjt?rev=569256&r1=569255&r2=569256&view=diff
==============================================================================
--- velocity/engine/trunk/src/parser/Parser.jjt (original)
+++ velocity/engine/trunk/src/parser/Parser.jjt Thu Aug 23 22:41:08 2007
@@ -699,17 +699,23 @@
| <"#**" ~["#"]>
{
- input_stream.backup(1);
- inComment = true;
- stateStackPush();
- SwitchTo( IN_FORMAL_COMMENT);
+ if (!inComment)
+ {
+ input_stream.backup(1);
+ inComment = true;
+ stateStackPush();
+ SwitchTo( IN_FORMAL_COMMENT);
+ }
}
| "#*"
{
- inComment=true;
- stateStackPush();
- SwitchTo( IN_MULTI_LINE_COMMENT );
+ if (!inComment)
+ {
+ inComment=true;
+ stateStackPush();
+ SwitchTo( IN_MULTI_LINE_COMMENT );
+ }
}
| <HASH : "#" >
Added: velocity/engine/trunk/src/test/org/apache/velocity/test/CommentsTestCase.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/test/org/apache/velocity/test/CommentsTestCase.java?rev=569256&view=auto
==============================================================================
--- velocity/engine/trunk/src/test/org/apache/velocity/test/CommentsTestCase.java (added)
+++ velocity/engine/trunk/src/test/org/apache/velocity/test/CommentsTestCase.java Thu Aug 23 22:41:08 2007
@@ -0,0 +1,109 @@
+package org.apache.velocity.test;
+
+/*
+ * 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.
+ */
+
+import java.io.StringWriter;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.VelocityEngine;
+import org.apache.velocity.context.Context;
+
+/**
+ * Test comments
+ *
+ * @author <a href="mailto:wglass@forio.com">Will Glass-Husain</a>
+ * @version $Id$
+ */
+public class CommentsTestCase extends BaseTestCase
+{
+
+ public static Test suite()
+ {
+ return new TestSuite(CommentsTestCase.class);
+ }
+
+ /**
+ * Default constructor.
+ * @param name
+ */
+ public CommentsTestCase(String name)
+ {
+ super(name);
+ }
+
+
+ /**
+ * Test multiline comments
+ * @throws Exception
+ */
+ public void testMultiLine()
+ throws Exception
+ {
+ VelocityEngine ve = new VelocityEngine();
+ ve.init();
+
+ Context context = new VelocityContext();
+ StringWriter writer = new StringWriter();
+ ve.evaluate(context, writer, "test","abc #* test\r\ntest2*#\r\ndef");
+ assertEquals("abc \r\ndef", writer.toString());
+ }
+
+ /**
+ * Test single line comments
+ * @throws Exception
+ */
+ public void testSingleLine()
+ throws Exception
+ {
+ VelocityEngine ve = new VelocityEngine();
+ ve.init();
+
+ Context context = new VelocityContext();
+ StringWriter writer = new StringWriter();
+ ve.evaluate(context, writer, "test","123 ## test test\r\nabc");
+ assertEquals("123 abc", writer.toString());
+
+ context = new VelocityContext();
+ writer = new StringWriter();
+ ve.evaluate(context, writer, "test","123 \r\n## test test\r\nabc");
+ assertEquals("123 \r\nabc", writer.toString());
+
+ }
+
+ /**
+ * Test combined comments
+ * @throws Exception
+ */
+ public void testCombined()
+ throws Exception
+ {
+ VelocityEngine ve = new VelocityEngine();
+ ve.init();
+
+ Context context = new VelocityContext();
+ StringWriter writer = new StringWriter();
+ ve.evaluate(context, writer, "test","test\r\n## #* *# ${user \r\nabc");
+ assertEquals("test\r\nabc", writer.toString());
+
+ }
+}
Propchange: velocity/engine/trunk/src/test/org/apache/velocity/test/CommentsTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: velocity/engine/trunk/src/test/org/apache/velocity/test/CommentsTestCase.java
------------------------------------------------------------------------------
svn:keywords = Id Author Date Revision