diff options
Diffstat (limited to 'lib/irb/ruby-lex.rb')
-rw-r--r-- | lib/irb/ruby-lex.rb | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/irb/ruby-lex.rb b/lib/irb/ruby-lex.rb index b4c31c16fe..d5630c8b52 100644 --- a/lib/irb/ruby-lex.rb +++ b/lib/irb/ruby-lex.rb @@ -211,6 +211,8 @@ class RubyLex else RubyVM::InstructionSequence.compile(code) end + rescue EncodingError + # This is for a hash with invalid encoding symbol, {"\xAE": 1} rescue SyntaxError => e case e.message when /unterminated (?:string|regexp) meets end of file/ @@ -317,11 +319,13 @@ class RubyLex def check_newline_depth_difference depth_difference = 0 + open_brace_on_line = 0 @tokens.each_with_index do |t, index| case t[1] when :on_ignored_nl, :on_nl, :on_comment if index != (@tokens.size - 1) depth_difference = 0 + open_brace_on_line = 0 end next when :on_sp @@ -330,8 +334,9 @@ class RubyLex case t[1] when :on_lbracket, :on_lbrace, :on_lparen depth_difference += 1 + open_brace_on_line += 1 when :on_rbracket, :on_rbrace, :on_rparen - depth_difference -= 1 + depth_difference -= 1 if open_brace_on_line > 0 when :on_kw next if index > 0 and @tokens[index - 1][3].allbits?(Ripper::EXPR_FNAME) case t[2] @@ -365,6 +370,7 @@ class RubyLex is_first_printable_of_line = true spaces_of_nest = [] spaces_at_line_head = 0 + open_brace_on_line = 0 @tokens.each_with_index do |t, index| case t[1] when :on_ignored_nl, :on_nl, :on_comment @@ -372,6 +378,7 @@ class RubyLex spaces_at_line_head = 0 is_first_spaces_of_line = true is_first_printable_of_line = true + open_brace_on_line = 0 next when :on_sp spaces_at_line_head = t[2].count(' ') if is_first_spaces_of_line @@ -380,7 +387,8 @@ class RubyLex end case t[1] when :on_lbracket, :on_lbrace, :on_lparen - spaces_of_nest.push(spaces_at_line_head) + spaces_of_nest.push(spaces_at_line_head + open_brace_on_line * 2) + open_brace_on_line += 1 when :on_rbracket, :on_rbrace, :on_rparen if is_first_printable_of_line corresponding_token_depth = spaces_of_nest.pop @@ -388,6 +396,7 @@ class RubyLex spaces_of_nest.pop corresponding_token_depth = nil end + open_brace_on_line -= 1 when :on_kw next if index > 0 and @tokens[index - 1][3].allbits?(Ripper::EXPR_FNAME) case t[2] |