Skip to content

Conversation

@tompng
Copy link
Member

@tompng tompng commented Apr 30, 2023

This pull request is an extract of refactor from #500

Refactored each_top_level_statement

  • Remove instance variables @exp_line_no @indent @continue @line from ruby-lex.rb
  • Extract reading line part from def each_top_level_statement to def readmultiline
  • Refactor complex flow using catch(:TERM_INPUT) and throw :TERM_INPUT into simple loop and break
  • Delete def lex because it is only used from test code now

@tompng tompng force-pushed the each_toplevel_statement_refactor branch from 9ac0f6f to 7907a48 Compare April 30, 2023 17:20
end
def save_prompt_to_context_io(ltype, indent, continue, line_num_offset)
# Implicitly saves prompt string to `@context.io.prompt`. This will be used in the next `@input.call`.
@prompt.call(ltype, indent, continue, @line_no + line_num_offset)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@prompt is not going to be nil in actual use cases because Irb#eval_input always calls RubyLex#set_prompt before calling RubyLex#each_top_level_statemen.
But I think this type of implicit dependency is risky and we should probably refactor that later.

Copy link
Member

@st0012 st0012 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 But I think there's a conflict in test file.

@tompng tompng force-pushed the each_toplevel_statement_refactor branch from da1c0aa to dfd4ced Compare May 19, 2023 12:41
@st0012 st0012 merged commit 172453c into ruby:master May 19, 2023
matzbot pushed a commit to ruby/ruby that referenced this pull request May 19, 2023
(ruby/irb#576)

* Simplify each_top_level_statement, reduce instance vars

* Update lib/irb/ruby-lex.rb

Co-authored-by: Stan Lo <stan001212@gmail.com>

* Remove unused ltype from TestRubyLex#check_state response

* Remove unnecessary const path of TerminateLineInput

* Combine duplicated code state check into method

---------

ruby/irb@172453cec4

Co-authored-by: Stan Lo <stan001212@gmail.com>
@tompng tompng deleted the each_toplevel_statement_refactor branch May 19, 2023 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants