Parent

Files

Class Index [+]

Quicksearch

TaskJuggler::MacroTable

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.

Public Class Methods

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

Public Instance Methods

add(macro) click to toggle source

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

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

Remove all definitions from the table.

    # File lib/MacroTable.rb, line 49
49:     def clear
50:       @macros = []
51:     end
error(id, text, sourceFileInfo) click to toggle source

This function sends an error message to the message handler.

    # File lib/MacroTable.rb, line 75
75:     def error(id, text, sourceFileInfo)
76:       message = Message.new(id, 'error', text, nil, nil, sourceFileInfo)
77:       @messageHandler.send(message)
78:       raise TjException.new, 'Macro expasion error'
79:     end
include?(name) click to toggle source

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
resolve(args, sourceFileInfo) click to toggle source

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:       resolved = @macros[name].value.dup
66:       i = 0
67:       args.each do |arg|
68:         resolved.gsub!("${#{i}}", arg)
69:         i += 1
70:       end
71:       [ @macros[name], resolved ]
72:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.