Class: Ibex::IR::AutomatonItem

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

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.

RBS:

  • (production: Integer, dot: Integer, lookaheads: Array[Integer]) -> void

Parameters:

  • production: (Integer)
  • dot: (Integer)
  • lookaheads: (Array[Integer])


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

#dotInteger (readonly)

Signature:

  • Integer

Returns:

  • (Integer)


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

def dot
  @dot
end

#lookaheadsArray[Integer] (readonly)

Signature:

  • Array[Integer]

Returns:

  • (Array[Integer])


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

def lookaheads
  @lookaheads
end

#productionInteger (readonly)

Signature:

  • Integer

Returns:

  • (Integer)


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

def production
  @production
end

Instance Method Details

#to_h(grammar) ⇒ Hash[Symbol, untyped]

RBS:

  • (Grammar grammar) -> Hash[Symbol, untyped]

Parameters:

Returns:

  • (Hash[Symbol, untyped])


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