Module: Ibex::TableSimulation::Text

Defined in:
lib/ibex/table_simulation/text.rb,
sig/ibex/table_simulation/text.rbs

Overview

Stable one-line renderer for simulation steps.

Class Method Summary collapse

Class Method Details

.render(result) ⇒ String

RBS:

  • (Result result) -> String

Parameters:

Returns:

  • (String)


23
24
25
26
27
# File 'lib/ibex/table_simulation/text.rb', line 23

def render(result)
  lines = result.steps.map { |step| render_step(step) }
  lines << "status=#{result.status}"
  "#{lines.join("\n")}\n"
end

.render_step(step) ⇒ String

RBS:

  • (Step step) -> String

Parameters:

Returns:

  • (String)


10
11
12
13
14
15
16
17
18
19
20
# File 'lib/ibex/table_simulation/text.rb', line 10

def render_step(step)
  detail = case step.action
           when "shift" then " target=#{step.target_state}"
           when "reduce"
             " production=#{step.production_id} lhs=#{step.lhs} rhs=#{step.rhs_length} " \
             "goto=#{step.target_state}"
           else ""
           end
  "#{step.sequence}: state=#{step.state} token=#{step.token.inspect} action=#{step.action}" \
    "#{detail} source=#{step.action_source} stack=#{step.stack_depth_before}->#{step.stack_depth_after}"
end