Class: RDoc::RD::BlockParser (Ruby 2.2.4)
Description: Class : RDoc::RD::BlockParser - Ruby 2.2.4

- Home
- Core 2.2.4
- Std-lib 2.2.4
- Downloads

Support for the Ruby 2.2 series has ended. See here for reference.

### Home Classes Methods

### In Files

- rdoc/rd/block_parser.rb

### Parent

Racc::Parser

### Methods

- ::new
- #add_footnote
- #add_label
- #content
- #line_index
- #on_error
- #paragraph
- #parse

### Class/Module Index

Quicksearch

- RDoc
- RDoc::Alias
- RDoc::AnonClass
- RDoc::AnyMethod
- RDoc::Attr
- RDoc::ClassModule
- RDoc::CodeObject
- RDoc::Comment
- RDoc::Constant
- RDoc::Context
- RDoc::Context::Section
- RDoc::CrossReference
- RDoc::ERBIO
- RDoc::ERBPartial
- RDoc::Encoding
- RDoc::Error
- RDoc::Extend
- RDoc::Generator
- RDoc::Generator::Darkfish
- RDoc::Generator::JsonIndex
- RDoc::Generator::Markup
- RDoc::Generator::POT
- RDoc::Generator::POT::MessageExtractor
- RDoc::Generator::POT::PO
- RDoc::Generator::POT::POEntry
- RDoc::Generator::RI
- RDoc::GhostMethod
- RDoc::I18n
- RDoc::I18n::Locale
- RDoc::I18n::Text
- RDoc::Include
- RDoc::Markdown
- RDoc::Markdown::Literals
- RDoc::Markup
- RDoc::Markup::AttrChanger
- RDoc::Markup::AttrSpan
- RDoc::Markup::AttributeManager
- RDoc::Markup::Attributes
- RDoc::Markup::BlankLine
- RDoc::Markup::BlockQuote
- RDoc::Markup::Document
- RDoc::Markup::Formatter
- RDoc::Markup::FormatterTestCase
- RDoc::Markup::HardBreak
- RDoc::Markup::Include
- RDoc::Markup::IndentedParagraph
- RDoc::Markup::List
- RDoc::Markup::ListItem
- RDoc::Markup::Paragraph
- RDoc::Markup::Parser
- RDoc::Markup::Parser::Error
- RDoc::Markup::Parser::ParseError
- RDoc::Markup::PreProcess
- RDoc::Markup::Raw
- RDoc::Markup::Rule
- RDoc::Markup::Special
- RDoc::Markup::TextFormatterTestCase
- RDoc::Markup::ToAnsi
- RDoc::Markup::ToBs
- RDoc::Markup::ToHtml
- RDoc::Markup::ToHtmlCrossref
- RDoc::Markup::ToHtmlSnippet
- RDoc::Markup::ToJoinedParagraph
- RDoc::Markup::ToLabel
- RDoc::Markup::ToMarkdown
- RDoc::Markup::ToRdoc
- RDoc::Markup::ToTableOfContents
- RDoc::Markup::ToTest
- RDoc::Markup::ToTtOnly
- RDoc::Markup::Verbatim
- RDoc::MetaMethod
- RDoc::MethodAttr
- RDoc::Mixin
- RDoc::NormalClass
- RDoc::NormalModule
- RDoc::Options
- RDoc::Parser
- RDoc::Parser::C
- RDoc::Parser::ChangeLog
- RDoc::Parser::Markdown
- RDoc::Parser::RD
- RDoc::Parser::Ruby
- RDoc::Parser::RubyTools
- RDoc::Parser::Simple
- RDoc::Parser::Text
- RDoc::RD
- RDoc::RD::BlockParser
- RDoc::RD::Inline
- RDoc::RD::InlineParser
- RDoc::RDoc
- RDoc::RI
- RDoc::RI::Driver
- RDoc::RI::Driver::Error
- RDoc::RI::Driver::NotFoundError
- RDoc::RI::Error
- RDoc::RI::Paths
- RDoc::RI::Task
- RDoc::Require
- RDoc::RubyLex
- RDoc::RubyLex::Error
- RDoc::RubyToken
- RDoc::RubygemsHook
- RDoc::Servlet
- RDoc::SingleClass
- RDoc::Stats
- RDoc::Stats::Normal
- RDoc::Stats::Quiet
- RDoc::Stats::Verbose
- RDoc::Store
- RDoc::Store::Error
- RDoc::Store::MissingFileError
- RDoc::Task
- RDoc::TestCase
- RDoc::Text
- RDoc::TokenStream
- RDoc::TomDoc
- RDoc::TopLevel
- RDocTask
- Test

