[macruby-changes] [4841] MacRuby/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Thu Oct 28 05:15:49 PDT 2010
Revision: 4841
http://trac.macosforge.org/projects/ruby/changeset/4841
Author: eloy.de.enige at gmail.com
Date: 2010-10-28 05:15:46 -0700 (Thu, 28 Oct 2010)
Log Message:
-----------
Update irb to DietRB 0.5.2
Modified Paths:
--------------
MacRuby/trunk/bin/irb
MacRuby/trunk/lib/irb/context.rb
MacRuby/trunk/lib/irb/driver/tty.rb
MacRuby/trunk/lib/irb/driver.rb
MacRuby/trunk/lib/irb/ext/completion.rb
MacRuby/trunk/lib/irb/ext/history.rb
MacRuby/trunk/lib/irb/source.rb
MacRuby/trunk/lib/irb/version.rb
MacRuby/trunk/lib/irb.rb
MacRuby/trunk/spec/dietrb/context_spec.rb
MacRuby/trunk/spec/dietrb/ext/completion_spec.rb
MacRuby/trunk/spec/dietrb/source_spec.rb
MacRuby/trunk/spec/dietrb/spec_helper.rb
Removed Paths:
-------------
MacRuby/trunk/spec/dietrb/tags/context_tags.txt
MacRuby/trunk/spec/dietrb/tags/ext/completion_tags.txt
MacRuby/trunk/spec/dietrb/tags/formatter_tags.txt
Modified: MacRuby/trunk/bin/irb
===================================================================
--- MacRuby/trunk/bin/irb 2010-10-28 12:06:16 UTC (rev 4840)
+++ MacRuby/trunk/bin/irb 2010-10-28 12:15:46 UTC (rev 4841)
@@ -39,18 +39,25 @@
IRB.formatter.filter_from_backtrace << /^#{__FILE__}/
if ARGV.empty?
- driver ||= begin
- require 'readline'
- 'readline'
- rescue LoadError
- 'tty'
+ if driver == 'socket'
+ require "irb/driver/socket"
+ IRB::Driver.redirect_output! do
+ irb(*IRB_CONTEXT_TOPLEVEL_ARGS)
+ end
+ else
+ driver ||= begin
+ require 'readline'
+ 'readline'
+ rescue LoadError
+ 'tty'
+ end
+ require "irb/driver/#{driver}"
+ irb(*IRB_CONTEXT_TOPLEVEL_ARGS)
end
- require "irb/driver/#{driver}"
- irb(*IRB_CONTEXT_TOPLEVEL_ARGS)
else
path = ARGV.shift
context = IRB::Context.new(*IRB_CONTEXT_TOPLEVEL_ARGS)
File.open(path, 'r') { |f| f.each_line { |line| context.input_line(line) } }
end
end
-end
\ No newline at end of file
+end
Modified: MacRuby/trunk/lib/irb/context.rb
===================================================================
--- MacRuby/trunk/lib/irb/context.rb 2010-10-28 12:06:16 UTC (rev 4840)
+++ MacRuby/trunk/lib/irb/context.rb 2010-10-28 12:15:46 UTC (rev 4841)
@@ -5,6 +5,7 @@
# Copyright (C) 2009-2010, Eloy Duran <eloy.de.enige at gmail.com>
require 'irb/formatter'
+require 'irb/source'
module IRB
class Context
@@ -26,17 +27,24 @@
def __evaluate__(source, file = __FILE__, line = __LINE__)
eval(source, @binding, file, line)
end
+
+ def to_s
+ object_description = "`#{object.inspect}'"
+ object_description = "of class `#{object.class.name}'" if object_description.length > 32
+ "#<IRB::Context for object #{object_description}>"
+ end
+ alias_method :inspect, :to_s
def evaluate(source)
result = __evaluate__(source.to_s, '(irb)', @line - @source.buffer.size + 1)
unless result == IGNORE_RESULT
store_result(result)
- puts(formatter.result(result))
+ output(formatter.result(result))
result
end
rescue Exception => e
store_exception(e)
- puts(formatter.exception(e))
+ output(formatter.exception(e))
end
# Returns whether or not the user wants to continue the current runloop.
@@ -56,7 +64,7 @@
return false if @source.terminate?
if @source.syntax_error?
- puts(formatter.syntax_error(@line, @source.syntax_error))
+ output(formatter.syntax_error(@line, @source.syntax_error))
@source.pop
elsif @source.code_block?
evaluate(@source)
@@ -67,12 +75,22 @@
true
end
+ # Output is directed to the IRB::Driver.current driver’s output if a
+ # current driver is available. Otherwise it’s simply printed to $stdout.
+ def output(string)
+ if driver = IRB::Driver.current
+ driver.output.puts(string)
+ else
+ puts(string)
+ end
+ end
+
def prompt
formatter.prompt(self)
end
def input_line(line)
- puts(formatter.prompt(self) + line)
+ output(formatter.prompt(self) + line)
process_line(line)
end
@@ -92,4 +110,4 @@
@exception_assigner.call(exception)
end
end
-end
\ No newline at end of file
+end
Modified: MacRuby/trunk/lib/irb/driver/tty.rb
===================================================================
--- MacRuby/trunk/lib/irb/driver/tty.rb 2010-10-28 12:06:16 UTC (rev 4840)
+++ MacRuby/trunk/lib/irb/driver/tty.rb 2010-10-28 12:15:46 UTC (rev 4841)
@@ -34,13 +34,11 @@
# subclass thereof.
def run(context)
@context_stack << context
- before, $stdout = $stdout, OutputRedirector.new unless $stdout.is_a?(OutputRedirector)
while line = consume
break unless context.process_line(line)
end
ensure
@context_stack.pop
- $stdout = before if before
end
end
end
Modified: MacRuby/trunk/lib/irb/driver.rb
===================================================================
--- MacRuby/trunk/lib/irb/driver.rb 2010-10-28 12:06:16 UTC (rev 4840)
+++ MacRuby/trunk/lib/irb/driver.rb 2010-10-28 12:15:46 UTC (rev 4841)
@@ -18,6 +18,13 @@
end
end
end
+
+ def redirect_output!(redirector = OutputRedirector.new)
+ before, $stdout = $stdout, redirector unless $stdout.is_a?(redirector.class)
+ yield
+ ensure
+ $stdout = before if before
+ end
end
class OutputRedirector
@@ -58,4 +65,4 @@
end
end
end
-end
\ No newline at end of file
+end
Modified: MacRuby/trunk/lib/irb/ext/completion.rb
===================================================================
--- MacRuby/trunk/lib/irb/ext/completion.rb 2010-10-28 12:06:16 UTC (rev 4840)
+++ MacRuby/trunk/lib/irb/ext/completion.rb 2010-10-28 12:15:46 UTC (rev 4841)
@@ -89,11 +89,10 @@
call = (source[-1,1] == '.')
receiver = source = source[0..-2] if call
- if sexp = Ripper::SexpBuilder.new(source).parse
- # [:program, [:stmts_add, [:stmts_new], [x, …]]]
- # ^
- root = sexp[1][2]
-
+ # root node:
+ # [:program, [:stmts_add, [:stmts_new], [x, …]]]
+ # ^
+ if (sexp = Ripper::SexpBuilder.new(source).parse) && root = sexp[1][2]
# [:call, [:hash, nil], :".", [:@ident, x, …]]
if root[TYPE] == :call
call = true
@@ -113,17 +112,14 @@
end
end
- if call
- if results = (methods || methods_of_object(root))
- format_methods(receiver, results, filter)
- else
- # this is mainly because MacRuby currently has a problem with local_variables,
- # normally I'd prefer to let the program die so the user might report it
- []
- end
- else
- match_methods_vars_or_consts_in_scope(root)
- end.sort.uniq
+ result = if call
+ if m = (methods || methods_of_object(root))
+ format_methods(receiver, m, filter)
+ end
+ else
+ match_methods_vars_or_consts_in_scope(root)
+ end
+ result.sort.uniq if result
end
end
@@ -140,7 +136,7 @@
def match_methods_vars_or_consts_in_scope(symbol)
var = symbol[VALUE]
filter = var[VALUE]
- case var[TYPE]
+ result = case var[TYPE]
when :@ident
local_variables + instance_methods + RESERVED_DOWNCASE_WORDS
when :@ivar
@@ -154,7 +150,8 @@
else
constants + RESERVED_UPCASE_WORDS
end
- end.grep(/^#{Regexp.quote(filter)}/)
+ end
+ (result && filter) ? result.grep(/^#{Regexp.quote(filter)}/) : result
end
def format_methods(receiver, methods, filter)
Modified: MacRuby/trunk/lib/irb/ext/history.rb
===================================================================
--- MacRuby/trunk/lib/irb/ext/history.rb 2010-10-28 12:06:16 UTC (rev 4840)
+++ MacRuby/trunk/lib/irb/ext/history.rb 2010-10-28 12:15:46 UTC (rev 4841)
@@ -89,4 +89,4 @@
IRB::History.file = File.expand_path("~/.irb_history")
IRB::History.max_entries_in_overview = 50
-IRB::History.setup
\ No newline at end of file
+IRB::History.setup if defined?(Readline)
Modified: MacRuby/trunk/lib/irb/source.rb
===================================================================
--- MacRuby/trunk/lib/irb/source.rb 2010-10-28 12:06:16 UTC (rev 4840)
+++ MacRuby/trunk/lib/irb/source.rb 2010-10-28 12:15:46 UTC (rev 4841)
@@ -220,7 +220,8 @@
end
def on_regexp_end(token)
- if tokens_match?(@in_regexp, token)
+ token_without_regexp_options = token[0,1]
+ if tokens_match?(@in_regexp, token_without_regexp_options)
@in_regexp = false
@level -= 1
end
Modified: MacRuby/trunk/lib/irb/version.rb
===================================================================
--- MacRuby/trunk/lib/irb/version.rb 2010-10-28 12:06:16 UTC (rev 4840)
+++ MacRuby/trunk/lib/irb/version.rb 2010-10-28 12:15:46 UTC (rev 4841)
@@ -9,7 +9,7 @@
NAME = 'DietRB'
MAJOR = 0
MINOR = 5
- TINY = 1
+ TINY = 2
STRING = [MAJOR, MINOR, TINY].join('.')
DESCRIPTION = "#{NAME} (#{STRING})"
Modified: MacRuby/trunk/lib/irb.rb
===================================================================
--- MacRuby/trunk/lib/irb.rb 2010-10-28 12:06:16 UTC (rev 4840)
+++ MacRuby/trunk/lib/irb.rb 2010-10-28 12:15:46 UTC (rev 4841)
@@ -5,6 +5,7 @@
# Copyright (C) 2009-2010, Eloy Duran <eloy.de.enige at gmail.com>
require 'irb/context'
+require 'irb/driver'
require 'irb/source'
require 'irb/version'
@@ -22,4 +23,4 @@
end
alias_method :setup, :start
end
-end
\ No newline at end of file
+end
Modified: MacRuby/trunk/spec/dietrb/context_spec.rb
===================================================================
--- MacRuby/trunk/spec/dietrb/context_spec.rb 2010-10-28 12:06:16 UTC (rev 4840)
+++ MacRuby/trunk/spec/dietrb/context_spec.rb 2010-10-28 12:15:46 UTC (rev 4841)
@@ -1,16 +1,11 @@
require File.expand_path('../spec_helper', __FILE__)
require 'tempfile'
-class TestProcessor
- def input(s)
- s * 2
- end
-end
-
main = self
describe "IRB::Context" do
before do
+ @output = setup_current_driver.output
@context = IRB::Context.new(main)
@context.extend(OutputStubMixin)
end
@@ -38,12 +33,25 @@
it "does not use the same binding copy of the top level object" do
lambda { eval("x", @context.binding) }.should raise_error(NameError)
end
+
+ it "prints to the output object of the current driver" do
+ @context.output("croque monsieur")
+ @output.printed.should == "croque monsieur\n"
+ @context.printed.should == ""
+ end
+
+ it "prints as normal when no current driver is available" do
+ IRB::Driver.current = nil
+ @context.output("croque monsieur")
+ @output.printed.should == ""
+ @context.printed.should == "croque monsieur\n"
+ end
end
describe "IRB::Context, when evaluating source" do
before do
+ @output = setup_current_driver.output
@context = IRB::Context.new(main)
- @context.extend(OutputStubMixin)
IRB.formatter = IRB::Formatter.new
end
@@ -53,7 +61,7 @@
it "prints the result" do
@context.evaluate("Hash[:foo, :foo]")
- @context.printed.should == "=> {:foo=>:foo}\n"
+ @output.printed.should == "=> {:foo=>:foo}\n"
end
it "assigns the result to the local variable `_'" do
@@ -84,31 +92,31 @@
it "prints the exception that occurs" do
@context.evaluate("DoesNotExist")
- @context.printed.should =~ /^NameError:.+DoesNotExist/
+ @output.printed.should =~ /^NameError:.+DoesNotExist/
end
it "uses the line number of the *first* line in the buffer, for the line parameter of eval" do
@context.process_line("DoesNotExist")
- @context.printed.should =~ /\(irb\):1:in/
+ @output.printed.should =~ /\(irb\):1:in/
@context.process_line("class A")
@context.process_line("DoesNotExist")
@context.process_line("end")
- @context.printed.should =~ /\(irb\):3:in.+\(irb\):2:in/m
+ @output.printed.should =~ /\(irb\):3:in.+\(irb\):2:in/m
end
it "ignores the result if it's IRB::Context::IGNORE_RESULT" do
@context.evaluate(":bananas")
@context.evaluate("IRB::Context::IGNORE_RESULT").should == nil
- @context.printed.should == "=> :bananas\n"
+ @output.printed.should == "=> :bananas\n"
@context.evaluate("_").should == :bananas
end
end
describe "IRB::Context, when receiving input" do
before do
+ @output = setup_current_driver.output
@context = IRB::Context.new(main)
@context.extend(InputStubMixin)
- @context.extend(OutputStubMixin)
end
it "adds the received code to the source buffer" do
@@ -147,7 +155,7 @@
@context.process_line(" };")
@context.source.to_s.should == "def foo"
- @context.printed.should == "SyntaxError: compile error\n(irb):2: syntax error, unexpected '}'\n"
+ @output.printed.should == "SyntaxError: compile error\n(irb):2: syntax error, unexpected '}'\n"
end
it "returns whether or not the runloop should continue, but only if the level is 0" do
@@ -161,6 +169,6 @@
it "inputs a line to be processed" do
expected = "#{@context.formatter.prompt(@context)}2 * 21\n=> 42\n"
@context.input_line("2 * 21")
- @context.printed.should == expected
+ @output.printed.should == expected
end
end
Modified: MacRuby/trunk/spec/dietrb/ext/completion_spec.rb
===================================================================
--- MacRuby/trunk/spec/dietrb/ext/completion_spec.rb 2010-10-28 12:06:16 UTC (rev 4840)
+++ MacRuby/trunk/spec/dietrb/ext/completion_spec.rb 2010-10-28 12:15:46 UTC (rev 4841)
@@ -248,4 +248,9 @@
complete(word[0..-2]).should include(word)
end
end
-end
\ No newline at end of file
+
+ it "does not crash when trying to complete garbage" do
+ complete("/").should == nil
+ complete("./Rake").should == nil
+ end
+end
Modified: MacRuby/trunk/spec/dietrb/source_spec.rb
===================================================================
--- MacRuby/trunk/spec/dietrb/source_spec.rb 2010-10-28 12:06:16 UTC (rev 4840)
+++ MacRuby/trunk/spec/dietrb/source_spec.rb 2010-10-28 12:15:46 UTC (rev 4841)
@@ -210,7 +210,7 @@
["%[ foo ", " bar ]"],
["%[foo ", " bar]"],
- ["%w{ ", " }"],
+ #["%w{ ", " }"], fails on 1.9
["%w{foo ", " bar}"],
["%w{ foo ", " bar }"],
["%w(foo ", " bar)"],
@@ -227,13 +227,17 @@
["%r{foo ", " bar}"],
["%r{ foo ", " bar }"],
+ ["%r{ foo ", " bar}i"],
["%r(foo ", " bar)"],
["%r( foo ", " bar )"],
+ ["%r( foo ", " bar)i"],
["%r[foo ", " bar]"],
["%r[ foo ", " bar ]"],
+ ["%r[ foo ", " bar]i"],
["/foo ", " bar/"],
["/ foo ", " bar /"],
+ ["/ foo ", " bar/iu"], # macruby ticket 965
].each do |open, close|
reflect(open).level.should == 1
reflect(open).code_block?.should == false
Modified: MacRuby/trunk/spec/dietrb/spec_helper.rb
===================================================================
--- MacRuby/trunk/spec/dietrb/spec_helper.rb 2010-10-28 12:06:16 UTC (rev 4840)
+++ MacRuby/trunk/spec/dietrb/spec_helper.rb 2010-10-28 12:15:46 UTC (rev 4841)
@@ -72,4 +72,14 @@
def output
@output || $stdout
end
+
+ def printed
+ @output.printed
+ end
end
+
+def setup_current_driver
+ driver = StubDriver.new
+ driver.output = OutputStub.new
+ IRB::Driver.current = driver
+end
Deleted: MacRuby/trunk/spec/dietrb/tags/context_tags.txt
===================================================================
--- MacRuby/trunk/spec/dietrb/tags/context_tags.txt 2010-10-28 12:06:16 UTC (rev 4840)
+++ MacRuby/trunk/spec/dietrb/tags/context_tags.txt 2010-10-28 12:15:46 UTC (rev 4841)
@@ -1 +0,0 @@
-fails:IRB::Context, when evaluating source uses the line number of the *first* line in the buffer, for the line parameter of eval
Deleted: MacRuby/trunk/spec/dietrb/tags/ext/completion_tags.txt
===================================================================
--- MacRuby/trunk/spec/dietrb/tags/ext/completion_tags.txt 2010-10-28 12:06:16 UTC (rev 4840)
+++ MacRuby/trunk/spec/dietrb/tags/ext/completion_tags.txt 2010-10-28 12:15:46 UTC (rev 4841)
@@ -1,5 +0,0 @@
-fails:IRB::Completion when *not* doing a method call on an explicit receiver matches local variables and instance method of the context object
-fails:IRB::Completion when *not* doing a method call on an explicit receiver matches local variables
-fails:IRB::Completion when doing a method call on an explicit receiver, and the source does *not* end with a period, filters the methods, of the variable receiver, by the given method name
-fails:IRB::Completion when doing a method call on an explicit receiver, and the source ends with a period, returns *all* public instance methods of the class (the receiver) that matches as a lambda literal
-fails:IRB::Completion when doing a method call on an explicit receiver, and the source ends with a period, returns *all* public methods of the receiver that matches as a local variable
Deleted: MacRuby/trunk/spec/dietrb/tags/formatter_tags.txt
===================================================================
--- MacRuby/trunk/spec/dietrb/tags/formatter_tags.txt 2010-10-28 12:06:16 UTC (rev 4840)
+++ MacRuby/trunk/spec/dietrb/tags/formatter_tags.txt 2010-10-28 12:15:46 UTC (rev 4841)
@@ -1,2 +0,0 @@
-fails:IRB::Formatter does not filter the backtrace if $DEBUG is true
-fails:IRB::Formatter returns a formatted exception message, with the lines, regarding dietrb, filtered out of the backtrace
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101028/200e2d16/attachment-0001.html>
More information about the macruby-changes
mailing list