source: trunk/yao/share/antlr-2.7.7/lib/csharp/antlr.runtime/antlr.debug/DebuggingCharScanner.cs @ 1

Last change on this file since 1 was 1, checked in by lnalod, 15 years ago

Initial import of YAO sources

File size: 7.7 KB
Line 
1namespace antlr.debug
2{
3        using System;
4        using System.Threading;
5        using antlr;
6
7        using BitSet    = antlr.collections.impl.BitSet;
8       
9        public abstract class DebuggingCharScanner : CharScanner, DebuggingParser
10        {
11                private void  InitBlock()
12                {
13                        eventSupport = new ScannerEventSupport(this);
14                }
15                public virtual void setDebugMode(bool mode)
16                {
17                        _notDebugMode = !mode;
18                }
19
20                private ScannerEventSupport eventSupport;
21                private bool _notDebugMode = false;
22                protected internal string[] ruleNames;
23                protected internal string[] semPredNames;
24               
25               
26                public DebuggingCharScanner(InputBuffer cb) : base(cb)
27                {
28                        InitBlock();
29                }
30                public DebuggingCharScanner(LexerSharedInputState state) : base(state)
31                {
32                        InitBlock();
33                }
34                public virtual void  addMessageListener(MessageListener l)
35                {
36                        eventSupport.addMessageListener(l);
37                }
38                public virtual void  addNewLineListener(NewLineListener l)
39                {
40                        eventSupport.addNewLineListener(l);
41                }
42                public virtual void  addParserListener(ParserListener l)
43                {
44                        eventSupport.addParserListener(l);
45                }
46                public virtual void  addParserMatchListener(ParserMatchListener l)
47                {
48                        eventSupport.addParserMatchListener(l);
49                }
50                public virtual void  addParserTokenListener(ParserTokenListener l)
51                {
52                        eventSupport.addParserTokenListener(l);
53                }
54                public virtual void  addSemanticPredicateListener(SemanticPredicateListener l)
55                {
56                        eventSupport.addSemanticPredicateListener(l);
57                }
58                public virtual void  addSyntacticPredicateListener(SyntacticPredicateListener l)
59                {
60                        eventSupport.addSyntacticPredicateListener(l);
61                }
62                public virtual void  addTraceListener(TraceListener l)
63                {
64                        eventSupport.addTraceListener(l);
65                }
66                public override void  consume()
67                {
68                        int la_1 = - 99;
69                        try
70                        {
71                                la_1 = LA(1);
72                        }
73                        catch (CharStreamException)
74                        {
75                        }
76                        base.consume();
77                        eventSupport.fireConsume(la_1);
78                }
79                protected internal virtual void  fireEnterRule(int num, int data)
80                {
81                        if (isDebugMode())
82                                eventSupport.fireEnterRule(num, inputState.guessing, data);
83                }
84                protected internal virtual void  fireExitRule(int num, int ttype)
85                {
86                        if (isDebugMode())
87                                eventSupport.fireExitRule(num, inputState.guessing, ttype);
88                }
89                protected internal virtual bool fireSemanticPredicateEvaluated(int type, int num, bool condition)
90                {
91                        if (isDebugMode())
92                                return eventSupport.fireSemanticPredicateEvaluated(type, num, condition, inputState.guessing);
93                        else
94                                return condition;
95                }
96                protected internal virtual void  fireSyntacticPredicateFailed()
97                {
98                        if (isDebugMode())
99                                eventSupport.fireSyntacticPredicateFailed(inputState.guessing);
100                }
101                protected internal virtual void  fireSyntacticPredicateStarted()
102                {
103                        if (isDebugMode())
104                                eventSupport.fireSyntacticPredicateStarted(inputState.guessing);
105                }
106                protected internal virtual void  fireSyntacticPredicateSucceeded()
107                {
108                        if (isDebugMode())
109                                eventSupport.fireSyntacticPredicateSucceeded(inputState.guessing);
110                }
111                public virtual string getRuleName(int num)
112                {
113                        return ruleNames[num];
114                }
115                public virtual string getSemPredName(int num)
116                {
117                        return semPredNames[num];
118                }
119                public virtual void  goToSleep()
120                {
121                        lock(this)
122                        {
123                                try
124                                {
125                                        Monitor.Wait(this);
126                                }
127                                catch (System.Threading.ThreadInterruptedException)
128                                {
129                                }
130                        }
131                }
132                public virtual bool isDebugMode()
133                {
134                        return !_notDebugMode;
135                }
136                public override char LA(int i)
137                {
138                        char la = base.LA(i);
139                        eventSupport.fireLA(i, la);
140                        return la;
141                }
142                protected internal override IToken makeToken(int t)
143                {
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);
159                }
160                public override void  match(int c)
161                {
162                        char la_1 = LA(1);
163                        try
164                        {
165                                base.match(c);
166                                eventSupport.fireMatch(Convert.ToChar(c), inputState.guessing);
167                        }
168                        catch (MismatchedCharException e)
169                        {
170                                if (inputState.guessing == 0)
171                                        eventSupport.fireMismatch(la_1, Convert.ToChar(c), inputState.guessing);
172                                throw e;
173                        }
174                }
175                public override void  match(BitSet b)
176                {
177                        string text = this.text.ToString();
178                        char la_1 = LA(1);
179                        try
180                        {
181                                base.match(b);
182                                eventSupport.fireMatch(la_1, b, text, inputState.guessing);
183                        }
184                        catch (MismatchedCharException e)
185                        {
186                                if (inputState.guessing == 0)
187                                        eventSupport.fireMismatch(la_1, b, text, inputState.guessing);
188                                throw e;
189                        }
190                }
191                public override void  match(string s)
192                {
193                        System.Text.StringBuilder la_s = new System.Text.StringBuilder("");
194                        int len = s.Length;
195                        // peek at the next len worth of characters
196                        try
197                        {
198                                 for (int i = 1; i <= len; i++)
199                                {
200                                        la_s.Append(base.LA(i));
201                                }
202                        }
203                        catch (System.Exception)
204                        {
205                        }
206                       
207                        try
208                        {
209                                base.match(s);
210                                eventSupport.fireMatch(s, inputState.guessing);
211                        }
212                        catch (MismatchedCharException e)
213                        {
214                                if (inputState.guessing == 0)
215                                        eventSupport.fireMismatch(la_s.ToString(), s, inputState.guessing);
216                                throw e;
217                        }
218                       
219                }
220                public override void  matchNot(int c)
221                {
222                        char la_1 = LA(1);
223                        try
224                        {
225                                base.matchNot(c);
226                                eventSupport.fireMatchNot(la_1, Convert.ToChar(c), inputState.guessing);
227                        }
228                        catch (MismatchedCharException e)
229                        {
230                                if (inputState.guessing == 0)
231                                        eventSupport.fireMismatchNot(la_1, Convert.ToChar(c), inputState.guessing);
232                                throw e;
233                        }
234                       
235                }
236                public override void  matchRange(int c1, int c2)
237                {
238                        char la_1 = LA(1);
239                        try
240                        {
241                                base.matchRange(c1, c2);
242                                eventSupport.fireMatch(la_1, "" + c1 + c2, inputState.guessing);
243                        }
244                        catch (MismatchedCharException e)
245                        {
246                                if (inputState.guessing == 0)
247                                        eventSupport.fireMismatch(la_1, "" + c1 + c2, inputState.guessing);
248                                throw e;
249                        }
250                       
251                }
252                public override void  newline()
253                {
254                        base.newline();
255                        eventSupport.fireNewLine(getLine());
256                }
257                public virtual void  removeMessageListener(MessageListener l)
258                {
259                        eventSupport.removeMessageListener(l);
260                }
261                public virtual void  removeNewLineListener(NewLineListener l)
262                {
263                        eventSupport.removeNewLineListener(l);
264                }
265                public virtual void  removeParserListener(ParserListener l)
266                {
267                        eventSupport.removeParserListener(l);
268                }
269                public virtual void  removeParserMatchListener(ParserMatchListener l)
270                {
271                        eventSupport.removeParserMatchListener(l);
272                }
273                public virtual void  removeParserTokenListener(ParserTokenListener l)
274                {
275                        eventSupport.removeParserTokenListener(l);
276                }
277                public virtual void  removeSemanticPredicateListener(SemanticPredicateListener l)
278                {
279                        eventSupport.removeSemanticPredicateListener(l);
280                }
281                public virtual void  removeSyntacticPredicateListener(SyntacticPredicateListener l)
282                {
283                        eventSupport.removeSyntacticPredicateListener(l);
284                }
285                public virtual void  removeTraceListener(TraceListener l)
286                {
287                        eventSupport.removeTraceListener(l);
288                }
289                /// <summary>Report exception errors caught in nextToken()
290                /// </summary>
291                public virtual void  reportError(MismatchedCharException e)
292                {
293                        eventSupport.fireReportError(e);
294                        base.reportError(e);
295                }
296                /// <summary>Parser error-reporting function can be overridden in subclass
297                /// </summary>
298                public override void  reportError(string s)
299                {
300                        eventSupport.fireReportError(s);
301                        base.reportError(s);
302                }
303                /// <summary>Parser warning-reporting function can be overridden in subclass
304                /// </summary>
305                public override void  reportWarning(string s)
306                {
307                        eventSupport.fireReportWarning(s);
308                        base.reportWarning(s);
309                }
310                public virtual void  setupDebugging()
311                {
312                }
313
314                public virtual void  wakeUp()
315                {
316                        lock(this)
317                        {
318                                Monitor.Pulse(this);
319                        }
320                }
321        }
322}
Note: See TracBrowser for help on using the repository browser.