No matching classes.

# RDoc::RD::BlockParser

RD format parser for headings, paragraphs, lists, verbatim sections that exist as blocks.

### Attributes

footnotes[R]

Footnotes for this document

include_path[RW]

Path to find included files in

labels[R]

Labels for items in this document

### Public Class Methods

new() click to toggle source

Creates a new RDoc::RD::BlockParser. Use parse to parse an rd-format document.

                   # File rdoc/rd/block_parser.rb, line 52
    def initialize
      @inline_parser = RDoc::RD::InlineParser.new self
      @include_path = []

      # for testing
      @footnotes = []
      @labels    = {}
    end

### Public Instance Methods

add_footnote(content) click to toggle source

Adds footnote `content` to the document

                   # File rdoc/rd/block_parser.rb, line 396
    def add_footnote content
      index = @footnotes.length / 2 + 1

      footmark_link = "{^#{index}}[rdoc-label:footmark-#{index}:foottext-#{index}]"

      @footnotes << RDoc::Markup::Paragraph.new(footmark_link, ' ', *content)
      @footnotes << RDoc::Markup::BlankLine.new

      index
    end

add_label(label) click to toggle source

Adds label `label` to the document

                   # File rdoc/rd/block_parser.rb, line 410
    def add_label label
      @labels[label] = true

      label
    end

content(values) click to toggle source

Retrieves the content of `values` as a single String

                   # File rdoc/rd/block_parser.rb, line 379
    def content values
     values.map { |value| value.content }.join
    end

line_index() click to toggle source

Current line number

                   # File rdoc/rd/block_parser.rb, line 334
    def line_index
      @i
    end

on_error(et, ev, _values) click to toggle source

Raises a ParseError when invalid formatting is found

                   # File rdoc/rd/block_parser.rb, line 318
    def on_error(et, ev, _values)
      prv, cur, nxt = format_line_num(@i, @i+1, @i+2)

      raise ParseError, <<Msg

    RD syntax error: line #{@i+1}:
      #{prv}  |#{@src[@i-1].chomp}
      #{cur}=>|#{@src[@i].chomp}
      #{nxt}  |#{@src[@i+1].chomp}

    Msg
    end

paragraph(value) click to toggle source

Creates a paragraph for `value`

                   # File rdoc/rd/block_parser.rb, line 386
    def paragraph value
      content = cut_off(value).join(' ').rstrip
      contents = @inline_parser.parse content

      RDoc::Markup::Paragraph.new(*contents)
    end

parse(src) click to toggle source

Parses `src` and returns an RDoc::Markup::Document.

                   # File rdoc/rd/block_parser.rb, line 64
    def parse src
      @src = src
      @src.push false

      @footnotes = []
      @labels    = {}

      # @i: index(line no.) of src
      @i = 0

      # stack for current indentation
      @indent_stack = []

      # how indented.
      @current_indent = @indent_stack.join("")

      # RDoc::RD::BlockParser for tmp src
      @subparser = nil

      # which part is in now
      @in_part = nil
      @part_content = []

      @in_verbatim = false

      @yydebug = true

      document = do_parse

      unless @footnotes.empty? then
        blankline = document.parts.pop

        document.parts << RDoc::Markup::Rule.new(1)
        document.parts.concat @footnotes

        document.parts.push blankline
      end

      document
    end