Skip to content

Commit

Permalink
Change ripper_lex_without_warning to a class method
Browse files Browse the repository at this point in the history
  • Loading branch information
aycabta committed Mar 24, 2021
1 parent 7f75269 commit d9f8abc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
14 changes: 7 additions & 7 deletions lib/irb/ruby-lex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def set_input(io, p = nil, &block)
@io.dynamic_prompt do |lines|
lines << '' if lines.empty?
result = []
tokens = ripper_lex_without_warning(lines.map{ |l| l + "\n" }.join)
tokens = self.class.ripper_lex_without_warning(lines.map{ |l| l + "\n" }.join)
code = String.new
partial_tokens = []
unprocessed_tokens = []
Expand Down Expand Up @@ -115,10 +115,10 @@ def set_prompt(p = nil, &block)
:on_param_error
]

def ripper_lex_without_warning(code)
def self.ripper_lex_without_warning(code)
verbose, $VERBOSE = $VERBOSE, nil
tokens = nil
self.class.compile_with_errors_suppressed(code) do |inner_code, line_no|
compile_with_errors_suppressed(code) do |inner_code, line_no|
lexer = Ripper::Lexer.new(inner_code, '-', line_no)
if lexer.respond_to?(:scan) # Ruby 2.7+
tokens = []
Expand Down Expand Up @@ -168,7 +168,7 @@ def set_auto_indent(context)
if @io.respond_to?(:auto_indent) and context.auto_indent_mode
@io.auto_indent do |lines, line_index, byte_pointer, is_newline|
if is_newline
@tokens = ripper_lex_without_warning(lines[0..line_index].join("\n"))
@tokens = self.class.ripper_lex_without_warning(lines[0..line_index].join("\n"))
prev_spaces = find_prev_spaces(line_index)
depth_difference = check_newline_depth_difference
depth_difference = 0 if depth_difference < 0
Expand All @@ -177,7 +177,7 @@ def set_auto_indent(context)
code = line_index.zero? ? '' : lines[0..(line_index - 1)].map{ |l| l + "\n" }.join
last_line = lines[line_index]&.byteslice(0, byte_pointer)
code += last_line if last_line
@tokens = ripper_lex_without_warning(code)
@tokens = self.class.ripper_lex_without_warning(code)
corresponding_token_depth = check_corresponding_token_depth
if corresponding_token_depth
corresponding_token_depth
Expand All @@ -190,7 +190,7 @@ def set_auto_indent(context)
end

def check_state(code, tokens = nil)
tokens = ripper_lex_without_warning(code) unless tokens
tokens = self.class.ripper_lex_without_warning(code) unless tokens
ltype = process_literal_type(tokens)
indent = process_nesting_level(tokens)
continue = process_continue(tokens)
Expand Down Expand Up @@ -256,7 +256,7 @@ def lex
end
code = @line + (line.nil? ? '' : line)
code.gsub!(/\s*\z/, '').concat("\n")
@tokens = ripper_lex_without_warning(code)
@tokens = self.class.ripper_lex_without_warning(code)
@continue = process_continue
@code_block_open = check_code_block(code)
@indent = process_nesting_level
Expand Down
6 changes: 2 additions & 4 deletions test/irb/test_ruby_lex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -558,8 +558,7 @@ def test_broken_percent_literal
skip 'This test needs Ripper::Lexer#scan to take broken tokens'
end

ruby_lex = RubyLex.new
tokens = ruby_lex.ripper_lex_without_warning('%wwww')
tokens = RubyLex.ripper_lex_without_warning('%wwww')
pos_to_index = {}
tokens.each_with_index { |t, i|
assert_nil(pos_to_index[t[0]], "There is already another token in the position of #{t.inspect}.")
Expand All @@ -572,8 +571,7 @@ def test_broken_percent_literal_in_method
skip 'This test needs Ripper::Lexer#scan to take broken tokens'
end

ruby_lex = RubyLex.new
tokens = ruby_lex.ripper_lex_without_warning(<<~EOC.chomp)
tokens = RubyLex.ripper_lex_without_warning(<<~EOC.chomp)
def foo
%wwww
end
Expand Down

0 comments on commit d9f8abc

Please sign in to comment.