ruby-changes:71128
From: Soutaro <ko1@a...>
Date: Wed, 9 Feb 2022 18:45:15 +0900 (JST)
Subject: [ruby-changes:71128] cbd54cba03 (master): [ruby/rdoc] Skip parentheses on singleton class declaration
https://git.ruby-lang.org/ruby.git/commit/?id=cbd54cba03 From cbd54cba03d0a0ecae1df590ca78751362fda826 Mon Sep 17 00:00:00 2001 From: Soutaro Matsumoto <matsumoto@s...> Date: Tue, 8 Feb 2022 21:23:13 +0900 Subject: [ruby/rdoc] Skip parentheses on singleton class declaration https://github.com/ruby/rdoc/commit/b6c6d4f978 --- lib/rdoc/parser/ruby.rb | 25 ++++++++++++++++++++++++- test/rdoc/test_rdoc_parser_ruby.rb | 13 +++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/lib/rdoc/parser/ruby.rb b/lib/rdoc/parser/ruby.rb index e546fe2141..3c5f79632c 100644 --- a/lib/rdoc/parser/ruby.rb +++ b/lib/rdoc/parser/ruby.rb @@ -399,6 +399,29 @@ class RDoc::Parser::Ruby < RDoc::Parser https://github.com/ruby/ruby/blob/trunk/lib/rdoc/parser/ruby.rb#L399 return [container, name_t, given_name, new_modules] end + ## + # Skip opening parentheses and yield the block. + # Skip closing parentheses too when exists. + + def skip_parentheses(&block) + left_tk = peek_tk + + if :on_lparen == left_tk[:kind] + get_tk + + ret = skip_parentheses(&block) + + right_tk = peek_tk + if :on_rparen == right_tk[:kind] + get_tk + end + + ret + else + yield + end + end + ## # Return a superclass, which can be either a constant of an expression @@ -833,7 +856,7 @@ class RDoc::Parser::Ruby < RDoc::Parser https://github.com/ruby/ruby/blob/trunk/lib/rdoc/parser/ruby.rb#L856 cls = parse_class_regular container, declaration_context, single, name_t, given_name, comment elsif name_t[:kind] == :on_op && name_t[:text] == '<<' - case name = get_class_specification + case name = skip_parentheses { get_class_specification } when 'self', container.name read_documentation_modifiers cls, RDoc::CLASS_MODIFIERS parse_statements container, SINGLE diff --git a/test/rdoc/test_rdoc_parser_ruby.rb b/test/rdoc/test_rdoc_parser_ruby.rb index 337cf9ea1a..b3026b14ca 100644 --- a/test/rdoc/test_rdoc_parser_ruby.rb +++ b/test/rdoc/test_rdoc_parser_ruby.rb @@ -4345,4 +4345,17 @@ end https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_parser_ruby.rb#L4345 assert_equal 'Hello', meth.comment.text end + def test_parenthesized_cdecl + util_parser <<-RUBY +module DidYouMean + class << (NameErrorCheckers = Object.new) + end +end + RUBY + + @parser.scan + + refute_predicate @store.find_class_or_module('DidYouMean'), :nil? + refute_predicate @store.find_class_or_module('DidYouMean::NameErrorCheckers'), :nil? + end end -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/