123456789_123456789_123456789_123456789_123456789_

Class: RDoc::RD::InlineParser

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: Racc::Parser
Defined in: lib/rdoc/rd/inline_parser.rb

Overview

::RDoc::RD format parser for inline markup such as emphasis, links, footnotes, etc.

Constant Summary

::Racc::Parser - Inherited

Racc_Runtime_Core_Version_R, Racc_Runtime_Version

Class Method Summary

::Racc::Parser - Inherited

.racc_runtime_type

See additional method definition at file lib/rdoc/rd/block_parser.rb line 239.

Instance Method Summary

::Racc::Parser - Inherited

#_racc_do_parse_rb

See additional method definition at file lib/rdoc/rd/block_parser.rb line 302.

#_racc_do_reduce

See additional method definition at file lib/rdoc/rd/block_parser.rb line 502.

#_racc_evalact

common.

#_racc_init_sysvars

See additional method definition at file lib/rdoc/rd/block_parser.rb line 255.

#_racc_setup

See additional method definition at file lib/rdoc/rd/block_parser.rb line 243.

#_racc_yyparse_rb

See additional method definition at file lib/rdoc/rd/block_parser.rb line 352.

#next_token

The method to fetch next token.

#on_error

This method is called when a parse error is found.

#racc_accept

See additional method definition at file lib/rdoc/rd/block_parser.rb line 607.

#racc_e_pop

See additional method definition at file lib/rdoc/rd/block_parser.rb line 612.

#racc_next_state

See additional method definition at file lib/rdoc/rd/block_parser.rb line 619.

#racc_print_stacks

See additional method definition at file lib/rdoc/rd/block_parser.rb line 625.

#racc_print_states

See additional method definition at file lib/rdoc/rd/block_parser.rb line 634.

#racc_read_token

For debugging output.

#racc_reduce

See additional method definition at file lib/rdoc/rd/block_parser.rb line 594.

#racc_shift

See additional method definition at file lib/rdoc/rd/block_parser.rb line 588.

#racc_token2str

See additional method definition at file lib/rdoc/rd/block_parser.rb line 641.

#token_to_str

Convert internal ID of token symbol to the string.

#yyaccept

Exit parser.

#yyerrok

Leave error recovering mode.

#yyerror

Enter error recovering mode.

Constructor Details

.new(block_parser) ⇒ InlineParser

Creates a new parser for inline markup in the rd format. The block_parser is used to for footnotes and labels in the inline text.

