Module: ANTLR3::Debug::ParserEvents
Overview
ParserEvents adds debugging event hook methods and functionality that is required by the code ANTLR generated when called with the -debug
switch.
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Error
EarlyExit, FailedPredicate, MismatchedNotSet, MismatchedRange, MismatchedSet, MismatchedToken, MismatchedTreeNode, MissingToken, NoViableAlternative, RewriteCardinalityError, RewriteEarlyExit, RewriteEmptyStream, UnwantedToken
Instance Attribute Details
#debug_listener ⇒ Object
Returns the value of attribute debug_listener.
156
157
158
|
# File 'lib/antlr3/debug.rb', line 156
def debug_listener
@debug_listener
end
|
Class Method Details
.included(klass) ⇒ Object
146
147
148
149
150
151
152
153
|
# File 'lib/antlr3/debug.rb', line 146
def self.included( klass )
super
if klass.is_a?( ::Class )
def klass.debug?
true
end
end
end
|
Instance Method Details
#backtrack ⇒ Object
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
|
# File 'lib/antlr3/debug.rb', line 217
def backtrack
@state.backtracking += 1
@debug_listener.begin_backtrack( @state.backtracking )
start = @input.mark
success =
begin yield
rescue BacktrackingFailed then false
else true
end
return success
ensure
@input.rewind( start )
@debug_listener.end_backtrack( @state.backtracking, ( success rescue nil ) )
@state.backtracking -= 1
end
|
#begin_backtrack ⇒ Object
209
210
211
|
# File 'lib/antlr3/debug.rb', line 209
def begin_backtrack
@debug_listener.begin_backtrack( @state.backtracking )
end
|
#begin_resync ⇒ Object
191
192
193
194
|
# File 'lib/antlr3/debug.rb', line 191
def begin_resync
@debug_listener.begin_resync
super
end
|
#cyclic_decision=(flag) ⇒ Object
179
180
181
|
# File 'lib/antlr3/debug.rb', line 179
def cyclic_decision=( flag )
@state.cyclic_decision = flag
end
|
#cyclic_decision? ⇒ Boolean
175
176
177
|
# File 'lib/antlr3/debug.rb', line 175
def cyclic_decision?
@state.cyclic_decision
end
|
#end_backtrack(successful) ⇒ Object
213
214
215
|
# File 'lib/antlr3/debug.rb', line 213
def end_backtrack( successful )
@debug_listener.end_backtrack( @state.backtracking, successful )
end
|
#end_resync ⇒ Object
196
197
198
199
|
# File 'lib/antlr3/debug.rb', line 196
def end_resync
@debug_listener.end_resync
super
end
|
#in_alternative(alt_number) ⇒ Object
266
267
268
|
# File 'lib/antlr3/debug.rb', line 266
def in_alternative( alt_number )
@debug_listener.enter_alternative( alt_number )
end
|
#in_decision(decision_number) ⇒ Object
277
278
279
280
281
282
|
# File 'lib/antlr3/debug.rb', line 277
def in_decision( decision_number )
@debug_listener.enter_decision( decision_number )
yield
ensure
@debug_listener.exit_decision( decision_number )
end
|
#in_rule(grammar_file, rule_name) ⇒ Object
245
246
247
248
249
250
251
252
253
254
|
# File 'lib/antlr3/debug.rb', line 245
def in_rule( grammar_file, rule_name )
@state.rule_invocation_stack.empty? and @debug_listener.commence
@debug_listener.enter_rule( grammar_file, rule_name )
@state.rule_invocation_stack.push( grammar_file, rule_name )
yield
ensure
@state.rule_invocation_stack.pop( 2 )
@debug_listener.exit_rule( grammar_file, rule_name )
@state.rule_invocation_stack.empty? and @debug_listener.terminate
end
|
#in_subrule(decision_number) ⇒ Object
270
271
272
273
274
275
|
# File 'lib/antlr3/debug.rb', line 270
def in_subrule( decision_number )
@debug_listener.enter_subrule( decision_number )
yield
ensure
@debug_listener.exit_subrule( decision_number )
end
|
#initialize(stream, options = {}) ⇒ Object
158
159
160
161
162
163
164
165
166
167
168
169
|
# File 'lib/antlr3/debug.rb', line 158
def initialize( stream, options = {} )
@debug_listener = options[ :debug_listener ] ||= begin
EventSocketProxy.new( self, options ).handshake
end
options[ :state ] ||= Debug::RecognizerSharedState.new
super( stream, options )
if @input.is_a?( Debug::TokenStream )
@input.debug_listener ||= @debug_listener
else
@input = Debug::TokenStream.wrap( @input, @debug_listener )
end
end
|
#missing_symbol(error, expected_type, follow) ⇒ Object
239
240
241
242
243
|
# File 'lib/antlr3/debug.rb', line 239
def missing_symbol( error, expected_type, follow )
symbol = super
@debug_listener.consume_node( symbol )
return( symbol )
end
|
#predicate?(description) ⇒ Boolean
260
261
262
263
264
|
# File 'lib/antlr3/debug.rb', line 260
def predicate?( description )
result = yield
@debug_listener.semantic_predicate( result, description )
return result
end
|
#report_error(exc) ⇒ Object
233
234
235
236
237
|
# File 'lib/antlr3/debug.rb', line 233
def report_error( exc )
ANTLR3::RecognitionError === exc and
@debug_listener.recognition_exception( exc )
super
end
|
#resync ⇒ Object
TO-DO: is this pointless?
202
203
204
205
206
207
|
# File 'lib/antlr3/debug.rb', line 202
def resync
begin_resync
yield( self )
ensure
end_resync
end
|
#rule_invocation_stack ⇒ Object
256
257
258
|
# File 'lib/antlr3/debug.rb', line 256
def rule_invocation_stack
@state.rule_invocation_stack.each_slice( 2 ).to_a
end
|
#rule_level ⇒ Object
171
172
173
|
# File 'lib/antlr3/debug.rb', line 171
def rule_level
@state.rule_invocation_stack.length
end
|