geirm 00/12/22 04:11:06
Modified: src/java/org/apache/velocity/runtime/parser Parser.jjt
Log:
Motivated by a bug report from Jason, fixed class of bugs where parser REF or REFMOD
state not correctly terminated. Would cause parser exceptions depending upon
following stream.
Revision Changes Path
1.47 +13 -32
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/Parser.jjt
Index: Parser.jjt
===================================================================
RCS file:
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/Parser.jjt,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -r1.46 -r1.47
--- Parser.jjt 2000/12/21 05:50:25 1.46
+++ Parser.jjt 2000/12/22 12:11:06 1.47
@@ -120,7 +120,7 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
- * @version $Id: Parser.jjt,v 1.46 2000/12/21 05:50:25 geirm Exp $
+ * @version $Id: Parser.jjt,v 1.47 2000/12/22 12:11:06 geirm Exp $
*/
public class Parser
{
@@ -132,7 +132,6 @@
/**
* Name of current template we are parsing. Passed to us in parse()
*/
-
String currentTemplateName = "";
/**
@@ -203,7 +202,7 @@
}
/**
- * This method gets the directives Hashtable
+ * This method gets a Directive from the directives Hashtable
*/
public Directive getDirective(String directive)
{
@@ -277,22 +276,6 @@
PARSER_END(Parser)
-/**
- * This gets inserted into the ParserMacroTokenManager
- * and is being used here strictly for the #parse
- * directive: an #include type behaviour. We have
- * to save the state the stream currently being
- * parsed and we have to save the state of the
- * lexer (TokenManager class) then we create
- * a new stream from the file named in the
- * #parse directive then we ReInit the lexer.
- * Whatever it parses will get placed
- * into the AST.
- *
- * I need a simple way to detect circular
- * inclusions so this thing doesn't go wild
- * and drag down the VM.
- */
TOKEN_MGR_DECLS:
{
private int fileDepth = 0;
@@ -314,11 +297,10 @@
* public because we need it in PD & VM handling
*
* @return boolean : success. It can fail if the state machine
- * gets messed up.
+ * gets messed up (do don't mess it up :)
*/
public boolean stateStackPop()
{
-
Hashtable h;
try
@@ -397,10 +379,9 @@
private void RPARENHandler()
{
/*
- * Ultimately, we want to drop down to the state below
- * the one that has an open (if we hit bottom (DEFAULT),
- * that's fine. It's just text schmoo.
- *
+ * Ultimately, we want to drop down to the state below
+ * the one that has an open (if we hit bottom (DEFAULT),
+ * that's fine. It's just text schmoo.
*/
boolean closed = false;
@@ -445,7 +426,6 @@
}
}
}
-
}
/* ------------------------------------------------------------------------
@@ -721,25 +701,26 @@
<WHITESPACE : ([" ","\t"])+ >
}
-<REFERENCE,DIRECTIVE,REFMODIFIER,REFMOD2>
+<DIRECTIVE,REFMOD2>
TOKEN :
{
<STRING_LITERAL: ( "\"" ( ~["\"","\n","\r"] )* "\"" ) | ( "'" ( ~["'","\n","\r"]
)* "'" ) >
{
/*
- * - if we are in REFERENCE || REFMODIFIER then " is an ender
* - if we are in DIRECTIVE and haven't seen ( yet, then also drop out.
* don't forget to account for the beloved yet wierd #set
* - finally, if we are in REFMOD2 (remember : $foo.bar( ) then " is ok!
*/
- if (curLexState == REFERENCE || curLexState == REFMODIFIER)
- stateStackPop();
- else if( curLexState == DIRECTIVE && !inSet && lparen == 0)
+ if( curLexState == DIRECTIVE && !inSet && lparen == 0)
stateStackPop();
}
+}
-| <TRUE: "true">
+<REFERENCE,DIRECTIVE,REFMODIFIER,REFMOD2>
+TOKEN:
+{
+ <TRUE: "true">
| <FALSE: "false">
}