Class TaskJuggler::RichTextParser
In: lib/taskjuggler/RichText/Parser.rb
Parent: TextParser

This is the parser class used by the RichText class to convert the input text into an intermediate representation. Most of the actual work is done by the generic TextParser class. The syntax description for the markup language is provided by the RichTextSyntaxRules module. To break the input String into tokens, the RichTextScanner class is used.

Methods

new   nextToken   open   returnToken   reuse  

Included Modules

RichTextSyntaxRules

Public Class methods

Create the parser and initialize the rule set. rt is the RichText object the resulting tree of RichTextElement objects should belong to.

[Source]

# File lib/taskjuggler/RichText/Parser.rb, line 32
    def initialize(rti, sectionCounter = [ 0, 0, 0, 0 ], tokenSet = nil)
      super()
      @richTextI = rti
      # These are the tokens that can be returned by the RichTextScanner.
      @variables = [ :LINEBREAK, :SPACE, :WORD,
                     :BOLD, :ITALIC, :CODE, :BOLDITALIC, :PRE,
                     :HREF, :HREFEND, :REF, :REFEND, :HLINE,
                     :FCOLSTART, :FCOLEND,
                     :QUERY,
                     :INLINEFUNCSTART, :INLINEFUNCEND,
                     :BLOCKFUNCSTART, :BLOCKFUNCEND, :ID, :STRING,
                     :TITLE1, :TITLE2, :TITLE3, :TITLE4,
                     :TITLE1END, :TITLE2END, :TITLE3END, :TITLE4END,
                     :BULLET1, :BULLET2, :BULLET3, :BULLET4,
                     :NUMBER1, :NUMBER2, :NUMBER3, :NUMBER4
                   ]
      limitTokenSet(tokenSet)
      # Load the rule set into the parser.
      initRules
      updateParserTables
      # The sections and numbered list can each nest 3 levels deep. We use these
      # counter Arrays to generate proper 1.2.3 type labels.
      @sectionCounter = sectionCounter
      @numberListCounter = [ 0, 0, 0, 0 ]
    end

Public Instance methods

Get the next token from the scanner.

[Source]

# File lib/taskjuggler/RichText/Parser.rb, line 76
    def nextToken
      @scanner.nextToken
    end

Construct the parser and get ready to read.

[Source]

# File lib/taskjuggler/RichText/Parser.rb, line 68
    def open(text)
      # Make sure that the last line is properly terminated with a newline.
      # Multiple newlines at the end are simply ignored.
      @scanner = RichTextScanner.new(text + "\n\n", Log)
      @scanner.open(true)
    end

Return the last fetch token again to the scanner.

[Source]

# File lib/taskjuggler/RichText/Parser.rb, line 81
    def returnToken(token)
      @scanner.returnToken(token)
    end

[Source]

# File lib/taskjuggler/RichText/Parser.rb, line 58
    def reuse(rti, sectionCounter = [ 0, 0, 0, 0],
              tokenSet = nil)
      @blockedVariables = {}
      @stack = nil
      @richTextI = rti
      @sectionCounter = sectionCounter
      limitTokenSet(tokenSet)
    end

[Validate]