Class: Rley::RGN::ASTVisitor

Inherits:
Object
  • Object
show all
Defined in:
lib/rley/rgn/ast_visitor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(aTop) ⇒ ASTVisitor

Build a visitor for the given top.

Parameters:

Raises:

  • (StandardError)


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

#subscribersObject (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

#topObject (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.

Parameters:



47
48
49
# File 'lib/rley/rgn/ast_visitor.rb', line 47

def end_visit_ptree(aParseTree)
  broadcast(:after_ptree, aParseTree)
end

#startObject

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.

Parameters:



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.

Parameters:

  • aSubscriber (Object)


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.

Parameters:

  • aSubscriber (Object)


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.

Parameters:

  • aRepetitionNode (RGN::GroupingNode)

    the repetition node to visit



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.

Parameters:



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.

Parameters:



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