228228
229229---- inner
230230
231+ # :stopdoc:
232+
231233TMPFILE = ["rdtmp", $$, 0]
232234
233235MARK_TO_LEVEL = {
@@ -239,10 +241,27 @@ MARK_TO_LEVEL = {
239241 '++' => 6,
240242}
241243
244+ # :startdoc:
245+
246+ ##
247+ # Footnotes for this document
248+
242249attr_reader :footnotes
250+
251+ ##
252+ # Labels for items in this document
253+
243254attr_reader :labels
255+
256+ ##
257+ # Path to find included files in
258+
244259attr_accessor :include_path
245260
261+ ##
262+ # Creates a new RDoc::RD::BlockParser. Use #parse to parse an rd-format
263+ # document.
264+
246265def initialize
247266 @inline_parser = RDoc::RD::InlineParser.new self
248267 @include_path = []
@@ -252,6 +271,9 @@ def initialize
252271 @labels = {}
253272end
254273
274+ ##
275+ # Parses +src+ and returns an RDoc::Markup::Document.
276+
255277def parse src
256278 @src = src
257279 @src.push false
@@ -293,7 +315,10 @@ def parse src
293315 document
294316end
295317
296- def next_token
318+ ##
319+ # Returns the next token from the document
320+
321+ def next_token # :nodoc:
297322 # preprocessing
298323 # if it is not in RD part
299324 # => method
@@ -445,12 +470,10 @@ def next_token
445470 end
446471end
447472
448- =begin private
449- --- RDParser#if_current_indent_equal(indent)
450- if (({@current_indent == ((|indent|))})) then yield block, otherwise
451- process indentation.
452- =end
453- # always @current_indent = @indent_stack.join("")
473+ ##
474+ # Yields to the given block if +indent+ matches the current indent, otherwise
475+ # an indentation token is processed.
476+
454477def if_current_indent_equal(indent)
455478 indent = indent.sub(/\t/, "\s" * 8)
456479 if @current_indent == indent
@@ -466,6 +489,9 @@ def if_current_indent_equal(indent)
466489end
467490private :if_current_indent_equal
468491
492+ ##
493+ # Cuts off excess whitespace in +src+
494+
469495def cut_off(src)
470496 ret = []
471497 whiteline_buf = []
@@ -499,6 +525,9 @@ def set_term_to_element(parent, term)
499525end
500526private :set_term_to_element
501527
528+ ##
529+ # Raises a ParseError
530+
502531def on_error(et, ev, _values)
503532 prv, cur, nxt = format_line_num(@i, @i+1, @i+2)
504533
@@ -512,17 +541,26 @@ RD syntax error: line #{@i+1}:
512541Msg
513542end
514543
544+ ##
545+ # Current line number
546+
515547def line_index
516548 @i
517549end
518550
551+ ##
552+ # Parses subtree +src+
553+
519554def parse_subtree src
520555 @subparser ||= RDoc::RD::BlockParser.new
521556
522557 @subparser.parse src
523558end
524559private :parse_subtree
525560
561+ ##
562+ # Retrieves the content for +file+ from the include_path
563+
526564def get_included(file)
527565 included = []
528566
@@ -539,23 +577,35 @@ def get_included(file)
539577end
540578private :get_included
541579
542- def format_line_num(*args)
543- width = args.collect{|i| i.to_s.length }.max
544- args.collect{|i| sprintf("%#{width}d", i) }
580+ ##
581+ # Formats line numbers +line_numbers+ prettily
582+
583+ def format_line_num(*line_numbers)
584+ width = line_numbers.collect{|i| i.to_s.length }.max
585+ line_numbers.collect{|i| sprintf("%#{width}d", i) }
545586end
546587private :format_line_num
547588
589+ ##
590+ # Retrieves the content of +values+ as a single String
591+
548592def content values
549593 values.map { |value| value.content }.join
550594end
551595
596+ ##
597+ # Creates a paragraph for +value+
598+
552599def paragraph value
553600 content = cut_off(value).join(' ').rstrip
554601 contents = @inline_parser.parse content
555602
556603 RDoc::Markup::Paragraph.new(*contents)
557604end
558605
606+ ##
607+ # Adds footnote +content+ to the document
608+
559609def add_footnote content
560610 index = @footnotes.length + 1
561611
@@ -566,6 +616,9 @@ def add_footnote content
566616 index
567617end
568618
619+ ##
620+ # Adds label +label+ to the document
621+
569622def add_label label
570623 @labels[label] = true
571624
0 commit comments