Class: Ibex::IR::AutomatonItem

Inherits:
Object
  • Object
show all
Defined in:
lib/ibex/ir/automaton_ir.rb

Overview

A merged LALR item with its lookahead token ids.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(production:, dot:, lookaheads:) ⇒ AutomatonItem

Returns a new instance of AutomatonItem.



12
13
14
15
16
17
# File 'lib/ibex/ir/automaton_ir.rb', line 12

def initialize(production:, dot:, lookaheads:)
  @production = production
  @dot = dot
  @lookaheads = lookaheads.sort.freeze
  freeze
end

Instance Attribute Details

#dotObject (readonly)

: Integer



8
9
10
# File 'lib/ibex/ir/automaton_ir.rb', line 8

def dot
  @dot
end

#lookaheadsObject (readonly)

: Array



9
10
11
# File 'lib/ibex/ir/automaton_ir.rb', line 9

def lookaheads
  @lookaheads
end

#productionObject (readonly)

: Integer



7
8
9
# File 'lib/ibex/ir/automaton_ir.rb', line 7

def production
  @production
end

Instance Method Details

#to_h(grammar) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/ibex/ir/automaton_ir.rb', line 20

def to_h(grammar)
  { production: @production, dot: @dot,
    lookaheads: @lookaheads.map do |id|
      symbol = grammar.symbol_by_id(id) || raise(Ibex::Error, "missing grammar symbol id #{id}")
      symbol.name
    end }
end