Skip to content

Commit fde99f1

Browse files
authored
Add new ruby parser that uses Prism (#1144)
* Add a new ruby parser RDoc::Parser::PrismRuby * Add a new ruby parser testcase independent from parser's internal implementation * unknown meta method * Use MethodSignatureVisitor only to scan params, block_params and calls_super * Add calls_super test * Drop ruby 2.6. Prism requires ruby >= 2.7 * Remove duplicated documentation comment from prism_ruby.rb * Add test for wrong argument passed to metaprogramming method * Rename visit_call_[DSL_METHOD_NAME] to make it distinguishable from visit_[NODE_TYPE]_node * Method receiver switch of true/false/nil to a case statement * Extract common part of add_method(by def keyword) and add meta_comment method * Reuse consecutive comments array when collecting comments * Simplify DSL call_node handling * Refactor extracting method visibility arguments
1 parent 97c497d commit fde99f1

File tree

6 files changed

+3042
-7
lines changed

6 files changed

+3042
-7
lines changed

lib/rdoc/markup/pre_process.rb

+9-6
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,18 @@ def initialize(input_file_name, include_path)
9797
# RDoc::CodeObject#metadata for details.
9898

9999
def handle text, code_object = nil, &block
100+
first_line = 1
100101
if RDoc::Comment === text then
101102
comment = text
102103
text = text.text
104+
first_line = comment.line || 1
103105
end
104106

105107
# regexp helper (square brackets for optional)
106108
# $1 $2 $3 $4 $5
107109
# [prefix][\]:directive:[spaces][param]newline
108-
text = text.gsub(/^([ \t]*(?:#|\/?\*)?[ \t]*)(\\?):(\w+):([ \t]*)(.+)?(\r?\n|$)/) do
110+
text = text.lines.map.with_index(first_line) do |line, num|
111+
next line unless line =~ /\A([ \t]*(?:#|\/?\*)?[ \t]*)(\\?):([\w-]+):([ \t]*)(.+)?(\r?\n|$)/
109112
# skip something like ':toto::'
110113
next $& if $4.empty? and $5 and $5[0, 1] == ':'
111114

@@ -120,8 +123,8 @@ def handle text, code_object = nil, &block
120123
next "#{$1.strip}\n"
121124
end
122125

123-
handle_directive $1, $3, $5, code_object, text.encoding, &block
124-
end
126+
handle_directive $1, $3, $5, code_object, text.encoding, num, &block
127+
end.join
125128

126129
if comment then
127130
comment.text = text
@@ -148,7 +151,7 @@ def handle text, code_object = nil, &block
148151
# When 1.8.7 support is ditched prefix can be defaulted to ''
149152

150153
def handle_directive prefix, directive, param, code_object = nil,
151-
encoding = nil
154+
encoding = nil, line = nil
152155
blankline = "#{prefix.strip}\n"
153156
directive = directive.downcase
154157

@@ -220,11 +223,11 @@ def handle_directive prefix, directive, param, code_object = nil,
220223
# remove parameter &block
221224
code_object.params = code_object.params.sub(/,?\s*&\w+/, '') if code_object.params
222225

223-
code_object.block_params = param
226+
code_object.block_params = param || ''
224227

225228
blankline
226229
else
227-
result = yield directive, param if block_given?
230+
result = yield directive, param, line if block_given?
228231

229232
case result
230233
when nil then

0 commit comments

Comments
 (0)