Skip to content

Commit fd547c5

Browse files
authored
Merge pull request #635 from aycabta/treat-if-with-expr_mid-as-postfix
Treat "if" with EXPR_MID as postfix "if"
2 parents a3da09c + 53cb21f commit fd547c5

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

lib/rdoc/parser/ripper_state_lex.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def on_kw(tok, data)
114114
@continue = true
115115
@in_fname = true
116116
when 'if', 'unless', 'while', 'until'
117-
if ((EXPR_END | EXPR_ENDARG | EXPR_ENDFN | EXPR_ARG | EXPR_CMDARG) & @lex_state) != 0 # postfix if
117+
if ((EXPR_MID | EXPR_END | EXPR_ENDARG | EXPR_ENDFN | EXPR_ARG | EXPR_CMDARG) & @lex_state) != 0 # postfix if
118118
@lex_state = EXPR_BEG | EXPR_LABEL
119119
else
120120
@lex_state = EXPR_BEG

test/test_rdoc_parser_ruby.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2310,6 +2310,31 @@ def bar
23102310
assert_equal 'C#bar', methods[1].full_name
23112311
end
23122312

2313+
def test_parse_statements_postfix_if_unless_with_expr_mid
2314+
util_parser <<-CODE
2315+
class A
2316+
class B
2317+
def foo
2318+
return if nil
2319+
end
2320+
end
2321+
2322+
class C
2323+
end
2324+
end
2325+
CODE
2326+
2327+
@parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil
2328+
2329+
a = @top_level.classes.first
2330+
assert_equal 'A', a.full_name, 'class A'
2331+
assert_equal 2, a.classes.length
2332+
b = a.classes[0]
2333+
assert_equal 'A::B', b.full_name, 'class A::B'
2334+
c = a.classes[1]
2335+
assert_equal 'A::C', c.full_name, 'class A::C'
2336+
end
2337+
23132338
def test_parse_statements_class_nested
23142339
comment = RDoc::Comment.new "##\n# my method\n", @top_level
23152340

0 commit comments

Comments
 (0)