diff options
author | Nobuhiro IMAI <[email protected]> | 2020-03-02 22:16:11 +0900 |
---|---|---|
committer | aycabta <[email protected]> | 2020-07-22 02:31:47 +0900 |
commit | f6e789e3b07ede0b5842c7f64940e4cd9ed876fd (patch) | |
tree | ac0dbfbd17e187fa7515ea28fd732c44b79ab094 /lib/irb/ruby-lex.rb | |
parent | 22d38d54751e3e23144d4b4e1fb8ed67626c89c8 (diff) |
[ruby/irb] handle rescue modifier properly
https://github.com/ruby/irb/commit/6de1341f5e
Diffstat (limited to 'lib/irb/ruby-lex.rb')
-rw-r--r-- | lib/irb/ruby-lex.rb | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/irb/ruby-lex.rb b/lib/irb/ruby-lex.rb index c7a47fd99d..6a7df1ad96 100644 --- a/lib/irb/ruby-lex.rb +++ b/lib/irb/ruby-lex.rb @@ -324,7 +324,7 @@ class RubyLex 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 + # postfix if/unless/while/until must be Ripper::EXPR_LABEL indent += 1 unless t[3].allbits?(Ripper::EXPR_LABEL) when 'end' indent -= 1 @@ -369,12 +369,12 @@ class RubyLex end when 'def', 'case', 'for', 'begin', 'class', 'module' depth_difference += 1 - when 'if', 'unless', 'while', 'until' + when 'if', 'unless', 'while', 'until', 'rescue' # postfix if/unless/while/until/rescue must be Ripper::EXPR_LABEL unless t[3].allbits?(Ripper::EXPR_LABEL) depth_difference += 1 end - when 'else', 'elsif', 'rescue', 'ensure', 'when', 'in' + when 'else', 'elsif', 'ensure', 'when', 'in' depth_difference += 1 end end @@ -420,12 +420,16 @@ class RubyLex case t[2] when 'def', 'do', 'case', 'for', 'begin', 'class', 'module' spaces_of_nest.push(spaces_at_line_head) + when 'rescue' + unless t[3].allbits?(Ripper::EXPR_LABEL) + corresponding_token_depth = spaces_of_nest.last + end when 'if', 'unless', 'while', 'until' - # postfix if/unless/while/until/rescue must be Ripper::EXPR_LABEL + # postfix if/unless/while/until must be Ripper::EXPR_LABEL unless t[3].allbits?(Ripper::EXPR_LABEL) spaces_of_nest.push(spaces_at_line_head) end - when 'else', 'elsif', 'rescue', 'ensure', 'when', 'in' + when 'else', 'elsif', 'ensure', 'when', 'in' corresponding_token_depth = spaces_of_nest.last when 'end' if is_first_printable_of_line |