lib/rdoc/rd/inline_parser.ry in rdoc-3.10.pre.1 vs lib/rdoc/rd/inline_parser.ry in rdoc-3.10.pre.2

- old
+ new

@@ -420,29 +420,32 @@ #{Regexp.quote(BACK_SLASH)}| #{Regexp.quote(URL)})", other_re_mode) # :startdoc: +## +# 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. + def initialize block_parser @block_parser = block_parser end +## +# Parses the +inline+ text from RD format into RDoc format. + def parse inline @inline = inline @src = StringScanner.new inline @pre = "" @yydebug = true do_parse.to_s -rescue - puts $! - puts - puts @inline[0, @src.pos].inspect - puts @src.rest[0..40] - puts - raise end +## +# Returns the next token from the inline text + def next_token return [false, false] if @src.eos? # p @src.rest if @yydebug if ret = @src.scan(EM_OPEN_RE) @pre << ret @@ -516,10 +519,13 @@ @src.terminate [:OTHER, ret] end end +## +# Raises a ParseError when invalid formatting is found + 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 @@ -530,33 +536,45 @@ message << " " * at + "^" * (ev ? ev.length : 0) + "\n" raise ParseError, message end +## +# Returns words before the error + def prev_words_on_error(ev) pre = @pre if ev and /#{Regexp.quote(ev)}$/ =~ pre pre = $` end last_line(pre) end +## +# Returns the last line of +src+ + def last_line(src) if n = src.rindex("\n") src[(n+1) .. -1] else src end end private :last_line +## +# Returns words following an error + def next_words_on_error if n = @src.rest.index("\n") @src.rest[0 .. (n-1)] else @src.rest end end + +## +# Creates a new RDoc::RD::Inline for the +rdoc+ markup and the raw +reference+ def inline rdoc, reference = rdoc RDoc::RD::Inline.new rdoc, reference end