4 using System
.Threading
;
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
)
30 public DebuggingCharScanner(LexerSharedInputState state
) : base(state
)
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()
73 catch (CharStreamException
)
77 eventSupport
.fireConsume(la_1
);
79 protected internal virtual void fireEnterRule(int num
, int data
)
82 eventSupport
.fireEnterRule(num
, inputState
.guessing
, data
);
84 protected internal virtual void fireExitRule(int num
, int ttype
)
87 eventSupport
.fireExitRule(num
, inputState
.guessing
, ttype
);
89 protected internal virtual bool fireSemanticPredicateEvaluated(int type
, int num
, bool condition
)
92 return eventSupport
.fireSemanticPredicateEvaluated(type
, num
, condition
, inputState
.guessing
);
96 protected internal virtual void fireSyntacticPredicateFailed()
99 eventSupport
.fireSyntacticPredicateFailed(inputState
.guessing
);
101 protected internal virtual void fireSyntacticPredicateStarted()
104 eventSupport
.fireSyntacticPredicateStarted(inputState
.guessing
);
106 protected internal virtual void fireSyntacticPredicateSucceeded()
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()
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
);
142 protected internal override IToken
makeToken(int t
)
144 // do something with char buffer???
146 // IToken tok = (Token)tokenObjectClass.newInstance();
148 // // tok.setText(getText()); done in generated lexer now
149 // tok.setLine(line);
152 // catch (InstantiationException ie) {
153 // panic("can't instantiate a Token");
155 // catch (IllegalAccessException iae) {
156 // panic("Token class is not accessible");
158 return base.makeToken(t
);
160 public override void match(int 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
);
175 public override void match(BitSet b
)
177 string text
= this.text
.ToString();
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
);
191 public override void match(string s
)
193 System
.Text
.StringBuilder la_s
= new System
.Text
.StringBuilder("");
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
)
210 eventSupport
.fireMatch(s
, inputState
.guessing
);
212 catch (MismatchedCharException e
)
214 if (inputState
.guessing
== 0)
215 eventSupport
.fireMismatch(la_s
.ToString(), s
, inputState
.guessing
);
220 public override void matchNot(int 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
);
236 public override void matchRange(int c1
, int c2
)
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
);
252 public override void 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()
291 public virtual void reportError(MismatchedCharException e
)
293 eventSupport
.fireReportError(e
);
296 /// <summary>Parser error-reporting function can be overridden in subclass
298 public override void reportError(string s
)
300 eventSupport
.fireReportError(s
);
303 /// <summary>Parser warning-reporting function can be overridden in subclass
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()