Class: Rley::RGN::ASTVisitor
- Inherits:
-
Object
- Object
- Rley::RGN::ASTVisitor
- Defined in:
- lib/rley/rgn/ast_visitor.rb
Instance Attribute Summary collapse
-
#subscribers ⇒ Object
readonly
List of objects that subscribed to the visit event notification.
-
#top ⇒ Object
readonly
Link to the top node to visit.
Instance Method Summary collapse
-
#end_visit_ptree(aParseTree) ⇒ Object
Visit event.
-
#initialize(aTop) ⇒ ASTVisitor
constructor
Build a visitor for the given top.
-
#start ⇒ Object
The signal to begin the visit of the top.
-
#start_visit_ptree(aParseTree) ⇒ Object
Visit event.
-
#subscribe(aSubscriber) ⇒ Object
Add a subscriber for the visit event notifications.
-
#unsubscribe(aSubscriber) ⇒ Object
Remove the given object from the subscription list.
-
#visit_repetition_node(aRepetitionNode) ⇒ Object
Visit event.
-
#visit_sequence_node(aSequenceNode) ⇒ Object
Visit event.
-
#visit_symbol_node(aSymbolNode) ⇒ Object
Visit event.
Constructor Details
#initialize(aTop) ⇒ ASTVisitor
Build a visitor for the given top.
14 15 16 17 18 19 |
# File 'lib/rley/rgn/ast_visitor.rb', line 14 def initialize(aTop) raise StandardError if aTop.nil? @top = aTop @subscribers = [] end |
Instance Attribute Details
#subscribers ⇒ Object (readonly)
List of objects that subscribed to the visit event notification.
10 11 12 |
# File 'lib/rley/rgn/ast_visitor.rb', line 10 def subscribers @subscribers end |
#top ⇒ Object (readonly)
Link to the top node to visit
7 8 9 |
# File 'lib/rley/rgn/ast_visitor.rb', line 7 def top @top end |
Instance Method Details
#end_visit_ptree(aParseTree) ⇒ Object
Visit event. The visitor has completed the visit of the ptree.
47 48 49 |
# File 'lib/rley/rgn/ast_visitor.rb', line 47 def end_visit_ptree(aParseTree) broadcast(:after_ptree, aParseTree) end |
#start ⇒ Object
The signal to begin the visit of the top.
35 36 37 |
# File 'lib/rley/rgn/ast_visitor.rb', line 35 def start top.accept(self) end |
#start_visit_ptree(aParseTree) ⇒ Object
Visit event. The visitor is about to visit the ptree.
41 42 43 |
# File 'lib/rley/rgn/ast_visitor.rb', line 41 def start_visit_ptree(aParseTree) broadcast(:before_ptree, aParseTree) end |
#subscribe(aSubscriber) ⇒ Object
Add a subscriber for the visit event notifications.
23 24 25 |
# File 'lib/rley/rgn/ast_visitor.rb', line 23 def subscribe(aSubscriber) subscribers << aSubscriber end |
#unsubscribe(aSubscriber) ⇒ Object
Remove the given object from the subscription list. The object won't be notified of visit events.
30 31 32 |
# File 'lib/rley/rgn/ast_visitor.rb', line 30 def unsubscribe(aSubscriber) subscribers.delete_if { |entry| entry == aSubscriber } end |
#visit_repetition_node(aRepetitionNode) ⇒ Object
Visit event. The visitor is about to visit a repetition node.
68 69 70 71 72 |
# File 'lib/rley/rgn/ast_visitor.rb', line 68 def visit_repetition_node(aRepetitionNode) broadcast(:before_repetition_node, aRepetitionNode, self) traverse_subnodes(aRepetitionNode) if aRepetitionNode.repetition == :exactly_one broadcast(:after_repetition_node, aRepetitionNode, self) end |
#visit_sequence_node(aSequenceNode) ⇒ Object
Visit event. The visitor is about to visit a sequence node.
60 61 62 63 64 |
# File 'lib/rley/rgn/ast_visitor.rb', line 60 def visit_sequence_node(aSequenceNode) broadcast(:before_sequence_node, aSequenceNode, self) traverse_subnodes(aSequenceNode) broadcast(:after_sequence_node, aSequenceNode, self) end |
#visit_symbol_node(aSymbolNode) ⇒ Object
Visit event. The visitor is about to visit a symbol node.
53 54 55 56 |
# File 'lib/rley/rgn/ast_visitor.rb', line 53 def visit_symbol_node(aSymbolNode) broadcast(:before_symbol_node, aSymbolNode, self) broadcast(:after_symbol_node, aSymbolNode, self) end |