@@ -16,7 +16,8 @@ def initialize
1616 end
1717 end
1818
19- def initialize
19+ def initialize ( context )
20+ @context = context
2021 @exp_line_no = @line_no = 1
2122 @indent = 0
2223 @continue = false
@@ -42,13 +43,13 @@ def self.compile_with_errors_suppressed(code, line_no: 1)
4243 end
4344
4445 # io functions
45- def set_input ( io , context : , &block )
46+ def set_input ( io , &block )
4647 @io = io
4748 if @io . respond_to? ( :check_termination )
4849 @io . check_termination do |code |
4950 if Reline ::IOGate . in_pasting?
50- lex = RubyLex . new
51- rest = lex . check_termination_in_prev_line ( code , context : context )
51+ lex = RubyLex . new ( @context )
52+ rest = lex . check_termination_in_prev_line ( code )
5253 if rest
5354 Reline . delete_text
5455 rest . bytes . reverse_each do |c |
@@ -61,13 +62,13 @@ def set_input(io, context:, &block)
6162 else
6263 # Accept any single-line input for symbol aliases or commands that transform args
6364 command = code . split ( /\s / , 2 ) . first
64- if context . symbol_alias? ( command ) || context . transform_args? ( command )
65+ if @ context. symbol_alias? ( command ) || @ context. transform_args? ( command )
6566 next true
6667 end
6768
6869 code . gsub! ( /\s *\z / , '' ) . concat ( "\n " )
69- tokens = self . class . ripper_lex_without_warning ( code , context : context )
70- ltype , indent , continue , code_block_open = check_state ( code , tokens , context : context )
70+ tokens = self . class . ripper_lex_without_warning ( code , context : @ context)
71+ ltype , indent , continue , code_block_open = check_state ( code , tokens )
7172 if ltype or indent > 0 or continue or code_block_open
7273 false
7374 else
@@ -80,7 +81,7 @@ def set_input(io, context:, &block)
8081 @io . dynamic_prompt do |lines |
8182 lines << '' if lines . empty?
8283 result = [ ]
83- tokens = self . class . ripper_lex_without_warning ( lines . map { |l | l + "\n " } . join , context : context )
84+ tokens = self . class . ripper_lex_without_warning ( lines . map { |l | l + "\n " } . join , context : @ context)
8485 code = String . new
8586 partial_tokens = [ ]
8687 unprocessed_tokens = [ ]
@@ -93,7 +94,7 @@ def set_input(io, context:, &block)
9394 t_str . each_line ( "\n " ) do |s |
9495 code << s
9596 next unless s . include? ( "\n " )
96- ltype , indent , continue , code_block_open = check_state ( code , partial_tokens , context : context )
97+ ltype , indent , continue , code_block_open = check_state ( code , partial_tokens )
9798 result << @prompt . call ( ltype , indent , continue || code_block_open , @line_no + line_num_offset )
9899 line_num_offset += 1
99100 end
@@ -104,7 +105,7 @@ def set_input(io, context:, &block)
104105 end
105106
106107 unless unprocessed_tokens . empty?
107- ltype , indent , continue , code_block_open = check_state ( code , unprocessed_tokens , context : context )
108+ ltype , indent , continue , code_block_open = check_state ( code , unprocessed_tokens )
108109 result << @prompt . call ( ltype , indent , continue || code_block_open , @line_no + line_num_offset )
109110 end
110111 result
@@ -187,11 +188,11 @@ def find_prev_spaces(line_index)
187188 prev_spaces
188189 end
189190
190- def set_auto_indent ( context )
191- if @io . respond_to? ( :auto_indent ) and context . auto_indent_mode
191+ def set_auto_indent
192+ if @io . respond_to? ( :auto_indent ) and @ context. auto_indent_mode
192193 @io . auto_indent do |lines , line_index , byte_pointer , is_newline |
193194 if is_newline
194- @tokens = self . class . ripper_lex_without_warning ( lines [ 0 ..line_index ] . join ( "\n " ) , context : context )
195+ @tokens = self . class . ripper_lex_without_warning ( lines [ 0 ..line_index ] . join ( "\n " ) , context : @ context)
195196 prev_spaces = find_prev_spaces ( line_index )
196197 depth_difference = check_newline_depth_difference
197198 depth_difference = 0 if depth_difference < 0
@@ -200,18 +201,18 @@ def set_auto_indent(context)
200201 code = line_index . zero? ? '' : lines [ 0 ..( line_index - 1 ) ] . map { |l | l + "\n " } . join
201202 last_line = lines [ line_index ] &.byteslice ( 0 , byte_pointer )
202203 code += last_line if last_line
203- @tokens = self . class . ripper_lex_without_warning ( code , context : context )
204+ @tokens = self . class . ripper_lex_without_warning ( code , context : @ context)
204205 check_corresponding_token_depth ( lines , line_index )
205206 end
206207 end
207208 end
208209 end
209210
210- def check_state ( code , tokens , context : )
211+ def check_state ( code , tokens )
211212 ltype = process_literal_type ( tokens )
212213 indent = process_nesting_level ( tokens )
213214 continue = process_continue ( tokens )
214- lvars_code = self . class . generate_local_variables_assign_code ( context . local_variables )
215+ lvars_code = self . class . generate_local_variables_assign_code ( @ context. local_variables )
215216 code = "#{ lvars_code } \n #{ code } " if lvars_code
216217 code_block_open = check_code_block ( code , tokens )
217218 [ ltype , indent , continue , code_block_open ]
@@ -232,13 +233,13 @@ def initialize_input
232233 @code_block_open = false
233234 end
234235
235- def each_top_level_statement ( context )
236+ def each_top_level_statement
236237 initialize_input
237238 catch ( :TERM_INPUT ) do
238239 loop do
239240 begin
240241 prompt
241- unless l = lex ( context )
242+ unless l = lex
242243 throw :TERM_INPUT if @line == ''
243244 else
244245 @line_no += l . count ( "\n " )
@@ -268,15 +269,15 @@ def each_top_level_statement(context)
268269 end
269270 end
270271
271- def lex ( context )
272+ def lex
272273 line = @input . call
273274 if @io . respond_to? ( :check_termination )
274275 return line # multiline
275276 end
276277 code = @line + ( line . nil? ? '' : line )
277278 code . gsub! ( /\s *\z / , '' ) . concat ( "\n " )
278- @tokens = self . class . ripper_lex_without_warning ( code , context : context )
279- @ltype , @indent , @continue , @code_block_open = check_state ( code , @tokens , context : context )
279+ @tokens = self . class . ripper_lex_without_warning ( code , context : @ context)
280+ @ltype , @indent , @continue , @code_block_open = check_state ( code , @tokens )
280281 line
281282 end
282283
@@ -777,8 +778,8 @@ def process_literal_type(tokens)
777778 end
778779 end
779780
780- def check_termination_in_prev_line ( code , context : )
781- tokens = self . class . ripper_lex_without_warning ( code , context : context )
781+ def check_termination_in_prev_line ( code )
782+ tokens = self . class . ripper_lex_without_warning ( code , context : @ context)
782783 past_first_newline = false
783784 index = tokens . rindex do |t |
784785 # traverse first token before last line
0 commit comments