[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 738

def initialize block_parser
  @block_parser = block_parser
end

Instance Method Details

#_reduce_101(val, _values, result)

This method is for internal use only.

reduce 100 omitted

[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1750

def _reduce_101(val, _values, result)
      index = @block_parser.add_footnote val[1].rdoc
      result = "{*#{index}}[rdoc-label:foottext-#{index}:footmark-#{index}]"

    result
end

#_reduce_102(val, _values, result)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1757

def _reduce_102(val, _values, result)
      result = inline "<tt>#{val[1]}</tt>", val[1]

    result
end

#_reduce_109(val, _values, result)

This method is for internal use only.

reduce 108 omitted

[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1775

def _reduce_109(val, _values, result)
 result << val[1]
    result
end

#_reduce_111(val, _values, result)

This method is for internal use only.

reduce 110 omitted

[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1782

def _reduce_111(val, _values, result)
      result = inline val[0]

    result
end

#_reduce_113(val, _values, result)

This method is for internal use only.

reduce 112 omitted

[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1790

def _reduce_113(val, _values, result)
 result = val[1]
    result
end

#_reduce_114(val, _values, result)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1795

def _reduce_114(val, _values, result)
 result = val[1]
    result
end

#_reduce_115(val, _values, result)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1800

def _reduce_115(val, _values, result)
 result = val[1]
    result
end

#_reduce_13(val, _values, result)

This method is for internal use only.

reduce 12 omitted

[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1413

def _reduce_13(val, _values, result)
      content = val[1]
      result = inline "<em>#{content}</em>", content

    result
end

#_reduce_136(val, _values, result)

This method is for internal use only.

reduce 135 omitted

[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1845

def _reduce_136(val, _values, result)
 result << val[1]
    result
end

#_reduce_14(val, _values, result)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1420

def _reduce_14(val, _values, result)
      content = val[1]
      result = inline "<code>#{content}</code>", content

    result
end

#_reduce_15(val, _values, result)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1427

def _reduce_15(val, _values, result)
      content = val[1]
      result = inline "#{content}", content

    result
end

#_reduce_16(val, _values, result)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1434

def _reduce_16(val, _values, result)
      content = val[1]
      result = inline "<tt>#{content}</tt>", content

    result
end

#_reduce_17(val, _values, result)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1441

def _reduce_17(val, _values, result)
      label = val[1]
      @block_parser.add_label label.reference
      result = "<span id=\"label-#{label}\">#{label}</span>"

    result
end

#_reduce_18(val, _values, result)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1449

def _reduce_18(val, _values, result)
      result = "{#{val[1]}}[#{val[2].join}]"

    result
end

#_reduce_19(val, _values, result)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1455

def _reduce_19(val, _values, result)
      scheme, inline = val[1]

      result = "{#{inline}}[#{scheme}#{inline.reference}]"

    result
end

#_reduce_2(val, _values, result)

This method is for internal use only.

reduce 1 omitted

[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1385

def _reduce_2(val, _values, result)
 result.append val[1]
    result
end

#_reduce_20(val, _values, result)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1463

def _reduce_20(val, _values, result)
      result = [nil, inline(val[1])]

    result
end

#_reduce_21(val, _values, result)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1469

def _reduce_21(val, _values, result)
      result = [
        'rdoc-label:',
        inline("#{val[0].reference}/#{val[1].reference}")
      ]

    result
end

#_reduce_22(val, _values, result)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1478

def _reduce_22(val, _values, result)
      result = ['rdoc-label:', val[0].reference]

    result
end

#_reduce_23(val, _values, result)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1484

def _reduce_23(val, _values, result)
      result = ['rdoc-label:', "#{val[0].reference}/"]

    result
end

#_reduce_24(val, _values, result)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1490

def _reduce_24(val, _values, result)
      result = [nil, inline(val[1])]

    result
end

#_reduce_25(val, _values, result)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1496

def _reduce_25(val, _values, result)
      result = [
        'rdoc-label:',
        inline("#{val[0].reference}/#{val[1].reference}")
      ]

    result
end

#_reduce_26(val, _values, result)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1505

def _reduce_26(val, _values, result)
      result = ['rdoc-label:', val[0]]

    result
end

#_reduce_27(val, _values, result)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1511

def _reduce_27(val, _values, result)
      ref = val[0].reference
      result = ['rdoc-label:', inline(ref, "#{ref}/")]

    result
end

#_reduce_29(val, _values, result)

This method is for internal use only.

reduce 28 omitted

[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1520

def _reduce_29(val, _values, result)
 result = val[1]
    result
end

#_reduce_3(val, _values, result)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1390

def _reduce_3(val, _values, result)
 result = val[0]
    result
end

#_reduce_30(val, _values, result)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1525

def _reduce_30(val, _values, result)
 result = val[1]
    result
end

#_reduce_31(val, _values, result)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1530

def _reduce_31(val, _values, result)
      result = inline val[0]

    result
end

#_reduce_32(val, _values, result)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1536

def _reduce_32(val, _values, result)
      result = inline "\"#{val[1]}\""

    result
end

#_reduce_33(val, _values, result)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1542

def _reduce_33(val, _values, result)
      result = inline val[0]

    result
end

#_reduce_34(val, _values, result)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1548

def _reduce_34(val, _values, result)
      result = inline "\"#{val[1]}\""

    result
end

#_reduce_36(val, _values, result)

This method is for internal use only.

reduce 35 omitted

[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1556

def _reduce_36(val, _values, result)
 result = val[1]
    result
end

#_reduce_37(val, _values, result)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1561

def _reduce_37(val, _values, result)
 result = inline val[1]
    result
end

#_reduce_38(val, _values, result)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1566

def _reduce_38(val, _values, result)
      result = val[0].append val[1]

    result
end

#_reduce_39(val, _values, result)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1572

def _reduce_39(val, _values, result)
      result = val[0].append val[1]

    result
end

#_reduce_40(val, _values, result)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1578

def _reduce_40(val, _values, result)
      result = val[0]

    result
end

#_reduce_41(val, _values, result)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1584

def _reduce_41(val, _values, result)
      result = inline val[0]

    result
end

#_reduce_43(val, _values, result)

This method is for internal use only.

reduce 42 omitted

[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1592

def _reduce_43(val, _values, result)
      result = val[0].append val[1]

    result
end

#_reduce_44(val, _values, result)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1598

def _reduce_44(val, _values, result)
      result = inline val[0]

    result
end

#_reduce_45(val, _values, result)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1604

def _reduce_45(val, _values, result)
      result = val[0].append val[1]

    result
end

#_reduce_46(val, _values, result)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1610

def _reduce_46(val, _values, result)
      result = val[0]

    result
end

#_reduce_57(val, _values, result)

This method is for internal use only.

reduce 56 omitted

[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1636

def _reduce_57(val, _values, result)
      result = val[0]

    result
end

#_reduce_58(val, _values, result)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1642

def _reduce_58(val, _values, result)
      result = inline val[0]

    result
end

#_reduce_59(val, _values, result)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1648

def _reduce_59(val, _values, result)
      result = inline val[0]

    result
end

#_reduce_60(val, _values, result)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1654

def _reduce_60(val, _values, result)
 result << val[1]
    result
end

#_reduce_62(val, _values, result)

This method is for internal use only.

reduce 61 omitted

[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1661

def _reduce_62(val, _values, result)
      result << val[1]

    result
end

#_reduce_64(val, _values, result)

This method is for internal use only.

reduce 63 omitted

[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1669

def _reduce_64(val, _values, result)
      result << val[1]

    result
end

#_reduce_78(val, _values, result)

This method is for internal use only.

reduce 77 omitted

[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1701

def _reduce_78(val, _values, result)
 result << val[1]
    result
end

#_reduce_none(val, _values, result)

This method is for internal use only.

reduce 137 omitted

[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 1852

def _reduce_none(val, _values, result)
  val[0]
end

#inline(rdoc, reference = rdoc)

Creates a new Inline for the rdoc markup and the raw reference

[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 887

def inline rdoc, reference = rdoc
  RDoc::RD::Inline.new rdoc, reference
end

#last_line(src) (private)

Returns the last line of src

[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 864

def last_line(src)
  if n = src.rindex("\n")
    src[(n+1) .. -1]
  else
    src
  end
end

#next_token

Returns the next token from the inline text

[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 756

def next_token
  return [false, false] if @src.eos?
#  p @src.rest if @yydebug
  if ret = @src.scan(EM_OPEN_RE)
    @pre << ret
    [:EM_OPEN, ret]
  elsif ret = @src.scan(EM_CLOSE_RE)
    @pre << ret
    [:EM_CLOSE, ret]
  elsif ret = @src.scan(CODE_OPEN_RE)
    @pre << ret
    [:CODE_OPEN, ret]
  elsif ret = @src.scan(CODE_CLOSE_RE)
    @pre << ret
    [:CODE_CLOSE, ret]
  elsif ret = @src.scan(VAR_OPEN_RE)
    @pre << ret
    [:VAR_OPEN, ret]
  elsif ret = @src.scan(VAR_CLOSE_RE)
    @pre << ret
    [:VAR_CLOSE, ret]
  elsif ret = @src.scan(KBD_OPEN_RE)
    @pre << ret
    [:KBD_OPEN, ret]
  elsif ret = @src.scan(KBD_CLOSE_RE)
    @pre << ret
    [:KBD_CLOSE, ret]
  elsif ret = @src.scan(INDEX_OPEN_RE)
    @pre << ret
    [:INDEX_OPEN, ret]
  elsif ret = @src.scan(INDEX_CLOSE_RE)
    @pre << ret
    [:INDEX_CLOSE, ret]
  elsif ret = @src.scan(REF_OPEN_RE)
    @pre << ret
    [:REF_OPEN, ret]
  elsif ret = @src.scan(REF_CLOSE_RE)
    @pre << ret
    [:REF_CLOSE, ret]
  elsif ret = @src.scan(FOOTNOTE_OPEN_RE)
    @pre << ret
    [:FOOTNOTE_OPEN, ret]
  elsif ret = @src.scan(FOOTNOTE_CLOSE_RE)
    @pre << ret
    [:FOOTNOTE_CLOSE, ret]
  elsif ret = @src.scan(VERB_OPEN_RE)
    @pre << ret
    [:VERB_OPEN, ret]
  elsif ret = @src.scan(VERB_CLOSE_RE)
    @pre << ret
    [:VERB_CLOSE, ret]
  elsif ret = @src.scan(BAR_RE)
    @pre << ret
    [:BAR, ret]
  elsif ret = @src.scan(QUOTE_RE)
    @pre << ret
    [:QUOTE, ret]
  elsif ret = @src.scan(SLASH_RE)
    @pre << ret
    [:SLASH, ret]
  elsif ret = @src.scan(BACK_SLASH_RE)
    @pre << ret
    [:BACK_SLASH, ret]
  elsif ret = @src.scan(URL_RE)
    @pre << ret
    [:URL, ret]
  elsif ret = @src.scan(OTHER_RE)
    @pre << ret
    [:OTHER, ret]
  else
    ret = @src.rest
    @pre << ret
    @src.terminate
    [:OTHER, ret]
  end
end

#next_words_on_error

Returns words following an error

[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 876

def next_words_on_error
  if n = @src.rest.index("\n")
    @src.rest[0 .. (n-1)]
  else
    @src.rest
  end
end

#on_error(et, ev, values)

Raises a ParseError when invalid formatting is found

Raises:

[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 836

def on_error(et, ev, values)
  lines_of_rest = @src.rest.lines.to_a.length
  prev_words = prev_words_on_error(ev)
  at = 4 + prev_words.length

  message = <<-MSG
RD syntax error: line #{@block_parser.line_index - lines_of_rest}:
#...#{prev_words} #{(ev||'')} #{next_words_on_error()} ...
  MSG

  message << " " * at + "^" * (ev ? ev.length : 0) + "\n"
  raise ParseError, message
end

#parse(inline)

Parses the #inline text from ::RDoc::RD format into ::RDoc::RDoc format.

[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 745

def parse inline
  @inline = inline
  @src = StringScanner.new inline
  @pre = "".dup
  @yydebug = true
  do_parse.to_s
end

#prev_words_on_error(ev)

Returns words before the error

[ GitHub ]

  
# File 'lib/rdoc/rd/inline_parser.rb', line 853

def prev_words_on_error(ev)
  pre = @pre
  if ev and /#{Regexp.quote(ev)}$/ =~ pre
    pre = $`
  end
  last_line(pre)
end