Class: Dendroid::Recognizer::EItem
- Inherits:
-
Object
- Object
- Dendroid::Recognizer::EItem
- Extended by:
- Forwardable
- Defined in:
- lib/dendroid/recognizer/e_item.rb
Overview
An Earley item is essentially a pair consisting of a dotted item and the rank of a token. It helps to keep track the progress of an Earley recognizer.
Instance Attribute Summary collapse
-
#algo ⇒ Symbol
Specifies the algorithm with which this entry can be derived from its predecessor(s).
-
#dotted_item ⇒ Dendroid::GrmAnalysis::DottedItem
readonly
(Weak) reference to the dotted item.
-
#origin ⇒ Integer
readonly
The rank of the token that correspond to the start of the rule.
-
#predecessors ⇒ Array<WeakRef>
Predecessors sorted by decreasing origin value.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Equality test.
- #add_predecessor(pred) ⇒ Object
-
#initialize(aDottedItem, origin) ⇒ EItem
constructor
A new instance of EItem.
-
#lhs ⇒ Dendroid::Syntax::NonTerminal
The head of the production rule.
-
#to_s ⇒ String
(also: #inspect)
The text representation of the Earley item.
Constructor Details
#initialize(aDottedItem, origin) ⇒ EItem
Returns a new instance of EItem.
32 33 34 35 36 |
# File 'lib/dendroid/recognizer/e_item.rb', line 32 def initialize(aDottedItem, origin) @dotted_item = WeakRef.new(aDottedItem) @origin = origin @predecessors = [] end |
Instance Attribute Details
#algo ⇒ Symbol
Specifies the algorithm with which this entry can be derived from its predecessor(s).
23 24 25 |
# File 'lib/dendroid/recognizer/e_item.rb', line 23 def algo @algo end |
#dotted_item ⇒ Dendroid::GrmAnalysis::DottedItem (readonly)
(Weak) reference to the dotted item
16 17 18 |
# File 'lib/dendroid/recognizer/e_item.rb', line 16 def dotted_item @dotted_item end |
#origin ⇒ Integer (readonly)
Returns the rank of the token that correspond to the start of the rule.
19 20 21 |
# File 'lib/dendroid/recognizer/e_item.rb', line 19 def origin @origin end |
#predecessors ⇒ Array<WeakRef>
Returns predecessors sorted by decreasing origin value.
26 27 28 |
# File 'lib/dendroid/recognizer/e_item.rb', line 26 def predecessors @predecessors end |
Instance Method Details
#==(other) ⇒ Boolean
Equality test.
45 46 47 48 49 50 |
# File 'lib/dendroid/recognizer/e_item.rb', line 45 def ==(other) return true if eql?(other) di = dotted_item (origin == other.origin) && (di == other.dotted_item) end |
#add_predecessor(pred) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/dendroid/recognizer/e_item.rb', line 59 def add_predecessor(pred) if predecessors.size > 1 && pred.origin < predecessors[0].origin predecessors.insert(2, WeakRef.new(pred)) else predecessors.unshift(WeakRef.new(pred)) end end |
#lhs ⇒ Dendroid::Syntax::NonTerminal
Returns the head of the production rule.
39 40 41 |
# File 'lib/dendroid/recognizer/e_item.rb', line 39 def lhs dotted_item.rule.lhs end |
#to_s ⇒ String Also known as: inspect
Returns the text representation of the Earley item.
53 54 55 |
# File 'lib/dendroid/recognizer/e_item.rb', line 53 def to_s "#{dotted_item} @ #{origin}" end |