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/08/29 08:36:05 UTC
cvs commit: jakarta-velocity/src/java/org/apache/velocity/visitor DumpVisitor.java InjectorVisitor.java ProcessVisitor.java
jvanzyl 00/08/28 23:36:03
Modified: src/java/org/apache/velocity/visitor DumpVisitor.java
InjectorVisitor.java ProcessVisitor.java
Log:
- added support in the DumpVisitor to display the tokens
parsed next to the node type. When adding new features to
the parser this visitor will now display the full behaviour
of the parsing mechanism. I'm using this to implement better
property and method parsing, full compatibility with WM.
Revision Changes Path
1.4 +106 -18 jakarta-velocity/src/java/org/apache/velocity/visitor/DumpVisitor.java
Index: DumpVisitor.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/visitor/DumpVisitor.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DumpVisitor.java 2000/08/28 10:21:44 1.3
+++ DumpVisitor.java 2000/08/29 06:36:00 1.4
@@ -66,13 +66,13 @@
* as well.
*
* @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
- * @version $Id: DumpVisitor.java,v 1.3 2000/08/28 10:21:44 jvanzyl Exp $
+ * @version $Id: DumpVisitor.java,v 1.4 2000/08/29 06:36:00 jvanzyl Exp $
*/
public class DumpVisitor implements ParserVisitor
{
private int indent = 0;
+ private boolean showTokens = true;
-
public void setContext(Context context)
{
}
@@ -100,36 +100,65 @@
--indent;
return data;
}
+
public Object visit(ASTprocess node, Object data)
+ {
+ data = node.childrenAccept(this, data);
+ return data;
+ }
+
+ public Object visit(ASTVariable node, Object data)
{
- System.out.println(indentString() + node);
+ String tokens = "";
+
+ if (showTokens)
+ tokens = " -> " + node.getFirstToken().image;
+
+ System.out.println(indentString() + node + tokens);
++indent;
data = node.childrenAccept(this, data);
--indent;
return data;
}
- public Object visit(ASTVariable node, Object data)
+ public Object visit(ASTProperty node, Object data)
{
- System.out.println(indentString() + node);
+ String tokens = "";
+
+ if (showTokens)
+ tokens = " -> " + node.getFirstToken().image;
+
+ System.out.println(indentString() + node + tokens);
++indent;
data = node.childrenAccept(this, data);
--indent;
return data;
}
- public Object visit(ASTProperty node, Object data)
+ public Object visit(ASTPropertyMethod node, Object data)
{
- System.out.println(indentString() + node);
+ String tokens = "";
+
+ if (showTokens)
+ tokens = " -> " + node.getFirstToken().image;
+
+ System.out.println(indentString() + node + tokens);
++indent;
data = node.childrenAccept(this, data);
--indent;
return data;
}
+
public Object visit(ASTParameter node, Object data)
{
- System.out.println(indentString() + node);
+ String tokens = "";
+ Token token = node.getFirstToken();
+ if (showTokens)
+ tokens = " -> " + token.image + " " + token.next.image + " " +
+ token.next.next.image + " " + token.next.next.next.image;
+
+ System.out.println(indentString() + node + tokens);
++indent;
data = node.childrenAccept(this, data);
--indent;
@@ -138,7 +167,12 @@
}
public Object visit(ASTParameters node, Object data)
{
- System.out.println(indentString() + node);
+ String tokens = "";
+
+ if (showTokens)
+ tokens = " -> " + node.getFirstToken().image;
+
+ System.out.println(indentString() + node + tokens);
++indent;
data = node.childrenAccept(this, data);
--indent;
@@ -147,7 +181,12 @@
}
public Object visit(ASTMethod node, Object data)
{
- System.out.println(indentString() + node);
+ String tokens = "";
+
+ if (showTokens)
+ tokens = " -> " + node.getFirstToken().image;
+
+ System.out.println(indentString() + node + tokens);
++indent;
data = node.childrenAccept(this, data);
--indent;
@@ -156,7 +195,12 @@
}
public Object visit(ASTExpression node, Object data)
{
- System.out.println(indentString() + node);
+ String tokens = "";
+
+ if (showTokens)
+ tokens = " -> " + node.getFirstToken().image;
+
+ System.out.println(indentString() + node + tokens);
++indent;
data = node.childrenAccept(this, data);
--indent;
@@ -165,7 +209,12 @@
}
public Object visit(ASTBlock node, Object data)
{
- System.out.println(indentString() + node);
+ String tokens = "";
+
+ if (showTokens)
+ tokens = " -> " + node.getFirstToken().image;
+
+ System.out.println(indentString() + node + tokens);
++indent;
data = node.childrenAccept(this, data);
--indent;
@@ -174,7 +223,14 @@
}
public Object visit(ASTIfStatement node, Object data)
{
- System.out.println(indentString() + node);
+ String tokens = "";
+
+ Token token = node.getFirstToken();
+ if (showTokens)
+ tokens = " -> " + token.image + " " + token.next.image + " " +
+ token.next.next.image + " " + token.next.next.next.image;
+
+ System.out.println(indentString() + node + tokens);
++indent;
data = node.childrenAccept(this, data);
--indent;
@@ -183,7 +239,14 @@
}
public Object visit(ASTForeachStatement node, Object data)
{
- System.out.println(indentString() + node);
+ String tokens = "";
+
+ Token token = node.getFirstToken();
+ if (showTokens)
+ tokens = " -> " + token.image + " " + token.next.image + " " +
+ token.next.next.image + " " + token.next.next.next.image;
+
+ System.out.println(indentString() + node + tokens);
++indent;
data = node.childrenAccept(this, data);
--indent;
@@ -192,7 +255,14 @@
}
public Object visit(ASTSetStatement node, Object data)
{
- System.out.println(indentString() + node);
+ String tokens = "";
+
+ Token token = node.getFirstToken();
+ if (showTokens)
+ tokens = " -> " + token.image + " " + token.next.image + " " +
+ token.next.next.image + " " + token.next.next.next.image;
+
+ System.out.println(indentString() + node + tokens);
++indent;
data = node.childrenAccept(this, data);
--indent;
@@ -201,7 +271,12 @@
}
public Object visit(ASTUseStatement node, Object data)
{
- System.out.println(indentString() + node);
+ String tokens = "";
+
+ if (showTokens)
+ tokens = " -> " + node.getFirstToken().image;
+
+ System.out.println(indentString() + node + tokens);
++indent;
data = node.childrenAccept(this, data);
--indent;
@@ -210,16 +285,29 @@
}
public Object visit(ASTParamStatement node, Object data)
{
- System.out.println(indentString() + node);
+ String tokens = "";
+
+ Token token = node.getFirstToken();
+ if (showTokens)
+ tokens = " -> " + token.image + " " + token.next.image + " " +
+ token.next.next.image + " " + token.next.next.next.image;
+
+ System.out.println(indentString() + node + tokens);
++indent;
data = node.childrenAccept(this, data);
--indent;
return data;
}
+
public Object visit(ASTText node, Object data)
{
- System.out.println(indentString() + node);
+ String tokens = "";
+
+ if (showTokens)
+ tokens = " -> " + node.getFirstToken().image;
+
+ System.out.println(indentString() + node + tokens);
++indent;
data = node.childrenAccept(this, data);
--indent;
1.4 +7 -1 jakarta-velocity/src/java/org/apache/velocity/visitor/InjectorVisitor.java
Index: InjectorVisitor.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/visitor/InjectorVisitor.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- InjectorVisitor.java 2000/08/28 18:15:18 1.3
+++ InjectorVisitor.java 2000/08/29 06:36:01 1.4
@@ -69,7 +69,7 @@
*
*
* @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
- * @version $Id: InjectorVisitor.java,v 1.3 2000/08/28 18:15:18 jvanzyl Exp $
+ * @version $Id: InjectorVisitor.java,v 1.4 2000/08/29 06:36:01 jvanzyl Exp $
*/
public class InjectorVisitor implements ParserVisitor
{
@@ -183,6 +183,12 @@
else
print(t.toString(), t.beginColumn, t.beginLine);
+ data = node.childrenAccept(this, data);
+ return data;
+ }
+
+ public Object visit(ASTPropertyMethod node, Object data)
+ {
data = node.childrenAccept(this, data);
return data;
}
1.7 +25 -4 jakarta-velocity/src/java/org/apache/velocity/visitor/ProcessVisitor.java
Index: ProcessVisitor.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/visitor/ProcessVisitor.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ProcessVisitor.java 2000/08/28 10:25:46 1.6
+++ ProcessVisitor.java 2000/08/29 06:36:01 1.7
@@ -149,7 +149,7 @@
* Look at the InjectorVisitor for that.
*
* @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
- * @version $Id: ProcessVisitor.java,v 1.6 2000/08/28 10:25:46 jvanzyl Exp $
+ * @version $Id: ProcessVisitor.java,v 1.7 2000/08/29 06:36:01 jvanzyl Exp $
*/
public class ProcessVisitor implements ParserVisitor
{
@@ -271,6 +271,12 @@
return data;
}
+ public Object visit(ASTPropertyMethod node, Object data)
+ {
+ data = node.childrenAccept(this, data);
+ return data;
+ }
+
public Object visit(ASTParameter node, Object data)
{
data = node.childrenAccept(this, data);
@@ -680,11 +686,22 @@
return data;
}
+ // These methods should probably be moved out
+ // of this class so they can be reused by
+ // a base class visitor.
+
+ /**
+ * Simply remove the quotes from a
+ * string literal
+ */
public Object getStringLiteralValue(String s)
{
return s.substring(1, s.length() - 1);
}
-
+
+ /**
+ * Get the value of variable from the context
+ */
public Object getVariableValue(String s)
{
String variable = s.substring(1);
@@ -698,7 +715,10 @@
return null;
}
}
-
+
+ /**
+ * Get the value of property
+ */
public Object getPropertyValue(String s)
{
String contextKey = s.substring(1, s.indexOf("."));
@@ -732,7 +752,8 @@
}
// Add some logging if the property doesn't
- // exist.
+ // exist. Think about Bob's idea of making
+ // the logging configurable.
}
public Object getMethodValue(String s)