Class: Dendroid::Parsing::EmptyRuleNode

Inherits:
ParseNode
  • Object
show all
Defined in:
lib/dendroid/parsing/empty_rule_node.rb

Overview

A parse tree/forest node that is related to a production rule with an empty RHS (right-hand side).

Instance Attribute Summary collapse

Attributes inherited from ParseNode

#range

Instance Method Summary collapse

Constructor Details

#initialize(anEItem, rank) ⇒ EmptyRuleNode

Returns a new instance of EmptyRuleNode.

Parameters:

  • anEItem (Dendroid::Recognizer::EItem)

    An entry from the chart.

  • rank (Integer)

    rank of the last input token matched by this node



19
20
21
22
23
# File 'lib/dendroid/parsing/empty_rule_node.rb', line 19

def initialize(anEItem, rank)
  super(rank, rank)
  @rule = WeakRef.new(anEItem.dotted_item.rule)
  @alt_index = anEItem.dotted_item.alt_index
end

Instance Attribute Details

#alt_indexInteger (readonly)

Returns Index of the rule alternative.

Returns:

  • (Integer)

    Index of the rule alternative.



15
16
17
# File 'lib/dendroid/parsing/empty_rule_node.rb', line 15

def alt_index
  @alt_index
end

#ruleWeakRef<Dendroid::Syntax::Rule> (readonly)

Returns Grammar rule.

Returns:



12
13
14
# File 'lib/dendroid/parsing/empty_rule_node.rb', line 12

def rule
  @rule
end

Instance Method Details

#accept(aVisitor) ⇒ Object

Part of the ‘visitee’ role in Visitor design pattern.

Parameters:



33
34
35
# File 'lib/dendroid/parsing/empty_rule_node.rb', line 33

def accept(aVisitor)
  aVisitor.visit_empty_rule_node(self)
end

#to_sString

Return a String representation of itself

Returns:

  • (String)

    text representation of itself



27
28
29
# File 'lib/dendroid/parsing/empty_rule_node.rb', line 27

def to_s
  "_ #{range_to_s}"
end