Module: Ibex::Tables
- Defined in:
- lib/ibex/tables.rb,
lib/ibex/tables/compact.rb,
lib/ibex/tables/compact_actions.rb,
lib/ibex/tables/compact_productions.rb
Overview
Parser table construction and row-displacement compression.
Defined Under Namespace
Modules: PackedIntegers Classes: Compact, CompactActions, CompactProductions, TableSet
Class Method Summary collapse
Class Method Details
.build(automaton, format: :compact) ⇒ Object
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 |