class ANTLR3::Debug::TraceEventListener

A listener that simply records text representations of the events. Useful for debugging the debugging facility ;) Subclasses can override the record() method (which defaults to printing to stdout) to record the events in a different way.

Public Class Methods

new( adaptor = nil, device = $stderr ) click to toggle source
Calls superclass method
# File lib/antlr3/debug/trace-event-listener.rb, line 17
def initialize( adaptor = nil, device = $stderr )
  super()
  @device = device
  @adaptor = adaptor ||= ANTLR3::AST::CommonTreeAdaptor.new
end

Public Instance Methods

add_child( root, child ) click to toggle source
# File lib/antlr3/debug/trace-event-listener.rb, line 81
def add_child( root, child )
  record '(%s): root_id=%s child_id=%s', __method__, @adaptor.unique_id( root ),
          @adaptor.unique_id( child )
end
become_root( new_root, old_root ) click to toggle source
# File lib/antlr3/debug/trace-event-listener.rb, line 76
def become_root( new_root, old_root )
  record '(%s): old_root_id=%s new_root_id=%s', __method__, @adaptor.unique_id( new_root ),
          @adaptor.unique_id( old_root )
end
consume_node( tree ) click to toggle source
# File lib/antlr3/debug/trace-event-listener.rb, line 52
def consume_node( tree )
  record '(%s) unique_id=%s text=%p type=%s[%s]', __method__, @adaptor.unique_id( tree ),
         @adaptor.text_of( tree ), @adaptor.type_name( tree ), @adaptor.type_of( tree )
end
create_node( tree, token = nil ) click to toggle source
# File lib/antlr3/debug/trace-event-listener.rb, line 66
def create_node( tree, token = nil )
  unless token
    record '(%s): unique_id=%s text=%p type=%s[%s]', __method__, @adaptor.unique_id( tree ),
          @adaptor.text_of( tree ), @adaptor.type_name( tree ), @adaptor.type_of( tree )
  else
    record '(%s): unique_id=%s type=%s[%s]', __method__, @adaptor.unique_id( tree ),
            @adaptor.type_of( tree ), @adaptor.type_name( tree ), @adaptor.type_of( tree )
  end
end
enter_alternative( alt_number ) click to toggle source
# File lib/antlr3/debug/trace-event-listener.rb, line 28
def enter_alternative( alt_number )
  record "(%s): number=%s", __method__, alt_number
end
enter_rule( grammar_file_name, rule_name ) click to toggle source
# File lib/antlr3/debug/trace-event-listener.rb, line 32
def enter_rule( grammar_file_name, rule_name )
  record "(%s): rule=%s", __method__, rule_name
end
enter_subrule( decision_number ) click to toggle source
# File lib/antlr3/debug/trace-event-listener.rb, line 40
def enter_subrule( decision_number )
  record "(%s): decision=%s", __method__, decision_number
end
exit_rule( grammar_file_name, rule_name ) click to toggle source
# File lib/antlr3/debug/trace-event-listener.rb, line 36
def exit_rule( grammar_file_name, rule_name )
  record "(%s): rule=%s", __method__, rule_name
end
exit_subrule( decision_number ) click to toggle source
# File lib/antlr3/debug/trace-event-listener.rb, line 44
def exit_subrule( decision_number )
  record "(%s): decision=%s", __method__, decision_number
end
flat_node( tree ) click to toggle source
# File lib/antlr3/debug/trace-event-listener.rb, line 62
def flat_node( tree )
  record '(%s): unique_id=%s', __method__, @adaptor.unique_id( tree )
end
location( line, position ) click to toggle source
# File lib/antlr3/debug/trace-event-listener.rb, line 48
def location( line, position )
  record '(%s): line=%s position=%s', __method__, line, position
end
look( i, tree ) click to toggle source
# File lib/antlr3/debug/trace-event-listener.rb, line 57
def look( i, tree )
  record '(%s): k=%s unique_id=%s text=%p type=%s[%s]', __method__, i, @adaptor.unique_id( tree ),
          @adaptor.text_of( tree ), @adaptor.type_name( tree ), @adaptor.type_of( tree )
end
record( event_message, *interpolation_arguments ) click to toggle source
# File lib/antlr3/debug/trace-event-listener.rb, line 23
def record( event_message, *interpolation_arguments )
  event_message = event_message.to_s << "\n"
  @device.printf( event_message, *interpolation_arguments )
end
set_token_boundaries( tree, token_start_index, token_stop_index ) click to toggle source
# File lib/antlr3/debug/trace-event-listener.rb, line 86
def set_token_boundaries( tree, token_start_index, token_stop_index )
  record '(%s): unique_id=%s index_range=%s..%s', __method__, @adaptor.unique_id( tree ),
          token_start_index, token_stop_index
end