1#!/usr/bin/ruby
2# encoding: utf-8
3
4module ANTLR3
5module Debug
6=begin rdoc ANTLR3::Debug::EventHub
7
8A special event listener that intercepts debug events and forwards them to other
9debug event listners. As debug-mode recognizers are able to send event
10information to only one listener, EventHubs provide a simple solution in
11situations where multiple event listners are desired.
12
13=end
14class EventHub
15  include ANTLR3::Debug::EventListener
16  attr_reader :listeners
17  
18  def initialize( *listeners )
19    @listeners = [ listeners ].flatten!
20    @listeners.compact!
21  end
22  
23  def add( *listeners )
24    @listeners.push( *listeners )
25  end
26
27  def add_child( root, child )
28    for listener in @listeners
29      listener.add_child( root, child )
30    end
31  end
32  
33  def backtrack( level )
34    for listener in @listeners
35      listener.backtrack( level )
36    end
37  end
38  
39  def become_root( new_root, old_root )
40    for listener in @listeners
41      listener.become_root( new_root, old_root )
42    end
43  end
44  
45  def begin_backtrack( level )
46    for listener in @listeners
47      listener.begin_backtrack( level )
48    end
49  end
50  
51  def begin_resync()
52    for listener in @listeners
53      listener.begin_resync()
54    end
55  end
56  
57  def commence()
58    for listener in @listeners
59      listener.commence()
60    end
61  end
62  
63  def consume_hidden_token( tree )
64    for listener in @listeners
65      listener.consume_hidden_token( tree )
66    end
67  end
68  
69  def consume_node( tree )
70    for listener in @listeners
71      listener.consume_node( tree )
72    end
73  end
74  
75  def consume_token( tree )
76    for listener in @listeners
77      listener.consume_token( tree )
78    end
79  end
80  
81  def create_node( node, token )
82    for listener in @listeners
83      listener.create_node( node, token )
84    end
85  end
86  
87  def end_backtrack( level, successful )
88    for listener in @listeners
89      listener.end_backtrack( level, successful )
90    end
91  end
92  
93  def end_resync()
94    for listener in @listeners
95      listener.end_resync()
96    end
97  end
98  
99  def enter_alternative( alt )
100    for listener in @listeners
101      listener.enter_alternative( alt )
102    end
103  end
104  
105  def enter_decision( decision_number )
106    for listener in @listeners
107      listener.enter_decision( decision_number )
108    end
109  end
110  
111  def enter_rule( grammar_file_name, rule_name )
112    for listener in @listeners
113      listener.enter_rule( grammar_file_name, rule_name )
114    end
115  end
116  
117  def enter_sub_rule( decision_number )
118    for listener in @listeners
119      listener.enter_sub_rule( decision_number )
120    end
121  end
122  
123  def error_node( tree )
124    for listener in @listeners
125      listener.error_node( tree )
126    end
127  end
128  
129  def exit_decision( decision_number )
130    for listener in @listeners
131      listener.exit_decision( decision_number )
132    end
133  end
134  
135  def exit_rule( grammar_file_name, rule_name )
136    for listener in @listeners
137      listener.exit_rule( grammar_file_name, rule_name )
138    end
139  end
140  
141  def exit_sub_rule( decision_number )
142    for listener in @listeners
143      listener.exit_sub_rule( decision_number )
144    end
145  end
146  
147  def flat_node( tree )
148    for listener in @listeners
149      listener.flat_node( tree )
150    end
151  end
152  
153  def location( line, position )
154    for listener in @listeners
155      listener.location( line, position )
156    end
157  end
158  
159  def look( i, tree )
160    for listener in @listeners
161      listener.look( i, tree )
162    end
163  end
164  
165  def mark( marker )
166    for listener in @listeners
167      listener.mark( marker )
168    end
169  end
170  
171  def recognition_exception( exception )
172    for listener in @listeners
173      listener.recognition_exception( exception )
174    end
175  end
176  
177  def resync()
178    for listener in @listeners
179      listener.resync()
180    end
181  end
182  
183  def rewind( marker )
184    for listener in @listeners
185      listener.rewind( marker )
186    end
187  end
188  
189  def semantic_predicate( result, predicate )
190    for listener in @listeners
191      listener.semantic_predicate( result, predicate )
192    end
193  end
194  
195  def set_token_boundaries( tree, token_start_index, token_stop_index )
196    for listener in @listeners
197      listener.set_token_boundaries( tree, token_start_index, token_stop_index )
198    end
199  end
200  
201  def terminate()
202    for listener in @listeners
203      listener.terminate()
204    end
205  end
206  
207end
208
209end
210end
211