@@ -69,9 +69,7 @@ def configure_io(io)
6969 # Accept any single-line input for symbol aliases or commands that transform args
7070 next true if single_line_command? ( code )
7171
72- code . gsub! ( /\s *\z / , '' ) . concat ( "\n " )
73- tokens = self . class . ripper_lex_without_warning ( code , context : @context )
74- ltype , indent , continue , code_block_open = check_state ( code , tokens )
72+ ltype , indent , continue , code_block_open = check_code_state ( code )
7573 if ltype or indent > 0 or continue or code_block_open
7674 false
7775 else
@@ -209,6 +207,12 @@ def check_state(code, tokens)
209207 [ ltype , indent , continue , code_block_open ]
210208 end
211209
210+ def check_code_state ( code )
211+ check_target_code = code . gsub ( /\s *\z / , '' ) . concat ( "\n " )
212+ tokens = self . class . ripper_lex_without_warning ( check_target_code , context : @context )
213+ check_state ( check_target_code , tokens )
214+ end
215+
212216 def save_prompt_to_context_io ( ltype , indent , continue , line_num_offset )
213217 # Implicitly saves prompt string to `@context.io.prompt`. This will be used in the next `@input.call`.
214218 @prompt . call ( ltype , indent , continue , @line_no + line_num_offset )
@@ -233,9 +237,7 @@ def readmultiline
233237 # Accept any single-line input for symbol aliases or commands that transform args
234238 return code if single_line_command? ( code )
235239
236- check_target_code = code . gsub ( /\s *\z / , '' ) . concat ( "\n " )
237- tokens = self . class . ripper_lex_without_warning ( check_target_code , context : @context )
238- ltype , indent , continue , code_block_open = check_state ( check_target_code , tokens )
240+ ltype , indent , continue , code_block_open = check_code_state ( code )
239241 return code unless ltype or indent > 0 or continue or code_block_open
240242
241243 line_offset += 1
0 commit comments