1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Treat two types "do" correctly

A "do" what has followed a token what has EXPR_CMDARG is for a block,
and in other cases "do" is for "while", "until" or "for".
This commit is contained in:
aycabta 2019-08-20 08:24:50 +09:00
parent dc0e45e39b
commit aa03de8ba1

View file

@ -298,7 +298,16 @@ class RubyLex
when :on_kw
next if index > 0 and @tokens[index - 1][3].allbits?(Ripper::EXPR_FNAME)
case t[2]
when 'def', 'do', 'case', 'for', 'begin', 'class', 'module'
when 'do'
if index > 0 and @tokens[index - 1][3].allbits?(Ripper::EXPR_CMDARG)
# method_with_bock do; end
indent += 1
else
# while cond do; end # also "until" or "for"
# This "do" doesn't increment indent because "while" already
# incremented.
end
when 'def', 'case', 'for', 'begin', 'class', 'module'
indent += 1
when 'if', 'unless', 'while', 'until'
# postfix if/unless/while/until/rescue must be Ripper::EXPR_LABEL
@ -332,7 +341,16 @@ class RubyLex
when :on_kw
next if index > 0 and @tokens[index - 1][3].allbits?(Ripper::EXPR_FNAME)
case t[2]
when 'def', 'do', 'case', 'for', 'begin', 'class', 'module'
when 'do'
if index > 0 and @tokens[index - 1][3].allbits?(Ripper::EXPR_CMDARG)
# method_with_bock do; end
depth_difference += 1
else
# while cond do; end # also "until" or "for"
# This "do" doesn't increment indent because "while" already
# incremented.
end
when 'def', 'case', 'for', 'begin', 'class', 'module'
depth_difference += 1
when 'if', 'unless', 'while', 'until'
# postfix if/unless/while/until/rescue must be Ripper::EXPR_LABEL