Class: Ibex::IR::AutomatonState

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

Overview

A deterministic LALR automaton state.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, items:, transitions:, actions:, gotos:, default_action: nil, conflicts: []) ⇒ AutomatonState

Returns a new instance of AutomatonState.

RBS:

  • (id: Integer, items: Array[AutomatonItem], transitions: Hash[Integer, Integer], actions: Hash[Integer, parser_action], gotos: Hash[Integer, Integer], ?default_action: parser_action?, ?conflicts: Array[conflict]) -> void

Parameters:

  • id: (Integer)
  • items: (Array[AutomatonItem])
  • transitions: (Hash[Integer, Integer])
  • actions: (Hash[Integer, parser_action])
  • gotos: (Hash[Integer, Integer])
  • default_action: (parser_action, nil) (defaults to: nil)
  • conflicts: (Array[conflict]) (defaults to: [])


42
43
44
45
46
47
48
49
50
51
# File 'lib/ibex/ir/automaton_ir.rb', line 42

def initialize(id:, items:, transitions:, actions:, gotos:, default_action: nil, conflicts: [])
  @id = id
  @items = items.freeze
  @transitions = IR.deep_freeze(transitions)
  @actions = IR.deep_freeze(actions)
  @gotos = IR.deep_freeze(gotos)
  @default_action = IR.deep_freeze(default_action)
  @conflicts = IR.deep_freeze(conflicts)
  freeze
end

Instance Attribute Details

#actionsHash[Integer, parser_action] (readonly)

Signature:

  • Hash[Integer, parser_action]

Returns:

  • (Hash[Integer, parser_action])


34
35
36
# File 'lib/ibex/ir/automaton_ir.rb', line 34

def actions
  @actions
end

#conflictsArray[conflict] (readonly)

Signature:

  • Array[conflict]

Returns:

  • (Array[conflict])


37
38
39
# File 'lib/ibex/ir/automaton_ir.rb', line 37

def conflicts
  @conflicts
end

#default_actionparser_action? (readonly)

Signature:

  • parser_action?

Returns:

  • (parser_action, nil)


36
37
38
# File 'lib/ibex/ir/automaton_ir.rb', line 36

def default_action
  @default_action
end

#gotosHash[Integer, Integer] (readonly)

Signature:

  • Hash[Integer, Integer]

Returns:

  • (Hash[Integer, Integer])


35
36
37
# File 'lib/ibex/ir/automaton_ir.rb', line 35

def gotos
  @gotos
end

#idInteger (readonly)

Signature:

  • Integer

Returns:

  • (Integer)


31
32
33
# File 'lib/ibex/ir/automaton_ir.rb', line 31

def id
  @id
end

#itemsArray[AutomatonItem] (readonly)

Signature:

  • Array[AutomatonItem]

Returns:



32
33
34
# File 'lib/ibex/ir/automaton_ir.rb', line 32

def items
  @items
end

#transitionsHash[Integer, Integer] (readonly)

Signature:

  • Hash[Integer, Integer]

Returns:

  • (Hash[Integer, Integer])


33
34
35
# File 'lib/ibex/ir/automaton_ir.rb', line 33

def transitions
  @transitions
end

Instance Method Details

#named_keys(values, grammar) ⇒ Hash[String, untyped]

RBS:

  • (Hash[Integer, untyped] values, Grammar grammar) -> Hash[String, untyped]

Parameters:

  • values (Hash[Integer, untyped])
  • grammar (Grammar)

Returns:

  • (Hash[String, untyped])


63
64
65
66
67
68
# File 'lib/ibex/ir/automaton_ir.rb', line 63

def named_keys(values, grammar)
  values.to_h do |symbol_id, value|
    symbol = grammar.symbol_by_id(symbol_id) || raise(Ibex::Error, "missing grammar symbol id #{symbol_id}")
    [symbol.name, value]
  end
end

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

RBS:

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

Parameters:

Returns:

  • (Hash[Symbol, untyped])


54
55
56
57
58
# File 'lib/ibex/ir/automaton_ir.rb', line 54

def to_h(grammar)
  { id: @id, items: @items.map { |item| item.to_h(grammar) },
    transitions: named_keys(@transitions, grammar), actions: named_keys(@actions, grammar),
    gotos: named_keys(@gotos, grammar), default_action: @default_action, conflicts: @conflicts }
end