rdoc 6.13.0 → 6.17.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/README.md +112 -0
- data/RI.md +1 -1
- data/lib/rdoc/code_object/any_method.rb +4 -4
- data/lib/rdoc/code_object/attr.rb +3 -3
- data/lib/rdoc/code_object/class_module.rb +18 -16
- data/lib/rdoc/code_object/constant.rb +5 -5
- data/lib/rdoc/code_object/context/section.rb +8 -7
- data/lib/rdoc/code_object/context.rb +19 -19
- data/lib/rdoc/code_object/method_attr.rb +7 -6
- data/lib/rdoc/code_object/mixin.rb +3 -3
- data/lib/rdoc/code_object/normal_class.rb +1 -1
- data/lib/rdoc/code_object/normal_module.rb +1 -1
- data/lib/rdoc/code_object/single_class.rb +1 -1
- data/lib/rdoc/code_object/top_level.rb +28 -33
- data/lib/rdoc/code_object.rb +3 -3
- data/lib/rdoc/comment.rb +196 -14
- data/lib/rdoc/cross_reference.rb +4 -4
- data/lib/rdoc/encoding.rb +4 -4
- data/lib/rdoc/erb_partial.rb +1 -1
- data/lib/rdoc/erbio.rb +2 -2
- data/lib/rdoc/generator/aliki.rb +42 -0
- data/lib/rdoc/generator/darkfish.rb +20 -16
- data/lib/rdoc/generator/json_index.rb +3 -3
- data/lib/rdoc/generator/markup.rb +12 -0
- data/lib/rdoc/generator/pot/message_extractor.rb +4 -4
- data/lib/rdoc/generator/pot/po.rb +1 -1
- data/lib/rdoc/generator/pot/po_entry.rb +7 -7
- data/lib/rdoc/generator/pot.rb +1 -1
- data/lib/rdoc/generator/ri.rb +1 -1
- 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 +158 -0
- data/lib/rdoc/generator/template/aliki/_header.rhtml +56 -0
- data/lib/rdoc/generator/template/aliki/_icons.rhtml +208 -0
- data/lib/rdoc/generator/template/aliki/_sidebar_ancestors.rhtml +16 -0
- data/lib/rdoc/generator/template/aliki/_sidebar_classes.rhtml +15 -0
- data/lib/rdoc/generator/template/aliki/_sidebar_extends.rhtml +25 -0
- data/lib/rdoc/generator/template/aliki/_sidebar_includes.rhtml +25 -0
- data/lib/rdoc/generator/template/aliki/_sidebar_installed.rhtml +16 -0
- data/lib/rdoc/generator/template/aliki/_sidebar_methods.rhtml +41 -0
- data/lib/rdoc/generator/template/aliki/_sidebar_pages.rhtml +67 -0
- data/lib/rdoc/generator/template/aliki/_sidebar_search.rhtml +15 -0
- data/lib/rdoc/generator/template/aliki/_sidebar_sections.rhtml +21 -0
- data/lib/rdoc/generator/template/aliki/_sidebar_toggle.rhtml +3 -0
- data/lib/rdoc/generator/template/aliki/class.rhtml +220 -0
- data/lib/rdoc/generator/template/aliki/css/rdoc.css +1737 -0
- data/lib/rdoc/generator/template/aliki/index.rhtml +22 -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 +18 -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/_footer.rhtml +3 -3
- data/lib/rdoc/generator/template/darkfish/_head.rhtml +16 -16
- data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +8 -8
- data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +8 -8
- data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +7 -6
- data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +6 -6
- data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +19 -19
- data/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml +2 -2
- data/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml +1 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +3 -3
- data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +14 -14
- data/lib/rdoc/generator/template/darkfish/class.rhtml +62 -60
- data/lib/rdoc/generator/template/darkfish/css/rdoc.css +2 -0
- data/lib/rdoc/generator/template/darkfish/index.rhtml +4 -3
- data/lib/rdoc/generator/template/darkfish/js/darkfish.js +21 -1
- data/lib/rdoc/generator/template/darkfish/js/search.js +11 -1
- data/lib/rdoc/generator/template/darkfish/page.rhtml +2 -1
- data/lib/rdoc/generator/template/darkfish/servlet_not_found.rhtml +2 -1
- data/lib/rdoc/generator/template/darkfish/servlet_root.rhtml +19 -19
- data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +19 -17
- data/lib/rdoc/generator/template/json_index/js/searcher.js +48 -6
- data/lib/rdoc/generator.rb +1 -0
- data/lib/rdoc/markdown.kpeg +72 -18
- data/lib/rdoc/markdown.rb +411 -547
- data/lib/rdoc/markup/attribute_manager.rb +5 -5
- data/lib/rdoc/markup/attributes.rb +3 -3
- data/lib/rdoc/markup/blank_line.rb +2 -2
- data/lib/rdoc/markup/block_quote.rb +1 -1
- data/lib/rdoc/markup/document.rb +8 -8
- data/lib/rdoc/markup/formatter.rb +12 -12
- data/lib/rdoc/markup/hard_break.rb +3 -3
- data/lib/rdoc/markup/heading.rb +4 -4
- data/lib/rdoc/markup/include.rb +3 -3
- data/lib/rdoc/markup/indented_paragraph.rb +3 -3
- data/lib/rdoc/markup/list.rb +4 -4
- data/lib/rdoc/markup/list_item.rb +4 -4
- data/lib/rdoc/markup/paragraph.rb +2 -2
- data/lib/rdoc/markup/parser.rb +11 -11
- data/lib/rdoc/markup/pre_process.rb +39 -15
- data/lib/rdoc/markup/raw.rb +5 -5
- data/lib/rdoc/markup/rule.rb +2 -2
- data/lib/rdoc/markup/table.rb +4 -4
- data/lib/rdoc/markup/to_ansi.rb +7 -3
- data/lib/rdoc/markup/to_bs.rb +10 -6
- data/lib/rdoc/markup/to_html.rb +182 -30
- data/lib/rdoc/markup/to_html_crossref.rb +58 -28
- data/lib/rdoc/markup/to_html_snippet.rb +17 -17
- data/lib/rdoc/markup/to_joined_paragraph.rb +1 -1
- data/lib/rdoc/markup/to_label.rb +6 -5
- data/lib/rdoc/markup/to_markdown.rb +12 -12
- data/lib/rdoc/markup/to_rdoc.rb +40 -31
- data/lib/rdoc/markup/to_table_of_contents.rb +3 -3
- data/lib/rdoc/markup/to_test.rb +1 -1
- data/lib/rdoc/markup/to_tt_only.rb +8 -8
- data/lib/rdoc/markup/verbatim.rb +3 -3
- data/lib/rdoc/markup.rb +3 -3
- data/lib/rdoc/options.rb +53 -23
- data/lib/rdoc/parser/c.rb +31 -62
- data/lib/rdoc/parser/changelog.rb +9 -9
- data/lib/rdoc/parser/prism_ruby.rb +122 -114
- data/lib/rdoc/parser/ruby.rb +51 -51
- data/lib/rdoc/parser/ruby_tools.rb +5 -7
- data/lib/rdoc/parser/simple.rb +5 -22
- data/lib/rdoc/parser.rb +8 -8
- data/lib/rdoc/rd/inline.rb +4 -4
- data/lib/rdoc/rd.rb +1 -1
- data/lib/rdoc/rdoc.rb +9 -8
- data/lib/rdoc/ri/driver.rb +49 -49
- data/lib/rdoc/ri/paths.rb +2 -2
- data/lib/rdoc/ri/task.rb +3 -3
- data/lib/rdoc/rubygems_hook.rb +14 -11
- data/lib/rdoc/servlet.rb +15 -15
- data/lib/rdoc/stats/normal.rb +1 -1
- data/lib/rdoc/stats/quiet.rb +1 -1
- data/lib/rdoc/stats/verbose.rb +3 -3
- data/lib/rdoc/stats.rb +12 -12
- data/lib/rdoc/store.rb +32 -32
- data/lib/rdoc/task.rb +6 -6
- data/lib/rdoc/text.rb +11 -11
- data/lib/rdoc/token_stream.rb +14 -2
- data/lib/rdoc/tom_doc.rb +8 -8
- data/lib/rdoc/version.rb +1 -1
- data/man/ri.1 +2 -0
- data/rdoc.gemspec +72 -0
- metadata +61 -6
- data/README.rdoc +0 -142
|
@@ -77,7 +77,7 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
|
|
|
77
77
|
# Records the location of this +container+ in the file for this parser and
|
|
78
78
|
# adds it to the list of classes and modules in the file.
|
|
79
79
|
|
|
80
|
-
def record_location
|
|
80
|
+
def record_location(container) # :nodoc:
|
|
81
81
|
case container
|
|
82
82
|
when RDoc::ClassModule then
|
|
83
83
|
@top_level.add_to_classes_or_modules container
|
|
@@ -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)
|