[macruby-changes] [4704] DietRB/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Fri Oct 8 04:02:11 PDT 2010
Revision: 4704
http://trac.macosforge.org/projects/ruby/changeset/4704
Author: eloy.de.enige at gmail.com
Date: 2010-10-08 04:02:10 -0700 (Fri, 08 Oct 2010)
Log Message:
-----------
Make 'quit' and 'exit' work
From: Andrei Bocan <zmaxor at gmail.com>
Modified Paths:
--------------
DietRB/trunk/lib/irb/context.rb
DietRB/trunk/lib/irb/source.rb
DietRB/trunk/spec/context_spec.rb
DietRB/trunk/spec/source_spec.rb
Modified: DietRB/trunk/lib/irb/context.rb
===================================================================
--- DietRB/trunk/lib/irb/context.rb 2010-10-08 11:02:00 UTC (rev 4703)
+++ DietRB/trunk/lib/irb/context.rb 2010-10-08 11:02:10 UTC (rev 4704)
@@ -85,7 +85,7 @@
# process_line("quit") # => false
def process_line(line)
@source << line
- return false if @source.to_s == "quit"
+ return false if @source.terminate?
if @source.syntax_error?
puts formatter.syntax_error(@line, @source.syntax_error)
Modified: DietRB/trunk/lib/irb/source.rb
===================================================================
--- DietRB/trunk/lib/irb/source.rb 2010-10-08 11:02:00 UTC (rev 4703)
+++ DietRB/trunk/lib/irb/source.rb 2010-10-08 11:02:10 UTC (rev 4704)
@@ -51,6 +51,11 @@
def syntax_error?
reflect.syntax_error?
end
+
+ # Reflects on the accumulated source to see if it contains a terminate signal.
+ def terminate?
+ reflect.terminate?
+ end
# Reflects on the accumulated source and returns the actual syntax error
# message if one occurs.
@@ -110,6 +115,20 @@
def syntax_error?
!@syntax_error.nil?
end
+
+ # Returns whether or not the source contains a call to toplevel
+ # quit or exit, namely if the current session should be terminated
+ #
+ # For example, this would terminate the session
+ #
+ # def foo; end; quit
+ #
+ # This does not:
+ #
+ # def foo; quit; end
+ def terminate?
+ !@terminate.nil?
+ end
UNEXPECTED_END = "syntax error, unexpected $end"
@@ -120,6 +139,7 @@
end
INCREASE_LEVEL_KEYWORDS = %w{ class module def begin if unless case while for do }
+ TERMINATE_KEYWORDS = %w{ exit quit }
def on_kw(token) #:nodoc:
case token
@@ -145,6 +165,14 @@
@level += 1
super
end
+
+ def on_ident(token) #:nodoc:
+ if @level == 0 && TERMINATE_KEYWORDS.include?(token)
+ @terminate = true
+ else
+ super
+ end
+ end
def on_lbrace(token) #:nodoc:
@level += 1
@@ -157,4 +185,4 @@
end
end
end
-end
\ No newline at end of file
+end
Modified: DietRB/trunk/spec/context_spec.rb
===================================================================
--- DietRB/trunk/spec/context_spec.rb 2010-10-08 11:02:00 UTC (rev 4703)
+++ DietRB/trunk/spec/context_spec.rb 2010-10-08 11:02:10 UTC (rev 4704)
@@ -241,4 +241,4 @@
irb(o)
IRBRan.should == o
end
-end
\ No newline at end of file
+end
Modified: DietRB/trunk/spec/source_spec.rb
===================================================================
--- DietRB/trunk/spec/source_spec.rb 2010-10-08 11:02:00 UTC (rev 4703)
+++ DietRB/trunk/spec/source_spec.rb 2010-10-08 11:02:10 UTC (rev 4704)
@@ -130,6 +130,16 @@
reflect("if true").should.not.be.code_block
reflect("p :ok if true").should.be.code_block
end
+
+ it "returns whether or not the current session should be terminated" do
+ reflect("exit").should.terminate
+ reflect("quit").should.terminate
+ reflect("def foo; end; exit").should.terminate
+ reflect("def foo; end; quit").should.terminate
+
+ reflect("def foo; exit; end").should.not.terminate
+ reflect("def foo; quit; end").should.not.terminate
+ end
it "returns whether or not the source contains a syntax error, except a code block not ending" do
reflect("def;").should.have.syntax_error
@@ -187,4 +197,4 @@
reflect("#{open}\n#{close}").level.should == 0
end
end
-end
\ No newline at end of file
+end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101008/5f0a00ca/attachment-0001.html>
More information about the macruby-changes
mailing list