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
Public Class Methods
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 30 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
# File lib/taskjuggler/TextParser/StackElement.rb, line 77 def each @val.each { |x| yield x } end
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 48 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
# File lib/taskjuggler/TextParser/StackElement.rb, line 81 def length @val.length end
Store a collected value and move the position to the next pattern.
# File lib/taskjuggler/TextParser/StackElement.rb, line 71 def store(val, sourceFileInfo = nil) @val[@position] = val @sourceFileInfo[@position] = sourceFileInfo @position += 1 end