Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move assignment check to RubyLex #670

Merged
merged 1 commit into from
Aug 11, 2023
Merged

Conversation

st0012
Copy link
Member

@st0012 st0012 commented Aug 6, 2023

Since assignment check relies on tokenization with Ripper, it feels like the responsibility of RubyLex. Irb#eval_input should simply get the result when calling each_top_level_statement on RubyLex.

Since assignment check relies on tokenization with `Ripper`, it feels like
the responsibility of `RubyLex`. `Irb#eval_input` should simply get the result
when calling `each_top_level_statement` on `RubyLex`.
@@ -555,11 +531,9 @@ def eval_input

@scanner.configure_io(@context.io)

@scanner.each_top_level_statement do |line, line_no|
@scanner.each_top_level_statement do |line, line_no, is_assignment|
Copy link
Member

Choose a reason for hiding this comment

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

There is a plan to add end_with_semicolon_check and number of parameter will increase. Then it will look like this.

@scanner.each_top_level_statement do |line, line_no, is_a, is_b, is_c|

end

How about this?

@scanner.each_top_level_statement do |line, line_no| # line_no and line is always needed.
  # IMO optional information of `line` should be explicitly calculated here
  is_a = @scanner.check_a?(line)
  is_c = @scanner.check_c?(line)
  is_d = @scanner.check_d?(line)
end

Copy link
Member Author

Choose a reason for hiding this comment

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

For the assignment check, I think it's better to be handled from each_top_level_statement so it's always calculated before line evaluation. I'm fine using the suggested pattern for semicolon check though.

I was also thinking instead of returning individual information as the yielding argument, perhaps we can encapsulate them inside a Statement object? But I will explore it after this and #669 is merged.

@tompng tompng merged commit 89d1adb into master Aug 11, 2023
47 checks passed
@tompng tompng deleted the refactor-assignment-check branch August 11, 2023 18:44
matzbot pushed a commit to ruby/ruby that referenced this pull request Aug 11, 2023
(ruby/irb#670)

Since assignment check relies on tokenization with `Ripper`, it feels like
the responsibility of `RubyLex`. `Irb#eval_input` should simply get the result
when calling `each_top_level_statement` on `RubyLex`.

ruby/irb@89d1adb3fd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants