diff options
author | aycabta <aycabta@gmail.com> | 2019-08-20 08:24:50 +0900 |
---|---|---|
committer | aycabta <aycabta@gmail.com> | 2019-08-20 08:31:02 +0900 |
commit | aa03de8ba13e5ffa7049d3a881d2f5fe70dd4092 (patch) | |
tree | 2c19085b6f50f1a1b90d43b252a8ed6bd5893f20 /lib | |
parent | dc0e45e39b37556af8abf6cdb0180e2973041931 (diff) | |
download | ruby-aa03de8ba13e5ffa7049d3a881d2f5fe70dd4092.tar.gz |
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".
Diffstat (limited to 'lib')
-rw-r--r-- | lib/irb/ruby-lex.rb | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/lib/irb/ruby-lex.rb b/lib/irb/ruby-lex.rb index fd2e122e1b..a7b8ad8a07 100644 --- a/lib/irb/ruby-lex.rb +++ b/lib/irb/ruby-lex.rb @@ -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 |