rdoc 6.15.1 → 6.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/History.rdoc +1 -1
- data/lib/rdoc/code_object/top_level.rb +18 -17
- data/lib/rdoc/comment.rb +190 -8
- data/lib/rdoc/generator/aliki.rb +42 -0
- data/lib/rdoc/generator/template/aliki/_aside_toc.rhtml +8 -0
- data/lib/rdoc/generator/template/aliki/_footer.rhtml +23 -0
- data/lib/rdoc/generator/template/aliki/_head.rhtml +91 -0
- data/lib/rdoc/generator/template/aliki/_header.rhtml +56 -0
- data/lib/rdoc/generator/template/aliki/_sidebar_ancestors.rhtml +6 -0
- data/lib/rdoc/generator/template/aliki/_sidebar_classes.rhtml +5 -0
- data/lib/rdoc/generator/template/aliki/_sidebar_extends.rhtml +15 -0
- data/lib/rdoc/generator/template/aliki/_sidebar_includes.rhtml +15 -0
- data/lib/rdoc/generator/template/aliki/_sidebar_installed.rhtml +16 -0
- data/lib/rdoc/generator/template/aliki/_sidebar_methods.rhtml +21 -0
- data/lib/rdoc/generator/template/aliki/_sidebar_pages.rhtml +37 -0
- data/lib/rdoc/generator/template/aliki/_sidebar_search.rhtml +15 -0
- data/lib/rdoc/generator/template/aliki/_sidebar_sections.rhtml +11 -0
- data/lib/rdoc/generator/template/aliki/_sidebar_toggle.rhtml +3 -0
- data/lib/rdoc/generator/template/aliki/class.rhtml +219 -0
- data/lib/rdoc/generator/template/aliki/css/rdoc.css +1612 -0
- data/lib/rdoc/generator/template/aliki/index.rhtml +21 -0
- data/lib/rdoc/generator/template/aliki/js/aliki.js +483 -0
- data/lib/rdoc/generator/template/aliki/js/c_highlighter.js +299 -0
- data/lib/rdoc/generator/template/aliki/js/search.js +120 -0
- data/lib/rdoc/generator/template/aliki/js/theme-toggle.js +112 -0
- data/lib/rdoc/generator/template/aliki/page.rhtml +17 -0
- data/lib/rdoc/generator/template/aliki/servlet_not_found.rhtml +14 -0
- data/lib/rdoc/generator/template/aliki/servlet_root.rhtml +65 -0
- data/lib/rdoc/generator/template/darkfish/_head.rhtml +2 -7
- data/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml +1 -0
- data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +1 -1
- data/lib/rdoc/generator/template/json_index/js/searcher.js +5 -1
- data/lib/rdoc/generator.rb +1 -0
- data/lib/rdoc/markup/pre_process.rb +34 -10
- data/lib/rdoc/markup/to_html.rb +6 -4
- data/lib/rdoc/options.rb +21 -10
- data/lib/rdoc/parser/c.rb +15 -46
- data/lib/rdoc/parser/prism_ruby.rb +121 -113
- data/lib/rdoc/parser/ruby.rb +8 -8
- data/lib/rdoc/parser/ruby_tools.rb +5 -7
- data/lib/rdoc/parser/simple.rb +4 -21
- data/lib/rdoc/rdoc.rb +1 -0
- data/lib/rdoc/text.rb +1 -1
- data/lib/rdoc/token_stream.rb +13 -1
- data/lib/rdoc/tom_doc.rb +1 -1
- data/lib/rdoc/version.rb +1 -1
- metadata +27 -2
|
@@ -98,9 +98,9 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
|
|
|
98
98
|
prepare_comments(result.comments)
|
|
99
99
|
return if @top_level.done_documenting
|
|
100
100
|
|
|
101
|
-
@
|
|
102
|
-
if (_line_no, start_line
|
|
103
|
-
@
|
|
101
|
+
@first_non_meta_comment_start_line = nil
|
|
102
|
+
if (_line_no, start_line = @unprocessed_comments.first)
|
|
103
|
+
@first_non_meta_comment_start_line = start_line if start_line < @program_node.location.start_line
|
|
104
104
|
end
|
|
105
105
|
|
|
106
106
|
@program_node.accept(RDocVisitor.new(self, @top_level, @store))
|
|
@@ -150,7 +150,9 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
|
|
|
150
150
|
if comment.is_a? Prism::EmbDocComment
|
|
151
151
|
consecutive_comments << [comment] << (current = [])
|
|
152
152
|
elsif comment.location.start_line_slice.match?(/\S/)
|
|
153
|
-
|
|
153
|
+
text = comment.slice
|
|
154
|
+
text = RDoc::Encoding.change_encoding(text, @encoding) if @encoding
|
|
155
|
+
@modifier_comments[comment.location.start_line] = text
|
|
154
156
|
elsif current.empty? || current.last.location.end_line + 1 == comment.location.start_line
|
|
155
157
|
current << comment
|
|
156
158
|
else
|
|
@@ -172,22 +174,18 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
|
|
|
172
174
|
texts = comments.map do |c|
|
|
173
175
|
c.is_a?(Prism::EmbDocComment) ? c.slice.lines[1...-1].join : c.slice
|
|
174
176
|
end
|
|
175
|
-
text =
|
|
177
|
+
text = texts.join("\n")
|
|
178
|
+
text = RDoc::Encoding.change_encoding(text, @encoding) if @encoding
|
|
176
179
|
line_no += 1 while @lines[line_no - 1]&.match?(/\A\s*$/)
|
|
177
|
-
|
|
178
|
-
comment.line = start_line
|
|
179
|
-
[line_no, start_line, comment]
|
|
180
|
+
[line_no, start_line, text]
|
|
180
181
|
end
|
|
181
182
|
|
|
182
183
|
# The first comment is special. It defines markup for the rest of the comments.
|
|
183
184
|
_, first_comment_start_line, first_comment_text = @unprocessed_comments.first
|
|
184
185
|
if first_comment_text && @lines[0...first_comment_start_line - 1].all? { |l| l.match?(/\A\s*$/) }
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
@markup =
|
|
188
|
-
end
|
|
189
|
-
@unprocessed_comments.each do |_, _, comment|
|
|
190
|
-
comment.format = @markup
|
|
186
|
+
_text, directives = @preprocess.parse_comment(first_comment_text, first_comment_start_line, :ruby)
|
|
187
|
+
markup, = directives['markup']
|
|
188
|
+
@markup = markup.downcase if markup
|
|
191
189
|
end
|
|
192
190
|
end
|
|
193
191
|
|
|
@@ -205,42 +203,25 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
|
|
|
205
203
|
meth.call_seq = signature
|
|
206
204
|
return unless meth.name
|
|
207
205
|
|
|
208
|
-
meth.start_collecting_tokens
|
|
206
|
+
meth.start_collecting_tokens(:ruby)
|
|
209
207
|
node = @line_nodes[line_no]
|
|
210
208
|
tokens = node ? visible_tokens_from_location(node.location) : [file_line_comment_token(start_line)]
|
|
211
209
|
tokens.each { |token| meth.token_stream << token }
|
|
212
210
|
|
|
213
211
|
container.add_method meth
|
|
214
|
-
comment.remove_private
|
|
215
|
-
comment.normalize
|
|
216
212
|
meth.comment = comment
|
|
217
213
|
@stats.add_method meth
|
|
218
214
|
end
|
|
219
215
|
|
|
220
216
|
def has_modifier_nodoc?(line_no) # :nodoc:
|
|
221
|
-
@modifier_comments[line_no]&.
|
|
217
|
+
@modifier_comments[line_no]&.match?(/\A#\s*:nodoc:/)
|
|
222
218
|
end
|
|
223
219
|
|
|
224
220
|
def handle_modifier_directive(code_object, line_no) # :nodoc:
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
def handle_consecutive_comment_directive(code_object, comment) # :nodoc:
|
|
230
|
-
return unless comment
|
|
231
|
-
@preprocess.handle(comment, code_object) do |directive, param|
|
|
232
|
-
case directive
|
|
233
|
-
when 'method', 'singleton-method',
|
|
234
|
-
'attr', 'attr_accessor', 'attr_reader', 'attr_writer' then
|
|
235
|
-
# handled elsewhere
|
|
236
|
-
''
|
|
237
|
-
when 'section' then
|
|
238
|
-
@container.set_current_section(param, comment.dup)
|
|
239
|
-
comment.text = ''
|
|
240
|
-
break
|
|
241
|
-
end
|
|
221
|
+
if (comment_text = @modifier_comments[line_no])
|
|
222
|
+
_text, directives = @preprocess.parse_comment(comment_text, line_no, :ruby)
|
|
223
|
+
handle_code_object_directives(code_object, directives)
|
|
242
224
|
end
|
|
243
|
-
comment.remove_private
|
|
244
225
|
end
|
|
245
226
|
|
|
246
227
|
def call_node_name_arguments(call_node) # :nodoc:
|
|
@@ -257,39 +238,32 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
|
|
|
257
238
|
|
|
258
239
|
# Handles meta method comments
|
|
259
240
|
|
|
260
|
-
def handle_meta_method_comment(comment, node)
|
|
241
|
+
def handle_meta_method_comment(comment, directives, node)
|
|
242
|
+
handle_code_object_directives(@container, directives)
|
|
261
243
|
is_call_node = node.is_a?(Prism::CallNode)
|
|
262
244
|
singleton_method = false
|
|
263
245
|
visibility = @visibility
|
|
264
246
|
attributes = rw = line_no = method_name = nil
|
|
265
|
-
|
|
266
|
-
processed_comment = comment.dup
|
|
267
|
-
@preprocess.handle(processed_comment, @container) do |directive, param, line|
|
|
247
|
+
directives.each do |directive, (param, line)|
|
|
268
248
|
case directive
|
|
269
249
|
when 'attr', 'attr_reader', 'attr_writer', 'attr_accessor'
|
|
270
250
|
attributes = [param] if param
|
|
271
251
|
attributes ||= call_node_name_arguments(node) if is_call_node
|
|
272
252
|
rw = directive == 'attr_writer' ? 'W' : directive == 'attr_accessor' ? 'RW' : 'R'
|
|
273
|
-
''
|
|
274
253
|
when 'method'
|
|
275
|
-
method_name = param
|
|
254
|
+
method_name = param if param
|
|
276
255
|
line_no = line
|
|
277
|
-
''
|
|
278
256
|
when 'singleton-method'
|
|
279
|
-
method_name = param
|
|
257
|
+
method_name = param if param
|
|
280
258
|
line_no = line
|
|
281
259
|
singleton_method = true
|
|
282
260
|
visibility = :public
|
|
283
|
-
''
|
|
284
|
-
when 'section' then
|
|
285
|
-
@container.set_current_section(param, comment.dup)
|
|
286
|
-
return # If the comment contains :section:, it is not a meta method comment
|
|
287
261
|
end
|
|
288
262
|
end
|
|
289
263
|
|
|
290
264
|
if attributes
|
|
291
265
|
attributes.each do |attr|
|
|
292
|
-
a = RDoc::Attr.new(@container, attr, rw,
|
|
266
|
+
a = RDoc::Attr.new(@container, attr, rw, comment, singleton: @singleton)
|
|
293
267
|
a.store = @store
|
|
294
268
|
a.line = line_no
|
|
295
269
|
record_location(a)
|
|
@@ -298,11 +272,6 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
|
|
|
298
272
|
end
|
|
299
273
|
elsif line_no || node
|
|
300
274
|
method_name ||= call_node_name_arguments(node).first if is_call_node
|
|
301
|
-
meth = RDoc::AnyMethod.new(@container, method_name, singleton: @singleton || singleton_method)
|
|
302
|
-
handle_consecutive_comment_directive(meth, comment)
|
|
303
|
-
comment.normalize
|
|
304
|
-
meth.call_seq = comment.extract_call_seq
|
|
305
|
-
meth.comment = comment
|
|
306
275
|
if node
|
|
307
276
|
tokens = visible_tokens_from_location(node.location)
|
|
308
277
|
line_no = node.location.start_line
|
|
@@ -310,37 +279,41 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
|
|
|
310
279
|
tokens = [file_line_comment_token(line_no)]
|
|
311
280
|
end
|
|
312
281
|
internal_add_method(
|
|
282
|
+
method_name,
|
|
313
283
|
@container,
|
|
314
|
-
|
|
284
|
+
comment: comment,
|
|
285
|
+
directives: directives,
|
|
286
|
+
dont_rename_initialize: false,
|
|
315
287
|
line_no: line_no,
|
|
316
288
|
visibility: visibility,
|
|
317
|
-
|
|
289
|
+
singleton: @singleton || singleton_method,
|
|
290
|
+
params: nil,
|
|
318
291
|
calls_super: false,
|
|
319
292
|
block_params: nil,
|
|
320
|
-
tokens: tokens
|
|
293
|
+
tokens: tokens,
|
|
321
294
|
)
|
|
322
295
|
end
|
|
323
296
|
end
|
|
324
297
|
|
|
325
|
-
|
|
298
|
+
INVALID_GHOST_METHOD_ACCEPT_DIRECTIVE_LIST = %w[
|
|
299
|
+
method singleton-method attr attr_reader attr_writer attr_accessor
|
|
300
|
+
].freeze
|
|
301
|
+
private_constant :INVALID_GHOST_METHOD_ACCEPT_DIRECTIVE_LIST
|
|
302
|
+
|
|
303
|
+
def normal_comment_treat_as_ghost_method_for_now?(directives, line_no) # :nodoc:
|
|
326
304
|
# Meta method comment should start with `##` but some comments does not follow this rule.
|
|
327
305
|
# For now, RDoc accepts them as a meta method comment if there is no node linked to it.
|
|
328
|
-
!@line_nodes[line_no] &&
|
|
306
|
+
!@line_nodes[line_no] && INVALID_GHOST_METHOD_ACCEPT_DIRECTIVE_LIST.any? { |directive| directives.has_key?(directive) }
|
|
329
307
|
end
|
|
330
308
|
|
|
331
|
-
def handle_standalone_consecutive_comment_directive(comment, line_no, start_line) # :nodoc:
|
|
332
|
-
if
|
|
333
|
-
parse_comment_tomdoc(@container, comment, line_no, start_line)
|
|
334
|
-
return
|
|
335
|
-
end
|
|
336
|
-
|
|
337
|
-
if comment.text =~ /\A#\#$/ && comment != @first_non_meta_comment
|
|
309
|
+
def handle_standalone_consecutive_comment_directive(comment, directives, start_with_sharp_sharp, line_no, start_line) # :nodoc:
|
|
310
|
+
if start_with_sharp_sharp && start_line != @first_non_meta_comment_start_line
|
|
338
311
|
node = @line_nodes[line_no]
|
|
339
|
-
handle_meta_method_comment(comment, node)
|
|
340
|
-
elsif normal_comment_treat_as_ghost_method_for_now?(
|
|
341
|
-
handle_meta_method_comment(comment, nil)
|
|
312
|
+
handle_meta_method_comment(comment, directives, node)
|
|
313
|
+
elsif normal_comment_treat_as_ghost_method_for_now?(directives, line_no) && start_line != @first_non_meta_comment_start_line
|
|
314
|
+
handle_meta_method_comment(comment, directives, nil)
|
|
342
315
|
else
|
|
343
|
-
|
|
316
|
+
handle_code_object_directives(@container, directives)
|
|
344
317
|
end
|
|
345
318
|
end
|
|
346
319
|
|
|
@@ -348,8 +321,15 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
|
|
|
348
321
|
|
|
349
322
|
def process_comments_until(line_no_until)
|
|
350
323
|
while !@unprocessed_comments.empty? && @unprocessed_comments.first[0] <= line_no_until
|
|
351
|
-
line_no, start_line,
|
|
352
|
-
|
|
324
|
+
line_no, start_line, text = @unprocessed_comments.shift
|
|
325
|
+
if @markup == 'tomdoc'
|
|
326
|
+
comment = RDoc::Comment.new(text, @top_level, :ruby)
|
|
327
|
+
comment.format = 'tomdoc'
|
|
328
|
+
parse_comment_tomdoc(@container, comment, line_no, start_line)
|
|
329
|
+
@preprocess.run_post_processes(comment, @container)
|
|
330
|
+
elsif (comment_text, directives = parse_comment_text_to_directives(text, start_line))
|
|
331
|
+
handle_standalone_consecutive_comment_directive(comment_text, directives, text.start_with?(/#\#$/), line_no, start_line)
|
|
332
|
+
end
|
|
353
333
|
end
|
|
354
334
|
end
|
|
355
335
|
|
|
@@ -365,9 +345,27 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
|
|
|
365
345
|
# Returns consecutive comment linked to the given line number
|
|
366
346
|
|
|
367
347
|
def consecutive_comment(line_no)
|
|
368
|
-
|
|
369
|
-
|
|
348
|
+
return unless @unprocessed_comments.first&.first == line_no
|
|
349
|
+
_line_no, start_line, text = @unprocessed_comments.shift
|
|
350
|
+
parse_comment_text_to_directives(text, start_line)
|
|
351
|
+
end
|
|
352
|
+
|
|
353
|
+
# Parses comment text and retuns a pair of RDoc::Comment and directives
|
|
354
|
+
|
|
355
|
+
def parse_comment_text_to_directives(comment_text, start_line) # :nodoc:
|
|
356
|
+
comment_text, directives = @preprocess.parse_comment(comment_text, start_line, :ruby)
|
|
357
|
+
comment = RDoc::Comment.new(comment_text, @top_level, :ruby)
|
|
358
|
+
comment.normalized = true
|
|
359
|
+
comment.line = start_line
|
|
360
|
+
markup, = directives['markup']
|
|
361
|
+
comment.format = markup&.downcase || @markup
|
|
362
|
+
if (section, = directives['section'])
|
|
363
|
+
# If comment has :section:, it is not a documentable comment for a code object
|
|
364
|
+
@container.set_current_section(section, comment.dup)
|
|
365
|
+
return
|
|
370
366
|
end
|
|
367
|
+
@preprocess.run_post_processes(comment, @container)
|
|
368
|
+
[comment, directives]
|
|
371
369
|
end
|
|
372
370
|
|
|
373
371
|
def slice_tokens(start_pos, end_pos) # :nodoc:
|
|
@@ -443,11 +441,17 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
|
|
|
443
441
|
end
|
|
444
442
|
end
|
|
445
443
|
|
|
444
|
+
def handle_code_object_directives(code_object, directives) # :nodoc:
|
|
445
|
+
directives.each do |directive, (param)|
|
|
446
|
+
@preprocess.handle_directive('', directive, param, code_object)
|
|
447
|
+
end
|
|
448
|
+
end
|
|
449
|
+
|
|
446
450
|
# Handles `alias foo bar` and `alias_method :foo, :bar`
|
|
447
451
|
|
|
448
452
|
def add_alias_method(old_name, new_name, line_no)
|
|
449
|
-
comment = consecutive_comment(line_no)
|
|
450
|
-
|
|
453
|
+
comment, directives = consecutive_comment(line_no)
|
|
454
|
+
handle_code_object_directives(@container, directives) if directives
|
|
451
455
|
visibility = @container.find_method(old_name, @singleton)&.visibility || :public
|
|
452
456
|
a = RDoc::Alias.new(nil, old_name, new_name, comment, singleton: @singleton)
|
|
453
457
|
handle_modifier_directive(a, line_no)
|
|
@@ -463,8 +467,8 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
|
|
|
463
467
|
# Handles `attr :a, :b`, `attr_reader :a, :b`, `attr_writer :a, :b` and `attr_accessor :a, :b`
|
|
464
468
|
|
|
465
469
|
def add_attributes(names, rw, line_no)
|
|
466
|
-
comment = consecutive_comment(line_no)
|
|
467
|
-
|
|
470
|
+
comment, directives = consecutive_comment(line_no)
|
|
471
|
+
handle_code_object_directives(@container, directives) if directives
|
|
468
472
|
return unless @container.document_children
|
|
469
473
|
|
|
470
474
|
names.each do |symbol|
|
|
@@ -480,8 +484,8 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
|
|
|
480
484
|
|
|
481
485
|
def add_includes_extends(names, rdoc_class, line_no) # :nodoc:
|
|
482
486
|
return if @in_proc_block
|
|
483
|
-
comment = consecutive_comment(line_no)
|
|
484
|
-
|
|
487
|
+
comment, directives = consecutive_comment(line_no)
|
|
488
|
+
handle_code_object_directives(@container, directives) if directives
|
|
485
489
|
names.each do |name|
|
|
486
490
|
ie = @container.add(rdoc_class, name, '')
|
|
487
491
|
ie.store = @store
|
|
@@ -505,63 +509,67 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
|
|
|
505
509
|
|
|
506
510
|
# Adds a method defined by `def` syntax
|
|
507
511
|
|
|
508
|
-
def add_method(
|
|
512
|
+
def add_method(method_name, receiver_name:, receiver_fallback_type:, visibility:, singleton:, params:, calls_super:, block_params:, tokens:, start_line:, args_end_line:, end_line:)
|
|
509
513
|
return if @in_proc_block
|
|
510
514
|
|
|
511
515
|
receiver = receiver_name ? find_or_create_module_path(receiver_name, receiver_fallback_type) : @container
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
handle_consecutive_comment_directive(@container, comment)
|
|
515
|
-
handle_consecutive_comment_directive(meth, comment)
|
|
516
|
-
|
|
517
|
-
comment.normalize
|
|
518
|
-
meth.call_seq = comment.extract_call_seq
|
|
519
|
-
meth.comment = comment
|
|
520
|
-
end
|
|
521
|
-
handle_modifier_directive(meth, start_line)
|
|
522
|
-
handle_modifier_directive(meth, args_end_line)
|
|
523
|
-
handle_modifier_directive(meth, end_line)
|
|
524
|
-
return unless should_document?(meth)
|
|
516
|
+
comment, directives = consecutive_comment(start_line)
|
|
517
|
+
handle_code_object_directives(@container, directives) if directives
|
|
525
518
|
|
|
526
519
|
internal_add_method(
|
|
520
|
+
method_name,
|
|
527
521
|
receiver,
|
|
528
|
-
|
|
522
|
+
comment: comment,
|
|
523
|
+
directives: directives,
|
|
524
|
+
modifier_comment_lines: [start_line, args_end_line, end_line].uniq,
|
|
529
525
|
line_no: start_line,
|
|
530
526
|
visibility: visibility,
|
|
527
|
+
singleton: singleton,
|
|
531
528
|
params: params,
|
|
532
529
|
calls_super: calls_super,
|
|
533
530
|
block_params: block_params,
|
|
534
531
|
tokens: tokens
|
|
535
532
|
)
|
|
533
|
+
end
|
|
536
534
|
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
meth.name = 'new'
|
|
544
|
-
meth.singleton = true
|
|
545
|
-
meth.visibility = :public
|
|
546
|
-
end
|
|
535
|
+
private def internal_add_method(method_name, container, comment:, dont_rename_initialize: false, directives:, modifier_comment_lines: nil, line_no:, visibility:, singleton:, params:, calls_super:, block_params:, tokens:) # :nodoc:
|
|
536
|
+
meth = RDoc::AnyMethod.new(nil, method_name, singleton: singleton)
|
|
537
|
+
meth.comment = comment
|
|
538
|
+
handle_code_object_directives(meth, directives) if directives
|
|
539
|
+
modifier_comment_lines&.each do |line|
|
|
540
|
+
handle_modifier_directive(meth, line)
|
|
547
541
|
end
|
|
548
|
-
|
|
542
|
+
return unless should_document?(meth)
|
|
549
543
|
|
|
550
|
-
|
|
544
|
+
if directives && (call_seq, = directives['call-seq'])
|
|
545
|
+
meth.call_seq = call_seq.lines.map(&:chomp).reject(&:empty?).join("\n") if call_seq
|
|
546
|
+
end
|
|
551
547
|
meth.name ||= meth.call_seq[/\A[^()\s]+/] if meth.call_seq
|
|
552
548
|
meth.name ||= 'unknown'
|
|
553
549
|
meth.store = @store
|
|
554
550
|
meth.line = line_no
|
|
555
551
|
container.add_method(meth) # should add after setting singleton and before setting visibility
|
|
556
552
|
meth.visibility = visibility
|
|
557
|
-
meth.params ||= params
|
|
553
|
+
meth.params ||= params || '()'
|
|
558
554
|
meth.calls_super = calls_super
|
|
559
555
|
meth.block_params ||= block_params if block_params
|
|
560
556
|
record_location(meth)
|
|
561
|
-
meth.start_collecting_tokens
|
|
557
|
+
meth.start_collecting_tokens(:ruby)
|
|
562
558
|
tokens.each do |token|
|
|
563
559
|
meth.token_stream << token
|
|
564
560
|
end
|
|
561
|
+
|
|
562
|
+
# Rename after add_method to register duplicated 'new' and 'initialize'
|
|
563
|
+
# defined in c and ruby just like the old parser did.
|
|
564
|
+
if !dont_rename_initialize && method_name == 'initialize' && !singleton
|
|
565
|
+
if meth.dont_rename_initialize
|
|
566
|
+
meth.visibility = :protected
|
|
567
|
+
else
|
|
568
|
+
meth.name = 'new'
|
|
569
|
+
meth.singleton = true
|
|
570
|
+
meth.visibility = :public
|
|
571
|
+
end
|
|
572
|
+
end
|
|
565
573
|
end
|
|
566
574
|
|
|
567
575
|
# Find or create module or class from a given module name.
|
|
@@ -633,8 +641,8 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
|
|
|
633
641
|
# Adds a constant
|
|
634
642
|
|
|
635
643
|
def add_constant(constant_name, rhs_name, start_line, end_line)
|
|
636
|
-
comment = consecutive_comment(start_line)
|
|
637
|
-
|
|
644
|
+
comment, directives = consecutive_comment(start_line)
|
|
645
|
+
handle_code_object_directives(@container, directives) if directives
|
|
638
646
|
owner, name = find_or_create_constant_owner_name(constant_name)
|
|
639
647
|
return unless owner
|
|
640
648
|
|
|
@@ -662,8 +670,8 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
|
|
|
662
670
|
# Adds module or class
|
|
663
671
|
|
|
664
672
|
def add_module_or_class(module_name, start_line, end_line, is_class: false, superclass_name: nil, superclass_expr: nil)
|
|
665
|
-
comment = consecutive_comment(start_line)
|
|
666
|
-
|
|
673
|
+
comment, directives = consecutive_comment(start_line)
|
|
674
|
+
handle_code_object_directives(@container, directives) if directives
|
|
667
675
|
return unless @container.document_children
|
|
668
676
|
|
|
669
677
|
owner, name = find_or_create_constant_owner_name(module_name)
|
data/lib/rdoc/parser/ruby.rb
CHANGED
|
@@ -120,7 +120,7 @@ require_relative 'ripper_state_lex'
|
|
|
120
120
|
# # :singleton-method: some_method!
|
|
121
121
|
#
|
|
122
122
|
# You can define arguments for metaprogrammed methods via either the
|
|
123
|
-
#
|
|
123
|
+
# \:call-seq:, :arg: or :args: directives.
|
|
124
124
|
#
|
|
125
125
|
# Additionally you can mark a method as an attribute by
|
|
126
126
|
# using :attr:, :attr_reader:, :attr_writer: or :attr_accessor:. Just like
|
|
@@ -1088,7 +1088,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
|
1088
1088
|
|
|
1089
1089
|
##
|
|
1090
1090
|
# Generates an RDoc::Method or RDoc::Attr from +comment+ by looking for
|
|
1091
|
-
#
|
|
1091
|
+
# \:method: or :attr: directives in +comment+.
|
|
1092
1092
|
|
|
1093
1093
|
def parse_comment(container, tk, comment)
|
|
1094
1094
|
return parse_comment_tomdoc container, tk, comment if @markup == 'tomdoc'
|
|
@@ -1137,7 +1137,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
|
1137
1137
|
meth = RDoc::GhostMethod.new get_tkread, name
|
|
1138
1138
|
record_location meth
|
|
1139
1139
|
|
|
1140
|
-
meth.start_collecting_tokens
|
|
1140
|
+
meth.start_collecting_tokens(:ruby)
|
|
1141
1141
|
indent = RDoc::Parser::RipperStateLex::Token.new(1, 1, :on_sp, ' ' * column)
|
|
1142
1142
|
position_comment = RDoc::Parser::RipperStateLex::Token.new(line_no, 1, :on_comment)
|
|
1143
1143
|
position_comment[:text] = "# File #{@top_level.relative_name}, line #{line_no}"
|
|
@@ -1180,7 +1180,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
|
1180
1180
|
record_location meth
|
|
1181
1181
|
meth.line = line_no
|
|
1182
1182
|
|
|
1183
|
-
meth.start_collecting_tokens
|
|
1183
|
+
meth.start_collecting_tokens(:ruby)
|
|
1184
1184
|
indent = RDoc::Parser::RipperStateLex::Token.new(1, 1, :on_sp, ' ' * column)
|
|
1185
1185
|
position_comment = RDoc::Parser::RipperStateLex::Token.new(line_no, 1, :on_comment)
|
|
1186
1186
|
position_comment[:text] = "# File #{@top_level.relative_name}, line #{line_no}"
|
|
@@ -1344,7 +1344,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
|
1344
1344
|
column = tk[:char_no]
|
|
1345
1345
|
line_no = tk[:line_no]
|
|
1346
1346
|
|
|
1347
|
-
start_collecting_tokens
|
|
1347
|
+
start_collecting_tokens(:ruby)
|
|
1348
1348
|
add_token tk
|
|
1349
1349
|
add_token_listener self
|
|
1350
1350
|
|
|
@@ -1363,7 +1363,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
|
1363
1363
|
|
|
1364
1364
|
remove_token_listener self
|
|
1365
1365
|
|
|
1366
|
-
meth.start_collecting_tokens
|
|
1366
|
+
meth.start_collecting_tokens(:ruby)
|
|
1367
1367
|
indent = RDoc::Parser::RipperStateLex::Token.new(1, 1, :on_sp, ' ' * column)
|
|
1368
1368
|
position_comment = RDoc::Parser::RipperStateLex::Token.new(line_no, 1, :on_comment)
|
|
1369
1369
|
position_comment[:text] = "# File #{@top_level.relative_name}, line #{line_no}"
|
|
@@ -1448,7 +1448,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
|
1448
1448
|
column = tk[:char_no]
|
|
1449
1449
|
line_no = tk[:line_no]
|
|
1450
1450
|
|
|
1451
|
-
start_collecting_tokens
|
|
1451
|
+
start_collecting_tokens(:ruby)
|
|
1452
1452
|
add_token tk
|
|
1453
1453
|
|
|
1454
1454
|
token_listener self do
|
|
@@ -1471,7 +1471,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
|
1471
1471
|
record_location meth
|
|
1472
1472
|
meth.line = line_no
|
|
1473
1473
|
|
|
1474
|
-
meth.start_collecting_tokens
|
|
1474
|
+
meth.start_collecting_tokens(:ruby)
|
|
1475
1475
|
indent = RDoc::Parser::RipperStateLex::Token.new(1, 1, :on_sp, ' ' * column)
|
|
1476
1476
|
token = RDoc::Parser::RipperStateLex::Token.new(line_no, 1, :on_comment)
|
|
1477
1477
|
token[:text] = "# File #{@top_level.relative_name}, line #{line_no}"
|
|
@@ -20,7 +20,7 @@ module RDoc::Parser::RubyTools
|
|
|
20
20
|
|
|
21
21
|
if @tokens.empty? then
|
|
22
22
|
if @scanner_point >= @scanner.size
|
|
23
|
-
return
|
|
23
|
+
return
|
|
24
24
|
else
|
|
25
25
|
tk = @scanner[@scanner_point]
|
|
26
26
|
@scanner_point += 1
|
|
@@ -31,16 +31,14 @@ module RDoc::Parser::RubyTools
|
|
|
31
31
|
tk = @tokens.shift
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
-
if tk
|
|
35
|
-
|
|
34
|
+
if tk.nil? || :on___end__ == tk[:kind]
|
|
35
|
+
return
|
|
36
36
|
end
|
|
37
37
|
|
|
38
|
-
return nil unless tk
|
|
39
|
-
|
|
40
38
|
# inform any listeners of our shiny new token
|
|
41
|
-
@token_listeners
|
|
39
|
+
@token_listeners&.each do |obj|
|
|
42
40
|
obj.add_token(tk)
|
|
43
|
-
end
|
|
41
|
+
end
|
|
44
42
|
|
|
45
43
|
tk
|
|
46
44
|
end
|
data/lib/rdoc/parser/simple.rb
CHANGED
|
@@ -19,17 +19,17 @@ class RDoc::Parser::Simple < RDoc::Parser
|
|
|
19
19
|
|
|
20
20
|
preprocess = RDoc::Markup::PreProcess.new @file_name, @options.rdoc_include
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
content = RDoc::Text.expand_tabs(@content)
|
|
23
|
+
@content, = preprocess.run_pre_processes(content, @top_level, 1, :simple)
|
|
23
24
|
end
|
|
24
25
|
|
|
25
26
|
##
|
|
26
27
|
# Extract the file contents and attach them to the TopLevel as a comment
|
|
27
28
|
|
|
28
29
|
def scan
|
|
29
|
-
|
|
30
|
-
comment = remove_private_comment comment
|
|
30
|
+
content = remove_coding_comment @content
|
|
31
31
|
|
|
32
|
-
comment = RDoc::Comment.new
|
|
32
|
+
comment = RDoc::Comment.new content, @top_level
|
|
33
33
|
|
|
34
34
|
@top_level.comment = comment
|
|
35
35
|
@top_level
|
|
@@ -41,21 +41,4 @@ class RDoc::Parser::Simple < RDoc::Parser
|
|
|
41
41
|
def remove_coding_comment(text)
|
|
42
42
|
text.sub(/\A# .*coding[=:].*$/, '')
|
|
43
43
|
end
|
|
44
|
-
|
|
45
|
-
##
|
|
46
|
-
# Removes private comments.
|
|
47
|
-
#
|
|
48
|
-
# Unlike RDoc::Comment#remove_private this implementation only looks for two
|
|
49
|
-
# dashes at the beginning of the line. Three or more dashes are considered
|
|
50
|
-
# to be a rule and ignored.
|
|
51
|
-
|
|
52
|
-
def remove_private_comment(comment)
|
|
53
|
-
# Workaround for gsub encoding for Ruby 1.9.2 and earlier
|
|
54
|
-
empty = ''
|
|
55
|
-
empty = RDoc::Encoding.change_encoding empty, comment.encoding
|
|
56
|
-
|
|
57
|
-
comment = comment.gsub(%r%^--\n.*?^\+\+\n?%m, empty)
|
|
58
|
-
comment.sub(%r%^--\n.*%m, empty)
|
|
59
|
-
end
|
|
60
|
-
|
|
61
44
|
end
|
data/lib/rdoc/rdoc.rb
CHANGED
data/lib/rdoc/text.rb
CHANGED
data/lib/rdoc/token_stream.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
|
|
2
3
|
##
|
|
3
4
|
# A TokenStream is a list of tokens, gathered during the parse of some entity
|
|
4
5
|
# (say a method). Entities populate these streams by being registered with the
|
|
@@ -87,9 +88,11 @@ module RDoc::TokenStream
|
|
|
87
88
|
|
|
88
89
|
##
|
|
89
90
|
# Starts collecting tokens
|
|
91
|
+
#
|
|
90
92
|
|
|
91
|
-
def collect_tokens
|
|
93
|
+
def collect_tokens(language)
|
|
92
94
|
@token_stream = []
|
|
95
|
+
@token_stream_language = language
|
|
93
96
|
end
|
|
94
97
|
|
|
95
98
|
alias start_collecting_tokens collect_tokens
|
|
@@ -115,4 +118,13 @@ module RDoc::TokenStream
|
|
|
115
118
|
(token_stream or return '').compact.map { |token| token[:text] }.join ''
|
|
116
119
|
end
|
|
117
120
|
|
|
121
|
+
##
|
|
122
|
+
# Returns the source language of the token stream as a string
|
|
123
|
+
#
|
|
124
|
+
# Returns 'c' or 'ruby'
|
|
125
|
+
|
|
126
|
+
def source_language
|
|
127
|
+
@token_stream_language == :c ? 'c' : 'ruby'
|
|
128
|
+
end
|
|
129
|
+
|
|
118
130
|
end
|
data/lib/rdoc/tom_doc.rb
CHANGED
|
@@ -49,7 +49,7 @@ class RDoc::TomDoc < RDoc::Markup::Parser
|
|
|
49
49
|
next unless code_object and
|
|
50
50
|
RDoc::Comment === comment and comment.format == 'tomdoc'
|
|
51
51
|
|
|
52
|
-
comment.text.gsub!(
|
|
52
|
+
comment.text.gsub!(/\A(\s*# |)(Public|Internal|Deprecated):\s+/) do
|
|
53
53
|
section = code_object.add_section $2
|
|
54
54
|
code_object.temporary_section = section
|
|
55
55
|
|