Class TaskJuggler::ProjectFileParser
In: lib/taskjuggler/ProjectFileParser.rb
Parent: TextParser

This class specializes the TextParser class for use with TaskJuggler project files (TJP Files). The primary purpose is to provide functionality that make it more comfortable to define the TaskJuggler syntax in a form that is human creatable but also powerful enough to define the data structures the parser needs to understand the syntax.

By adding some additional information to the syntax rules, we can also generate the complete reference manual from this rule set.

Methods

Included Modules

TjpSyntaxRules

Public Class methods

Create the parser object. messageHandler is a TjMessageHandler that is used for error reporting.

[Source]

# File lib/taskjuggler/ProjectFileParser.rb, line 36
    def initialize(messageHandler)
      super

      @tjMessageHandler = messageHandler

      # Define the token types that the ProjectFileScanner may return for
      # variable elements.
      @variables = [ :INTEGER, :FLOAT, :DATE, :TIME, :STRING, :LITERAL,
                     :ID, :ID_WITH_COLON, :ABSOLUTE_ID, :MACRO ]

      initRules
      updateParserTables

      @project = nil
    end

Public Instance methods

Call this function to cleanup the parser structures after the file processing has been completed.

[Source]

# File lib/taskjuggler/ProjectFileParser.rb, line 70
    def close
      @scanner.close
    end

This function will deliver the next token from the scanner. A token is a two element Array that contains the ID or type of the token as well as the text string of the token.

[Source]

# File lib/taskjuggler/ProjectFileParser.rb, line 77
    def nextToken
      @scanner.nextToken
    end

Call this function with the master file to start processing a TJP file or a set of TJP files.

[Source]

# File lib/taskjuggler/ProjectFileParser.rb, line 54
    def open(file, master, fileNameIsBuffer = false)
      @scanner = ProjectFileScanner.new(file, @messageHandler)
      # We need the ProjectFileScanner object for error reporting.
      if master && !fileNameIsBuffer && file != '.' && file[-4, 4] != '.tjp'
        error('illegal_extension', "Project file name must end with " +
              '\'.tjp\' extension')
      end
      @scanner.open(fileNameIsBuffer)

      @property = nil
      @scenarioIdx = 0
      initFileStack
    end

[Source]

# File lib/taskjuggler/ProjectFileParser.rb, line 104
    def parseReportAttributes(report, attributes)
      open(attributes, false, true)
      @property = report
      @project = report.project
      parse(:reportAttributes)
    end

This function can be used to return tokens. Returned tokens will be pushed on a LIFO stack. To preserve the order of the original tokens the last token must be returned first. This mechanism is used to implement look-ahead functionality.

[Source]

# File lib/taskjuggler/ProjectFileParser.rb, line 85
    def returnToken(token)
      @scanner.returnToken(token)
    end

A set of standard marcros is defined in all files as soon as the project header has been read. Calling this functions gets the values from @project and inserts the Macro objects into the ProjectFileScanner.

[Source]

# File lib/taskjuggler/ProjectFileParser.rb, line 92
    def setGlobalMacros
      @scanner.addMacro(Macro.new('projectstart', @project['start'].to_s,
                                  @scanner.sourceFileInfo))
      @scanner.addMacro(Macro.new('projectend', @project['end'].to_s,
                                  @scanner.sourceFileInfo))
      @scanner.addMacro(Macro.new('now', @project['now'].to_s,
                                  @scanner.sourceFileInfo))
      @scanner.addMacro(Macro.new('today', @project['now'].
                                   to_s(@project['timeFormat']),
                                  @scanner.sourceFileInfo))
    end

[Validate]