diff options
author | aycabta <[email protected]> | 2021-01-23 11:39:51 +0900 |
---|---|---|
committer | git <[email protected]> | 2021-01-24 14:35:34 +0900 |
commit | 743c44ee2167e41c828c631ee764e96640f99736 (patch) | |
tree | 5cb887d6095e5c7cedca861cc65cb76c5cb43e87 /lib/irb/ruby-lex.rb | |
parent | fc54af8aa136888d8c5a8bf7d68594f979a43946 (diff) |
[ruby/irb] Indent correctly with method calling with receiver
https://github.com/ruby/irb/commit/e7c68e74a0
Diffstat (limited to 'lib/irb/ruby-lex.rb')
-rw-r--r-- | lib/irb/ruby-lex.rb | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/lib/irb/ruby-lex.rb b/lib/irb/ruby-lex.rb index b41126f985..7b365a39cf 100644 --- a/lib/irb/ruby-lex.rb +++ b/lib/irb/ruby-lex.rb @@ -424,6 +424,24 @@ class RubyLex indent end + def is_method_calling?(tokens, index) + tk = tokens[index] + if tk[3].anybits?(Ripper::EXPR_CMDARG) and tk[1] == :on_ident + # The target method call to pass the block with "do". + return true + elsif tk[3].anybits?(Ripper::EXPR_ARG) and tk[1] == :on_ident + non_sp_index = tokens[0..(index - 1)].rindex{ |t| t[1] != :on_sp } + if non_sp_index + prev_tk = tokens[non_sp_index] + if prev_tk[3].anybits?(Ripper::EXPR_DOT) and prev_tk[1] == :on_period + # The target method call with receiver to pass the block with "do". + return true + end + end + end + false + end + def take_corresponding_syntax_to_kw_do(tokens, index) syntax_of_do = nil # Finding a syntax correnponding to "do". @@ -437,8 +455,7 @@ class RubyLex elsif [:on_ignored_nl, :on_nl, :on_comment].include?(tokens[non_sp_index][1]) first_in_fomula = true end - if tk[3].anybits?(Ripper::EXPR_CMDARG) and tk[1] == :on_ident - # The target method call to pass the block with "do". + if is_method_calling?(tokens, i) syntax_of_do = :method_calling break if first_in_fomula elsif tk[1] == :on_kw && %w{while until for}.include?(tk[2]) |