class TaskJuggler::TextParser::StackElement

This class models the elements of the stack that the TextParser uses to keep track of its state. It stores the current TextParserRule, the current pattern position and the TextScanner position at the start of processing. It also store the function that must be called to store the collected values.

Attributes

firstSourceFileInfo[R]
function[R]
sourceFileInfo[R]
state[RW]
val[R]

Public Class Methods

new(function, state = nil) click to toggle source

Create a new stack element. rule is the TextParserRule that triggered the creation of this element. function is the function that will be called at the end to store the collected data. sourceFileInfo is a SourceFileInfo reference that describes the TextScanner position when the rule was entered.

# File lib/taskjuggler/TextParser/StackElement.rb, line 29
def initialize(function, state = nil)
  # This Array stores the collected values.
  @val = []
  # Array to store the source file references for the collected values.
  @sourceFileInfo = []
  # A shortcut to the first non-nil sourceFileInfo.
  @firstSourceFileInfo = nil
  # Counter used for StackElement::store()
  @position = 0
  # The method that will process the collected values.
  @function = function
  @state = state
end

Public Instance Methods

each() { |x| ... } click to toggle source
# File lib/taskjuggler/TextParser/StackElement.rb, line 76
def each
  @val.each { |x| yield x }
end
insert(index, val, sourceFileInfo, multiValue) click to toggle source

Insert the value val at the position index. It also stores the sourceFileInfo for this element. In case multiValue is true, the old value is not overwritten, but values are stored in an TextParserResultArray object.

# File lib/taskjuggler/TextParser/StackElement.rb, line 47
def insert(index, val, sourceFileInfo, multiValue)
  if multiValue
    if @val[index]
      # We already have a value for this token position.
      unless @val[index].is_a?(TextParserResultArray)
        # This should never happen.
        raise "#{@val[index].class} must be an Array"
      end
    else
      @val[index] = TextParserResultArray.new
    end
    # Just append the value and apply the special Array merging.
    @val[index] << val
  else
    @val[index] = val
  end
  @sourceFileInfo[index] = sourceFileInfo
  # Store the first SFI for faster access.
  @firstSourceFileInfo = sourceFileInfo unless @firstSourceFileInfo
  val
end
length() click to toggle source
# File lib/taskjuggler/TextParser/StackElement.rb, line 80
def length
  @val.length
end
store(val, sourceFileInfo = nil) click to toggle source

Store a collected value and move the position to the next pattern.

# File lib/taskjuggler/TextParser/StackElement.rb, line 70
def store(val, sourceFileInfo = nil)
  @val[@position] = val
  @sourceFileInfo[@position] = sourceFileInfo
  @position += 1
end