Class: TaskJuggler::RichTextParser
- Inherits:
-
TextParser
- Object
- TextParser
- TaskJuggler::RichTextParser
- Includes:
- RichTextSyntaxRules
- Defined in:
- lib/taskjuggler/RichText/Parser.rb
Overview
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.
Instance Attribute Summary
Attributes inherited from TextParser
Instance Method Summary collapse
-
#initialize(rti, sectionCounter = [ 0, 0, 0, 0 ], tokenSet = nil) ⇒ RichTextParser
constructor
Create the parser and initialize the rule set.
-
#nextToken ⇒ Object
Get the next token from the scanner.
-
#open(text) ⇒ Object
Construct the parser and get ready to read.
-
#returnToken(token) ⇒ Object
Return the last fetch token again to the scanner.
- #reuse(rti, sectionCounter = [ 0, 0, 0, 0], tokenSet = nil) ⇒ Object
Methods included from RichTextSyntaxRules
#rule_blankLines, #rule_blockFunction, #rule_bulletList1, #rule_bulletList2, #rule_bulletList3, #rule_bulletList4, #rule_functionArguments, #rule_headlines, #rule_htmlBlob, #rule_inlineFunction, #rule_moreRefToken, #rule_numberList1, #rule_numberList2, #rule_numberList3, #rule_numberList4, #rule_paragraph, #rule_plainText, #rule_plainTextWithLinks, #rule_plainTextWithQueries, #rule_pre, #rule_refToken, #rule_richtext, #rule_section, #rule_sections, #rule_space, #rule_text, #rule_textWithSpace, #rule_title1, #rule_title2, #rule_title3, #rule_title4, #rule_wordWithQueries
Methods inherited from TextParser
#error, #initRules, #limitTokenSet, #newRule, #optional, #parse, #pattern, #repeatable, #sourceFileInfo, #updateParserTables, #warning
Methods included from MessageHandler
#critical, #debug, #error, #fatal, #info, #warning
Constructor Details
#initialize(rti, sectionCounter = [ 0, 0, 0, 0 ], tokenSet = nil) ⇒ RichTextParser
Create the parser and initialize the rule set. rt is the RichText object the resulting tree of RichTextElement objects should belong to.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# 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, :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 |
Instance Method Details
#nextToken ⇒ Object
Get the next token from the scanner.
76 77 78 |
# File 'lib/taskjuggler/RichText/Parser.rb', line 76 def nextToken @scanner.nextToken end |
#open(text) ⇒ Object
Construct the parser and get ready to read.
68 69 70 71 72 73 |
# 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 |
#returnToken(token) ⇒ Object
Return the last fetch token again to the scanner.
81 82 83 |
# File 'lib/taskjuggler/RichText/Parser.rb', line 81 def returnToken(token) @scanner.returnToken(token) end |
#reuse(rti, sectionCounter = [ 0, 0, 0, 0], tokenSet = nil) ⇒ Object
58 59 60 61 62 63 64 65 |
# 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 |