Module: ANTLR3::Debug::TokenStream

Defined in:
lib/antlr3/debug.rb

Overview

A module that wraps token stream methods with debugging event code. A debuggable parser will extend its input stream with this module if the stream is not already a Debug::TokenStream.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#debug_listenerObject

Returns the value of attribute debug_listener


305
306
307
# File 'lib/antlr3/debug.rb', line 305

def debug_listener
  @debug_listener
end

#last_markerObject (readonly)

Returns the value of attribute last_marker


304
305
306
# File 'lib/antlr3/debug.rb', line 304

def last_marker
  @last_marker
end

Class Method Details

.wrap(stream, debug_listener = nil) ⇒ Object


295
296
297
298
299
300
301
302
303
# File 'lib/antlr3/debug.rb', line 295

def self.wrap( stream, debug_listener = nil )
  stream.extend( self )
  stream.instance_eval do
    @initial_stream_state = true
    @debug_listener = debug_listener
    @last_marker = nil
  end
  return( stream )
end

Instance Method Details

#consumeObject


307
308
309
310
311
312
313
314
315
316
317
318
# File 'lib/antlr3/debug.rb', line 307

def consume
  @initial_stream_state and consume_initial_hidden_tokens
  a = index + 1 # the next position IF there are no hidden tokens in between
  t = super
  b = index     # the actual position after consuming
  @debug_listener.consume_token( t ) if @debug_listener
  
  # if b > a, report the consumption of hidden tokens
  for i in a...b
    @debug_listener.consume_hidden_token at( i )
  end
end

#look(steps = 1) ⇒ Object

Stream Methods ######################################


346
347
348
349
350
351
# File 'lib/antlr3/debug.rb', line 346

def look( steps = 1 )
  @initial_stream_state and consume_initial_hidden_tokens
  token = super( steps )
  @debug_listener.look( steps, token )
  return token
end

#markObject


357
358
359
360
361
# File 'lib/antlr3/debug.rb', line 357

def mark
  @last_marker = super
  @debug_listener.mark( @last_marker )
  return @last_marker
end

#peek(steps = 1) ⇒ Object


353
354
355
# File 'lib/antlr3/debug.rb', line 353

def peek( steps = 1 )
  look( steps ).type
end

#rewind(marker = nil, release = true) ⇒ Object


363
364
365
366
# File 'lib/antlr3/debug.rb', line 363

def rewind( marker = nil, release = true )
  @debug_listener.rewind( marker )
  super
end