class TaskJuggler::ProjectFileParser

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.

Public Class Methods

new() click to toggle source

Create the parser object.

Calls superclass method
# File lib/taskjuggler/ProjectFileParser.rb, line 35
def initialize
  super

  # 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

close() click to toggle source

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

# File lib/taskjuggler/ProjectFileParser.rb, line 70
def close
  @scanner.close
end
nextToken() click to toggle source

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.

# File lib/taskjuggler/ProjectFileParser.rb, line 77
def nextToken
  @scanner.nextToken
end
open(file, master, fileNameIsBuffer = false) click to toggle source

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

# File lib/taskjuggler/ProjectFileParser.rb, line 51
def open(file, master, fileNameIsBuffer = false)
  @scanner = ProjectFileScanner.new(file)
  # 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
  # Stack for property IDs. Needed to handle nested 'supplement'
  # statements.
  @idStack = []
end
parseReportAttributes(report, attributes) click to toggle source
# File lib/taskjuggler/ProjectFileParser.rb, line 104
def parseReportAttributes(report, attributes)
  open(attributes, false, true)
  @property = report
  @project = report.project
  parse(:dynamicAttributes)
end
returnToken(token) click to toggle source

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.

# File lib/taskjuggler/ProjectFileParser.rb, line 85
def returnToken(token)
  @scanner.returnToken(token)
end
setGlobalMacros() click to toggle source

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.

# 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