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

- old
+ new

@@ -17,12 +17,10 @@ # This class specializes the TextScanner class to detect the tokens of the # TJP syntax. class ProjectFileScanner < TextScanner def initialize(masterFile, messageHandler) - super - tokenPatterns = [ # Any white spaces [ nil, /\s+/, :tjp, method('newPos') ], # Single line comments starting with # @@ -53,18 +51,18 @@ # the first line. Arguments that span multiple lines are not # supported. As above, we need rules for the start, the end and lines # with neither start nor end. Macro calls inside of strings need a # special start pattern that is active in the string modes. Both # patterns switch the scanner to macroCall mode. - [ nil, /([-a-zA-Z_0-9>:.+]*|"(\\"|[^"])*|'(\\'|[^'])*|-8<-.*)?\$\{\s*([a-zA-Z_]\w*)(\s*"(\\"|[^"])*")*/, + [ nil, /([-a-zA-Z_0-9>:.+]*|"(\\"|[^"])*?|'(\\'|[^'])*?)?\$\{\s*([a-zA-Z_]\w*)(\s*"(\\"|[^"])*")*/, :tjp, method('startMacroCall') ], # This pattern is similar to the previous one, but is active inside of # multi-line strings. The corresponding rule for sizzors strings # can be found below. - [ nil, /(\\"|[^"])*\$\{\s*([a-zA-Z_]\w*)(\s*"(\\"|[^"])*")*/, + [ nil, /(\\"|[^"])*?\$\{\s*([a-zA-Z_]\w*)(\s*"(\\"|[^"])*")*/, :dqString, method('startMacroCall') ], - [ nil, /(\\'|[^'])*\$\{\s*([a-zA-Z_]\w*)(\s*"(\\"|[^"])*")*/, + [ nil, /(\\'|[^'])*?\$\{\s*([a-zA-Z_]\w*)(\s*"(\\"|[^"])*")*/, :sqString, method('startMacroCall') ], # This pattern matches the end of a macro call. It injects the prefix # and the expanded macro into the scanner again. The mode is restored # to the previous mode. [ nil, /(\s*"(\\"|[^"])*")*\s*\}/, :macroCall, method('endMacroCall') ], @@ -118,11 +116,11 @@ # 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') ], # This rule handles macros inside of sizzors strings. - [ nil, /.*\$\{\s*([a-zA-Z_]\w*)(\s*"(\\"|[^"])*")*/, + [ 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') ], @@ -145,18 +143,11 @@ # Everything else is returned as a single-char literal. [ 'LITERAL', /./ ] ] - tokenPatterns.each do |pat| - type = pat[0] - regExp = pat[1] - mode = pat[2] || :tjp - postProc = pat[3] - addPattern(type, regExp, mode, postProc) - end - self.mode = :tjp + super(masterFile, messageHandler, tokenPatterns, :tjp) end private def to_i(type, match) @@ -264,11 +255,11 @@ end def firstStringSZR(type, match) self.mode = :szrString # Split the leading indentation and the rest of the string. - foo, @indent, @string = */(\s*)(.*\n)/.match(match) + @indent, @string = */(\s*)(.*\n)/.match(match)[1, 2] [ nil, '' ] end def midStringSZR(type, match) # Ignore all the characters from the begining of match that are the same @@ -331,10 +322,10 @@ end # Remove '${' and '}' argsStr = @macroCall[2..-2] # Extract the macro name. - if (nameEnd = argsStr.index(' ')).nil? + if argsStr.index(' ').nil? expandMacro(prefix, [ argsStr ]) else macroName = argsStr[0, argsStr.index(' ')] # Remove the name part from argsStr argsStr = argsStr[macroName.length..-1]