Class: ANTLR3::Debug::TraceEventListener

Inherits:
Object
  • Object
show all
Includes:
EventListener
Defined in:
lib/antlr3/debug/trace-event-listener.rb

Overview

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.

Direct Known Subclasses

RecordEventListener

Constant Summary

Constant Summary

Constants included from EventListener

EventListener::EVENTS, EventListener::PROTOCOL_VERSION

Instance Method Summary collapse

Methods included from EventListener

#backtrack, #begin_backtrack, #begin_resync, #commence, #consume_hidden_token, #consume_token, #end_backtrack, #end_resync, #enter_decision, #error_node, #examine_rule_memoization, #exit_decision, #mark, #on, #recognition_exception, #resync, #rewind, #semantic_predicate, #terminate

Constructor Details

#initialize(adaptor = nil, device = $stderr) ⇒ TraceEventListener

Returns a new instance of TraceEventListener



17
18
19
20
21
# 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

Instance Method Details

#add_child(root, child) ⇒ Object



81
82
83
84
# 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) ⇒ Object



76
77
78
79
# 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) ⇒ Object



52
53
54
55
# 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) ⇒ Object



66
67
68
69
70
71
72
73
74
# 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) ⇒ Object



28
29
30
# 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) ⇒ Object



32
33
34
# 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) ⇒ Object



40
41
42
# 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) ⇒ Object



36
37
38
# 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) ⇒ Object



44
45
46
# 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) ⇒ Object



62
63
64
# 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) ⇒ Object



48
49
50
# 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) ⇒ Object



57
58
59
60
# 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) ⇒ Object



23
24
25
26
# 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) ⇒ Object



86
87
88
89
# 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