Class: Ibex::TableSimulation::Session
- Inherits:
-
Object
- Object
- Ibex::TableSimulation::Session
- Defined in:
- lib/ibex/table_simulation/simulator.rb
Overview
Stateful token-at-a-time table simulation session.
Instance Attribute Summary collapse
- #status ⇒ Object readonly
Instance Method Summary collapse
- #finish ⇒ Object
-
#initialize(simulator) ⇒ Session
constructor
A new instance of Session.
- #push(spelling) ⇒ Object
- #steps ⇒ Object
- #tokens ⇒ Object
Constructor Details
#initialize(simulator) ⇒ Session
Returns a new instance of Session.
91 92 93 94 95 96 97 98 |
# File 'lib/ibex/table_simulation/simulator.rb', line 91 def initialize(simulator) @simulator = simulator @state_stack = [0] #: Array[Integer] @status = nil @steps = [] @tokens = [] @finished = false end |
Instance Attribute Details
#status ⇒ Object (readonly)
88 89 90 |
# File 'lib/ibex/table_simulation/simulator.rb', line 88 def status @status end |
Instance Method Details
#finish ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/ibex/table_simulation/simulator.rb', line 115 def finish raise Ibex::Error, "(debug):1:1: simulation session is already finished" if @finished @finished = true process(@simulator.eof, eof: true) until @status Result.new( grammar_digest: @simulator.automaton.grammar_digest, algorithm: @simulator.automaton.algorithm, tokens: @tokens, status: @status || raise(Ibex::Error, "(debug):1:1: simulation did not terminate"), steps: @steps ) end |
#push(spelling) ⇒ Object
101 102 103 104 105 106 |
# File 'lib/ibex/table_simulation/simulator.rb', line 101 def push(spelling) ensure_active! terminal = @simulator.terminal(spelling) @tokens << terminal.name process(terminal, eof: false) end |
#steps ⇒ Object
109 |
# File 'lib/ibex/table_simulation/simulator.rb', line 109 def steps = @steps.dup.freeze |
#tokens ⇒ Object
112 |
# File 'lib/ibex/table_simulation/simulator.rb', line 112 def tokens = @tokens.dup.freeze |