Class: BabelBridge::NonTerminalNode

Inherits:
Node
  • Object
show all
Includes:
Enumerable
Defined in:
lib/nodes/non_terminal_node.rb

Overview

subclassed automatically by parser.rule for each unique non-terminal

Direct Known Subclasses

RuleNode

Instance Attribute Summary

Attributes inherited from Node

#delimiter, #many_delimiter, #match_length, #offset, #parent, #parser, #src

Instance Method Summary collapse

Methods inherited from Node

#column, #init_line_column, #initialize, #inspect, #line, #match_range, #node_init, #node_path, #offset_after_match, #on_matched, #onlychildren_list, #parent_list, #path_string, #relative_class_name, #remaining_src, #text, #to_s, #to_sym

Constructor Details

This class inherits a constructor from BabelBridge::Node

Instance Method Details

#[](i) ⇒ Object



40
41
42
# File 'lib/nodes/non_terminal_node.rb', line 40

def [](i)
  matches[i]
end

#add_match(node) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/nodes/non_terminal_node.rb', line 32

def add_match(node)
  return if !node || node.kind_of?(EmptyNode) || node == self
  node.tap do
    matches << node
    update_match_length
  end
end

#each(&block) ⇒ Object



44
45
46
# File 'lib/nodes/non_terminal_node.rb', line 44

def each(&block)
  matches.each(&block)
end

#last_matchObject



23
24
25
# File 'lib/nodes/non_terminal_node.rb', line 23

def last_match
  matches[-1]
end

#lengthObject



28
29
30
# File 'lib/nodes/non_terminal_node.rb', line 28

def length
  matches.length
end

#matchesObject

***************************** Array interface implementation *****************************



19
20
21
# File 'lib/nodes/non_terminal_node.rb', line 19

def matches
  @matches ||= []
end

#update_match_lengthObject



12
13
14
# File 'lib/nodes/non_terminal_node.rb', line 12

def update_match_length
  @match_length = last_match ? last_match.offset_after_match - offset : 0
end