Class: Romanesco::ExpressionState

Inherits:
Object
  • Object
show all
Defined in:
lib/romanesco/state_machine.rb

Direct Known Subclasses

StateOne, StateThree, StateTwo, StateZero

Class Method Summary collapse

Class Method Details

.finish_hereObject



14
15
16
# File 'lib/romanesco/state_machine.rb', line 14

def finish_here
  @finishing_state = true
end

.next_state(token) ⇒ Object



8
9
10
11
12
# File 'lib/romanesco/state_machine.rb', line 8

def next_state(token)
  state = @states[token.state_machine_class]
  return state if state
  raise InvalidExpressionError
end

.transition(tree, tokens) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/romanesco/state_machine.rb', line 22

def transition(tree, tokens)
  if tokens.empty?
    return tree if @finishing_state
    raise InvalidExpressionError
  end
  current_token = tokens.shift
  tree.add(current_token.element.new(current_token.expression_part)) unless current_token.is_a? CloseParenthesisToken
  tree.close_parenthesis if current_token.is_a? CloseParenthesisToken
  next_state = next_state(current_token)
  classify(next_state).transition(tree, tokens)
end

.transitions(value) ⇒ Object



18
19
20
# File 'lib/romanesco/state_machine.rb', line 18

def transitions(value)
  @states = value
end