Class: TaskJuggler::TextParser::StackElement
- Defined in:
- lib/taskjuggler/TextParser/StackElement.rb
Overview
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.
Instance Attribute Summary collapse
-
#firstSourceFileInfo ⇒ Object
readonly
Returns the value of attribute firstSourceFileInfo.
-
#function ⇒ Object
readonly
Returns the value of attribute function.
-
#sourceFileInfo ⇒ Object
readonly
Returns the value of attribute sourceFileInfo.
-
#state ⇒ Object
Returns the value of attribute state.
-
#val ⇒ Object
readonly
Returns the value of attribute val.
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(function, state = nil) ⇒ StackElement
constructor
Create a new stack element.
-
#insert(index, val, sourceFileInfo, multiValue) ⇒ Object
Insert the value val at the position index.
- #length ⇒ Object
-
#store(val, sourceFileInfo = nil) ⇒ Object
Store a collected value and move the position to the next pattern.
Constructor Details
#initialize(function, state = nil) ⇒ StackElement
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.
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# 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 |
Instance Attribute Details
#firstSourceFileInfo ⇒ Object (readonly)
Returns the value of attribute firstSourceFileInfo.
22 23 24 |
# File 'lib/taskjuggler/TextParser/StackElement.rb', line 22 def firstSourceFileInfo @firstSourceFileInfo end |
#function ⇒ Object (readonly)
Returns the value of attribute function.
22 23 24 |
# File 'lib/taskjuggler/TextParser/StackElement.rb', line 22 def function @function end |
#sourceFileInfo ⇒ Object (readonly)
Returns the value of attribute sourceFileInfo.
22 23 24 |
# File 'lib/taskjuggler/TextParser/StackElement.rb', line 22 def sourceFileInfo @sourceFileInfo end |
#state ⇒ Object
Returns the value of attribute state.
23 24 25 |
# File 'lib/taskjuggler/TextParser/StackElement.rb', line 23 def state @state end |
#val ⇒ Object (readonly)
Returns the value of attribute val.
22 23 24 |
# File 'lib/taskjuggler/TextParser/StackElement.rb', line 22 def val @val end |
Instance Method Details
#each ⇒ Object
77 78 79 |
# File 'lib/taskjuggler/TextParser/StackElement.rb', line 77 def each @val.each { |x| yield x } end |
#insert(index, val, sourceFileInfo, multiValue) ⇒ Object
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.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# 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 |
#length ⇒ Object
81 82 83 |
# File 'lib/taskjuggler/TextParser/StackElement.rb', line 81 def length @val.length end |
#store(val, sourceFileInfo = nil) ⇒ Object
Store a collected value and move the position to the next pattern.
71 72 73 74 75 |
# File 'lib/taskjuggler/TextParser/StackElement.rb', line 71 def store(val, sourceFileInfo = nil) @val[@position] = val @sourceFileInfo[@position] = sourceFileInfo @position += 1 end |