Class: Dendroid::Recognizer::EItem

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(aDottedItem, origin) ⇒ EItem

Returns a new instance of EItem.

Parameters:



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

#algoSymbol

Specifies the algorithm with which this entry can be derived from its predecessor(s).

Returns:

  • (Symbol)

    of one: :predictor, :completer, :scanner



23
24
25
# File 'lib/dendroid/recognizer/e_item.rb', line 23

def algo
  @algo
end

#dotted_itemDendroid::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

#originInteger (readonly)

Returns the rank of the token that correspond to the start of the rule.

Returns:

  • (Integer)

    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

#predecessorsArray<WeakRef>

Returns predecessors sorted by decreasing origin value.

Returns:

  • (Array<WeakRef>)

    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.

Returns:

  • (Boolean)

    true iff dotted items and origins are equal



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

#lhsDendroid::Syntax::NonTerminal

Returns the head of the production rule.

Returns:



39
40
41
# File 'lib/dendroid/recognizer/e_item.rb', line 39

def lhs
  dotted_item.rule.lhs
end

#to_sString Also known as: inspect

Returns the text representation of the Earley item.

Returns:

  • (String)

    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