jon 00/11/07 18:28:40
Modified: src/java/org/apache/velocity/runtime/parser Parser.jjt
Log:
added documentation
fixed javadocs
create a new hashtable for the directives to prevent possible NPE
create a way for parser exceptions to be properly logged, not just for debugging. :-)
Revision Changes Path
1.26 +31 -22
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.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- Parser.jjt 2000/11/07 21:29:37 1.25
+++ Parser.jjt 2000/11/08 02:28:38 1.26
@@ -113,8 +113,10 @@
import java.io.*;
import java.util.*;
+import org.apache.velocity.runtime.Runtime;
import org.apache.velocity.runtime.parser.node.*;
import org.apache.velocity.runtime.directive.Directive;
+import org.apache.velocity.util.StringUtils;
/**
* This class is responsible for parsing a Velocity
@@ -127,15 +129,16 @@
*
* @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.25 2000/11/07 21:29:37 geirm Exp $
+ * @version $Id: Parser.jjt,v 1.26 2000/11/08 02:28:38 jon Exp $
*/
public class Parser
{
-
-
- Hashtable directives;
+ /**
+ * This Hashtable contains a list of all of the dynamic directives.
+ */
+ private Hashtable directives = new Hashtable(0);
- /* This was added to allow the parser to be associated
+ /** This was added to allow the parser to be associated
* with a particular syntax. JavaCC doesn't generate
* a constructor without parameters. The normal constructor
* takes a single argument which an InputStream. But in
@@ -149,7 +152,7 @@
this(new ByteArrayInputStream("\n".getBytes()));
}
- /* This was also added to allow parsers to be dynamically
+ /** This was also added to allow parsers to be dynamically
* loadable.
*
* Taken from the generated constructor in Parser.java.
@@ -165,33 +168,39 @@
*/
public SimpleNode parse(InputStream stream) throws ParseException
{
- token_source.clearStateVars();
- ReInit(stream);
- return process();
-
- /*
- * leave the following. Useful for debugging the parser. thx - geir
- */
-
- //SimpleNode n = null;
- //
- // try {
- // n = process();
- // } catch (Exception e ) { System.out.println( e ); }
- //
- // return n;
+ SimpleNode sn = null;
+ try
+ {
+ token_source.clearStateVars();
+ ReInit(stream);
+ n = process();
+ }
+ catch (Exception e )
+ {
+ Runtime.error ("Parser Error: " + StringUtils.stackTrace(e));
+ }
+ return sn;
}
-
+ /**
+ * This method sets the directives Hashtable
+ */
public void setDirectives(Hashtable directives)
{
this.directives = directives;
}
+ /**
+ * This method gets the directives Hashtable
+ */
public Directive getDirective(String directive)
{
return (Directive) directives.get(directive);
}
+ /**
+ * This method finds out of the directive exists in the directives
+ * Hashtable.
+ */
public boolean isDirective(String directive)
{
if (directives.containsKey(directive))