lib/ProjectFileScanner.rb in taskjuggler-0.0.7 vs lib/ProjectFileScanner.rb in taskjuggler-0.0.8

- old
+ new

@@ -69,82 +69,82 @@ # This pattern collects macro call arguments in lines that contain # neither the start nor the end of the macro. [ nil, /.*\n/, :macroCall, method('midMacroCall') ], # An ID with a colon suffix: foo: - [ 'ID_WITH_COLON', /[a-zA-Z_]\w*:/, :tjp, method('chop') ], + [ :ID_WITH_COLON, /[a-zA-Z_]\w*:/, :tjp, method('chop') ], # An absolute ID: a.b.c - [ 'ABSOLUTE_ID', /[a-zA-Z_]\w*(\.[a-zA-Z_]\w*)+/ ], + [ :ABSOLUTE_ID, /[a-zA-Z_]\w*(\.[a-zA-Z_]\w*)+/ ], # A normal ID: bar - [ 'ID', /[a-zA-Z_]\w*/ ], + [ :ID, /[a-zA-Z_]\w*/ ], # A date - [ 'DATE', /\d{4}-\d{1,2}-\d{1,2}(-\d{1,2}:\d{1,2}(:\d{1,2})?(-[-+]?\d{4})?)?/, :tjp, method('to_date') ], + [ :DATE, /\d{4}-\d{1,2}-\d{1,2}(-\d{1,2}:\d{1,2}(:\d{1,2})?(-[-+]?\d{4})?)?/, :tjp, method('to_date') ], # A time of day - [ 'TIME', /\d{1,2}:\d{2}/, :tjp, method('to_time') ], + [ :TIME, /\d{1,2}:\d{2}/, :tjp, method('to_time') ], # A floating point number (e. g. 3.143) - [ 'FLOAT', /\d*\.\d+/, :tjp, method('to_f') ], + [ :FLOAT, /\d*\.\d+/, :tjp, method('to_f') ], # An integer number - [ 'INTEGER', /\d+/, :tjp, method('to_i') ], + [ :INTEGER, /\d+/, :tjp, method('to_i') ], # Multi line string enclosed with double quotes. The string may # contain double quotes prefixed by a backslash. The first rule # switches the scanner to dqString mode. [ 'nil', /"(\\"|[^"])*/, :tjp, method('startStringDQ') ], # Any line not containing the start or end. [ 'nil', /^(\\"|[^"])*\n/, :dqString, method('midStringDQ') ], # The end of the string. - [ 'STRING', /(\\"|[^"])*"/, :dqString, method('endStringDQ') ], + [ :STRING, /(\\"|[^"])*"/, :dqString, method('endStringDQ') ], # Multi line string enclosed with single quotes. [ 'nil', /'(\\'|[^'])*/, :tjp, method('startStringSQ') ], # Any line not containing the start or end. [ 'nil', /^(\\'|[^'])*\n/, :sqString, method('midStringSQ') ], # The end of the string. - [ 'STRING', /(\\'|[^'])*'/, :sqString, method('endStringSQ') ], + [ :STRING, /(\\'|[^'])*'/, :sqString, method('endStringSQ') ], # Scizzors marked string -8<- ... ->8-: The opening mark must be the # last thing in the line. The indentation of the first line after the # opening mark determines the indentation for all following lines. So, # we first switch the scanner to szrString1 mode. [ 'nil', /-8<-.*\n/, :tjp, method('startStringSZR') ], # Since the first line can be the last line (empty string case), we # need to detect the end in szrString1 and szrString mode. The # patterns switch the scanner back to tjp mode. - [ 'STRING', /\s*->8-/, :szrString1, method('endStringSZR') ], - [ 'STRING', /\s*->8-/, :szrString, method('endStringSZR') ], + [ :STRING, /\s*->8-/, :szrString1, method('endStringSZR') ], + [ :STRING, /\s*->8-/, :szrString, method('endStringSZR') ], # This rule handles macros inside of sizzors strings. [ nil, /.*?\$\{\s*([a-zA-Z_]\w*)(\s*"(\\"|[^"])*")*/, [ :szrString, :szrString1 ], method('startMacroCall') ], # Any line not containing the start or end. [ 'nil', /.*\n/, :szrString1, method('firstStringSZR') ], [ 'nil', /.*\n/, :szrString, method('midStringSZR') ], # Single line macro definition - [ 'MACRO', /\[.*\]\n/, :tjp, method('chop2nl') ], + [ :MACRO, /\[.*\]\n/, :tjp, method('chop2nl') ], # Multi line macro definition: The pattern switches the scanner into # macroDef mode. [ nil, /\[.*\n/, :tjp, method('startMacroDef') ], # The end of the macro is marked by a ']' that is immediately followed # by a line break. It switches the scanner back to tjp mode. - [ 'MACRO', /.*\]\n/, :macroDef, method('endMacroDef') ], + [ :MACRO, /.*\]\n/, :macroDef, method('endMacroDef') ], # Any line not containing the start or end. [ nil, /.*\n/, :macroDef, method('midMacroDef') ], # Some multi-char literals. - [ 'LITERAL', /<=?/ ], - [ 'LITERAL', />=?/ ], - [ 'LITERAL', /!=?/ ], + [ :LITERAL, /<=?/ ], + [ :LITERAL, />=?/ ], + [ :LITERAL, /!=?/ ], # Everything else is returned as a single-char literal. - [ 'LITERAL', /./ ] + [ :LITERAL, /./ ] ] super(masterFile, messageHandler, tokenPatterns, :tjp) end @@ -157,19 +157,32 @@ def to_f(type, match) [ type, match.to_f ] end def to_time(type, match) - h, m, s = match.split(':') + h, m = match.split(':') h = h.to_i + if h < 0 || h > 24 + error('time_bad_hour', "Hour #{h} out of range (0 - 24)") + end m = m.to_i - s = 0 if s.nil? - [ type, h * 3600 + m * 60 + s ] + if m < 0 || h > 59 + error('time_bad_minute', "Minute #{m} out of range (0 - 59)") + end + if h == 24 && m != 0 + error('time_bad_time', "Time #{match} cannot be larger then 24:00") + end + + [ type, (h * 60 + m) * 60 ] end def to_date(type, match) - [ type, TjTime.new(match) ] + begin + [ type, TjTime.new(match) ] + rescue TjException => msg + error('time_error', msg) + end end def newPos(type, match) @startOfToken = sourceFileInfo [ nil, '' ] @@ -214,11 +227,11 @@ def endStringDQ(type, match) self.mode = :tjp # Remove the trailing " and remove the backslashes from escaped ". @string += match[0..-2].gsub(/\\"/, '"') - [ 'STRING', @string ] + [ :STRING, @string ] end def startStringSQ(type, match) self.mode = :sqString # Remove the opening ' and remove the backslashes from escaped '. @@ -234,11 +247,11 @@ def endStringSQ(type, match) self.mode = :tjp # Remove the trailing ' and remove the backslashes from escaped '. @string += match[0..-2].gsub(/\\'/, "'") - [ 'STRING', @string ] + [ :STRING, @string ] end def startStringSZR(type, match) # There should be a line break after the cut mark, but we allow some # spaces between the mark and the line break as well. @@ -272,11 +285,11 @@ [ nil, '' ] end def endStringSZR(type, match) self.mode = :tjp - [ 'STRING', @string ] + [ :STRING, @string ] end def startMacroDef(type, match) self.mode = :macroDef # Remove the opening '[' @@ -291,10 +304,10 @@ def endMacroDef(type, match) self.mode = :tjp # Remove "]\n" @macroDef += match[0..-3] - [ 'MACRO', @macroDef ] + [ :MACRO, @macroDef ] end def startMacroCall(type, match) @macroCallPreviousMode = @scannerMode self.mode = :macroCall