Skip to content

Commit fe44516

Browse files
authored
Merge pull request #510 from aycabta/fix-handling-rescue-inside-paren
Fix handling "rescue" inside paren
2 parents 6bd9bf3 + 6bd9fa6 commit fe44516

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

lib/rdoc/parser/ruby.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,6 +1607,7 @@ def parse_require(context, comment)
16071607
def parse_rescue
16081608
skip_tkspace false
16091609

1610+
nest = 0
16101611
while tk = get_tk
16111612
case tk
16121613
when TkNL, TkSEMICOLON then
@@ -1615,6 +1616,11 @@ def parse_rescue
16151616
skip_tkspace false
16161617

16171618
get_tk if TkNL === peek_tk
1619+
when TkLPAREN, TkfLPAREN then
1620+
nest += 1
1621+
when TkRPAREN then
1622+
nest -= 1
1623+
break if nest < 0
16181624
end
16191625

16201626
skip_tkspace false

test/test_rdoc_parser_ruby.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3600,6 +3600,25 @@ class C
36003600
assert_equal :public, const_c.visibility
36013601
end
36023602

3603+
def test_document_after_rescue_inside_paren
3604+
util_parser <<-RUBY
3605+
class C
3606+
attr_accessor :sample if (1.inexistent_method rescue false)
3607+
# first
3608+
# second
3609+
def a
3610+
end
3611+
end
3612+
RUBY
3613+
3614+
@parser.scan
3615+
3616+
c = @store.find_class_named 'C'
3617+
3618+
c_a = c.find_method_named 'a'
3619+
assert_equal "first\nsecond", c_a.comment.text
3620+
end
3621+
36033622
def test_singleton_method_via_eigenclass
36043623
util_parser <<-RUBY
36053624
class C

0 commit comments

Comments
 (0)