Class: Ibex::IR::AutomatonState
- Inherits:
-
Object
- Object
- Ibex::IR::AutomatonState
- Defined in:
- lib/ibex/ir/automaton_ir.rb,
sig/ibex/ir/automaton_ir.rbs
Overview
A deterministic LALR automaton state.
Instance Attribute Summary collapse
- #actions ⇒ Hash[Integer, parser_action] readonly
- #conflicts ⇒ Array[conflict] readonly
- #default_action ⇒ parser_action? readonly
- #gotos ⇒ Hash[Integer, Integer] readonly
- #id ⇒ Integer readonly
- #items ⇒ Array[AutomatonItem] readonly
- #transitions ⇒ Hash[Integer, Integer] readonly
Instance Method Summary collapse
-
#initialize(id:, items:, transitions:, actions:, gotos:, default_action: nil, conflicts: []) ⇒ AutomatonState
constructor
A new instance of AutomatonState.
- #named_keys(values, grammar) ⇒ Hash[String, untyped]
- #to_h(grammar) ⇒ Hash[Symbol, untyped]
Constructor Details
#initialize(id:, items:, transitions:, actions:, gotos:, default_action: nil, conflicts: []) ⇒ AutomatonState
Returns a new instance of AutomatonState.
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
#actions ⇒ Hash[Integer, parser_action] (readonly)
34 35 36 |
# File 'lib/ibex/ir/automaton_ir.rb', line 34 def actions @actions end |
#conflicts ⇒ Array[conflict] (readonly)
37 38 39 |
# File 'lib/ibex/ir/automaton_ir.rb', line 37 def conflicts @conflicts end |
#default_action ⇒ parser_action? (readonly)
36 37 38 |
# File 'lib/ibex/ir/automaton_ir.rb', line 36 def default_action @default_action end |
#gotos ⇒ Hash[Integer, Integer] (readonly)
35 36 37 |
# File 'lib/ibex/ir/automaton_ir.rb', line 35 def gotos @gotos end |
#id ⇒ Integer (readonly)
31 32 33 |
# File 'lib/ibex/ir/automaton_ir.rb', line 31 def id @id end |
#items ⇒ Array[AutomatonItem] (readonly)
32 33 34 |
# File 'lib/ibex/ir/automaton_ir.rb', line 32 def items @items end |
#transitions ⇒ Hash[Integer, Integer] (readonly)
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]
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]
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 |