/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/rdoc/markdown.rb
Ruby | 16336 lines | 14783 code | 1131 blank | 422 comment | 1032 complexity | d02593a245f87b69b867ef7e4fbce24e MD5 | raw file
Possible License(s): Apache-2.0
Large files files are truncated, but you can click here to view the full file
- # coding: UTF-8
- # :markup: markdown
- ##
- # RDoc::Markdown as described by the [markdown syntax][syntax].
- #
- # To choose Markdown as your only default format see
- # RDoc::Options@Saved+Options for instructions on setting up a `.doc_options`
- # file to store your project default.
- #
- # ## Extensions
- #
- # The following markdown extensions are supported by the parser, but not all
- # are used in RDoc output by default.
- #
- # ### RDoc
- #
- # The RDoc Markdown parser has the following built-in behaviors that cannot be
- # disabled.
- #
- # Underscores embedded in words are never interpreted as emphasis. (While the
- # [markdown dingus][dingus] emphasizes in-word underscores, neither the
- # Markdown syntax nor MarkdownTest mention this behavior.)
- #
- # For HTML output, RDoc always auto-links bare URLs.
- #
- # ### Break on Newline
- #
- # The break_on_newline extension converts all newlines into hard line breaks
- # as in [Github Flavored Markdown][GFM]. This extension is disabled by
- # default.
- #
- # ### CSS
- #
- # The #css extension enables CSS blocks to be included in the output, but they
- # are not used for any built-in RDoc output format. This extension is disabled
- # by default.
- #
- # Example:
- #
- # <style type="text/css">
- # h1 { font-size: 3em }
- # </style>
- #
- # ### Definition Lists
- #
- # The definition_lists extension allows definition lists using the [PHP
- # Markdown Extra syntax][PHPE], but only one label and definition are supported
- # at this time. This extension is enabled by default.
- #
- # Example:
- #
- # ```
- # cat
- # : A small furry mammal
- # that seems to sleep a lot
- #
- # ant
- # : A little insect that is known
- # to enjoy picnics
- #
- # ```
- #
- # Produces:
- #
- # cat
- # : A small furry mammal
- # that seems to sleep a lot
- #
- # ant
- # : A little insect that is known
- # to enjoy picnics
- #
- # ### Github
- #
- # The #github extension enables a partial set of [Github Flavored Markdown]
- # [GFM]. This extension is enabled by default.
- #
- # Supported github extensions include:
- #
- # #### Fenced code blocks
- #
- # Use ` ``` ` around a block of code instead of indenting it four spaces.
- #
- # #### Syntax highlighting
- #
- # Use ` ``` ruby ` as the start of a code fence to add syntax highlighting.
- # (Currently only `ruby` syntax is supported).
- #
- # ### HTML
- #
- # Enables raw HTML to be included in the output. This extension is enabled by
- # default.
- #
- # Example:
- #
- # <table>
- # ...
- # </table>
- #
- # ### Notes
- #
- # The #notes extension enables footnote support. This extension is enabled by
- # default.
- #
- # Example:
- #
- # Here is some text[^1] including an inline footnote ^[for short footnotes]
- #
- # ...
- #
- # [^1]: With the footnote text down at the bottom
- #
- # Produces:
- #
- # Here is some text[^1] including an inline footnote ^[for short footnotes]
- #
- # [^1]: With the footnote text down at the bottom
- #
- # ## Limitations
- #
- # * Link titles are not used
- # * Image links are not generated correctly
- # * Footnotes are collapsed into a single paragraph
- #
- # ## Author
- #
- # This markdown parser is a port to kpeg from [peg-markdown][pegmarkdown] by
- # John MacFarlane.
- #
- # It is used under the MIT license:
- #
- # Permission is hereby granted, free of charge, to any person obtaining a copy
- # of this software and associated documentation files (the "Software"), to deal
- # in the Software without restriction, including without limitation the rights
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- # copies of the Software, and to permit persons to whom the Software is
- # furnished to do so, subject to the following conditions:
- #
- # The above copyright notice and this permission notice shall be included in
- # all copies or substantial portions of the Software.
- #
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- # THE SOFTWARE.
- #
- # The port to kpeg was performed by Eric Hodel and Evan Phoenix
- #
- # [dingus]: http://daringfireball.net/projects/markdown/dingus
- # [GFM]: http://github.github.com/github-flavored-markdown/
- # [pegmarkdown]: https://github.com/jgm/peg-markdown
- # [PHPE]: http://michelf.com/projects/php-markdown/extra/#def-list
- # [syntax]: http://daringfireball.net/projects/markdown/syntax
- #--
- # Last updated to jgm/peg-markdown commit 8f8fc22ef0
- class RDoc::Markdown
- # :stopdoc:
- # This is distinct from setup_parser so that a standalone parser
- # can redefine #initialize and still have access to the proper
- # parser setup code.
- def initialize(str, debug=false)
- setup_parser(str, debug)
- end
- # Prepares for parsing +str+. If you define a custom initialize you must
- # call this method before #parse
- def setup_parser(str, debug=false)
- @string = str
- @pos = 0
- @memoizations = Hash.new { |h,k| h[k] = {} }
- @result = nil
- @failed_rule = nil
- @failing_rule_offset = -1
- setup_foreign_grammar
- end
- attr_reader :string
- attr_reader :failing_rule_offset
- attr_accessor :result, :pos
- def current_column(target=pos)
- if c = string.rindex("\n", target-1)
- return target - c - 1
- end
- target + 1
- end
- def current_line(target=pos)
- cur_offset = 0
- cur_line = 0
- string.each_line do |line|
- cur_line += 1
- cur_offset += line.size
- return cur_line if cur_offset >= target
- end
- -1
- end
- def lines
- lines = []
- string.each_line { |l| lines << l }
- lines
- end
- def get_text(start)
- @string[start..@pos-1]
- end
- def show_pos
- width = 10
- if @pos < width
- "#{@pos} (\"#{@string[0,@pos]}\" @ \"#{@string[@pos,width]}\")"
- else
- "#{@pos} (\"... #{@string[@pos - width, width]}\" @ \"#{@string[@pos,width]}\")"
- end
- end
- def failure_info
- l = current_line @failing_rule_offset
- c = current_column @failing_rule_offset
- if @failed_rule.kind_of? Symbol
- info = self.class::Rules[@failed_rule]
- "line #{l}, column #{c}: failed rule '#{info.name}' = '#{info.rendered}'"
- else
- "line #{l}, column #{c}: failed rule '#{@failed_rule}'"
- end
- end
- def failure_caret
- l = current_line @failing_rule_offset
- c = current_column @failing_rule_offset
- line = lines[l-1]
- "#{line}\n#{' ' * (c - 1)}^"
- end
- def failure_character
- l = current_line @failing_rule_offset
- c = current_column @failing_rule_offset
- lines[l-1][c-1, 1]
- end
- def failure_oneline
- l = current_line @failing_rule_offset
- c = current_column @failing_rule_offset
- char = lines[l-1][c-1, 1]
- if @failed_rule.kind_of? Symbol
- info = self.class::Rules[@failed_rule]
- "@#{l}:#{c} failed rule '#{info.name}', got '#{char}'"
- else
- "@#{l}:#{c} failed rule '#{@failed_rule}', got '#{char}'"
- end
- end
- class ParseError < RuntimeError
- end
- def raise_error
- raise ParseError, failure_oneline
- end
- def show_error(io=STDOUT)
- error_pos = @failing_rule_offset
- line_no = current_line(error_pos)
- col_no = current_column(error_pos)
- io.puts "On line #{line_no}, column #{col_no}:"
- if @failed_rule.kind_of? Symbol
- info = self.class::Rules[@failed_rule]
- io.puts "Failed to match '#{info.rendered}' (rule '#{info.name}')"
- else
- io.puts "Failed to match rule '#{@failed_rule}'"
- end
- io.puts "Got: #{string[error_pos,1].inspect}"
- line = lines[line_no-1]
- io.puts "=> #{line}"
- io.print(" " * (col_no + 3))
- io.puts "^"
- end
- def set_failed_rule(name)
- if @pos > @failing_rule_offset
- @failed_rule = name
- @failing_rule_offset = @pos
- end
- end
- attr_reader :failed_rule
- def match_string(str)
- len = str.size
- if @string[pos,len] == str
- @pos += len
- return str
- end
- return nil
- end
- def scan(reg)
- if m = reg.match(@string[@pos..-1])
- width = m.end(0)
- @pos += width
- return true
- end
- return nil
- end
- if "".respond_to? :getbyte
- def get_byte
- if @pos >= @string.size
- return nil
- end
- s = @string.getbyte @pos
- @pos += 1
- s
- end
- else
- def get_byte
- if @pos >= @string.size
- return nil
- end
- s = @string[@pos]
- @pos += 1
- s
- end
- end
- def parse(rule=nil)
- # We invoke the rules indirectly via apply
- # instead of by just calling them as methods because
- # if the rules use left recursion, apply needs to
- # manage that.
- if !rule
- apply(:_root)
- else
- method = rule.gsub("-","_hyphen_")
- apply :"_#{method}"
- end
- end
- class MemoEntry
- def initialize(ans, pos)
- @ans = ans
- @pos = pos
- @result = nil
- @set = false
- @left_rec = false
- end
- attr_reader :ans, :pos, :result, :set
- attr_accessor :left_rec
- def move!(ans, pos, result)
- @ans = ans
- @pos = pos
- @result = result
- @set = true
- @left_rec = false
- end
- end
- def external_invoke(other, rule, *args)
- old_pos = @pos
- old_string = @string
- @pos = other.pos
- @string = other.string
- begin
- if val = __send__(rule, *args)
- other.pos = @pos
- other.result = @result
- else
- other.set_failed_rule "#{self.class}##{rule}"
- end
- val
- ensure
- @pos = old_pos
- @string = old_string
- end
- end
- def apply_with_args(rule, *args)
- memo_key = [rule, args]
- if m = @memoizations[memo_key][@pos]
- @pos = m.pos
- if !m.set
- m.left_rec = true
- return nil
- end
- @result = m.result
- return m.ans
- else
- m = MemoEntry.new(nil, @pos)
- @memoizations[memo_key][@pos] = m
- start_pos = @pos
- ans = __send__ rule, *args
- lr = m.left_rec
- m.move! ans, @pos, @result
- # Don't bother trying to grow the left recursion
- # if it's failing straight away (thus there is no seed)
- if ans and lr
- return grow_lr(rule, args, start_pos, m)
- else
- return ans
- end
- return ans
- end
- end
- def apply(rule)
- if m = @memoizations[rule][@pos]
- @pos = m.pos
- if !m.set
- m.left_rec = true
- return nil
- end
- @result = m.result
- return m.ans
- else
- m = MemoEntry.new(nil, @pos)
- @memoizations[rule][@pos] = m
- start_pos = @pos
- ans = __send__ rule
- lr = m.left_rec
- m.move! ans, @pos, @result
- # Don't bother trying to grow the left recursion
- # if it's failing straight away (thus there is no seed)
- if ans and lr
- return grow_lr(rule, nil, start_pos, m)
- else
- return ans
- end
- return ans
- end
- end
- def grow_lr(rule, args, start_pos, m)
- while true
- @pos = start_pos
- @result = m.result
- if args
- ans = __send__ rule, *args
- else
- ans = __send__ rule
- end
- return nil unless ans
- break if @pos <= m.pos
- m.move! ans, @pos, @result
- end
- @result = m.result
- @pos = m.pos
- return m.ans
- end
- class RuleInfo
- def initialize(name, rendered)
- @name = name
- @rendered = rendered
- end
- attr_reader :name, :rendered
- end
- def self.rule_info(name, rendered)
- RuleInfo.new(name, rendered)
- end
- # :startdoc:
- require 'rubygems'
- require 'rdoc'
- require 'rdoc/markup/to_joined_paragraph'
- require 'rdoc/markdown/entities'
- if RUBY_VERSION > '1.9' then
- require 'rdoc/markdown/literals_1_9'
- else
- require 'rdoc/markdown/literals_1_8'
- end
- ##
- # Supported extensions
- EXTENSIONS = []
- ##
- # Extensions enabled by default
- DEFAULT_EXTENSIONS = [
- :definition_lists,
- :github,
- :html,
- :notes,
- ]
- # :section: Extensions
- ##
- # Creates extension methods for the `name` extension to enable and disable
- # the extension and to query if they are active.
- def self.extension name
- EXTENSIONS << name
- eval <<-RUBY
- def #{name}?
- extension? __method__
- end
- def #{name}= enable
- extension __method__, enable
- end
- RUBY
- end
- ##
- # Converts all newlines into hard breaks
- extension :break_on_newline
- ##
- # Allow style blocks
- extension :css
- ##
- # Allow PHP Markdown Extras style definition lists
- extension :definition_lists
- ##
- # Allow Github Flavored Markdown
- extension :github
- ##
- # Allow HTML
- extension :html
- ##
- # Enables the notes extension
- extension :notes
- # :section:
- ##
- # Parses the `markdown` document into an RDoc::Document using the default
- # extensions.
- def self.parse markdown
- parser = new
- parser.parse markdown
- end
- # TODO remove when kpeg 0.10 is released
- alias orig_initialize initialize # :nodoc:
- ##
- # Creates a new markdown parser that enables the given +extensions+.
- def initialize extensions = DEFAULT_EXTENSIONS, debug = false
- @debug = debug
- @formatter = RDoc::Markup::ToJoinedParagraph.new
- @extensions = extensions
- @references = nil
- @unlinked_references = nil
- @footnotes = nil
- @note_order = nil
- end
- ##
- # Wraps `text` in emphasis for rdoc inline formatting
- def emphasis text
- if text =~ /\A[a-z\d.\/]+\z/i then
- "_#{text}_"
- else
- "<em>#{text}</em>"
- end
- end
- ##
- # :category: Extensions
- #
- # Is the extension `name` enabled?
- def extension? name
- name = name.to_s.delete('?').intern
- @extensions.include? name
- end
- ##
- # :category: Extensions
- #
- # Enables or disables the extension with `name`
- def extension name, enable
- name = name.to_s.delete('=').intern
- if enable then
- @extensions |= [name]
- else
- @extensions -= [name]
- end
- end
- ##
- # Parses `text` in a clone of this parser. This is used for handling nested
- # lists the same way as markdown_parser.
- def inner_parse text # :nodoc:
- parser = clone
- parser.setup_parser text, @debug
- parser.peg_parse
- doc = parser.result
- doc.accept @formatter
- doc.parts
- end
- ##
- # Finds a link reference for `label` and creates a new link to it with
- # `content` as the link text. If `label` was not encountered in the
- # reference-gathering parser pass the label and content are reconstructed
- # with the linking `text` (usually whitespace).
- def link_to content, label = content, text = nil
- raise 'enable notes extension' if
- content.start_with? '^' and label.equal? content
- if ref = @references[label] then
- "{#{content}}[#{ref}]"
- elsif label.equal? content then
- "[#{content}]#{text}"
- else
- "[#{content}]#{text}[#{label}]"
- end
- end
- ##
- # Creates an RDoc::Markup::ListItem by parsing the `unparsed` content from
- # the first parsing pass.
- def list_item_from unparsed
- parsed = inner_parse unparsed.join
- RDoc::Markup::ListItem.new nil, *parsed
- end
- ##
- # Stores `label` as a note and fills in previously unknown note references.
- def note label
- #foottext = "rdoc-label:foottext-#{label}:footmark-#{label}"
- #ref.replace foottext if ref = @unlinked_notes.delete(label)
- @notes[label] = foottext
- #"{^1}[rdoc-label:footmark-#{label}:foottext-#{label}] "
- end
- ##
- # Creates a new link for the footnote `reference` and adds the reference to
- # the note order list for proper display at the end of the document.
- def note_for ref
- @note_order << ref
- label = @note_order.length
- "{*#{label}}[rdoc-label:foottext-#{label}:footmark-#{label}]"
- end
- ##
- # The internal kpeg parse method
- alias peg_parse parse # :nodoc:
- ##
- # Creates an RDoc::Markup::Paragraph from `parts` and including
- # extension-specific behavior
- def paragraph parts
- parts = parts.map do |part|
- if "\n" == part then
- RDoc::Markup::HardBreak.new
- else
- part
- end
- end if break_on_newline?
- RDoc::Markup::Paragraph.new(*parts)
- end
- ##
- # Parses `markdown` into an RDoc::Document
- def parse markdown
- @references = {}
- @unlinked_references = {}
- markdown += "\n\n"
- setup_parser markdown, @debug
- peg_parse 'References'
- if notes? then
- @footnotes = {}
- setup_parser markdown, @debug
- peg_parse 'Notes'
- # using note_order on the first pass would be a bug
- @note_order = []
- end
- setup_parser markdown, @debug
- peg_parse
- doc = result
- if notes? and not @footnotes.empty? then
- doc << RDoc::Markup::Rule.new(1)
- @note_order.each_with_index do |ref, index|
- label = index + 1
- note = @footnotes[ref]
- link = "{^#{label}}[rdoc-label:footmark-#{label}:foottext-#{label}] "
- note.parts.unshift link
- doc << note
- end
- end
- doc.accept @formatter
- doc
- end
- ##
- # Stores `label` as a reference to `link` and fills in previously unknown
- # link references.
- def reference label, link
- if ref = @unlinked_references.delete(label) then
- ref.replace link
- end
- @references[label] = link
- end
- ##
- # Wraps `text` in strong markup for rdoc inline formatting
- def strong text
- if text =~ /\A[a-z\d.\/-]+\z/i then
- "*#{text}*"
- else
- "<b>#{text}</b>"
- end
- end
- # :stopdoc:
- def setup_foreign_grammar
- @_grammar_literals = RDoc::Markdown::Literals.new(nil)
- end
- # root = Doc
- def _root
- _tmp = apply(:_Doc)
- set_failed_rule :_root unless _tmp
- return _tmp
- end
- # Doc = BOM? Block*:a { RDoc::Markup::Document.new(*a.compact) }
- def _Doc
- _save = self.pos
- while true # sequence
- _save1 = self.pos
- _tmp = apply(:_BOM)
- unless _tmp
- _tmp = true
- self.pos = _save1
- end
- unless _tmp
- self.pos = _save
- break
- end
- _ary = []
- while true
- _tmp = apply(:_Block)
- _ary << @result if _tmp
- break unless _tmp
- end
- _tmp = true
- @result = _ary
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; RDoc::Markup::Document.new(*a.compact) ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
- set_failed_rule :_Doc unless _tmp
- return _tmp
- end
- # Block = BlankLine* (BlockQuote | Verbatim | CodeFence | Note | Reference | HorizontalRule | Heading | OrderedList | BulletList | DefinitionList | HtmlBlock | StyleBlock | Para | Plain)
- def _Block
- _save = self.pos
- while true # sequence
- while true
- _tmp = apply(:_BlankLine)
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _save2 = self.pos
- while true # choice
- _tmp = apply(:_BlockQuote)
- break if _tmp
- self.pos = _save2
- _tmp = apply(:_Verbatim)
- break if _tmp
- self.pos = _save2
- _tmp = apply(:_CodeFence)
- break if _tmp
- self.pos = _save2
- _tmp = apply(:_Note)
- break if _tmp
- self.pos = _save2
- _tmp = apply(:_Reference)
- break if _tmp
- self.pos = _save2
- _tmp = apply(:_HorizontalRule)
- break if _tmp
- self.pos = _save2
- _tmp = apply(:_Heading)
- break if _tmp
- self.pos = _save2
- _tmp = apply(:_OrderedList)
- break if _tmp
- self.pos = _save2
- _tmp = apply(:_BulletList)
- break if _tmp
- self.pos = _save2
- _tmp = apply(:_DefinitionList)
- break if _tmp
- self.pos = _save2
- _tmp = apply(:_HtmlBlock)
- break if _tmp
- self.pos = _save2
- _tmp = apply(:_StyleBlock)
- break if _tmp
- self.pos = _save2
- _tmp = apply(:_Para)
- break if _tmp
- self.pos = _save2
- _tmp = apply(:_Plain)
- break if _tmp
- self.pos = _save2
- break
- end # end choice
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
- set_failed_rule :_Block unless _tmp
- return _tmp
- end
- # Para = NonindentSpace Inlines:a BlankLine+ { paragraph a }
- def _Para
- _save = self.pos
- while true # sequence
- _tmp = apply(:_NonindentSpace)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Inlines)
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- _save1 = self.pos
- _tmp = apply(:_BlankLine)
- if _tmp
- while true
- _tmp = apply(:_BlankLine)
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save1
- end
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; paragraph a ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
- set_failed_rule :_Para unless _tmp
- return _tmp
- end
- # Plain = Inlines:a { paragraph a }
- def _Plain
- _save = self.pos
- while true # sequence
- _tmp = apply(:_Inlines)
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; paragraph a ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
- set_failed_rule :_Plain unless _tmp
- return _tmp
- end
- # AtxInline = !Newline !(Sp? "#"* Sp Newline) Inline
- def _AtxInline
- _save = self.pos
- while true # sequence
- _save1 = self.pos
- _tmp = apply(:_Newline)
- _tmp = _tmp ? nil : true
- self.pos = _save1
- unless _tmp
- self.pos = _save
- break
- end
- _save2 = self.pos
- _save3 = self.pos
- while true # sequence
- _save4 = self.pos
- _tmp = apply(:_Sp)
- unless _tmp
- _tmp = true
- self.pos = _save4
- end
- unless _tmp
- self.pos = _save3
- break
- end
- while true
- _tmp = match_string("#")
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = apply(:_Sp)
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = apply(:_Newline)
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
- _tmp = _tmp ? nil : true
- self.pos = _save2
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Inline)
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
- set_failed_rule :_AtxInline unless _tmp
- return _tmp
- end
- # AtxStart = < ("######" | "#####" | "####" | "###" | "##" | "#") > { text.length }
- def _AtxStart
- _save = self.pos
- while true # sequence
- _text_start = self.pos
- _save1 = self.pos
- while true # choice
- _tmp = match_string("######")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("#####")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("####")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("###")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("##")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("#")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
- if _tmp
- text = get_text(_text_start)
- end
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; text.length ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
- set_failed_rule :_AtxStart unless _tmp
- return _tmp
- end
- # AtxHeading = AtxStart:s Sp? AtxInline+:a (Sp? "#"* Sp)? Newline { RDoc::Markup::Heading.new(s, a.join) }
- def _AtxHeading
- _save = self.pos
- while true # sequence
- _tmp = apply(:_AtxStart)
- s = @result
- unless _tmp
- self.pos = _save
- break
- end
- _save1 = self.pos
- _tmp = apply(:_Sp)
- unless _tmp
- _tmp = true
- self.pos = _save1
- end
- unless _tmp
- self.pos = _save
- break
- end
- _save2 = self.pos
- _ary = []
- _tmp = apply(:_AtxInline)
- if _tmp
- _ary << @result
- while true
- _tmp = apply(:_AtxInline)
- _ary << @result if _tmp
- break unless _tmp
- end
- _tmp = true
- @result = _ary
- else
- self.pos = _save2
- end
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- _save3 = self.pos
- _save4 = self.pos
- while true # sequence
- _save5 = self.pos
- _tmp = apply(:_Sp)
- unless _tmp
- _tmp = true
- self.pos = _save5
- end
- unless _tmp
- self.pos = _save4
- break
- end
- while true
- _tmp = match_string("#")
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save4
- break
- end
- _tmp = apply(:_Sp)
- unless _tmp
- self.pos = _save4
- end
- break
- end # end sequence
- unless _tmp
- _tmp = true
- self.pos = _save3
- end
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Newline)
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; RDoc::Markup::Heading.new(s, a.join) ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
- set_failed_rule :_AtxHeading unless _tmp
- return _tmp
- end
- # SetextHeading = (SetextHeading1 | SetextHeading2)
- def _SetextHeading
- _save = self.pos
- while true # choice
- _tmp = apply(:_SetextHeading1)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_SetextHeading2)
- break if _tmp
- self.pos = _save
- break
- end # end choice
- set_failed_rule :_SetextHeading unless _tmp
- return _tmp
- end
- # SetextBottom1 = "===" "="* Newline
- def _SetextBottom1
- _save = self.pos
- while true # sequence
- _tmp = match_string("===")
- unless _tmp
- self.pos = _save
- break
- end
- while true
- _tmp = match_string("=")
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Newline)
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
- set_failed_rule :_SetextBottom1 unless _tmp
- return _tmp
- end
- # SetextBottom2 = "---" "-"* Newline
- def _SetextBottom2
- _save = self.pos
- while true # sequence
- _tmp = match_string("---")
- unless _tmp
- self.pos = _save
- break
- end
- while true
- _tmp = match_string("-")
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Newline)
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
- set_failed_rule :_SetextBottom2 unless _tmp
- return _tmp
- end
- # SetextHeading1 = &(RawLine SetextBottom1) StartList:a (!Endline Inline:b { a << b })+ Sp? Newline SetextBottom1 { RDoc::Markup::Heading.new(1, a.join) }
- def _SetextHeading1
- _save = self.pos
- while true # sequence
- _save1 = self.pos
- _save2 = self.pos
- while true # sequence
- _tmp = apply(:_RawLine)
- unless _tmp
- self.pos = _save2
- break
- end
- _tmp = apply(:_SetextBottom1)
- unless _tmp
- self.pos = _save2
- end
- break
- end # end sequence
- self.pos = _save1
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_StartList)
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- _save3 = self.pos
- _save4 = self.pos
- while true # sequence
- _save5 = self.pos
- _tmp = apply(:_Endline)
- _tmp = _tmp ? nil : true
- self.pos = _save5
- unless _tmp
- self.pos = _save4
- break
- end
- _tmp = apply(:_Inline)
- b = @result
- unless _tmp
- self.pos = _save4
- break
- end
- @result = begin; a << b ; end
- _tmp = true
- unless _tmp
- self.pos = _save4
- end
- break
- end # end sequence
- if _tmp
- while true
- _save6 = self.pos
- while true # sequence
- _save7 = self.pos
- _tmp = apply(:_Endline)
- _tmp = _tmp ? nil : true
- self.pos = _save7
- unless _tmp
- self.pos = _save6
- break
- end
- _tmp = apply(:_Inline)
- b = @result
- unless _tmp
- self.pos = _save6
- break
- end
- @result = begin; a << b ; end
- _tmp = true
- unless _tmp
- self.pos = _save6
- end
- break
- end # end sequence
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save3
- end
- unless _tmp
- self.pos = _save
- break
- end
- _save8 = self.pos
- _tmp = apply(:_Sp)
- unless _tmp
- _tmp = true
- self.pos = _save8
- end
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Newline)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_SetextBottom1)
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; RDoc::Markup::Heading.new(1, a.join) ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
- set_failed_rule :_SetextHeading1 unless _tmp
- return _tmp
- end
- # SetextHeading2 = &(RawLine SetextBottom2) StartList:a (!Endline Inline:b { a << b })+ Sp? Newline SetextBottom2 { RDoc::Markup::Heading.new(2, a.join) }
- def _SetextHeading2
- _save = self.pos
- while true # sequence
- _save1 = self.pos
- _save2 = self.pos
- while true # sequence
- _tmp = apply(:_RawLine)
- unless _tmp
- self.pos = _save2
- break
- end
- _tmp = apply(:_SetextBottom2)
- unless _tmp
- self.pos = _save2
- end
- break
- end # end sequence
- self.pos = _save1
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_StartList)
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- _save3 = self.pos
- _save4 = self.pos
- while true # sequence
- _save5 = self.pos
- _tmp = apply(:_Endline)
- _tmp = _tmp ? nil : true
- self.pos = _save5
- unless _tmp
- self.pos = _save4
- break
- end
- _tmp = apply(:_Inline)
- b = @result
- unless _tmp
- self.pos = _save4
- break
- end
- @result = begin; a << b ; end
- _tmp = true
- unless _tmp
- self.pos = _save4
- end
- break
- end # end sequence
- if _tmp
- while true
- _save6 = self.pos
- while true # sequence
- _save7 = self.pos
- _tmp = apply(:_Endline)
- _tmp = _tmp ? nil : true
- self.pos = _save7
- unless _tmp
- self.pos = _save6
- break
- end
- _tmp = apply(:_Inline)
- b = @result
- unless _tmp
- self.pos = _save6
- break
- end
- @result = begin; a << b ; end
- _tmp = true
- unless _tmp
- self.pos = _save6
- end
- break
- end # end sequence
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save3
- end
- unless _tmp
- self.pos = _save
- break
- end
- _save8 = self.pos
- _tmp = apply(:_Sp)
- unless _tmp
- _tmp = true
- self.pos = _save8
- end
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Newline)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_SetextBottom2)
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; RDoc::Markup::Heading.new(2, a.join) ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
- set_failed_rule :_SetextHeading2 unless _tmp
- return _tmp
- end
- # Heading = (SetextHeading | AtxHeading)
- def _Heading
- _save = self.pos
- while true # choice
- _tmp = apply(:_SetextHeading)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_AtxHeading)
- break if _tmp
- self.pos = _save
- break
- end # end choice
- set_failed_rule :_Heading unless _tmp
- return _tmp
- end
- # BlockQuote = BlockQuoteRaw:a { RDoc::Markup::BlockQuote.new(*a) }
- def _BlockQuote
- _save = self.pos
- while true # sequence
- _tmp = apply(:_BlockQuoteRaw)
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; RDoc::Markup::BlockQuote.new(*a) ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
- set_failed_rule :_BlockQuote unless _tmp
- return _tmp
- end
- # BlockQuoteRaw = StartList:a (">" " "? Line:l { a << l } (!">" !BlankLine Line:c { a << c })* (BlankLine:n { a << n })*)+ { inner_parse a.join }
- def _BlockQuoteRaw
- _save = self.pos
- while true # sequence
- _tmp = apply(:_StartList)
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- _save1 = self.pos
- _save2 = self.pos
- while true # sequence
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save2
- break
- end
- _save3 = self.pos
- _tmp = match_string(" ")
- unless _tmp
- _tmp = true
- self.pos = _save3
- end
- unless _tmp
- self.pos = _save2
- break
- end
- _tmp = apply(:_Line)
- l = @result
- unless _tmp
- self.pos = _save2
- break
- end
- @result = begin; a << l ; end
- _tmp = true
- unless _tmp
- self.pos = _save2
- break
- end
- while true
- _save5 = self.pos
- while true # sequence
- _save6 = self.pos
- _tmp = match_string(">")
- _tmp = _tmp ? nil : true
- self.pos = _save6
- unless _tmp
- self.pos = _save5
- break
- end
- _save7 = self.pos
- _tmp = apply(:_BlankLine)
- _tmp = _tmp ? nil : true
- self.pos = _save7
- unless _tmp
- self.pos = _save5
- break
- end
- _tmp = apply(:_Line)
- c = @result
- unless _tmp
- self.pos = _save5
- break
- end
- @result = begin; a << c ; end
- _tmp = true
- unless _tmp
- self.pos = _save5
- end
- break
- end # end sequence
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save2
- break
- end
- while true
- _save9 = self.pos
- while true # sequence
- _tmp = apply(:_BlankLine)
- n = @result
- unless _tmp
- self.pos = _save9
- break
- end
- @result = begin; a << n ; end
- _tmp = true
- unless _tmp
- self.pos = _save9
- end
- break
- end # end sequence
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save2
- end
- break
- end # end sequence
- if _tmp
- while true
- _save10 = self.pos
- while true # sequence
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save10
- break
- end
- _save11 = self.pos
- _tmp = match_string(" ")
- unless _tmp
- _tmp = true
- self.pos = _save11
- end
- unless _tmp
- self.pos = _save10
- break
- end
- _tmp = apply(:_Line)
- l = @result
- unless _tmp
- self.pos = _save10
- break
- end
- @result = begin; a << l ; end
- _tmp = true
- unless _tmp
- self.pos = _save10
- break
- end
- while true
- _save13 = self.pos
- while true # sequence
- _save14 = self.pos
- _tmp = match_string(">")
- _tmp = _tmp ? nil : true
- self.pos = _save14
- unless _tmp
- self.pos = _save13
- break
- end
- _save15 = self.pos
- _tmp = apply(:_BlankLine)
- _tmp = _tmp ? nil : true
- self.pos = _save15
- unless _tmp
- self.pos = _save13
- break
- end
- _tmp = apply(:_Line)
- c = @result
- unless _tmp
- self.pos = _save13
- break
- end
- @result = begin; a << c ; end
- _tmp = true
- unless _tmp
- self.pos = _save13
- end
- break
- end # end sequence
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save10
- break
- end
- while true
- _save17 = self.pos
- while true # sequence
- _tmp = apply(:_BlankLine)
- n = @result
- unless _tmp
- self.pos = _save17
- break
- end
- @result = begin; a << n ; end
- _tmp = true
- unless _tmp
- self.pos = _save17
- end
- break
- end # end sequence
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save10
- end
- break
- end # end sequence
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save1
- end
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; inner_parse a.join ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
- set_failed_rule :_BlockQuoteRaw unless _tmp
- return _tmp
- end
- # NonblankIndentedLine = !BlankLine IndentedLine
- def _NonblankIndentedLine
- _save = self.pos
- while true # sequence
- _save1 = self.pos
- _tmp = apply(:_BlankLine)
- _tmp = _tmp ? nil : true
- self.pos = _save1
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_IndentedLine)
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
- set_failed_rule :_NonblankIndentedLine unless _tmp
- return _tmp
- end
- # VerbatimChunk = BlankLine*:a NonblankIndentedLine+:b { a.concat b }
- def _VerbatimChunk
- _save = self.pos
- while true # sequence
- _ary = []
- while true
- _tmp = apply(:_BlankLine)
- _ary << @result if _tmp
- break unless _tmp
- end
- _tmp = true
- @result = _ary
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- _save2 = self.pos
- _ary = []
- _tmp = apply(:_NonblankIndentedLine)
- if _tmp
- _ary << @result
- while true
- _tmp = apply(:_NonblankIndentedLine)
- _ary << @result if _tmp
- break unless _tmp
- end
- _tmp = true
- @result = _ary
- else
- self.pos = _save2
- end
- b = @result
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; a.concat b ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
- set_failed_rule :_VerbatimChunk unless _tmp
- return _tmp
- end
- # Verbatim = VerbatimChunk+:a { RDoc::Markup::Verbatim.new(*a.flatten) }
- def _Verbatim
- _save = self.pos
- while true # sequence
- _save1 = self.pos
- _ary = []
- _tmp = apply(:_VerbatimChunk)
- if _tmp
- _ary << @result
- while true
- _tmp = apply(:_VerbatimChunk)
- _ary << @result if _tmp
- break unless _tmp
- end
- _tmp = true
- @result = _ary
- else
- self.pos = _save1
- end
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; RDoc::Markup::Verbatim.new(*a.flatten) ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
- set_failed_rule :_Verbatim unless _tmp
- return _tmp
- end
- # HorizontalRule = NonindentSpace ("*" Sp "*" Sp "*" (Sp "*")* | "-" Sp "-" Sp "-" (Sp "-")* | "_" Sp "_" Sp "_" (Sp "_")*) Sp Newline BlankLine+ { RDoc::Markup::Rule.new 1 }
- def _HorizontalRule
- _save = self.pos
- while true # sequence
- _tmp = apply(:_NonindentSpace)
- unless _tmp
- self.pos = _save
- break
- end
- _save1 = self.pos
- while true # choice
- _save2 = self.pos
- while true # sequence
- _tmp = match_string("*")
- unless _tmp
- self.pos = _save2
- break
- end
- _tmp = apply(:_Sp)
- unless _tmp
- self.pos = _save2
- break
- end
- _tmp = match_string("*")
- unless _tmp
- self.pos = _save2
- break
- end
- _tmp = apply(:_Sp)
- unless _tmp
- self.pos = _save2
- break
- end
- _tmp = match_string("*")
- unless _tmp
- self.pos = _save2
- break
- end
- while true
- _save4 = self.pos
- while true # sequence
- _tmp = apply(:_Sp)
- unless _tmp
- self.pos = _save4
- break
- end
- _tmp = match_string("*")
- unless _tmp
- self.pos = _save4
- end
- break
- end # end sequence
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save2
- end
- break
- end # end sequence
- break if _tmp
- self.pos = _save1
- _save5 = self.pos
- while true # sequence
- _tmp = match_string("-")
- unless _tmp
- self.pos = _save5
- break
- end
- _tmp = apply(:_Sp)
- unless _tmp
- self.pos = _save5
- break
- end
- _tmp = match_string("-")
- unless _tmp
- self.pos = _save5
- break
- end
- _tmp = apply(:_Sp)
- unless _tmp
- self.pos = _save5
- break
- end
- _tmp = match_string("-")
- unless _tmp
- self.pos = _save5
- break
- end
- while true
- _save7 = self.pos
- while true # sequence
- _tmp = apply(:_Sp)
- unless _tmp
- self.pos = _save7
- break
- end
- _tmp = match_string("-")
- unless _tmp
- self.pos = _save7
- end
- break
- end # end sequence
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save5
- end
- break
- end # end sequence
- break if _tmp
- self.pos = _save1
- _save8 = self.pos
- while true # sequence
- _tmp = match_string("_")
- unless _tmp
- self.pos = _save8
- break
- end
- _tmp = apply(:_Sp)
- unless _tmp
- self.pos = _save8
- break
- end
- _tmp = match_string("_")
- unless _tmp
- self.pos = _save8
- break
- end
- _tmp = apply(:_Sp)
- unless _tmp
- self.pos = _save8
- break
- end
- _tmp = match_string("_")
- unless _tmp
- self.pos = _save8
- break
- end
- while true
- _save10 = self.pos
- while true # sequence
- _tmp = apply(:_Sp)
- unless _tmp
- self.pos = _save10
- break
- end
- _tmp = match_string("_")
- unless _tmp
- self.pos = _save10
- end
- break
- end # end sequence
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save8
- end
- break
- end # end sequence
- break if _tmp
- self.pos = _save1
- break
- end # end choice
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Sp)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Newline)
- unless _tmp
- self.pos = _save
- break
- end
- _save11 = self.pos
- _tmp = apply(:_BlankLine)
- if _tmp
- while true
- _tmp = apply(:_BlankLine)
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save11
- end
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; RDoc::Markup::Rule.new 1 ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
- set_failed_rule :_HorizontalRule unless _tmp
- return _tmp
- end
- # Bullet = !HorizontalRule NonindentSpace ("+" | "*" | "-") Spacechar+
- def _Bullet
- _save = self.pos
- while true # sequence
- _save1 = self.pos
- _tmp = apply(:_HorizontalRule)
- _tmp = _tmp ? nil : true
- self.pos = _save1
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_NonindentSpace)
- unless _tmp
- self.pos = _save
- break
- end
- _save2 = self.pos
- while true # choice
- _tmp = match_string("+")
- break if _tmp
- self.pos = _save2
- _tmp = match_string("*")
- break if _tmp
- self.pos = _save2
- _tmp = match_string("-")
- break if _tmp
- self.pos = _save2
- break
- end # end choice
- unless _tmp
- self.pos = _save
- break
- end
- _save3 = self.pos
- _tmp = apply(:_Spacechar)
- if _tmp
- while true
- _tmp = apply(:_Spacechar)
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save3
- end
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
- set_failed_rule :_Bullet unless _tmp
- return _tmp
- end
- # BulletList = &Bullet (ListTight | ListLoose):a { RDoc::Markup::List.new(:BULLET, *a) }
- def _BulletList
- _save = self.pos
- while true # sequence
- _save1 = self.pos
- _tmp = apply(:_Bullet)
- self.pos = _save1
- unless _tmp
- self.pos = _save
- break
- end
- _save2 = self.pos
- while true # choice
- _tmp = apply(:_ListTight)
- break if _tmp
- self.pos = _save2
- _tmp = apply(:_ListLoose)
- break if _tmp
- self.pos = _save2
- break
- end # end choice
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; RDoc::Markup::List.new(:BULLET, *a) ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
- set_failed_rule :_BulletList unless _tmp
- return _tmp
- end
- # ListTight = ListItemTight+:a BlankLine* !(Bullet | Enumerator) { a }
- def _ListTight
- _save = self.pos
- while true # sequence
- _save1 = self.pos
- _ary = []
- _tmp = apply(:_ListItemTight)
- if _tmp
- _ary << @result
- while true
- _tmp = apply(:_ListItemTight)
- _ary << @result if _tmp
- break unless _tmp
- end
- _tmp = true
- @result = _ary
- else
- …
Large files files are truncated, but you can click here to view the full file