Class: Dhaka::Item
- Inherits:
-
Object
- Object
- Dhaka::Item
- Defined in:
- lib/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/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:
5 6 7 |
# File 'lib/parser/item.rb', line 5 def lookaheadset @lookaheadset end |
#next_item_index ⇒ Object (readonly)
:nodoc:
5 6 7 |
# File 'lib/parser/item.rb', line 5 def next_item_index @next_item_index end |
#production ⇒ Object (readonly)
:nodoc:
5 6 7 |
# File 'lib/parser/item.rb', line 5 def production @production end |
Instance Method Details
#eql?(other) ⇒ Boolean
35 36 37 |
# File 'lib/parser/item.rb', line 35 def eql?(other) @production == other.production && @next_item_index==other.next_item_index end |
#hash ⇒ Object
38 39 40 |
# File 'lib/parser/item.rb', line 38 def hash @production.hash ^ @next_item_index.hash end |
#next_item ⇒ Object
18 19 20 |
# File 'lib/parser/item.rb', line 18 def next_item Item.new(@production, @next_item_index+1) end |
#next_symbol ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/parser/item.rb', line 11 def next_symbol if @next_item_index < @production.expansion.size @production.expansion[@next_item_index] else nil end end |
#to_s(options = {}) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/parser/item.rb', line 21 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(' ') if [:hide_lookaheads] "#{@production.symbol} ::= #{expansion_repr}" else "#{@production.symbol} ::= #{expansion_repr} [#{@lookaheadset.collect.sort}]" end end |