lib/rdoc/comment.rb in rdoc-6.5.1.1 vs lib/rdoc/comment.rb in rdoc-6.6.0
- old
+ new
@@ -4,13 +4,13 @@
# unified way of cleaning it up and parsing it into an RDoc::Markup::Document.
#
# Each comment may have a different markup format set by #format=. By default
# 'rdoc' is used. The :markup: directive tells RDoc which format to use.
#
-# See RDoc::Markup@Other+directives for instructions on adding an alternate
-# format.
+# See RDoc::MarkupReference@Directive+for+Specifying+RDoc+Source+Format.
+
class RDoc::Comment
include RDoc::Text
##
@@ -95,46 +95,30 @@
def extract_call_seq method
# we must handle situations like the above followed by an unindented first
# comment. The difficulty is to make sure not to match lines starting
# with ARGF at the same indent, but that are after the first description
# paragraph.
- if @text =~ /^\s*:?call-seq:(.*?(?:\S).*?)^\s*$/m then
- all_start, all_stop = $~.offset(0)
- seq_start, seq_stop = $~.offset(1)
+ if /^(?<S> ((?!\n)\s)*+ (?# whitespaces except newline))
+ :?call-seq:
+ (?<B> \g<S>(?<N>\n|\z) (?# trailing spaces))?
+ (?<seq>
+ (\g<S>(?!\w)\S.*\g<N>)*
+ (?>
+ (?<H> \g<S>\w+ (?# ' # ARGF' in the example above))
+ .*\g<N>)?
+ (\g<S>\S.*\g<N> (?# other non-blank line))*+
+ (\g<B>+(\k<H>.*\g<N> (?# ARGF.to_a lines))++)*+
+ )
+ (?m:^\s*$|\z)
+ /x =~ @text
+ seq = $~[:seq]
- # we get the following lines that start with the leading word at the
- # same indent, even if they have blank lines before
- if $1 =~ /(^\s*\n)+^(\s*\w+)/m then
- leading = $2 # ' * ARGF' in the example above
- re = %r%
- \A(
- (^\s*\n)+
- (^#{Regexp.escape leading}.*?\n)+
- )+
- ^\s*$
- %xm
-
- if @text[seq_stop..-1] =~ re then
- all_stop = seq_stop + $~.offset(0).last
- seq_stop = seq_stop + $~.offset(1).last
- end
- end
-
- seq = @text[seq_start..seq_stop]
- seq.gsub!(/^\s*(\S|\n)/m, '\1')
+ all_start, all_stop = $~.offset(0)
@text.slice! all_start...all_stop
- method.call_seq = seq.chomp
-
- else
- regexp = /^\s*:?call-seq:(.*?)(^\s*$|\z)/m
- if regexp =~ @text then
- @text = @text.sub(regexp, '')
- seq = $1
- seq.gsub!(/^\s*/, '')
- method.call_seq = seq
- end
+ seq.gsub!(/^\s*/, '')
+ method.call_seq = seq
end
method
end
@@ -147,15 +131,10 @@
##
# HACK dubious
def encode! encoding
- # TODO: Remove this condition after Ruby 2.2 EOL
- if RUBY_VERSION < '2.3.0'
- @text = @text.force_encoding encoding
- else
- @text = String.new @text, encoding: encoding
- end
+ @text = String.new @text, encoding: encoding
self
end
##
# Sets the format of this comment and resets any parsed document