* parse.y (words, qwords): dispatch array events. based on a

patch from Michael Edgar.  [Bug #4365].


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30805 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2011-02-06 03:18:44 +00:00
parent 58195557b2
commit b1986003bd
4 changed files with 44 additions and 11 deletions

View File

@ -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.

10
parse.y
View File

@ -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);
%*/
}
;

View File

@ -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)

View File

@ -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