| Class | TaskJuggler::MacroTable |
| In: |
lib/MacroTable.rb
|
| Parent: | Object |
The MacroTable is used by the TextScanner to store defined macros and resolve them on request later on. A macro is a text pattern that has a name. The pattern may contain variable parts that are replaced by arguments passed during the macro call.
# File lib/MacroTable.rb, line 38
38: def initialize(messageHandler)
39: @messageHandler = messageHandler
40: @macros = {}
41: end
Remove all definitions from the table.
# File lib/MacroTable.rb, line 49
49: def clear
50: @macros = []
51: end
Returns true only if a macro named name is defined in the table.
# File lib/MacroTable.rb, line 54
54: def include?(name)
55: @macros.include?(name)
56: end
Returns the definition of the macro specified by name as first entry of args. The other entries of args are parameters that are replacing the ${n} tokens in the macro definition. In case the macro call has less arguments than the macro definition uses, the ${n} tokens remain unchanged. No error is generated.
# File lib/MacroTable.rb, line 63
63: def resolve(args, sourceFileInfo)
64: name = args[0]
65: return nil unless @macros[name]
66:
67: resolved = @macros[name].value.dup
68: i = 0
69: args.each do |arg|
70: resolved.gsub!("${#{i}}", arg)
71: i += 1
72: end
73: [ @macros[name], resolved ]
74: end