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 ⇒ Object
TODO: :predictor, :completer, :scanner.
-
#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.
30 31 32 33 34 |
# File 'lib/dendroid/recognizer/e_item.rb', line 30 def initialize(aDottedItem, origin) @dotted_item = WeakRef.new(aDottedItem) @origin = origin @predecessors = [] end |
Instance Attribute Details
#algo ⇒ Object
TODO: :predictor, :completer, :scanner
21 22 23 |
# File 'lib/dendroid/recognizer/e_item.rb', line 21 def algo @algo end |
#dotted_item ⇒ Dendroid::GrmAnalysis::DottedItem (readonly)
(Weak) reference to the dotted item
15 16 17 |
# File 'lib/dendroid/recognizer/e_item.rb', line 15 def dotted_item @dotted_item end |
#origin ⇒ Integer (readonly)
Returns the rank of the token that correspond to the start of the rule.
18 19 20 |
# File 'lib/dendroid/recognizer/e_item.rb', line 18 def origin @origin end |
#predecessors ⇒ Array<WeakRef>
Returns predecessors sorted by decreasing origin value.
24 25 26 |
# File 'lib/dendroid/recognizer/e_item.rb', line 24 def predecessors @predecessors end |
Instance Method Details
#==(other) ⇒ Boolean
Equality test.
43 44 45 46 47 48 |
# File 'lib/dendroid/recognizer/e_item.rb', line 43 def ==(other) return true if eql?(other) di = dotted_item (origin == other.origin) && (di == other.dotted_item) end |
#add_predecessor(pred) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/dendroid/recognizer/e_item.rb', line 57 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.
37 38 39 |
# File 'lib/dendroid/recognizer/e_item.rb', line 37 def lhs dotted_item.rule.lhs end |
#to_s ⇒ String Also known as: inspect
Returns the text representation of the Earley item.
51 52 53 |
# File 'lib/dendroid/recognizer/e_item.rb', line 51 def to_s "#{dotted_item} @ #{origin}" end |