Class: TaskJuggler::TextParser::StateTransition

Inherits:
Object
  • Object
show all
Defined in:
lib/taskjuggler/TextParser/State.rb

Overview

A StateTransition maps a token type to the next state to be processed. A token descriptor is either a Symbol that maps to a RegExp in the TextScanner or an expected String. The transition may also have a list of State objects that are being activated by the transition.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(descriptor, state, stateStack, loopBack) ⇒ StateTransition

Create a new StateTransition object. descriptor is a [ token type, token value ] touple. state is the State objects this transition originates at. stateStack is the list of State objects that have been activated by this transition. loopBack is a boolean flag that specifies whether the transition describes a loop back to the start of the Rule or not.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/taskjuggler/TextParser/State.rb', line 30

def initialize(descriptor, state, stateStack, loopBack)
  if !descriptor.respond_to?(:length) || descriptor.length != 2
    raise "Bad parameter descriptor: #{descriptor} " +
          "of type #{descriptor.class}"
  end
  @tokenType = descriptor[0] == :eof ? :eof : descriptor[1]

  if !state.is_a?(State)
    raise "Bad parameter state: #{state} of type #{state.class}"
  end
  @state = state

  if !stateStack.is_a?(Array)
    raise "Bad parameter stateStack: #{stateStack} " +
          "of type #{stateStack.class}"
  end
  @stateStack = stateStack.dup
  @loopBack = loopBack
end

Instance Attribute Details

#loopBackObject (readonly)

Returns the value of attribute loopBack.



22
23
24
# File 'lib/taskjuggler/TextParser/State.rb', line 22

def loopBack
  @loopBack
end

#stateObject (readonly)

Returns the value of attribute state.



22
23
24
# File 'lib/taskjuggler/TextParser/State.rb', line 22

def state
  @state
end

#stateStackObject (readonly)

Returns the value of attribute stateStack.



22
23
24
# File 'lib/taskjuggler/TextParser/State.rb', line 22

def stateStack
  @stateStack
end

#tokenTypeObject (readonly)

Returns the value of attribute tokenType.



22
23
24
# File 'lib/taskjuggler/TextParser/State.rb', line 22

def tokenType
  @tokenType
end

Instance Method Details

#to_sObject

Generate a human readable form of the TransitionState date. It’s only used for debugging.



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/taskjuggler/TextParser/State.rb', line 52

def to_s
  str = "#{@state.rule.name}, " +
        "#{@state.rule.patterns.index(@state.pattern)}, #{@state.index} "
  unless @stateStack.empty?
    str += "("
    @stateStack.each do |s|
      str += "#{s.rule.name} "
    end
    str += ")"
  end
  str += '(loop)' if @loopBack
  str
end