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
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ibex/tables.rb', line 31 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
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/ibex/tables.rb', line 59 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?.build ⇒ TableSet
23 |
# File 'sig/ibex/tables.rbs', line 23
def self?.build: (IR::Automaton automaton, ?format: Symbol | String) -> TableSet
|