diff options
author | Stan Lo <stan001212@gmail.com> | 2023-08-16 11:13:41 +0100 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2023-08-16 10:13:46 +0000 |
commit | 5a40f7db54dfcc7dadb75dde32c25b88c78d6a85 (patch) | |
tree | 928a522f7c48a4c93fe0b7302ba469953e30c8d9 /lib/irb.rb | |
parent | 0982c5fa00f6163d04b17229e72d128263b98d50 (diff) | |
download | ruby-5a40f7db54dfcc7dadb75dde32c25b88c78d6a85.tar.gz |
[ruby/irb] Encapsulate input details in Statement objects
(https://github.com/ruby/irb/pull/682)
* Introduce Statement class
* Split Statement class for better clarity
https://github.com/ruby/irb/commit/65e8e68690
Diffstat (limited to 'lib/irb.rb')
-rw-r--r-- | lib/irb.rb | 42 |
1 files changed, 6 insertions, 36 deletions
diff --git a/lib/irb.rb b/lib/irb.rb index c884d70a67..93ab6370ed 100644 --- a/lib/irb.rb +++ b/lib/irb.rb @@ -570,26 +570,19 @@ module IRB configure_io - @scanner.each_top_level_statement do |line, line_no, is_assignment| + @scanner.each_top_level_statement do |statement, line_no| signal_status(:IN_EVAL) do begin # If the integration with debugger is activated, we need to handle certain input differently - if @context.with_debugger - command_class = load_command_class(line) - # First, let's pass debugging command's input to debugger - # Secondly, we need to let debugger evaluate non-command input - # Otherwise, the expression will be evaluated in the debugger's main session thread - # This is the only way to run the user's program in the expected thread - if !command_class || ExtendCommand::DebugCommand > command_class - return line - end + if @context.with_debugger && statement.should_be_handled_by_debugger? + return statement.code end - evaluate_line(line, line_no) + @context.evaluate(statement.evaluable_code, line_no) # Don't echo if the line ends with a semicolon - if @context.echo? && !line.match?(/;\s*\z/) - if is_assignment + if @context.echo? && !statement.suppresses_echo? + if statement.is_assignment? if @context.echo_on_assignment? output_value(@context.echo_on_assignment? == :truncate) end @@ -659,29 +652,6 @@ module IRB end end - def evaluate_line(line, line_no) - # Transform a non-identifier alias (@, $) or keywords (next, break) - command, args = line.split(/\s/, 2) - if original = @context.command_aliases[command.to_sym] - line = line.gsub(/\A#{Regexp.escape(command)}/, original.to_s) - command = original - end - - # Hook command-specific transformation - command_class = ExtendCommandBundle.load_command(command) - if command_class&.respond_to?(:transform_args) - line = "#{command} #{command_class.transform_args(args)}" - end - - @context.evaluate(line, line_no) - end - - def load_command_class(line) - command, _ = line.split(/\s/, 2) - command_name = @context.command_aliases[command.to_sym] - ExtendCommandBundle.load_command(command_name || command) - end - def convert_invalid_byte_sequence(str, enc) str.force_encoding(enc) str.scrub { |c| |