lib/irb.rb in irb-1.7.0 vs lib/irb.rb in irb-1.7.1
- old
+ new
@@ -504,12 +504,10 @@
# The lexer used by this irb session
attr_accessor :scanner
# Evaluates input for this session.
def eval_input
- exc = nil
-
@scanner.set_prompt do
|ltype, indent, continue, line_no|
if ltype
f = @context.prompt_s
elsif continue
@@ -558,51 +556,47 @@
@scanner.configure_io(@context.io)
@scanner.each_top_level_statement do |line, line_no|
signal_status(:IN_EVAL) do
begin
- if IRB.conf[:MEASURE] && IRB.conf[:MEASURE_CALLBACKS].empty?
- IRB.set_measure_callback
- end
- # Assignment expression check should be done before @context.evaluate to handle code like `a /2#/ if false; a = 1`
+ # Assignment expression check should be done before evaluate_line to handle code like `a /2#/ if false; a = 1`
is_assignment = assignment_expression?(line)
- if IRB.conf[:MEASURE] && !IRB.conf[:MEASURE_CALLBACKS].empty?
- result = nil
- last_proc = proc{ result = @context.evaluate(line, line_no, exception: exc) }
- IRB.conf[:MEASURE_CALLBACKS].inject(last_proc) { |chain, item|
- _name, callback, arg = item
- proc {
- callback.(@context, line, line_no, arg, exception: exc) do
- chain.call
- end
- }
- }.call
- @context.set_last_value(result)
- else
- @context.evaluate(line, line_no, exception: exc)
- end
+ evaluate_line(line, line_no)
+
if @context.echo?
if is_assignment
if @context.echo_on_assignment?
output_value(@context.echo_on_assignment? == :truncate)
end
else
output_value
end
end
- rescue Interrupt => exc
rescue SystemExit, SignalException
raise
- rescue Exception => exc
- else
- exc = nil
- next
+ rescue Interrupt, Exception => exc
+ handle_exception(exc)
+ @context.workspace.local_variable_set(:_, exc)
end
- handle_exception(exc)
- @context.workspace.local_variable_set(:_, exc)
- exc = nil
end
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 convert_invalid_byte_sequence(str, enc)
str.force_encoding(enc)
str.scrub { |c|