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

- (TraceEventListener) initialize(adaptor = nil, device = $stderr)

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

- (Object) add_child(root, child)



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

- (Object) become_root(new_root, old_root)



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

- (Object) consume_node(tree)



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

- (Object) create_node(tree, token = nil)



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

- (Object) enter_alternative(alt_number)



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

- (Object) enter_rule(grammar_file_name, rule_name)



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

- (Object) enter_subrule(decision_number)



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

- (Object) exit_rule(grammar_file_name, rule_name)



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

- (Object) exit_subrule(decision_number)



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

- (Object) flat_node(tree)



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

- (Object) location(line, position)



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

- (Object) look(i, tree)



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

- (Object) record(event_message, *interpolation_arguments)



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

- (Object) set_token_boundaries(tree, token_start_index, token_stop_index)



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