class Rley::RGN::ASTVisitor
Attributes
List of objects that subscribed to the visit event notification.
Link to the top node to visit
Public Class Methods
Source
# File lib/rley/rgn/ast_visitor.rb, line 14 def initialize(aTop) raise StandardError if aTop.nil? @top = aTop @subscribers = [] end
Build a visitor for the given top. @param aTop [RGN::ASTNode] the parse tree to visit.
Public Instance Methods
Source
# File lib/rley/rgn/ast_visitor.rb, line 47 def end_visit_ptree(aParseTree) broadcast(:after_ptree, aParseTree) end
Visit event. The visitor has completed the visit of the ptree. @param aParseTree [Rley::PTree::ParseTree] the visited ptree.
Source
# File lib/rley/rgn/ast_visitor.rb, line 35 def start top.accept(self) end
The signal to begin the visit of the top.
Source
# File lib/rley/rgn/ast_visitor.rb, line 41 def start_visit_ptree(aParseTree) broadcast(:before_ptree, aParseTree) end
Visit event. The visitor is about to visit the ptree. @param aParseTree [Rley::PTree::ParseTree] the ptree to visit.
Source
# File lib/rley/rgn/ast_visitor.rb, line 23 def subscribe(aSubscriber) subscribers << aSubscriber end
Add a subscriber for the visit event notifications. @param aSubscriber [Object]
Source
# File lib/rley/rgn/ast_visitor.rb, line 30 def unsubscribe(aSubscriber) subscribers.delete_if { |entry| entry == aSubscriber } end
Remove the given object from the subscription list. The object won’t be notified of visit events. @param aSubscriber [Object]
Source
# 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 event. The visitor is about to visit a repetition node. @param aRepetitionNode [RGN::GroupingNode] the repetition node to visit
Source
# 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 event. The visitor is about to visit a sequence node. @param aSequenceNode [RGN::SequenceNode] the sequence node to visit
Source
# 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
Visit event. The visitor is about to visit a symbol node. @param aSymbolNode [RGN::SymbolNode] the symbol node to visit
Private Instance Methods
Source
# File lib/rley/rgn/ast_visitor.rb, line 106 def broadcast(msg, *args) subscribers.each do |subscr| next unless subscr.respond_to?(msg) || subscr.respond_to?(:accept_all) subscr.send(msg, *args) end end
Send a notification to all subscribers. @param msg [Symbol] event to notify @param args [Array] arguments of the notification.
Source
# File lib/rley/rgn/ast_visitor.rb, line 93 def traverse_given_subnode(aParentNode, index) subnode = aParentNode.subnodes[index] broadcast(:before_given_subnode, aParentNode, subnode) # Now, let's proceed with the visit of that subnode subnode.accept(self) broadcast(:after_given_subnode, aParentNode, subnode) end
Visit event. The visitor is about to visit one given subnode of a non terminal node. @param aParentNode [CompositeNode] the parent node. @param index [integer] index of child subnode
Source
# File lib/rley/rgn/ast_visitor.rb, line 79 def traverse_subnodes(aParentNode) subnodes = aParentNode.subnodes broadcast(:before_subnodes, aParentNode, subnodes) # Let's proceed with the visit of subnodes subnodes.each { |a_node| a_node.accept(self) } broadcast(:after_subnodes, aParentNode, subnodes) end
Visit event. The visitor is about to visit the subnodes of a non terminal node. @param aParentNode [CompositeNode] the parent node.