[macruby-changes] [4760] DietRB/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Fri Oct 8 04:10:50 PDT 2010
Revision: 4760
http://trac.macosforge.org/projects/ruby/changeset/4760
Author: eloy.de.enige at gmail.com
Date: 2010-10-08 04:10:49 -0700 (Fri, 08 Oct 2010)
Log Message:
-----------
Ripper, or the Ruby parser, returns that a literal end token is received when in fact it?\226?\128?\153s not terminated.
From: Eloy Duran <eloy.de.enige at gmail.com>
Modified Paths:
--------------
DietRB/trunk/lib/irb/source.rb
DietRB/trunk/spec/source_spec.rb
Modified: DietRB/trunk/lib/irb/source.rb
===================================================================
--- DietRB/trunk/lib/irb/source.rb 2010-10-08 11:10:40 UTC (rev 4759)
+++ DietRB/trunk/lib/irb/source.rb 2010-10-08 11:10:49 UTC (rev 4760)
@@ -72,7 +72,7 @@
def initialize(source)
super
@level = 0
- @code_block = !parse.nil?
+ @code_block = !parse.nil? && !@in_string && !@in_regexp && !@in_array
end
# Returns the code block indentation level.
@@ -185,34 +185,63 @@
end
def on_tstring_beg(token)
+ @in_string = token
@level += 1
super
end
def on_tstring_end(token)
- @level -= 1
+ if tokens_match?(@in_string, token)
+ @in_string = nil
+ @level -= 1
+ end
super
end
def on_qwords_beg(token)
+ @in_array = token.strip
@level += 1
super
end
+ alias_method :on_words_beg, :on_qwords_beg
def on_words_sep(token)
- @level -= 1
+ if tokens_match?(@in_array, token)
+ @in_array = false
+ @level -= 1
+ end
super
end
def on_regexp_beg(token)
+ @in_regexp = token
@level += 1
super
end
def on_regexp_end(token)
- @level -= 1
+ if tokens_match?(@in_regexp, token)
+ @in_regexp = false
+ @level -= 1
+ end
super
end
+
+ def tokens_match?(open_token, close_token)
+ last_char_open_token = open_token[-1, 1]
+ last_char_close_token = close_token[-1, 1]
+ if last_char_open_token == last_char_close_token
+ true
+ else
+ case last_char_open_token
+ when '{' then last_char_close_token == '}'
+ when '(' then last_char_close_token == ')'
+ when '[' then last_char_close_token == ']'
+ else
+ false
+ end
+ end
+ end
end
end
end
Modified: DietRB/trunk/spec/source_spec.rb
===================================================================
--- DietRB/trunk/spec/source_spec.rb 2010-10-08 11:10:40 UTC (rev 4759)
+++ DietRB/trunk/spec/source_spec.rb 2010-10-08 11:10:49 UTC (rev 4760)
@@ -188,17 +188,50 @@
it "correctly increases and decreases the code block indentation level for literals" do
[
["lambda { |x|", "}"],
- ["{", "}"],
- ["[", "]"],
- ["'", "'"],
- ['"', '"'],
- ["%{", "}"],
- ["%w{", "}"],
- ["%r{", "}"],
- ["/", "/"]
+ ["{ :foo => ", " :bar }"],
+ ["[ 1", ", 2 ]"],
+
+ ["'foo ", " bar'"],
+ ["' foo ", " bar '"],
+
+ ['"foo ', ' bar"'],
+ ['" foo ', ' bar "'],
+
+ ["%{foo ", " bar}"],
+ ["%{ foo ", " bar }"],
+ ["%(foo ", " bar)"],
+ ["%( foo ", " bar )"],
+ ["%[ foo ", " bar ]"],
+ ["%[foo ", " bar]"],
+
+ ["%w{foo ", " bar}"],
+ ["%w{ foo ", " bar }"],
+ ["%w(foo ", " bar)"],
+ ["%w( foo ", " bar )"],
+ ["%w[foo ", " bar]"],
+ ["%w[ foo ", " bar ]"],
+
+ ["%W{foo ", " bar}"],
+ ["%W{ foo ", " bar }"],
+ ["%W(foo ", " bar)"],
+ ["%W( foo ", " bar )"],
+ ["%W[foo ", " bar]"],
+ ["%W[ foo ", " bar ]"],
+
+ ["%r{foo ", " bar}"],
+ ["%r{ foo ", " bar }"],
+ ["%r(foo ", " bar)"],
+ ["%r( foo ", " bar )"],
+ ["%r[foo ", " bar]"],
+ ["%r[ foo ", " bar ]"],
+
+ ["/foo ", " bar/"],
+ ["/ foo ", " bar /"],
].each do |open, close|
reflect(open).level.should == 1
+ reflect(open).code_block?.should == false
reflect("#{open}\n#{close}").level.should == 0
+ reflect("#{open}\n#{close}").code_block?.should == true
end
end
end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101008/a9d7e609/attachment.html>
More information about the macruby-changes
mailing list