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:
parent
dc0e45e39b
commit
aa03de8ba1
1 changed files with 20 additions and 2 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue