Class: Dhaka::Item
- Inherits:
-
Object
- Object
- Dhaka::Item
- Defined in:
- lib/dhaka/parser/item.rb
Overview
Represents parser state items
Instance Attribute Summary collapse
-
#lookaheadset ⇒ Object
readonly
:nodoc:.
-
#next_item_index ⇒ Object
readonly
:nodoc:.
-
#production ⇒ Object
readonly
:nodoc:.
Instance Method Summary collapse
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(production, next_item_index) ⇒ Item
constructor
A new instance of Item.
- #next_item ⇒ Object
- #next_symbol ⇒ Object
- #to_s(options = {}) ⇒ Object
Constructor Details
#initialize(production, next_item_index) ⇒ Item
Returns a new instance of Item.
6 7 8 9 10 |
# File 'lib/dhaka/parser/item.rb', line 6 def initialize(production, next_item_index) @production = production @next_item_index = next_item_index @lookaheadset = Set.new end |
Instance Attribute Details
#lookaheadset ⇒ Object (readonly)
:nodoc:
4 5 6 |
# File 'lib/dhaka/parser/item.rb', line 4 def lookaheadset @lookaheadset end |
#next_item_index ⇒ Object (readonly)
:nodoc:
4 5 6 |
# File 'lib/dhaka/parser/item.rb', line 4 def next_item_index @next_item_index end |
#production ⇒ Object (readonly)
:nodoc:
4 5 6 |
# File 'lib/dhaka/parser/item.rb', line 4 def production @production end |
Instance Method Details
#eql?(other) ⇒ Boolean
35 36 37 |
# File 'lib/dhaka/parser/item.rb', line 35 def eql?(other) production == other.production && next_item_index == other.next_item_index end |
#hash ⇒ Object
39 40 41 |
# File 'lib/dhaka/parser/item.rb', line 39 def hash production.hash ^ next_item_index.hash end |
#next_item ⇒ Object
16 17 18 |
# File 'lib/dhaka/parser/item.rb', line 16 def next_item Item.new(production, @next_item_index + 1) end |
#next_symbol ⇒ Object
12 13 14 |
# File 'lib/dhaka/parser/item.rb', line 12 def next_symbol production.expansion[next_item_index] end |
#to_s(options = {}) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/dhaka/parser/item.rb', line 20 def to_s( = {}) expansion_symbols = production.expansion.collect {|symbol| symbol.name} if next_item_index < expansion_symbols.size expansion_symbols.insert(next_item_index, '->') else expansion_symbols << '->' end expansion_repr = expansion_symbols.join(' ') item = "#{production.symbol} ::= #{expansion_repr}" item << " [#{lookaheadset.collect.sort.join('')}]" unless [:hide_lookaheads] item end |