Parent

Class Index [+]

Quicksearch

TaskJuggler::TextParser::Scanner::StreamHandle

This class is used to handle the low-level input operations. It knows whether it deals with a text buffer or a file and abstracts this to the Scanner. For each nested file the scanner puts an StreamHandle on the stack while the file is scanned. With this stack the scanner can resume the processing of the enclosing file once the included files has been completely processed.

Attributes

fileName[R]
macroStack[R]

Public Class Methods

new(log) click to toggle source
    # File lib/taskjuggler/TextParser/Scanner.rb, line 54
54:       def initialize(log)
55:         @log = log
56:         @fileName = nil
57:         @stream = nil
58:         @line = nil
59:         @endPos = 1
60:         @scanner = nil
61:         @wrapped = false
62:         @macroStack = []
63:         @nextMacroEnd = nil
64:       end

Public Instance Methods

close() click to toggle source
    # File lib/taskjuggler/TextParser/Scanner.rb, line 66
66:       def close
67:         @stream = nil
68:       end
dirname() click to toggle source
     # File lib/taskjuggler/TextParser/Scanner.rb, line 136
136:       def dirname
137:         @fileName ? File.dirname(@fileName) : ''
138:       end
eof?() click to toggle source
     # File lib/taskjuggler/TextParser/Scanner.rb, line 132
132:       def eof?
133:         @stream.eof? && @scanner.eos?
134:       end
injectMacro(macro, args, text) click to toggle source
    # File lib/taskjuggler/TextParser/Scanner.rb, line 80
80:       def injectMacro(macro, args, text)
81:         injectText(text)
82: 
83:         # Simple detection for recursive macro calls.
84:         return false if @macroStack.length > 20
85: 
86:         @macroStack << MacroStackEntry.new(macro, args, text, @nextMacroEnd)
87:         true
88:       end
injectText(text) click to toggle source

Inject the String text into the input stream at the current cursor position.

    # File lib/taskjuggler/TextParser/Scanner.rb, line 72
72:       def injectText(text)
73:         pos = @scanner.pos
74:         @nextMacroEnd = pos + text.length
75:         @line = @line[0, pos] + text + @line[pos..1]
76:         @scanner = StringScanner.new(@line)
77:         @scanner.pos = pos
78:       end
line() click to toggle source

Return the already processed part of the current line.

     # File lib/taskjuggler/TextParser/Scanner.rb, line 151
151:       def line
152:         return '' unless @line
153: 
154:         @line[0..(@scanner.pos - 1)]
155:       end
lineNo() click to toggle source

Return the number of the currently processed line.

     # File lib/taskjuggler/TextParser/Scanner.rb, line 141
141:       def lineNo
142:         # The IO object counts the lines for us by counting the gets() calls.
143:         currentLine = @stream && @scanner ? @stream.lineno : 1
144:         # If we've just read the LF, we have to add 1. The LF can only be the
145:         # last character of the line.
146:         currentLine += 1 if @wrapped && @line && @scanner && @scanner.eos?
147:         currentLine
148:       end
peek(n) click to toggle source
     # File lib/taskjuggler/TextParser/Scanner.rb, line 128
128:       def peek(n)
129:         @scanner ? @scanner.peek(n) : nil
130:       end
scan(re) click to toggle source
     # File lib/taskjuggler/TextParser/Scanner.rb, line 90
 90:       def scan(re)
 91:         # We read the file line by line with gets(). If we don't have a line
 92:         # yet or we've reached the end of a line, we get the next one.
 93:         if @scanner.nil? || @scanner.eos?
 94:           if (@line = @stream.gets)
 95:             # Update activity meter about every 1024 lines.
 96:             @log.activity if (@stream.lineno & 0x3FF) == 0
 97:             # Check for DOS or Mac end of line signatures.
 98:             if @line[1] == \r\
 99:               # Mac: Convert CR into LF
100:               @line[1] = \n\
101:             elsif @line[2] == \r\
102:               # DOS: Convert CR+LF into LF
103:               @line = @line.chomp + "\n"
104:             end
105:           else
106:             # We've reached the end of the current file.
107:             @scanner = nil
108:             # Return special EOF symbol.
109:             return :scannerEOF
110:           end
111:           @scanner = StringScanner.new(@line)
112:           @wrapped = @line[1] == \n\
113:         end
114:         return nil if (token = @scanner.scan(re)).nil?
115:         #puts "#{re.to_s[0..20]}: [#{token}]"
116: 
117:         if @nextMacroEnd
118:           pos = @scanner.pos
119:           while @nextMacroEnd && @nextMacroEnd < pos
120:             @macroStack.pop
121:             @nextMacroEnd = @macroStack.empty? ? nil : @macroStack.last.endPos
122:           end
123:         end
124: 
125:         token
126:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.