Class: Dendroid::Parsing::ANDNode
- Inherits:
-
CompositeParseNode
- Object
- ParseNode
- CompositeParseNode
- Dendroid::Parsing::ANDNode
- Defined in:
- lib/dendroid/parsing/and_node.rb
Instance Attribute Summary collapse
-
#alt_index ⇒ Object
readonly
Returns the value of attribute alt_index.
-
#rule ⇒ Object
readonly
Returns the value of attribute rule.
Attributes inherited from CompositeParseNode
Attributes inherited from ParseNode
Instance Method Summary collapse
-
#accept(aVisitor) ⇒ Object
Part of the ‘visitee’ role in Visitor design pattern.
- #add_child(child_node, index) ⇒ Object
- #expecting?(symbol, position) ⇒ Boolean
-
#initialize(anEItem, rank) ⇒ ANDNode
constructor
A new instance of ANDNode.
- #match(anEItem) ⇒ Object
- #partial? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(anEItem, rank) ⇒ ANDNode
Returns a new instance of ANDNode.
11 12 13 14 15 16 |
# File 'lib/dendroid/parsing/and_node.rb', line 11 def initialize(anEItem, rank) @rule = WeakRef.new(anEItem.dotted_item.rule) @alt_index = anEItem.dotted_item.alt_index upper_bound = rank super(anEItem.origin, upper_bound, rule.rhs[alt_index].size) end |
Instance Attribute Details
#alt_index ⇒ Object (readonly)
Returns the value of attribute alt_index.
9 10 11 |
# File 'lib/dendroid/parsing/and_node.rb', line 9 def alt_index @alt_index end |
#rule ⇒ Object (readonly)
Returns the value of attribute rule.
8 9 10 |
# File 'lib/dendroid/parsing/and_node.rb', line 8 def rule @rule end |
Instance Method Details
#accept(aVisitor) ⇒ Object
Part of the ‘visitee’ role in Visitor design pattern.
49 50 51 |
# File 'lib/dendroid/parsing/and_node.rb', line 49 def accept(aVisitor) aVisitor.visit_and_node(self) end |
#add_child(child_node, index) ⇒ Object
18 19 20 21 22 |
# File 'lib/dendroid/parsing/and_node.rb', line 18 def add_child(child_node, index) raise StandardError unless children[index].nil? # Is slot available? super(child_node, index) end |
#expecting?(symbol, position) ⇒ Boolean
34 35 36 37 |
# File 'lib/dendroid/parsing/and_node.rb', line 34 def expecting?(symbol, position) symb_seq = rule.rhs[alt_index] symb_seq[position] == symbol end |
#match(anEItem) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/dendroid/parsing/and_node.rb', line 24 def match(anEItem) return false if range[0] != anEItem.origin dotted = anEItem.dotted_item same_rule = (rule.lhs == dotted.rule.lhs) && (alt_index == dotted.alt_index) return false unless same_rule dotted.initial_pos? ? true : partial? end |
#partial? ⇒ Boolean
39 40 41 |
# File 'lib/dendroid/parsing/and_node.rb', line 39 def partial? children.any?(&:nil?) end |
#to_s ⇒ Object
43 44 45 |
# File 'lib/dendroid/parsing/and_node.rb', line 43 def to_s "#{rule.lhs} => #{rule.rhs[alt_index]} #{range}" end |