diff --git a/lib/rdoc/parser/ruby.rb b/lib/rdoc/parser/ruby.rb index 4188278b78..1bd2469c0f 100644 --- a/lib/rdoc/parser/ruby.rb +++ b/lib/rdoc/parser/ruby.rb @@ -861,6 +861,23 @@ def parse_constant container, tk, comment, ignore_constants = false eq_tk = get_tk end + is_array_or_hash = false + if TkfLBRACK === eq_tk + nest = 1 + while bracket_tk = get_tk + case bracket_tk + when TkfLBRACK, TkLBRACK + nest += 1 + when TkRBRACK + nest -= 1 + break if nest == 0 + end + end + skip_tkspace false + eq_tk = get_tk + is_array_or_hash = true + end + unless TkASSIGN === eq_tk then unget_tk eq_tk return false @@ -874,7 +891,7 @@ def parse_constant container, tk, comment, ignore_constants = false value = '' con = RDoc::Constant.new name, value, comment - body = parse_constant_body container, con + body = parse_constant_body container, con, is_array_or_hash return unless body @@ -883,13 +900,15 @@ def parse_constant container, tk, comment, ignore_constants = false con.line = line_no read_documentation_modifiers con, RDoc::CONSTANT_MODIFIERS + return if is_array_or_hash + @stats.add_constant con container.add_constant con true end - def parse_constant_body container, constant # :nodoc: + def parse_constant_body container, constant, is_array_or_hash # :nodoc: nest = 0 rhs_name = '' @@ -918,7 +937,7 @@ def parse_constant_body container, constant # :nodoc: rhs_name << tk.name if nest <= 0 and TkNL === peek_tk then - create_module_alias container, constant, rhs_name + create_module_alias container, constant, rhs_name unless is_array_or_hash break end when TkNL then diff --git a/test/test_rdoc_parser_ruby.rb b/test/test_rdoc_parser_ruby.rb index 0e7fce03e7..ad44dd841e 100644 --- a/test/test_rdoc_parser_ruby.rb +++ b/test/test_rdoc_parser_ruby.rb @@ -1358,6 +1358,33 @@ def test_parse_comment_nested assert_equal 'comment', c.comment end + def test_parse_constant_with_bracket + util_parser <<-RUBY +class Klass +end + +class Klass2 + CONSTANT = Klass +end + +class Klass3 + CONSTANT_2 = {} + CONSTANT_2[1] = Klass +end + RUBY + + @parser.scan + + klass = @store.find_class_named 'Klass' + klass2 = @store.find_class_named 'Klass2' + klass3 = @store.find_class_named 'Klass3' + constant = klass2.find_module_named 'CONSTANT' + constant2 = klass3.find_module_named 'CONSTANT_2' + assert_equal klass, klass2.constants.first.is_alias_for + refute_equal klass, klass3.constants.first.is_alias_for + assert_nil klass3.find_module_named 'CONSTANT_2' + end + def test_parse_extend_or_include_extend klass = RDoc::NormalClass.new 'C' klass.parent = @top_level