summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--parse.y10
-rw-r--r--test/ripper/dummyparser.rb38
-rw-r--r--test/ripper/test_parser_events.rb2
4 files changed, 44 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index baa15da..541e371 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sun Feb 6 12:18:25 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * parse.y (words, qwords): dispatch array events. based on a
+ patch from Michael Edgar. [Bug #4365].
+
Sun Feb 6 12:12:59 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
* test/fileutils/fileasserts.rb (FileAssertions): separate module.
diff --git a/parse.y b/parse.y
index e0bb2d8..0e4a735 100644
--- a/parse.y
+++ b/parse.y
@@ -3949,11 +3949,16 @@ words : tWORDS_BEG ' ' tSTRING_END
$$ = NEW_ZARRAY();
/*%
$$ = dispatch0(words_new);
+ $$ = dispatch1(array, $$);
%*/
}
| tWORDS_BEG word_list tSTRING_END
{
+ /*%%%*/
$$ = $2;
+ /*%
+ $$ = dispatch1(array, $2);
+ %*/
}
;
@@ -3999,11 +4004,16 @@ qwords : tQWORDS_BEG ' ' tSTRING_END
$$ = NEW_ZARRAY();
/*%
$$ = dispatch0(qwords_new);
+ $$ = dispatch1(array, $$);
%*/
}
| tQWORDS_BEG qword_list tSTRING_END
{
+ /*%%%*/
$$ = $2;
+ /*%
+ $$ = dispatch1(array, $2);
+ %*/
}
;
diff --git a/test/ripper/dummyparser.rb b/test/ripper/dummyparser.rb
index 07a7eda..d9bd69e 100644
--- a/test/ripper/dummyparser.rb
+++ b/test/ripper/dummyparser.rb
@@ -130,44 +130,44 @@ class DummyParser < Ripper
on_args_add_block(m.children, b)
m
end
-
+
def on_paren(params)
params
end
-
+
def on_brace_block(params, code)
Node.new('block', params, code)
end
-
+
def on_block_var(params, shadow)
params
end
-
+
def on_rest_param(var)
"*#{var}"
end
-
+
def on_blockarg(var)
"&#{var}"
end
-
+
def on_params(required, optional, rest, more, block)
args = NodeList.new
-
+
required.each do |req|
args.push(req)
end if required
-
+
optional.each do |var, val|
args.push("#{var}=#{val}")
end if optional
-
+
args.push(rest) if rest
-
+
more.each do |m|
args.push(m)
end if more
-
+
args.push(block) if block
args
end
@@ -184,6 +184,22 @@ class DummyParser < Ripper
Node.new('assocs', *a)
end
+ def on_words_new
+ NodeList.new
+ end
+
+ def on_words_add(words, word)
+ words.push word
+ end
+
+ def on_qwords_new
+ NodeList.new
+ end
+
+ def on_qwords_add(words, word)
+ words.push word
+ end
+
(Ripper::PARSER_EVENTS.map(&:to_s) - instance_methods(false).map {|n|n.to_s.sub(/^on_/, '')}).each do |event|
define_method(:"on_#{event}") do |*args|
Node.new(event, *args)
diff --git a/test/ripper/test_parser_events.rb b/test/ripper/test_parser_events.rb
index 829b405..9f97dba 100644
--- a/test/ripper/test_parser_events.rb
+++ b/test/ripper/test_parser_events.rb
@@ -160,6 +160,8 @@ class TestRipper::ParserEvents < Test::Unit::TestCase
def test_array # array literal
assert_equal '[array([1,2,3])]', parse('[1,2,3]')
+ assert_equal '[array([abc,def])]', parse('%w[abc def]')
+ assert_equal '[array([abc,def])]', parse('%W[abc def]')
end
def test_assign # generic assignment