Added ability to order the execution of dictionary adapter behaviors.
[castle.git] / Experiments / Attic / Rook / Castle.Rook.Compiler / Parser / antlr / debug / DebuggingCharScanner.cs
blob0a641f23044649232f085a6ee7ae69b26322d599
1 namespace antlr.debug
3 using System;
4 using System.Threading;
5 using antlr;
7 using BitSet = antlr.collections.impl.BitSet;
9 public abstract class DebuggingCharScanner : CharScanner, DebuggingParser
11 private void InitBlock()
13 eventSupport = new ScannerEventSupport(this);
15 public virtual void setDebugMode(bool mode)
17 _notDebugMode = !mode;
20 private ScannerEventSupport eventSupport;
21 private bool _notDebugMode = false;
22 protected internal string[] ruleNames;
23 protected internal string[] semPredNames;
26 public DebuggingCharScanner(InputBuffer cb) : base(cb)
28 InitBlock();
30 public DebuggingCharScanner(LexerSharedInputState state) : base(state)
32 InitBlock();
34 public virtual void addMessageListener(MessageListener l)
36 eventSupport.addMessageListener(l);
38 public virtual void addNewLineListener(NewLineListener l)
40 eventSupport.addNewLineListener(l);
42 public virtual void addParserListener(ParserListener l)
44 eventSupport.addParserListener(l);
46 public virtual void addParserMatchListener(ParserMatchListener l)
48 eventSupport.addParserMatchListener(l);
50 public virtual void addParserTokenListener(ParserTokenListener l)
52 eventSupport.addParserTokenListener(l);
54 public virtual void addSemanticPredicateListener(SemanticPredicateListener l)
56 eventSupport.addSemanticPredicateListener(l);
58 public virtual void addSyntacticPredicateListener(SyntacticPredicateListener l)
60 eventSupport.addSyntacticPredicateListener(l);
62 public virtual void addTraceListener(TraceListener l)
64 eventSupport.addTraceListener(l);
66 public override void consume()
68 int la_1 = - 99;
69 try
71 la_1 = LA(1);
73 catch (CharStreamException)
76 base.consume();
77 eventSupport.fireConsume(la_1);
79 protected internal virtual void fireEnterRule(int num, int data)
81 if (isDebugMode())
82 eventSupport.fireEnterRule(num, inputState.guessing, data);
84 protected internal virtual void fireExitRule(int num, int ttype)
86 if (isDebugMode())
87 eventSupport.fireExitRule(num, inputState.guessing, ttype);
89 protected internal virtual bool fireSemanticPredicateEvaluated(int type, int num, bool condition)
91 if (isDebugMode())
92 return eventSupport.fireSemanticPredicateEvaluated(type, num, condition, inputState.guessing);
93 else
94 return condition;
96 protected internal virtual void fireSyntacticPredicateFailed()
98 if (isDebugMode())
99 eventSupport.fireSyntacticPredicateFailed(inputState.guessing);
101 protected internal virtual void fireSyntacticPredicateStarted()
103 if (isDebugMode())
104 eventSupport.fireSyntacticPredicateStarted(inputState.guessing);
106 protected internal virtual void fireSyntacticPredicateSucceeded()
108 if (isDebugMode())
109 eventSupport.fireSyntacticPredicateSucceeded(inputState.guessing);
111 public virtual string getRuleName(int num)
113 return ruleNames[num];
115 public virtual string getSemPredName(int num)
117 return semPredNames[num];
119 public virtual void goToSleep()
121 lock(this)
125 Monitor.Wait(this);
127 catch (System.Threading.ThreadInterruptedException)
132 public virtual bool isDebugMode()
134 return !_notDebugMode;
136 public override char LA(int i)
138 char la = base.LA(i);
139 eventSupport.fireLA(i, la);
140 return la;
142 protected internal override IToken makeToken(int t)
144 // do something with char buffer???
145 // try {
146 // IToken tok = (Token)tokenObjectClass.newInstance();
147 // tok.setType(t);
148 // // tok.setText(getText()); done in generated lexer now
149 // tok.setLine(line);
150 // return tok;
151 // }
152 // catch (InstantiationException ie) {
153 // panic("can't instantiate a Token");
154 // }
155 // catch (IllegalAccessException iae) {
156 // panic("Token class is not accessible");
157 // }
158 return base.makeToken(t);
160 public override void match(int c)
162 char la_1 = LA(1);
165 base.match(c);
166 eventSupport.fireMatch(Convert.ToChar(c), inputState.guessing);
168 catch (MismatchedCharException e)
170 if (inputState.guessing == 0)
171 eventSupport.fireMismatch(la_1, Convert.ToChar(c), inputState.guessing);
172 throw e;
175 public override void match(BitSet b)
177 string text = this.text.ToString();
178 char la_1 = LA(1);
181 base.match(b);
182 eventSupport.fireMatch(la_1, b, text, inputState.guessing);
184 catch (MismatchedCharException e)
186 if (inputState.guessing == 0)
187 eventSupport.fireMismatch(la_1, b, text, inputState.guessing);
188 throw e;
191 public override void match(string s)
193 System.Text.StringBuilder la_s = new System.Text.StringBuilder("");
194 int len = s.Length;
195 // peek at the next len worth of characters
198 for (int i = 1; i <= len; i++)
200 la_s.Append(base.LA(i));
203 catch (System.Exception)
209 base.match(s);
210 eventSupport.fireMatch(s, inputState.guessing);
212 catch (MismatchedCharException e)
214 if (inputState.guessing == 0)
215 eventSupport.fireMismatch(la_s.ToString(), s, inputState.guessing);
216 throw e;
220 public override void matchNot(int c)
222 char la_1 = LA(1);
225 base.matchNot(c);
226 eventSupport.fireMatchNot(la_1, Convert.ToChar(c), inputState.guessing);
228 catch (MismatchedCharException e)
230 if (inputState.guessing == 0)
231 eventSupport.fireMismatchNot(la_1, Convert.ToChar(c), inputState.guessing);
232 throw e;
236 public override void matchRange(int c1, int c2)
238 char la_1 = LA(1);
241 base.matchRange(c1, c2);
242 eventSupport.fireMatch(la_1, "" + c1 + c2, inputState.guessing);
244 catch (MismatchedCharException e)
246 if (inputState.guessing == 0)
247 eventSupport.fireMismatch(la_1, "" + c1 + c2, inputState.guessing);
248 throw e;
252 public override void newline()
254 base.newline();
255 eventSupport.fireNewLine(getLine());
257 public virtual void removeMessageListener(MessageListener l)
259 eventSupport.removeMessageListener(l);
261 public virtual void removeNewLineListener(NewLineListener l)
263 eventSupport.removeNewLineListener(l);
265 public virtual void removeParserListener(ParserListener l)
267 eventSupport.removeParserListener(l);
269 public virtual void removeParserMatchListener(ParserMatchListener l)
271 eventSupport.removeParserMatchListener(l);
273 public virtual void removeParserTokenListener(ParserTokenListener l)
275 eventSupport.removeParserTokenListener(l);
277 public virtual void removeSemanticPredicateListener(SemanticPredicateListener l)
279 eventSupport.removeSemanticPredicateListener(l);
281 public virtual void removeSyntacticPredicateListener(SyntacticPredicateListener l)
283 eventSupport.removeSyntacticPredicateListener(l);
285 public virtual void removeTraceListener(TraceListener l)
287 eventSupport.removeTraceListener(l);
289 /// <summary>Report exception errors caught in nextToken()
290 /// </summary>
291 public virtual void reportError(MismatchedCharException e)
293 eventSupport.fireReportError(e);
294 base.reportError(e);
296 /// <summary>Parser error-reporting function can be overridden in subclass
297 /// </summary>
298 public override void reportError(string s)
300 eventSupport.fireReportError(s);
301 base.reportError(s);
303 /// <summary>Parser warning-reporting function can be overridden in subclass
304 /// </summary>
305 public override void reportWarning(string s)
307 eventSupport.fireReportWarning(s);
308 base.reportWarning(s);
310 public virtual void setupDebugging()
314 public virtual void wakeUp()
316 lock(this)
318 Monitor.Pulse(this);