diff options
author | aycabta <aycabta@gmail.com> | 2019-07-02 03:34:08 +0900 |
---|---|---|
committer | aycabta <aycabta@gmail.com> | 2019-07-02 03:34:15 +0900 |
commit | 776759e300e4659bb7468e2b97c8c2d4359a2953 (patch) | |
tree | 651b3beb9da58f1fad411bebd562bfdbf0903be6 /lib/irb | |
parent | 7ff2bfed92f8017184963eaac13e75cfb5ce5d4a (diff) |
Keyword token that follows EXPR_FNAME must be a method name
Diffstat (limited to 'lib/irb')
-rw-r--r-- | lib/irb/ruby-lex.rb | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/irb/ruby-lex.rb b/lib/irb/ruby-lex.rb index ac26f28c3a..e1d33b24cf 100644 --- a/lib/irb/ruby-lex.rb +++ b/lib/irb/ruby-lex.rb @@ -283,13 +283,15 @@ class RubyLex end def process_nesting_level - indent = @tokens.inject(0) { |indent, t| + indent = 0 + @tokens.each_with_index { |t, index| case t[1] when :on_lbracket, :on_lbrace, :on_lparen indent += 1 when :on_rbracket, :on_rbrace, :on_rparen indent -= 1 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' indent += 1 @@ -301,7 +303,6 @@ class RubyLex end end # percent literals are not indented - indent } indent end @@ -324,6 +325,7 @@ class RubyLex when :on_rbracket, :on_rbrace, :on_rparen depth_difference -= 1 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' depth_difference += 1 @@ -346,7 +348,7 @@ class RubyLex is_first_printable_of_line = true spaces_of_nest = [] spaces_at_line_head = 0 - @tokens.each do |t| + @tokens.each_with_index do |t, index| corresponding_token_depth = nil case t[1] when :on_ignored_nl, :on_nl @@ -370,6 +372,7 @@ class RubyLex corresponding_token_depth = nil end 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' spaces_of_nest.push(spaces_at_line_head) |