Module: Ibex::Tables

Defined in:
lib/ibex/tables.rb,
sig/ibex/tables.rbs

Overview

Parser table construction and row-displacement compression.

Defined Under Namespace

Classes: TableSet

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build(automaton, format: :compact) ⇒ Object

RBS:

  • (IR::Automaton automaton, ?format: Symbol | String) -> TableSet

Raises:

  • (ArgumentError)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ibex/tables.rb', line 17

def build(automaton, format: :compact)
  action_rows = automaton.states.map do |state|
    state.actions.transform_values do |action|
      runtime_action(action)
    end
  end
  goto_rows = automaton.states.map(&:gotos)
  defaults = automaton.states.map do |state|
    runtime_action(state.default_action) if state.default_action
  end
  if format.to_sym == :plain
    return TableSet.new(actions: action_rows, gotos: goto_rows,
                        default_actions: defaults)
  end
  raise ArgumentError, "unknown table format #{format.inspect}" unless format.to_sym == :compact

  TableSet.new(
    actions: CompactActions.build(action_rows),
    gotos: Compact.build(goto_rows),
    default_actions: defaults
  )
end

.runtime_action(action) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ibex/tables.rb', line 45

def runtime_action(action)
  case action.fetch(:type).to_sym
  when :shift
    shift = action #: IR::shift_action
    [:shift, shift.fetch(:state)]
  when :reduce
    reduce = action #: IR::reduce_action
    [:reduce, reduce.fetch(:production)]
  when :accept then [:accept]
  when :error then [:error]
  else raise Ibex::Error, "unknown parser action #{action.inspect}"
  end
end

Instance Method Details

#self?.buildTableSet

RBS:

  • (IR::Automaton automaton, ?format: Symbol | String) -> TableSet

Parameters:

Returns:



22
# File 'sig/ibex/tables.rbs', line 22

def self?.build: (IR::Automaton automaton, ?format: Symbol | String) -> TableSet