KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > persistence > antlr > debug > DebuggingCharScanner


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