Skip to content
Browse files

Merge branch 'master' of ssh://office.taskjuggler.org/srv/www/vhosts/w…

  • Loading branch information...
2 parents 176e3a2 + 87c508c commit 5bc756e6ebdefbc0c9978859cde847828d6435b9 @scrapper scrapper committed Aug 17, 2012
View
9 lib/taskjuggler/ProjectFileScanner.rb
@@ -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
@@ -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') ],
@@ -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)
View
7 lib/taskjuggler/TextParser/MacroTable.rb
@@ -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
View
7 lib/taskjuggler/TextParser/Scanner.rb
@@ -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
View
4 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.
Something went wrong with that request. Please try again.