File: DebuggingCharScanner.cs

package info (click to toggle)
antlr 2.7.7%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 9,920 kB
  • sloc: java: 54,649; cs: 12,533; makefile: 8,963; cpp: 7,359; pascal: 5,273; sh: 4,337; python: 4,301; lisp: 1,969; xml: 220; lex: 192; ansic: 134
file content (322 lines) | stat: -rwxr-xr-x 7,907 bytes parent folder | download | duplicates (15)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
namespace antlr.debug
{
	using System;
	using System.Threading;
	using antlr;

	using BitSet	= antlr.collections.impl.BitSet;
	
	public abstract class DebuggingCharScanner : CharScanner, DebuggingParser
	{
		private void  InitBlock()
		{
			eventSupport = new ScannerEventSupport(this);
		}
		public virtual void setDebugMode(bool mode)
		{
			_notDebugMode = !mode;
		}

		private ScannerEventSupport eventSupport;
		private bool _notDebugMode = false;
		protected internal string[] ruleNames;
		protected internal string[] semPredNames;
		
		
		public DebuggingCharScanner(InputBuffer cb) : base(cb)
		{
			InitBlock();
		}
		public DebuggingCharScanner(LexerSharedInputState state) : base(state)
		{
			InitBlock();
		}
		public virtual void  addMessageListener(MessageListener l)
		{
			eventSupport.addMessageListener(l);
		}
		public virtual void  addNewLineListener(NewLineListener l)
		{
			eventSupport.addNewLineListener(l);
		}
		public virtual void  addParserListener(ParserListener l)
		{
			eventSupport.addParserListener(l);
		}
		public virtual void  addParserMatchListener(ParserMatchListener l)
		{
			eventSupport.addParserMatchListener(l);
		}
		public virtual void  addParserTokenListener(ParserTokenListener l)
		{
			eventSupport.addParserTokenListener(l);
		}
		public virtual void  addSemanticPredicateListener(SemanticPredicateListener l)
		{
			eventSupport.addSemanticPredicateListener(l);
		}
		public virtual void  addSyntacticPredicateListener(SyntacticPredicateListener l)
		{
			eventSupport.addSyntacticPredicateListener(l);
		}
		public virtual void  addTraceListener(TraceListener l)
		{
			eventSupport.addTraceListener(l);
		}
		public override void  consume()
		{
			int la_1 = - 99;
			try
			{
				la_1 = LA(1);
			}
			catch (CharStreamException)
			{
			}
			base.consume();
			eventSupport.fireConsume(la_1);
		}
		protected internal virtual void  fireEnterRule(int num, int data)
		{
			if (isDebugMode())
				eventSupport.fireEnterRule(num, inputState.guessing, data);
		}
		protected internal virtual void  fireExitRule(int num, int ttype)
		{
			if (isDebugMode())
				eventSupport.fireExitRule(num, inputState.guessing, ttype);
		}
		protected internal virtual bool fireSemanticPredicateEvaluated(int type, int num, bool condition)
		{
			if (isDebugMode())
				return eventSupport.fireSemanticPredicateEvaluated(type, num, condition, inputState.guessing);
			else
				return condition;
		}
		protected internal virtual void  fireSyntacticPredicateFailed()
		{
			if (isDebugMode())
				eventSupport.fireSyntacticPredicateFailed(inputState.guessing);
		}
		protected internal virtual void  fireSyntacticPredicateStarted()
		{
			if (isDebugMode())
				eventSupport.fireSyntacticPredicateStarted(inputState.guessing);
		}
		protected internal virtual void  fireSyntacticPredicateSucceeded()
		{
			if (isDebugMode())
				eventSupport.fireSyntacticPredicateSucceeded(inputState.guessing);
		}
		public virtual string getRuleName(int num)
		{
			return ruleNames[num];
		}
		public virtual string getSemPredName(int num)
		{
			return semPredNames[num];
		}
		public virtual void  goToSleep()
		{
			lock(this)
			{
				try
				{
					Monitor.Wait(this);
				}
				catch (System.Threading.ThreadInterruptedException)
				{
				}
			}
		}
		public virtual bool isDebugMode()
		{
			return !_notDebugMode;
		}
		public override char LA(int i)
		{
			char la = base.LA(i);
			eventSupport.fireLA(i, la);
			return la;
		}
		protected internal override IToken makeToken(int t)
		{
			// do something with char buffer???
			//		try {
			//			IToken tok = (Token)tokenObjectClass.newInstance();
			//			tok.setType(t);
			//			// tok.setText(getText()); done in generated lexer now
			//			tok.setLine(line);
			//			return tok;
			//		}
			//		catch (InstantiationException ie) {
			//			panic("can't instantiate a Token");
			//		}
			//		catch (IllegalAccessException iae) {
			//			panic("Token class is not accessible");
			//		}
			return base.makeToken(t);
		}
		public override void  match(int c)
		{
			char la_1 = LA(1);
			try
			{
				base.match(c);
				eventSupport.fireMatch(Convert.ToChar(c), inputState.guessing);
			}
			catch (MismatchedCharException e)
			{
				if (inputState.guessing == 0)
					eventSupport.fireMismatch(la_1, Convert.ToChar(c), inputState.guessing);
				throw e;
			}
		}
		public override void  match(BitSet b)
		{
			string text = this.text.ToString();
			char la_1 = LA(1);
			try
			{
				base.match(b);
				eventSupport.fireMatch(la_1, b, text, inputState.guessing);
			}
			catch (MismatchedCharException e)
			{
				if (inputState.guessing == 0)
					eventSupport.fireMismatch(la_1, b, text, inputState.guessing);
				throw e;
			}
		}
		public override void  match(string s)
		{
			System.Text.StringBuilder la_s = new System.Text.StringBuilder("");
			int len = s.Length;
			// peek at the next len worth of characters
			try
			{
				 for (int i = 1; i <= len; i++)
				{
					la_s.Append(base.LA(i));
				}
			}
			catch (System.Exception)
			{
			}
			
			try
			{
				base.match(s);
				eventSupport.fireMatch(s, inputState.guessing);
			}
			catch (MismatchedCharException e)
			{
				if (inputState.guessing == 0)
					eventSupport.fireMismatch(la_s.ToString(), s, inputState.guessing);
				throw e;
			}
			
		}
		public override void  matchNot(int c)
		{
			char la_1 = LA(1);
			try
			{
				base.matchNot(c);
				eventSupport.fireMatchNot(la_1, Convert.ToChar(c), inputState.guessing);
			}
			catch (MismatchedCharException e)
			{
				if (inputState.guessing == 0)
					eventSupport.fireMismatchNot(la_1, Convert.ToChar(c), inputState.guessing);
				throw e;
			}
			
		}
		public override void  matchRange(int c1, int c2)
		{
			char la_1 = LA(1);
			try
			{
				base.matchRange(c1, c2);
				eventSupport.fireMatch(la_1, "" + c1 + c2, inputState.guessing);
			}
			catch (MismatchedCharException e)
			{
				if (inputState.guessing == 0)
					eventSupport.fireMismatch(la_1, "" + c1 + c2, inputState.guessing);
				throw e;
			}
			
		}
		public override void  newline()
		{
			base.newline();
			eventSupport.fireNewLine(getLine());
		}
		public virtual void  removeMessageListener(MessageListener l)
		{
			eventSupport.removeMessageListener(l);
		}
		public virtual void  removeNewLineListener(NewLineListener l)
		{
			eventSupport.removeNewLineListener(l);
		}
		public virtual void  removeParserListener(ParserListener l)
		{
			eventSupport.removeParserListener(l);
		}
		public virtual void  removeParserMatchListener(ParserMatchListener l)
		{
			eventSupport.removeParserMatchListener(l);
		}
		public virtual void  removeParserTokenListener(ParserTokenListener l)
		{
			eventSupport.removeParserTokenListener(l);
		}
		public virtual void  removeSemanticPredicateListener(SemanticPredicateListener l)
		{
			eventSupport.removeSemanticPredicateListener(l);
		}
		public virtual void  removeSyntacticPredicateListener(SyntacticPredicateListener l)
		{
			eventSupport.removeSyntacticPredicateListener(l);
		}
		public virtual void  removeTraceListener(TraceListener l)
		{
			eventSupport.removeTraceListener(l);
		}
		/// <summary>Report exception errors caught in nextToken() 
		/// </summary>
		public virtual void  reportError(MismatchedCharException e)
		{
			eventSupport.fireReportError(e);
			base.reportError(e);
		}
		/// <summary>Parser error-reporting function can be overridden in subclass 
		/// </summary>
		public override void  reportError(string s)
		{
			eventSupport.fireReportError(s);
			base.reportError(s);
		}
		/// <summary>Parser warning-reporting function can be overridden in subclass 
		/// </summary>
		public override void  reportWarning(string s)
		{
			eventSupport.fireReportWarning(s);
			base.reportWarning(s);
		}
		public virtual void  setupDebugging()
		{
		}

		public virtual void  wakeUp()
		{
			lock(this)
			{
				Monitor.Pulse(this);
			}
		}
	}
}