geirm 01/02/26 19:24:24
Modified: src/java/org/apache/velocity/runtime/parser/node
ASTStringLiteral.java
Log:
Added a little kludge to work around the infamous
"Dreaded <MORE> Parse Problem" (my name, but its a known issue with javacc)
which basically boils down to the hosing you get when your input
stream ends in a <MORE> token.
This is a general problem that I will fix real soon now as I am sick of
it.
You can't work around it if you have an interpolatable string literal
that is being passed to a directive or a VM :
#foo( "PO#" )
The workaround is
#foo( 'PO#' )
but then you can't do things like
#foo("$fieldname #")
So this fixes it until we can deal with it in javacc, or rework the <MORE>
constructions.
If this works well, will do the same in the general parsing to ensure that no
one runs across it again, anywhere.
Revision Changes Path
1.8 +17 -3
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java
Index: ASTStringLiteral.java
===================================================================
RCS file:
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- ASTStringLiteral.java 2001/01/03 05:27:04 1.7
+++ ASTStringLiteral.java 2001/02/27 03:24:23 1.8
@@ -59,7 +59,7 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
- * @version $Id: ASTStringLiteral.java,v 1.7 2001/01/03 05:27:04 geirm Exp $
+ * @version $Id: ASTStringLiteral.java,v 1.8 2001/02/27 03:24:23 geirm Exp $
*/
package org.apache.velocity.runtime.parser.node;
@@ -77,6 +77,7 @@
private boolean interpolate = true;
private SimpleNode nodeTree = null;
private String image = "";
+ private String interpolateimage = "";
public ASTStringLiteral(int id)
{
@@ -120,6 +121,12 @@
image = getFirstToken().image.substring(1, getFirstToken().image.length() -
1);
+ /*
+ * tack a space on the end (dreaded <MORE> kludge)
+ */
+
+ interpolateimage = image + " ";
+
return data;
}
@@ -148,7 +155,7 @@
if (nodeTree == null)
{
- ByteArrayInputStream inStream = new ByteArrayInputStream(
image.getBytes() );
+ ByteArrayInputStream inStream = new ByteArrayInputStream(
interpolateimage.getBytes() );
/*
* parse the stringlit
@@ -173,8 +180,15 @@
/*
* and return the result as a String
*/
+
+ String ret = writer.toString();
+
+ /*
+ * remove the space from the end (dreaded <MORE> kludge)
+ */
+
+ return ret.substring(0, ret.length() - 1 );
- return writer.toString();
}
catch( Exception e )
{