@@ -234,7 +234,9 @@ def tomdoc?
234
234
# There are more, but already handled by RDoc::Parser::C
235
235
COLON_LESS_DIRECTIVES = %w[ call-seq Document-method ] . freeze # :nodoc:
236
236
237
- private_constant :MULTILINE_DIRECTIVES , :COLON_LESS_DIRECTIVES
237
+ DIRECTIVE_OR_ESCAPED_DIRECTIV_REGEXP = /\A (?<colon>\\ ?:|:?)(?<directive>[\w -]+):(?<param>.*)/
238
+
239
+ private_constant :MULTILINE_DIRECTIVES , :COLON_LESS_DIRECTIVES , :DIRECTIVE_OR_ESCAPED_DIRECTIV_REGEXP
238
240
239
241
class << self
240
242
@@ -271,7 +273,7 @@ def from_document(document) # :nodoc:
271
273
# # private comment
272
274
# #++
273
275
274
- def parse ( text , filename , line_no , type )
276
+ def parse ( text , filename , line_no , type , & include_callback )
275
277
case type
276
278
when :ruby
277
279
text = text . gsub ( /^#+/ , '' ) if text . start_with? ( '#' )
@@ -283,8 +285,6 @@ def parse(text, filename, line_no, type)
283
285
private_end_regexp = /^(\s *\* )?\+ {2}$/
284
286
indent_regexp = /^\s *(\/ \* +|\* )?\s */
285
287
text = text . gsub ( /\s *\* +\/ \s *\z / , '' )
286
- # TODO: should not be here. Looks like another type of directive
287
- # text = text.gsub %r%Document-method:\s+[\w:.#=!?|^&<>~+\-/*\%@`\[\]]+%, ''
288
288
when :simple
289
289
# Unlike other types, this implementation only looks for two dashes at
290
290
# the beginning of the line. Three or more dashes are considered to be
@@ -302,10 +302,12 @@ def parse(text, filename, line_no, type)
302
302
line = lines . shift
303
303
read_lines = 1
304
304
if in_private
305
+ # If `++` appears in a private section that starts with `--`, private section ends.
305
306
in_private = false if line . match? ( private_end_regexp )
306
307
line_no += read_lines
307
308
next
308
309
elsif line . match? ( private_start_regexp )
310
+ # If `--` appears in a line, private section starts.
309
311
in_private = true
310
312
line_no += read_lines
311
313
next
@@ -314,20 +316,29 @@ def parse(text, filename, line_no, type)
314
316
prefix = line [ indent_regexp ]
315
317
prefix_indent = ' ' * prefix . size
316
318
line = line . byteslice ( prefix . bytesize ..)
317
- /\A (?<colon>\\ ?:|:?)(?<directive>[\w -]+):(?<param>.*)/ =~ line
318
319
319
- if colon == '\\:'
320
- # unescape if escaped
320
+ if ( directive_match = DIRECTIVE_OR_ESCAPED_DIRECTIV_REGEXP . match ( line ) )
321
+ colon = directive_match [ :colon ]
322
+ directive = directive_match [ :directive ]
323
+ raw_param = directive_match [ :param ]
324
+ param = raw_param . strip
325
+ else
326
+ colon = directive = raw_param = param = nil
327
+ end
328
+
329
+ if !directive
330
+ comment_lines << prefix_indent + line
331
+ elsif colon == '\\:'
332
+ # If directive is escaped, unescape it
321
333
comment_lines << prefix_indent + line . sub ( '\\:' , ':' )
322
- elsif ! directive || param . start_with? ( ':' ) || ( colon . empty? && !COLON_LESS_DIRECTIVES . include? ( directive ) )
334
+ elsif raw_param . start_with? ( ':' ) || ( colon . empty? && !COLON_LESS_DIRECTIVES . include? ( directive ) )
323
335
# Something like `:toto::` is not a directive
324
336
# Only few directives allows to start without a colon
325
337
comment_lines << prefix_indent + line
326
338
elsif directive == 'include'
327
- filename_to_include = param . strip
328
- yield ( filename_to_include , prefix_indent ) . lines . each { |l | comment_lines << l . chomp }
339
+ filename_to_include = param
340
+ include_callback . call ( filename_to_include , prefix_indent ) . lines . each { |l | comment_lines << l . chomp }
329
341
elsif MULTILINE_DIRECTIVES . include? ( directive )
330
- param = param . strip
331
342
value_lines = take_multiline_directive_value_lines ( directive , filename , line_no , lines , prefix_indent . size , indent_regexp , !param . empty? )
332
343
read_lines += value_lines . size
333
344
lines . shift ( value_lines . size )
@@ -338,8 +349,7 @@ def parse(text, filename, line_no, type)
338
349
value = value_lines . join ( "\n " )
339
350
directives [ directive ] = [ value . empty? ? nil : value , line_no ]
340
351
else
341
- value = param . strip
342
- directives [ directive ] = [ value . empty? ? nil : value , line_no ]
352
+ directives [ directive ] = [ param . empty? ? nil : param , line_no ]
343
353
end
344
354
line_no += read_lines
345
355
end
0 commit comments