[ruby/rdoc] Add new ruby parser that uses Prism
(https://github.com/ruby/rdoc/pull/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 https://github.com/ruby/rdoc/commit/fde99f1be6
This commit is contained in:
parent
e68e958231
commit
16b0242808
@ -97,15 +97,18 @@ class RDoc::Markup::PreProcess
|
|||||||
# RDoc::CodeObject#metadata for details.
|
# RDoc::CodeObject#metadata for details.
|
||||||
|
|
||||||
def handle text, code_object = nil, &block
|
def handle text, code_object = nil, &block
|
||||||
|
first_line = 1
|
||||||
if RDoc::Comment === text then
|
if RDoc::Comment === text then
|
||||||
comment = text
|
comment = text
|
||||||
text = text.text
|
text = text.text
|
||||||
|
first_line = comment.line || 1
|
||||||
end
|
end
|
||||||
|
|
||||||
# regexp helper (square brackets for optional)
|
# regexp helper (square brackets for optional)
|
||||||
# $1 $2 $3 $4 $5
|
# $1 $2 $3 $4 $5
|
||||||
# [prefix][\]:directive:[spaces][param]newline
|
# [prefix][\]:directive:[spaces][param]newline
|
||||||
text = text.gsub(/^([ \t]*(?:#|\/?\*)?[ \t]*)(\\?):(\w+):([ \t]*)(.+)?(\r?\n|$)/) do
|
text = text.lines.map.with_index(first_line) do |line, num|
|
||||||
|
next line unless line =~ /\A([ \t]*(?:#|\/?\*)?[ \t]*)(\\?):([\w-]+):([ \t]*)(.+)?(\r?\n|$)/
|
||||||
# skip something like ':toto::'
|
# skip something like ':toto::'
|
||||||
next $& if $4.empty? and $5 and $5[0, 1] == ':'
|
next $& if $4.empty? and $5 and $5[0, 1] == ':'
|
||||||
|
|
||||||
@ -120,8 +123,8 @@ class RDoc::Markup::PreProcess
|
|||||||
next "#{$1.strip}\n"
|
next "#{$1.strip}\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
handle_directive $1, $3, $5, code_object, text.encoding, &block
|
handle_directive $1, $3, $5, code_object, text.encoding, num, &block
|
||||||
end
|
end.join
|
||||||
|
|
||||||
if comment then
|
if comment then
|
||||||
comment.text = text
|
comment.text = text
|
||||||
@ -148,7 +151,7 @@ class RDoc::Markup::PreProcess
|
|||||||
# When 1.8.7 support is ditched prefix can be defaulted to ''
|
# When 1.8.7 support is ditched prefix can be defaulted to ''
|
||||||
|
|
||||||
def handle_directive prefix, directive, param, code_object = nil,
|
def handle_directive prefix, directive, param, code_object = nil,
|
||||||
encoding = nil
|
encoding = nil, line = nil
|
||||||
blankline = "#{prefix.strip}\n"
|
blankline = "#{prefix.strip}\n"
|
||||||
directive = directive.downcase
|
directive = directive.downcase
|
||||||
|
|
||||||
@ -220,11 +223,11 @@ class RDoc::Markup::PreProcess
|
|||||||
# remove parameter &block
|
# remove parameter &block
|
||||||
code_object.params = code_object.params.sub(/,?\s*&\w+/, '') if code_object.params
|
code_object.params = code_object.params.sub(/,?\s*&\w+/, '') if code_object.params
|
||||||
|
|
||||||
code_object.block_params = param
|
code_object.block_params = param || ''
|
||||||
|
|
||||||
blankline
|
blankline
|
||||||
else
|
else
|
||||||
result = yield directive, param if block_given?
|
result = yield directive, param, line if block_given?
|
||||||
|
|
||||||
case result
|
case result
|
||||||
when nil then
|
when nil then
|
||||||
|
1026
lib/rdoc/parser/prism_ruby.rb
Normal file
1026
lib/rdoc/parser/prism_ruby.rb
Normal file
File diff suppressed because it is too large
Load Diff
@ -8,6 +8,12 @@
|
|||||||
# by Keiju ISHITSUKA (Nippon Rational Inc.)
|
# by Keiju ISHITSUKA (Nippon Rational Inc.)
|
||||||
#
|
#
|
||||||
|
|
||||||
|
if ENV['RDOC_USE_PRISM_PARSER']
|
||||||
|
require 'rdoc/parser/prism_ruby'
|
||||||
|
RDoc::Parser.const_set(:Ruby, RDoc::Parser::PrismRuby)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
require 'ripper'
|
require 'ripper'
|
||||||
require_relative 'ripper_state_lex'
|
require_relative 'ripper_state_lex'
|
||||||
|
|
||||||
|
@ -230,8 +230,9 @@ RDoc includes the +rdoc+ and +ri+ tools for generating and displaying documentat
|
|||||||
s.rdoc_options = ["--main", "README.rdoc"]
|
s.rdoc_options = ["--main", "README.rdoc"]
|
||||||
s.extra_rdoc_files += s.files.grep(%r[\A[^\/]+\.(?:rdoc|md)\z])
|
s.extra_rdoc_files += s.files.grep(%r[\A[^\/]+\.(?:rdoc|md)\z])
|
||||||
|
|
||||||
s.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
|
s.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
|
||||||
s.required_rubygems_version = Gem::Requirement.new(">= 2.2")
|
s.required_rubygems_version = Gem::Requirement.new(">= 2.2")
|
||||||
|
|
||||||
|
s.add_dependency 'prism', '>= 0.30.0'
|
||||||
s.add_dependency 'psych', '>= 4.0.0'
|
s.add_dependency 'psych', '>= 4.0.0'
|
||||||
end
|
end
|
||||||
|
1997
test/rdoc/test_rdoc_parser_prism_ruby.rb
Normal file
1997
test/rdoc/test_rdoc_parser_prism_ruby.rb
Normal file
File diff suppressed because it is too large
Load Diff
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
require_relative 'helper'
|
require_relative 'helper'
|
||||||
|
|
||||||
|
return if ENV['RDOC_USE_PRISM_PARSER']
|
||||||
|
|
||||||
class TestRDocParserRuby < RDoc::TestCase
|
class TestRDocParserRuby < RDoc::TestCase
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
|
Loading…
x
Reference in New Issue
Block a user