geirm 00/11/05 20:12:42
Modified: src/java/org/apache/velocity/runtime/parser Parser.jjt
Log:
Major change : removed #include as a directive defined w/in the parser, and it is
now a 'Pluggable Directive'. Woo hoo. It works to boot. Also some more parser
cleanup.
Revision Changes Path
1.24 +3 -75
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.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- Parser.jjt 2000/11/06 01:20:02 1.23
+++ Parser.jjt 2000/11/06 04:12:42 1.24
@@ -127,7 +127,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.23 2000/11/06 01:20:02 jvanzyl Exp $
+ * @version $Id: Parser.jjt,v 1.24 2000/11/06 04:12:42 geirm Exp $
*/
public class Parser
{
@@ -221,7 +221,6 @@
*/
TOKEN_MGR_DECLS:
{
- private boolean incMode;
private int fileDepth = 0;
private int lparen = 0;
@@ -237,38 +236,7 @@
Stack streams = new Stack();
Stack states = new Stack();
-
- // remove double quotes in the string
- String stripQuotes(String str)
- {
- int start = str.indexOf("\"");
- int end = str.indexOf("\"",start+1);
- return str.substring(start+1,end);
- }
-
- /**
- * Save the state of the current input stream
- * and the state of the lexer. So we can process
- * the new one.
- */
- void pushFile(String filename)
- {
- fileDepth++;
-
- streams.push(input_stream);
- states.push(new Integer(curLexState));
-
- try
- {
- FileInputStream fs = new FileInputStream(filename);
- ASCII_CharStream new_stream = new ASCII_CharStream(fs,1,1);
- ReInit(new_stream);
- }
- catch(Exception e)
- {
- }
- }
-
+
/**
* Retrieve the oldStream and oldState and
* continue processing the input.
@@ -532,8 +500,6 @@
{ matchedToken.image = "#if"; }
| <ESCAPE_END_DIRECTIVE : "\\#end">
{ matchedToken.image = "#end"; }
-| <ESCAPE_INCLUDE_DIRECTIVE: "\\#include">
- { matchedToken.image = "#include"; }
| <ESCAPE_ELSEIF_DIRECTIVE: "\\#elseif">
{ matchedToken.image = "#elseif"; }
| <ESCAPE_ELSE_DIRECTIVE: "\\#else">
@@ -638,7 +604,6 @@
SwitchTo(PRE_DIRECTIVE);
}
}
-
}
TOKEN :
@@ -707,16 +672,8 @@
<REFERENCE,DIRECTIVE,REFMODIFIER,REFMOD2>
TOKEN :
{
-
<STRING_LITERAL: ( "\"" ( ~["\"","\n","\r"] )* "\"" ) >
{
- if (incMode)
- {
- matchedToken.image = stripQuotes(image.toString());
- pushFile(matchedToken.image);
- }
- incMode = false;
-
/*
* - if we are in REFERENCE || REFMODIFIER then " is an ender
* - if we are in DIRECTIVE and haven't seen ( yet, then also drop out.
@@ -728,7 +685,6 @@
stateStackPop();
else if( curLexState == DIRECTIVE && !inSet && lparen == 0)
stateStackPop();
-
}
| <TRUE: "true">
@@ -783,12 +739,6 @@
stateStackPop();
}
-| <INCLUDE_DIRECTIVE: "include">
- {
- incMode = true;
- SwitchTo(DIRECTIVE);
- }
-
| <IF_DIRECTIVE: "if">
{
SwitchTo(DIRECTIVE);
@@ -805,12 +755,6 @@
stateStackPop();
}
-//| <SET_DIRECTIVE: (" "|"\t")* "set" >
-// {
-// inSet = true;
-// SwitchTo(DIRECTIVE);
-// }
-
| <STOP_DIRECTIVE: "stop">
{
matchedToken.kind = EOF;
@@ -825,8 +769,7 @@
| <NUMBER_LITERAL: (<DIGIT>)+ >
{
/*
- * in the spirit of Jason's fix :)
- * but check to see if we are in set
+ * check to see if we are in set
* ex. #set $foo = $foo + 3
* because we want to handle the \n after
*/
@@ -953,7 +896,6 @@
void Statement() #void : {}
{
IfStatement()
-| IncludeStatement()
| StopStatement()
| Reference()
| Comment()
@@ -1146,7 +1088,6 @@
| <ESCAPE_SET_DIRECTIVE>
| <ESCAPE_IF_DIRECTIVE>
| <ESCAPE_END_DIRECTIVE>
-| <ESCAPE_INCLUDE_DIRECTIVE>
| <ESCAPE_ELSEIF_DIRECTIVE>
| <ESCAPE_ELSE_DIRECTIVE>
| <ESCAPE_STOP_DIRECTIVE>
@@ -1185,19 +1126,6 @@
(<SET_DIRECTIVE> Expression() [<NEWLINE>] )
}
-/**
- * This method corresponds to an #include
- * directive in a Velocity template. The
- * following are examples of #include
- * constructs that are acceptable in
- * a template:
- *
- * #include "foo.inc"
- */
-void IncludeStatement() #void: {}
-{
- <INCLUDE_DIRECTIVE> <STRING_LITERAL>
-}
/**
* This method corresponds to the #stop