Skip to content

Commit 7d99dc7

Browse files
committed
Fix handling complex expression in for/while/until
The parse_statements method calls skip_optional_do_after_expression method in case of for/while/until tokens. The skip_optional_do_after_expression method uses get_end_token method for checking end of loop condition expressions, but it's not correct, because the end is detected by only "do" token, newline and semi-colon token. This commit fixes it.
1 parent 53f146a commit 7d99dc7

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

lib/rdoc/parser/ruby.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2022,31 +2022,25 @@ def scan
20222022
def skip_optional_do_after_expression
20232023
skip_tkspace false
20242024
tk = get_tk
2025-
end_token = get_end_token tk
20262025

20272026
b_nest = 0
20282027
nest = 0
20292028
@scanner.continue = false
20302029

20312030
loop do
20322031
case tk
2033-
when TkSEMICOLON then
2032+
when TkSEMICOLON, TkNL then
20342033
break if b_nest.zero?
20352034
when TkLPAREN, TkfLPAREN then
20362035
nest += 1
2036+
when TkRPAREN then
2037+
nest -= 1
20372038
when TkBEGIN then
20382039
b_nest += 1
20392040
when TkEND then
20402041
b_nest -= 1
20412042
when TkDO
20422043
break if nest.zero?
2043-
when end_token then
2044-
if end_token == TkRPAREN
2045-
nest -= 1
2046-
break if @scanner.lex_state == :EXPR_END and nest.zero?
2047-
else
2048-
break unless @scanner.continue
2049-
end
20502044
when nil then
20512045
break
20522046
end

0 commit comments

Comments
 (0)