You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by jv...@locus.apache.org on 2000/09/19 21:50:02 UTC
cvs commit: jakarta-velocity/src/java/org/apache/velocity/runtime TemplateLoader.java
jvanzyl 00/09/19 12:50:02
Modified: src/java/org/apache/velocity Template.java
src/java/org/apache/velocity/processor Processor.java
src/java/org/apache/velocity/processor/javacc
JavaCCProcessor.java
src/java/org/apache/velocity/processor/javacc/parser
Parser.java
src/java/org/apache/velocity/processor/javacc/parser/velocity
Parser.java Parser.jj Parser.jjt
src/java/org/apache/velocity/processor/javacc/parser/webmacro
Parser.java Parser.jj Parser.jjt
src/java/org/apache/velocity/processor/javacc/visitor
InjectorMode.java SinglePassMode.java
src/java/org/apache/velocity/runtime TemplateLoader.java
Log:
- Added init() method to Processor interface in order to
reuse a parser and a visitor. Previously each time processor.parse()
was called a new parser and visitor were being created.
I also had to change the Parser.jjt slightly so that a parser
could be reused in a proper fashion. Used the proper methods
for re-initializing the parser.
Revision Changes Path
1.3 +3 -10 jakarta-velocity/src/java/org/apache/velocity/Template.java
Index: Template.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/Template.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Template.java 2000/09/19 16:49:44 1.2
+++ Template.java 2000/09/19 19:49:52 1.3
@@ -79,19 +79,13 @@
* template.merge(context, writer);
*
* @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
- * @version $Id: Template.java,v 1.2 2000/09/19 16:49:44 jvanzyl Exp $
+ * @version $Id: Template.java,v 1.3 2000/09/19 19:49:52 jvanzyl Exp $
*/
public class Template
{
/** Template processor */
private Processor processor;
- private static String TEMPLATE_MODE =
- Configuration.getString(Configuration.TEMPLATE_MODE);
-
- private static String TEMPLATE_SYNTAX =
- Configuration.getString(Configuration.TEMPLATE_SYNTAX);
-
// So now, after a template is constructed all the
// initial processing is done.
@@ -102,10 +96,9 @@
parse(inputStream);
}
- public void parse(InputStream inputStream)
- throws Exception
+ public void parse(InputStream inputStream) throws Exception
{
- processor.parse(TEMPLATE_MODE, TEMPLATE_SYNTAX, inputStream);
+ processor.parse(inputStream);
}
public void merge(Context context, Writer writer)
1.3 +2 -1 jakarta-velocity/src/java/org/apache/velocity/processor/Processor.java
Index: Processor.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/processor/Processor.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Processor.java 2000/09/19 16:49:50 1.2
+++ Processor.java 2000/09/19 19:49:53 1.3
@@ -62,6 +62,7 @@
public interface Processor
{
- public void parse(String mode, String syntax, InputStream inputStream) throws Exception;
+ public void init(String mode, String syntax) throws Exception;
+ public void parse(InputStream inputStream) throws Exception;
public void merge(Context context, Writer writer) throws IOException;
}
1.5 +9 -11 jakarta-velocity/src/java/org/apache/velocity/processor/javacc/JavaCCProcessor.java
Index: JavaCCProcessor.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/processor/javacc/JavaCCProcessor.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- JavaCCProcessor.java 2000/09/19 17:22:18 1.4
+++ JavaCCProcessor.java 2000/09/19 19:49:54 1.5
@@ -86,22 +86,20 @@
"org.apache.velocity.processor.javacc.parser";
private Parser parser;
- private SimpleNode root;
private BaseVisitor visitor;
-
- public void parse(String mode, String syntax, InputStream inputStream)
- throws Exception
- {
+
+ public void init(String mode, String syntax) throws Exception
+ {
parser = (Parser) Class.forName(
PARSER_PACKAGE + "." + syntax + "." + "Parser").newInstance();
-
- parser.parse(inputStream);
- root = parser.getRoot();
-
+
visitor = (BaseVisitor) Class.forName(
VISITOR_PACKAGE + "." + mode + "Mode").newInstance();
-
- visitor.init(root);
+ }
+
+ public void parse(InputStream inputStream) throws Exception
+ {
+ visitor.init(parser.parse(inputStream));
}
public void merge(Context context, Writer writer)
1.2 +1 -2 jakarta-velocity/src/java/org/apache/velocity/processor/javacc/parser/Parser.java
Index: Parser.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/processor/javacc/parser/Parser.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Parser.java 2000/09/19 01:58:49 1.1
+++ Parser.java 2000/09/19 19:49:54 1.2
@@ -5,6 +5,5 @@
public interface Parser
{
public Token getToken(int t);
- public void parse(InputStream i) throws ParseException;
- public SimpleNode getRoot();
+ public SimpleNode parse(InputStream i) throws ParseException;
}
1.3 +65 -76 jakarta-velocity/src/java/org/apache/velocity/processor/javacc/parser/velocity/Parser.java
Index: Parser.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/processor/javacc/parser/velocity/Parser.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Parser.java 2000/09/19 06:58:53 1.2
+++ Parser.java 2000/09/19 19:49:56 1.3
@@ -16,7 +16,7 @@
* what controls the generation of this class.
*
* @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
- * @version $Id: Parser.java,v 1.2 2000/09/19 06:58:53 jvanzyl Exp $
+ * @version $Id: Parser.java,v 1.3 2000/09/19 19:49:56 jvanzyl Exp $
*/
public class Parser implements/*@bgen(jjtree)*/ ParserTreeConstants,org.apache.velocity.processor.javacc.parser.Parser, ParserConstants {/*@bgen(jjtree)*/
protected JJTParserState jjtree = new JJTParserState();
@@ -30,10 +30,13 @@
* a constructor without parameters. The normal constructor
* takes a single argument which an InputStream. But in
* order to make the parser dynamically loadable this
- * constructor had to be added.
+ * constructor had to be added. This also allows us to
+ * create a single instance of a parser and reuse
+ * it over and over.
*/
public Parser()
{
+ this(new ByteArrayInputStream("\n".getBytes()));
}
/* This was also added to allow parsers to be dynamically
@@ -50,24 +53,10 @@
* possible with JavaCC. I believe that you can do
* this with ANTLR though.
*/
- public void parse(InputStream stream) throws ParseException
+ public SimpleNode parse(InputStream stream) throws ParseException
{
- //* taken from generated source
- jj_input_stream = new ASCII_CharStream(stream, 1, 1);
- token_source = new ParserTokenManager(jj_input_stream);
- token = new Token();
- jj_ntk = -1;
- jj_gen = 0;
- for (int i = 0; i < 22; i++) jj_la1[i] = -1;
- for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
- //* taken from generated source
-
- root = process();
- }
-
- public SimpleNode getRoot()
- {
- return root;
+ ReInit(stream);
+ return process();
}
/**
@@ -1543,6 +1532,63 @@
return retval;
}
+ final private boolean jj_3R_19() {
+ if (jj_3R_24()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ Token xsp;
+ while (true) {
+ xsp = jj_scanpos;
+ if (jj_3R_45()) { jj_scanpos = xsp; break; }
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ }
+ return false;
+ }
+
+ final private boolean jj_3R_51() {
+ if (jj_scan_token(LOGICAL_NOT_EQUALS)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ if (jj_3R_46()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_46() {
+ if (jj_3R_48()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ Token xsp;
+ while (true) {
+ xsp = jj_scanpos;
+ if (jj_3R_49()) { jj_scanpos = xsp; break; }
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ }
+ return false;
+ }
+
+ final private boolean jj_3R_50() {
+ if (jj_scan_token(LOGICAL_EQUALS)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ if (jj_3R_46()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_47() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_50()) {
+ jj_scanpos = xsp;
+ if (jj_3R_51()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_32() {
+ if (jj_scan_token(DIDENTIFIER)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
final private boolean jj_3R_38() {
if (jj_scan_token(FALSE)) return true;
if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
@@ -1981,63 +2027,6 @@
} else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
} else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
} else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
- return false;
- }
-
- final private boolean jj_3R_19() {
- if (jj_3R_24()) return true;
- if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
- Token xsp;
- while (true) {
- xsp = jj_scanpos;
- if (jj_3R_45()) { jj_scanpos = xsp; break; }
- if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
- }
- return false;
- }
-
- final private boolean jj_3R_51() {
- if (jj_scan_token(LOGICAL_NOT_EQUALS)) return true;
- if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
- if (jj_3R_46()) return true;
- if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
- return false;
- }
-
- final private boolean jj_3R_46() {
- if (jj_3R_48()) return true;
- if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
- Token xsp;
- while (true) {
- xsp = jj_scanpos;
- if (jj_3R_49()) { jj_scanpos = xsp; break; }
- if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
- }
- return false;
- }
-
- final private boolean jj_3R_50() {
- if (jj_scan_token(LOGICAL_EQUALS)) return true;
- if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
- if (jj_3R_46()) return true;
- if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
- return false;
- }
-
- final private boolean jj_3R_47() {
- Token xsp;
- xsp = jj_scanpos;
- if (jj_3R_50()) {
- jj_scanpos = xsp;
- if (jj_3R_51()) return true;
- if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
- } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
- return false;
- }
-
- final private boolean jj_3R_32() {
- if (jj_scan_token(DIDENTIFIER)) return true;
- if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
return false;
}
1.3 +8 -19 jakarta-velocity/src/java/org/apache/velocity/processor/javacc/parser/velocity/Parser.jj
Index: Parser.jj
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/processor/javacc/parser/velocity/Parser.jj,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Parser.jj 2000/09/19 06:58:54 1.2
+++ Parser.jj 2000/09/19 19:49:57 1.3
@@ -99,7 +99,7 @@
* what controls the generation of this class.
*
* @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
- * @version $Id: Parser.jj,v 1.2 2000/09/19 06:58:54 jvanzyl Exp $
+ * @version $Id: Parser.jj,v 1.3 2000/09/19 19:49:57 jvanzyl Exp $
*/
public class Parser implements/*@bgen(jjtree)*/ ParserTreeConstants, /*@egen*/ org.apache.velocity.processor.javacc.parser.Parser
{/*@bgen(jjtree)*/
@@ -117,10 +117,13 @@
* a constructor without parameters. The normal constructor
* takes a single argument which an InputStream. But in
* order to make the parser dynamically loadable this
- * constructor had to be added.
+ * constructor had to be added. This also allows us to
+ * create a single instance of a parser and reuse
+ * it over and over.
*/
public Parser()
{
+ this(new ByteArrayInputStream("\n".getBytes()));
}
/* This was also added to allow parsers to be dynamically
@@ -137,24 +140,10 @@
* possible with JavaCC. I believe that you can do
* this with ANTLR though.
*/
- public void parse(InputStream stream) throws ParseException
+ public SimpleNode parse(InputStream stream) throws ParseException
{
- //* taken from generated source
- jj_input_stream = new ASCII_CharStream(stream, 1, 1);
- token_source = new ParserTokenManager(jj_input_stream);
- token = new Token();
- jj_ntk = -1;
- jj_gen = 0;
- for (int i = 0; i < 22; i++) jj_la1[i] = -1;
- for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
- //* taken from generated source
-
- root = process();
- }
-
- public SimpleNode getRoot()
- {
- return root;
+ ReInit(stream);
+ return process();
}
}
1.4 +8 -19 jakarta-velocity/src/java/org/apache/velocity/processor/javacc/parser/velocity/Parser.jjt
Index: Parser.jjt
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/processor/javacc/parser/velocity/Parser.jjt,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Parser.jjt 2000/09/19 07:12:50 1.3
+++ Parser.jjt 2000/09/19 19:49:57 1.4
@@ -123,7 +123,7 @@
* what controls the generation of this class.
*
* @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
- * @version $Id: Parser.jjt,v 1.3 2000/09/19 07:12:50 jvanzyl Exp $
+ * @version $Id: Parser.jjt,v 1.4 2000/09/19 19:49:57 jvanzyl Exp $
*/
public class Parser implements org.apache.velocity.processor.javacc.parser.Parser
{
@@ -138,10 +138,13 @@
* a constructor without parameters. The normal constructor
* takes a single argument which an InputStream. But in
* order to make the parser dynamically loadable this
- * constructor had to be added.
+ * constructor had to be added. This also allows us to
+ * create a single instance of a parser and reuse
+ * it over and over.
*/
public Parser()
{
+ this(new ByteArrayInputStream("\n".getBytes()));
}
/* This was also added to allow parsers to be dynamically
@@ -158,24 +161,10 @@
* possible with JavaCC. I believe that you can do
* this with ANTLR though.
*/
- public void parse(InputStream stream) throws ParseException
+ public SimpleNode parse(InputStream stream) throws ParseException
{
- //* taken from generated source
- jj_input_stream = new ASCII_CharStream(stream, 1, 1);
- token_source = new ParserTokenManager(jj_input_stream);
- token = new Token();
- jj_ntk = -1;
- jj_gen = 0;
- for (int i = 0; i < 22; i++) jj_la1[i] = -1;
- for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
- //* taken from generated source
-
- root = process();
- }
-
- public SimpleNode getRoot()
- {
- return root;
+ ReInit(stream);
+ return process();
}
}
1.2 +117 -128 jakarta-velocity/src/java/org/apache/velocity/processor/javacc/parser/webmacro/Parser.java
Index: Parser.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/processor/javacc/parser/webmacro/Parser.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Parser.java 2000/09/19 01:58:50 1.1
+++ Parser.java 2000/09/19 19:49:58 1.2
@@ -16,7 +16,7 @@
* what controls the generation of this class.
*
* @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
- * @version $Id: Parser.java,v 1.1 2000/09/19 01:58:50 jvanzyl Exp $
+ * @version $Id: Parser.java,v 1.2 2000/09/19 19:49:58 jvanzyl Exp $
*/
public class Parser implements/*@bgen(jjtree)*/ ParserTreeConstants,org.apache.velocity.processor.javacc.parser.Parser, ParserConstants {/*@bgen(jjtree)*/
protected JJTParserState jjtree = new JJTParserState();
@@ -33,10 +33,13 @@
* a constructor without parameters. The normal constructor
* takes a single argument which an InputStream. But in
* order to make the parser dynamically loadable this
- * constructor had to be added.
+ * constructor had to be added. This also allows us to
+ * create a single instance of a parser and reuse
+ * it over and over.
*/
public Parser()
{
+ this(new ByteArrayInputStream("\n".getBytes()));
}
/* This was also added to allow parsers to be dynamically
@@ -53,24 +56,10 @@
* possible with JavaCC. I believe that you can do
* this with ANTLR though.
*/
- public void parse(InputStream stream) throws ParseException
+ public SimpleNode parse(InputStream stream) throws ParseException
{
- //* taken from generated source
- jj_input_stream = new ASCII_CharStream(stream, 1, 1);
- token_source = new ParserTokenManager(jj_input_stream);
- token = new Token();
- jj_ntk = -1;
- jj_gen = 0;
- for (int i = 0; i < 22; i++) jj_la1[i] = -1;
- for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
- //* taken from generated source
-
- root = process();
- }
-
- public SimpleNode getRoot()
- {
- return root;
+ ReInit(stream);
+ return process();
}
/**
@@ -1562,6 +1551,115 @@
return retval;
}
+ final private boolean jj_3R_33() {
+ if (jj_scan_token(TRUE)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_38() {
+ if (jj_scan_token(LOGICAL_OR)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ if (jj_3R_37()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_27() {
+ if (jj_scan_token(IDENTIFIER)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_36() {
+ if (jj_3R_37()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ Token xsp;
+ while (true) {
+ xsp = jj_scanpos;
+ if (jj_3R_38()) { jj_scanpos = xsp; break; }
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ }
+ return false;
+ }
+
+ final private boolean jj_3R_19() {
+ if (jj_scan_token(LPAREN)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ if (jj_3R_24()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ if (jj_scan_token(RPAREN)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_23() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_27()) {
+ jj_scanpos = xsp;
+ if (jj_3R_28()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ while (true) {
+ xsp = jj_scanpos;
+ if (jj_3_1()) { jj_scanpos = xsp; break; }
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ }
+ return false;
+ }
+
+ final private boolean jj_3R_35() {
+ if (jj_3R_13()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ if (jj_scan_token(EQUALS)) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ if (jj_3R_24()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_18() {
+ if (jj_3R_23()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_26() {
+ if (jj_3R_21()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_17() {
+ if (jj_3R_22()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_16() {
+ if (jj_3R_21()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
+ final private boolean jj_3R_13() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_16()) {
+ jj_scanpos = xsp;
+ if (jj_3R_17()) {
+ jj_scanpos = xsp;
+ if (jj_3R_18()) {
+ jj_scanpos = xsp;
+ if (jj_3R_19()) return true;
+ if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
+ return false;
+ }
+
final private boolean jj_3R_12() {
if (jj_3R_14()) return true;
if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
@@ -1948,115 +2046,6 @@
if (jj_3R_40()) { jj_scanpos = xsp; break; }
if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
}
- return false;
- }
-
- final private boolean jj_3R_33() {
- if (jj_scan_token(TRUE)) return true;
- if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
- return false;
- }
-
- final private boolean jj_3R_38() {
- if (jj_scan_token(LOGICAL_OR)) return true;
- if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
- if (jj_3R_37()) return true;
- if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
- return false;
- }
-
- final private boolean jj_3R_27() {
- if (jj_scan_token(IDENTIFIER)) return true;
- if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
- return false;
- }
-
- final private boolean jj_3R_36() {
- if (jj_3R_37()) return true;
- if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
- Token xsp;
- while (true) {
- xsp = jj_scanpos;
- if (jj_3R_38()) { jj_scanpos = xsp; break; }
- if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
- }
- return false;
- }
-
- final private boolean jj_3R_23() {
- Token xsp;
- xsp = jj_scanpos;
- if (jj_3R_27()) {
- jj_scanpos = xsp;
- if (jj_3R_28()) return true;
- if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
- } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
- while (true) {
- xsp = jj_scanpos;
- if (jj_3_1()) { jj_scanpos = xsp; break; }
- if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
- }
- return false;
- }
-
- final private boolean jj_3R_19() {
- if (jj_scan_token(LPAREN)) return true;
- if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
- if (jj_3R_24()) return true;
- if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
- if (jj_scan_token(RPAREN)) return true;
- if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
- return false;
- }
-
- final private boolean jj_3R_26() {
- if (jj_3R_21()) return true;
- if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
- return false;
- }
-
- final private boolean jj_3R_35() {
- if (jj_3R_13()) return true;
- if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
- if (jj_scan_token(EQUALS)) return true;
- if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
- if (jj_3R_24()) return true;
- if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
- return false;
- }
-
- final private boolean jj_3R_18() {
- if (jj_3R_23()) return true;
- if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
- return false;
- }
-
- final private boolean jj_3R_17() {
- if (jj_3R_22()) return true;
- if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
- return false;
- }
-
- final private boolean jj_3R_16() {
- if (jj_3R_21()) return true;
- if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
- return false;
- }
-
- final private boolean jj_3R_13() {
- Token xsp;
- xsp = jj_scanpos;
- if (jj_3R_16()) {
- jj_scanpos = xsp;
- if (jj_3R_17()) {
- jj_scanpos = xsp;
- if (jj_3R_18()) {
- jj_scanpos = xsp;
- if (jj_3R_19()) return true;
- if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
- } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
- } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
- } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
return false;
}
1.2 +8 -19 jakarta-velocity/src/java/org/apache/velocity/processor/javacc/parser/webmacro/Parser.jj
Index: Parser.jj
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/processor/javacc/parser/webmacro/Parser.jj,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Parser.jj 2000/09/19 01:58:50 1.1
+++ Parser.jj 2000/09/19 19:49:58 1.2
@@ -100,7 +100,7 @@
* what controls the generation of this class.
*
* @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
- * @version $Id: Parser.jj,v 1.1 2000/09/19 01:58:50 jvanzyl Exp $
+ * @version $Id: Parser.jj,v 1.2 2000/09/19 19:49:58 jvanzyl Exp $
*/
public class Parser implements/*@bgen(jjtree)*/ ParserTreeConstants, /*@egen*/ org.apache.velocity.processor.javacc.parser.Parser
{/*@bgen(jjtree)*/
@@ -121,10 +121,13 @@
* a constructor without parameters. The normal constructor
* takes a single argument which an InputStream. But in
* order to make the parser dynamically loadable this
- * constructor had to be added.
+ * constructor had to be added. This also allows us to
+ * create a single instance of a parser and reuse
+ * it over and over.
*/
public Parser()
{
+ this(new ByteArrayInputStream("\n".getBytes()));
}
/* This was also added to allow parsers to be dynamically
@@ -141,24 +144,10 @@
* possible with JavaCC. I believe that you can do
* this with ANTLR though.
*/
- public void parse(InputStream stream) throws ParseException
+ public SimpleNode parse(InputStream stream) throws ParseException
{
- //* taken from generated source
- jj_input_stream = new ASCII_CharStream(stream, 1, 1);
- token_source = new ParserTokenManager(jj_input_stream);
- token = new Token();
- jj_ntk = -1;
- jj_gen = 0;
- for (int i = 0; i < 22; i++) jj_la1[i] = -1;
- for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
- //* taken from generated source
-
- root = process();
- }
-
- public SimpleNode getRoot()
- {
- return root;
+ ReInit(stream);
+ return process();
}
}
1.2 +8 -19 jakarta-velocity/src/java/org/apache/velocity/processor/javacc/parser/webmacro/Parser.jjt
Index: Parser.jjt
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/processor/javacc/parser/webmacro/Parser.jjt,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Parser.jjt 2000/09/19 01:58:50 1.1
+++ Parser.jjt 2000/09/19 19:49:59 1.2
@@ -124,7 +124,7 @@
* what controls the generation of this class.
*
* @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
- * @version $Id: Parser.jjt,v 1.1 2000/09/19 01:58:50 jvanzyl Exp $
+ * @version $Id: Parser.jjt,v 1.2 2000/09/19 19:49:59 jvanzyl Exp $
*/
public class Parser implements org.apache.velocity.processor.javacc.parser.Parser
{
@@ -142,10 +142,13 @@
* a constructor without parameters. The normal constructor
* takes a single argument which an InputStream. But in
* order to make the parser dynamically loadable this
- * constructor had to be added.
+ * constructor had to be added. This also allows us to
+ * create a single instance of a parser and reuse
+ * it over and over.
*/
public Parser()
{
+ this(new ByteArrayInputStream("\n".getBytes()));
}
/* This was also added to allow parsers to be dynamically
@@ -162,24 +165,10 @@
* possible with JavaCC. I believe that you can do
* this with ANTLR though.
*/
- public void parse(InputStream stream) throws ParseException
+ public SimpleNode parse(InputStream stream) throws ParseException
{
- //* taken from generated source
- jj_input_stream = new ASCII_CharStream(stream, 1, 1);
- token_source = new ParserTokenManager(jj_input_stream);
- token = new Token();
- jj_ntk = -1;
- jj_gen = 0;
- for (int i = 0; i < 22; i++) jj_la1[i] = -1;
- for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
- //* taken from generated source
-
- root = process();
- }
-
- public SimpleNode getRoot()
- {
- return root;
+ ReInit(stream);
+ return process();
}
}
1.3 +5 -1 jakarta-velocity/src/java/org/apache/velocity/processor/javacc/visitor/InjectorMode.java
Index: InjectorMode.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/processor/javacc/visitor/InjectorMode.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- InjectorMode.java 2000/09/19 18:07:55 1.2
+++ InjectorMode.java 2000/09/19 19:50:00 1.3
@@ -84,7 +84,7 @@
* the first step toward an efficient caching system.
*
* @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
- * @version $Id: InjectorMode.java,v 1.2 2000/09/19 18:07:55 jvanzyl Exp $
+ * @version $Id: InjectorMode.java,v 1.3 2000/09/19 19:50:00 jvanzyl Exp $
*/
public class InjectorMode extends SinglePassMode
{
@@ -99,6 +99,10 @@
staticBody = new StringBuffer();
injectors = new ArrayList();
}
+
+ // ok, this little experiment worked, but the
+ // array of injectors has to go back to
+ // the template. hmmm.
/**
* Take the parent node of the template
1.2 +4 -4 jakarta-velocity/src/java/org/apache/velocity/processor/javacc/visitor/SinglePassMode.java
Index: SinglePassMode.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/processor/javacc/visitor/SinglePassMode.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SinglePassMode.java 2000/09/19 17:23:50 1.1
+++ SinglePassMode.java 2000/09/19 19:50:00 1.2
@@ -73,12 +73,12 @@
* that traverses the AST, produced by the Velocity
* parsing process, and re-constitutes the input
* into fully formatted output. This class just
- * does straight through processing. This particular
- * visitor make no provision for future caching.
- * Look at the InjectorVisitor for that.
+ * does single pass processing. This particular
+ * visitor makes no provision for future caching.
+ * Look at the InjectorMode visitor for that.
*
* @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
- * @version $Id: SinglePassMode.java,v 1.1 2000/09/19 17:23:50 jvanzyl Exp $
+ * @version $Id: SinglePassMode.java,v 1.2 2000/09/19 19:50:00 jvanzyl Exp $
*/
public class SinglePassMode extends BaseVisitor
{
1.2 +7 -0 jakarta-velocity/src/java/org/apache/velocity/runtime/TemplateLoader.java
Index: TemplateLoader.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/TemplateLoader.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TemplateLoader.java 2000/09/19 01:58:58 1.1
+++ TemplateLoader.java 2000/09/19 19:50:01 1.2
@@ -62,7 +62,7 @@
/**
* Each loader should implement this class
* @author Dave Bryson
- * $Revision: 1.1 $
+ * $Revision: 1.2 $
*/
public abstract class TemplateLoader
{
@@ -71,6 +71,12 @@
protected static String TEMPLATE_PROCESSOR =
Configuration.getString(Configuration.TEMPLATE_PROCESSOR);
+ protected static String TEMPLATE_MODE =
+ Configuration.getString(Configuration.TEMPLATE_MODE);
+
+ protected static String TEMPLATE_SYNTAX =
+ Configuration.getString(Configuration.TEMPLATE_SYNTAX);
+
/**
* Initialize anything needed for this loader.
*/
@@ -79,6 +85,7 @@
try
{
processor = (Processor) Class.forName(TEMPLATE_PROCESSOR).newInstance();
+ processor.init(TEMPLATE_MODE, TEMPLATE_SYNTAX);
}
catch (Exception e)
{