01: package org.antlr.runtime.debug;
02:
03: import org.antlr.runtime.Token;
04: import org.antlr.runtime.tree.TreeAdaptor;
05:
06: /** Print out (most of) the events... Useful for debugging, testing... */
07: public class TraceDebugEventListener extends BlankDebugEventListener {
08: TreeAdaptor adaptor;
09:
10: public TraceDebugEventListener(TreeAdaptor adaptor) {
11: this .adaptor = adaptor;
12: }
13:
14: public void enterRule(String ruleName) {
15: System.out.println("enterRule " + ruleName);
16: }
17:
18: public void exitRule(String ruleName) {
19: System.out.println("exitRule " + ruleName);
20: }
21:
22: public void enterSubRule(int decisionNumber) {
23: System.out.println("enterSubRule");
24: }
25:
26: public void exitSubRule(int decisionNumber) {
27: System.out.println("exitSubRule");
28: }
29:
30: public void location(int line, int pos) {
31: System.out.println("location " + line + ":" + pos);
32: }
33:
34: // Tree parsing stuff
35:
36: public void consumeNode(Object t) {
37: int ID = adaptor.getUniqueID(t);
38: String text = adaptor.getText(t);
39: int type = adaptor.getType(t);
40: System.out.println("consumeNode " + ID + " " + text + " "
41: + type);
42: }
43:
44: public void LT(int i, Object t) {
45: int ID = adaptor.getUniqueID(t);
46: String text = adaptor.getText(t);
47: int type = adaptor.getType(t);
48: System.out.println("LT " + i + " " + ID + " " + text + " "
49: + type);
50: }
51:
52: // AST stuff
53: public void nilNode(Object t) {
54: System.out.println("nilNode " + adaptor.getUniqueID(t));
55: }
56:
57: public void createNode(Object t) {
58: int ID = adaptor.getUniqueID(t);
59: String text = adaptor.getText(t);
60: int type = adaptor.getType(t);
61: System.out.println("create " + ID + ": " + text + ", " + type);
62: }
63:
64: public void createNode(Object node, Token token) {
65: int ID = adaptor.getUniqueID(node);
66: String text = adaptor.getText(node);
67: int tokenIndex = token.getTokenIndex();
68: System.out.println("create " + ID + ": " + tokenIndex);
69: }
70:
71: public void becomeRoot(Object newRoot, Object oldRoot) {
72: System.out.println("becomeRoot " + adaptor.getUniqueID(newRoot)
73: + ", " + adaptor.getUniqueID(oldRoot));
74: }
75:
76: public void addChild(Object root, Object child) {
77: System.out.println("addChild " + adaptor.getUniqueID(root)
78: + ", " + adaptor.getUniqueID(child));
79: }
80:
81: public void setTokenBoundaries(Object t, int tokenStartIndex,
82: int tokenStopIndex) {
83: System.out.println("setTokenBoundaries "
84: + adaptor.getUniqueID(t) + ", " + tokenStartIndex
85: + ", " + tokenStopIndex);
86: }
87: }
|