Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip parentheses on singleton class declaration #867

Merged
merged 1 commit into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 24 additions & 1 deletion lib/rdoc/parser/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,29 @@ def get_class_or_module container, ignore_constants = false
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

Expand Down Expand Up @@ -833,7 +856,7 @@ def parse_class container, single, tk, comment
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
Expand Down
13 changes: 13 additions & 0 deletions test/rdoc/test_rdoc_parser_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4345,4 +4345,17 @@ def foo() end
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