class TaskJuggler::RichTextParser

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.

Public Class Methods

new(rti, sectionCounter = [ 0, 0, 0, 0 ], tokenSet = nil) click to toggle source

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

Calls superclass method
# File lib/taskjuggler/RichText/Parser.rb, line 31
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,
                 :HTMLBLOB, :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

nextToken() click to toggle source

Get the next token from the scanner.

# File lib/taskjuggler/RichText/Parser.rb, line 75
def nextToken
  @scanner.nextToken
end
open(text) click to toggle source

Construct the parser and get ready to read.

# File lib/taskjuggler/RichText/Parser.rb, line 67
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
returnToken(token) click to toggle source

Return the last fetch token again to the scanner.

# File lib/taskjuggler/RichText/Parser.rb, line 80
def returnToken(token)
  @scanner.returnToken(token)
end
reuse(rti, sectionCounter = [ 0, 0, 0, 0], tokenSet = nil) click to toggle source
# File lib/taskjuggler/RichText/Parser.rb, line 57
def reuse(rti, sectionCounter = [ 0, 0, 0, 0],
          tokenSet = nil)
  @blockedVariables = {}
  @stack = nil
  @richTextI = rti
  @sectionCounter = sectionCounter
  limitTokenSet(tokenSet)
end