[ruby/irb] Remove redundant argument defaults from some RubyLex
methods (https://github.com/ruby/irb/pull/502) * Remove unnecessary parameter defaults These methods are always called with tokens specified. So their default `@tokens` value is never used and is misleading. * Remove unnecessary context default * Require tokens for `RubyLex#check_state`
This commit is contained in:
parent
aa66595876
commit
019c65828b
@ -66,7 +66,8 @@ class RubyLex
|
|||||||
end
|
end
|
||||||
|
|
||||||
code.gsub!(/\s*\z/, '').concat("\n")
|
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
|
if ltype or indent > 0 or continue or code_block_open
|
||||||
false
|
false
|
||||||
else
|
else
|
||||||
@ -206,8 +207,7 @@ class RubyLex
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_state(code, tokens = nil, context: nil)
|
def check_state(code, tokens, context:)
|
||||||
tokens = self.class.ripper_lex_without_warning(code, context: context) unless tokens
|
|
||||||
ltype = process_literal_type(tokens)
|
ltype = process_literal_type(tokens)
|
||||||
indent = process_nesting_level(tokens)
|
indent = process_nesting_level(tokens)
|
||||||
continue = process_continue(tokens)
|
continue = process_continue(tokens)
|
||||||
@ -280,7 +280,7 @@ class RubyLex
|
|||||||
line
|
line
|
||||||
end
|
end
|
||||||
|
|
||||||
def process_continue(tokens = @tokens)
|
def process_continue(tokens)
|
||||||
# last token is always newline
|
# last token is always newline
|
||||||
if tokens.size >= 2 and tokens[-2].event == :on_regexp_end
|
if tokens.size >= 2 and tokens[-2].event == :on_regexp_end
|
||||||
# end of regexp literal
|
# end of regexp literal
|
||||||
@ -301,7 +301,7 @@ class RubyLex
|
|||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_code_block(code, tokens = @tokens)
|
def check_code_block(code, tokens)
|
||||||
return true if tokens.empty?
|
return true if tokens.empty?
|
||||||
if tokens.last.event == :on_heredoc_beg
|
if tokens.last.event == :on_heredoc_beg
|
||||||
return true
|
return true
|
||||||
@ -393,7 +393,7 @@ class RubyLex
|
|||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
def process_nesting_level(tokens = @tokens)
|
def process_nesting_level(tokens)
|
||||||
indent = 0
|
indent = 0
|
||||||
in_oneliner_def = nil
|
in_oneliner_def = nil
|
||||||
tokens.each_with_index { |t, index|
|
tokens.each_with_index { |t, index|
|
||||||
@ -749,7 +749,7 @@ class RubyLex
|
|||||||
pending_heredocs.first || start_token.last
|
pending_heredocs.first || start_token.last
|
||||||
end
|
end
|
||||||
|
|
||||||
def process_literal_type(tokens = @tokens)
|
def process_literal_type(tokens)
|
||||||
start_token = check_string_literal(tokens)
|
start_token = check_string_literal(tokens)
|
||||||
return nil if start_token == ""
|
return nil if start_token == ""
|
||||||
|
|
||||||
@ -777,7 +777,7 @@ class RubyLex
|
|||||||
end
|
end
|
||||||
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)
|
tokens = self.class.ripper_lex_without_warning(code, context: context)
|
||||||
past_first_newline = false
|
past_first_newline = false
|
||||||
index = tokens.rindex do |t|
|
index = tokens.rindex do |t|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user