Skip to content

Commit

Permalink
Merge branch 'master' of ssh://office.taskjuggler.org/srv/www/vhosts/w…
Browse files Browse the repository at this point in the history
  • Loading branch information
scrapper committed Aug 17, 2012
2 parents 176e3a2 + 87c508c commit 5bc756e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
9 changes: 5 additions & 4 deletions lib/taskjuggler/ProjectFileScanner.rb
Expand Up @@ -54,14 +54,14 @@ def initialize(masterFile)
# 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>:.+]*|"(\\"|[^"])*?|'(\\'|[^'])*?)?\$\{\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
Expand Down Expand Up @@ -123,7 +123,7 @@ def initialize(masterFile)
[ :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') ],
Expand Down Expand Up @@ -373,6 +373,7 @@ def endMacroCall(type, match)
macroCallLength = @macroCall.length
# Remove '${' and '}' and white spaces at begin and end
argsStr = @macroCall[2..-2].sub(/^[ \t\n]*(.*?)[ \t\n]*$/, '\1')

# Extract the macro name.
if argsStr.index(' ').nil?
expandMacro(prefix, [ argsStr ], macroCallLength)
Expand Down
7 changes: 7 additions & 0 deletions lib/taskjuggler/TextParser/MacroTable.rb
Expand Up @@ -57,6 +57,13 @@ def include?(name)
# unchanged. No error is generated.
def resolve(args, sourceFileInfo)
name = args[0]
# If the first character of the macro name is a '?', the macro may be
# undefined and is silently ignored.
if name[0] == ??
# Remove the '?' from the name.
name = name[1..-1]
return [ nil, '' ] unless @macros[name]
end
return nil unless @macros[name]

resolved = @macros[name].value.dup
Expand Down
7 changes: 4 additions & 3 deletions lib/taskjuggler/TextParser/Scanner.rb
Expand Up @@ -449,13 +449,14 @@ def macroDefined?(name)
def expandMacro(prefix, args, callLength)
# Get the expanded macro from the @macroTable.
macro, text = @macroTable.resolve(args, sourceFileInfo)
unless macro && text
error('undefined_macro', "Undefined macro '#{args[0]}' called")
end

# If the expanded macro is empty, we can ignore it.
return if text == ''

unless macro && text
error('undefined_macro', "Undefined macro '#{args[0]}' called")
end

unless @cf.injectMacro(macro, args, prefix + text, callLength)
error('macro_stack_overflow', "Too many nested macro calls.")
end
Expand Down
4 changes: 4 additions & 0 deletions test/TestSuite/Syntax/Correct/Macro-4.tjp
@@ -0,0 +1,4 @@
project "Test" 2012-08-17 +1m

task t ${?undef} "T"

0 comments on commit 5bc756e

Please sign in to comment.