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.

Methods

add   clear   error   include?   new   resolve  

Public Class methods

[Source]

    # File lib/MacroTable.rb, line 38
38:     def initialize(messageHandler)
39:       @messageHandler = messageHandler
40:       @macros = {}
41:     end

Public Instance methods

Add a new macro definition to the table or replace an existing one.

[Source]

    # File lib/MacroTable.rb, line 44
44:     def add(macro)
45:       @macros[macro.name] = macro
46:     end

Remove all definitions from the table.

[Source]

    # File lib/MacroTable.rb, line 49
49:     def clear
50:       @macros = []
51:     end

This function sends an error message to the message handler.

[Source]

    # File lib/MacroTable.rb, line 77
77:     def error(id, text, sourceFileInfo)
78:       @messageHandler.error(id, text, sourceFileInfo)
79:     end

Returns true only if a macro named name is defined in the table.

[Source]

    # 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.

[Source]

    # 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

[Validate]