KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > antlr > debug > DebuggingCharScanner


1 package antlr.debug;
2
3 import antlr.collections.impl.*;
4 import java.io.*;
5
6 public abstract class DebuggingCharScanner extends CharScanner implements DebuggingParser {
7     private ParserEventSupport parserEventSupport = new ParserEventSupport(this);
8     private boolean _notDebugMode = false;
9     protected String JavaDoc ruleNames[];
10     protected String JavaDoc semPredNames[];
11
12
13     public DebuggingCharScanner(InputBuffer cb) {
14         super(cb);
15     }
16     public DebuggingCharScanner(LexerSharedInputState state) {
17         super(state);
18     }
19     public void addMessageListener(MessageListener l) {
20         parserEventSupport.addMessageListener(l);
21     }
22     public void addNewLineListener(NewLineListener l) {
23         parserEventSupport.addNewLineListener(l);
24     }
25     public void addParserListener(ParserListener l) {
26         parserEventSupport.addParserListener(l);
27     }
28     public void addParserMatchListener(ParserMatchListener l) {
29         parserEventSupport.addParserMatchListener(l);
30     }
31     public void addParserTokenListener(ParserTokenListener l) {
32         parserEventSupport.addParserTokenListener(l);
33     }
34     public void addSemanticPredicateListener(SemanticPredicateListener l) {
35         parserEventSupport.addSemanticPredicateListener(l);
36     }
37     public void addSyntacticPredicateListener(SyntacticPredicateListener l) {
38         parserEventSupport.addSyntacticPredicateListener(l);
39     }
40     public void addTraceListener(TraceListener l) {
41         parserEventSupport.addTraceListener(l);
42     }
43     public void consume() throws CharStreamException {
44         int la_1 = -99;
45         try {la_1 = LA(1);}
46         catch (CharStreamException ignoreAnIOException) {}
47         super.consume();
48         parserEventSupport.fireConsume(la_1);
49     }
50     protected void fireEnterRule(int num, int data) {
51         if (isDebugMode())
52             parserEventSupport.fireEnterRule(num,inputState.guessing,data);
53     }
54     protected void fireExitRule(int num, int ttype) {
55         if (isDebugMode())
56             parserEventSupport.fireExitRule(num,inputState.guessing, ttype);
57     }
58     protected boolean fireSemanticPredicateEvaluated(int type, int num, boolean condition) {
59         if (isDebugMode())
60             return parserEventSupport.fireSemanticPredicateEvaluated(type,num,condition,inputState.guessing);
61         else
62             return condition;
63     }
64     protected void fireSyntacticPredicateFailed() {
65         if (isDebugMode())
66             parserEventSupport.fireSyntacticPredicateFailed(inputState.guessing);
67     }
68     protected void fireSyntacticPredicateStarted() {
69         if (isDebugMode())
70             parserEventSupport.fireSyntacticPredicateStarted(inputState.guessing);
71     }
72     protected void fireSyntacticPredicateSucceeded() {
73         if (isDebugMode())
74             parserEventSupport.fireSyntacticPredicateSucceeded(inputState.guessing);
75     }
76     public String JavaDoc getRuleName(int num) {
77         return ruleNames[num];
78     }
79     public String JavaDoc getSemPredName(int num) {
80         return semPredNames[num];
81     }
82     public synchronized void goToSleep() {
83         try {wait();}
84         catch (InterruptedException JavaDoc e) { }
85     }
86     public boolean isDebugMode() {
87         return !_notDebugMode;
88     }
89     public char LA(int i) throws CharStreamException {
90         char la = super.LA(i);
91         parserEventSupport.fireLA(i, la);
92         return la;
93     }
94     protected Token makeToken(int t) {
95         // do something with char buffer???
96
// try {
97
// Token tok = (Token)tokenObjectClass.newInstance();
98
// tok.setType(t);
99
// // tok.setText(getText()); done in generated lexer now
100
// tok.setLine(line);
101
// return tok;
102
// }
103
// catch (InstantiationException ie) {
104
// panic("can't instantiate a Token");
105
// }
106
// catch (IllegalAccessException iae) {
107
// panic("Token class is not accessible");
108
// }
109
return super.makeToken(t);
110     }
111     public void match(char c) throws MismatchedCharException, CharStreamException {
112         char la_1 = LA(1);
113         try {
114             super.match(c);
115             parserEventSupport.fireMatch(c, inputState.guessing);
116         }
117         catch (MismatchedCharException e) {
118             if (inputState.guessing == 0)
119                 parserEventSupport.fireMismatch(la_1, c, inputState.guessing);
120             throw e;
121         }
122     }
123     public void match(BitSet b) throws MismatchedCharException, CharStreamException {
124         String JavaDoc text = this.text.toString();
125         char la_1 = LA(1);
126         try {
127             super.match(b);
128             parserEventSupport.fireMatch(la_1, b, text, inputState.guessing);
129         }
130         catch (MismatchedCharException e) {
131             if (inputState.guessing == 0)
132                 parserEventSupport.fireMismatch(la_1, b, text, inputState.guessing);
133             throw e;
134         }
135     }
136     public void match(String JavaDoc s) throws MismatchedCharException, CharStreamException {
137         StringBuffer JavaDoc la_s = new StringBuffer JavaDoc("");
138         int len = s.length();
139         // peek at the next len worth of characters
140
try {
141             for(int i = 1; i <= len; i++) {
142                 la_s.append(super.LA(i));
143             }
144         }
145         catch(Exception JavaDoc ignoreMe) {}
146
147         try {
148             super.match(s);
149             parserEventSupport.fireMatch(s, inputState.guessing);
150         }
151         catch (MismatchedCharException e) {
152             if (inputState.guessing == 0)
153                 parserEventSupport.fireMismatch(la_s.toString(), s, inputState.guessing);
154             throw e;
155         }
156
157     }
158     public void matchNot(char c) throws MismatchedCharException, CharStreamException {
159         char la_1 = LA(1);
160         try {
161             super.matchNot(c);
162             parserEventSupport.fireMatchNot(la_1, c, inputState.guessing);
163         }
164         catch (MismatchedCharException e) {
165             if (inputState.guessing == 0)
166                 parserEventSupport.fireMismatchNot(la_1, c, inputState.guessing);
167             throw e;
168         }
169
170     }
171     public void matchRange(char c1, char c2) throws MismatchedCharException, CharStreamException {
172         char la_1 = LA(1);
173         try {
174             super.matchRange(c1,c2);
175             parserEventSupport.fireMatch(la_1, ""+c1+c2, inputState.guessing);
176         }
177         catch (MismatchedCharException e) {
178             if (inputState.guessing == 0)
179                 parserEventSupport.fireMismatch(la_1, ""+c1+c2, inputState.guessing);
180             throw e;
181         }
182
183     }
184     public void newline() {
185         super.newline();
186         parserEventSupport.fireNewLine(getLine());
187     }
188     public void removeMessageListener(MessageListener l) {
189         parserEventSupport.removeMessageListener(l);
190     }
191     public void removeNewLineListener(NewLineListener l) {
192         parserEventSupport.removeNewLineListener(l);
193     }
194     public void removeParserListener(ParserListener l) {
195         parserEventSupport.removeParserListener(l);
196     }
197     public void removeParserMatchListener(ParserMatchListener l) {
198         parserEventSupport.removeParserMatchListener(l);
199     }
200     public void removeParserTokenListener(ParserTokenListener l) {
201         parserEventSupport.removeParserTokenListener(l);
202     }
203     public void removeSemanticPredicateListener(SemanticPredicateListener l) {
204         parserEventSupport.removeSemanticPredicateListener(l);
205     }
206     public void removeSyntacticPredicateListener(SyntacticPredicateListener l) {
207         parserEventSupport.removeSyntacticPredicateListener(l);
208     }
209     public void removeTraceListener(TraceListener l) {
210         parserEventSupport.removeTraceListener(l);
211     }
212     /** Report exception errors caught in nextToken() */
213     public void reportError(MismatchedCharException e) {
214         parserEventSupport.fireReportError(e);
215         super.reportError(e);
216     }
217     /** Parser error-reporting function can be overridden in subclass */
218     public void reportError(String JavaDoc s) {
219         parserEventSupport.fireReportError(s);
220         super.reportError(s);
221     }
222     /** Parser warning-reporting function can be overridden in subclass */
223     public void reportWarning(String JavaDoc s) {
224         parserEventSupport.fireReportWarning(s);
225         super.reportWarning(s);
226     }
227     public void setDebugMode(boolean value) {
228         _notDebugMode = !value;
229     }
230     public void setupDebugging() {
231     }
232     public synchronized void wakeUp() {
233         notify();
234     }
235 }
236
Popular Tags