Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions lib/irb/ruby-lex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ def set_input(io, p = nil, context:, &block)
end

code.gsub!(/\s*\z/, '').concat("\n")
ltype, indent, continue, code_block_open = check_state(code, context: context)
tokens = self.class.ripper_lex_without_warning(code, context: context)
ltype, indent, continue, code_block_open = check_state(code, tokens, context: context)
if ltype or indent > 0 or continue or code_block_open
false
else
Expand Down Expand Up @@ -219,8 +220,7 @@ def set_auto_indent(context)
end
end

def check_state(code, tokens = nil, context: nil)
tokens = self.class.ripper_lex_without_warning(code, context: context) unless tokens
def check_state(code, tokens, context:)
ltype = process_literal_type(tokens)
indent = process_nesting_level(tokens)
continue = process_continue(tokens)
Expand Down Expand Up @@ -293,7 +293,7 @@ def lex(context)
line
end

def process_continue(tokens = @tokens)
def process_continue(tokens)
# last token is always newline
if tokens.size >= 2 and tokens[-2].event == :on_regexp_end
# end of regexp literal
Expand All @@ -314,7 +314,7 @@ def process_continue(tokens = @tokens)
false
end

def check_code_block(code, tokens = @tokens)
def check_code_block(code, tokens)
return true if tokens.empty?
if tokens.last.event == :on_heredoc_beg
return true
Expand Down Expand Up @@ -406,7 +406,7 @@ def check_code_block(code, tokens = @tokens)
false
end

def process_nesting_level(tokens = @tokens)
def process_nesting_level(tokens)
indent = 0
in_oneliner_def = nil
tokens.each_with_index { |t, index|
Expand Down Expand Up @@ -762,7 +762,7 @@ def check_string_literal(tokens)
pending_heredocs.first || start_token.last
end

def process_literal_type(tokens = @tokens)
def process_literal_type(tokens)
start_token = check_string_literal(tokens)
return nil if start_token == ""

Expand Down Expand Up @@ -790,7 +790,7 @@ def process_literal_type(tokens = @tokens)
end
end

def check_termination_in_prev_line(code, context: nil)
def check_termination_in_prev_line(code, context:)
tokens = self.class.ripper_lex_without_warning(code, context: context)
past_first_newline = false
index = tokens.rindex do |t|
Expand Down