From aec8a4b0a4eb332140d363d5c81d00eae382ff6a Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 2 Oct 2009 11:37:44 +0000 Subject: * parse.y (ripper_yylval_id, ripper_get_{id,value}): wrap ID by NODE to track local variable assignment. * parse.y (lvar_defined_gen, assignable_gen): enable local variable check. [ruby-core:24923] * parse.y (validate): use value only. * test/ripper/test_parser_events.rb (test_local_variables): tests based on a patch from Magnus Holm in [ruby-core:25885]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25187 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ripper/dummyparser.rb | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) (limited to 'test/ripper/dummyparser.rb') diff --git a/test/ripper/dummyparser.rb b/test/ripper/dummyparser.rb index 483ac0d013..a76632e466 100644 --- a/test/ripper/dummyparser.rb +++ b/test/ripper/dummyparser.rb @@ -13,7 +13,15 @@ class Node attr_reader :children def to_s - "#{@name}(#{@children.map {|n| n.to_s }.join(',')})" + "#{@name}(#{Node.trim_nil(@children).map {|n| n.to_s }.join(',')})" + end + + def self.trim_nil(list) + if !list.empty? and list.last.nil? + list = list[0...-1] + list.pop while !list.empty? and list.last.nil? + end + list end end @@ -34,14 +42,23 @@ class NodeList end def to_s - '[' + @list.join(',') + ']' + "[#{@list.join(',')}]" end end class DummyParser < Ripper + def hook(name) + class << self; self; end.class_eval do + define_method(name) do |*a, &b| + result = super(*a, &b) + yield + result + end + end + self + end def on_program(stmts) - $thru_program = true stmts end @@ -170,8 +187,8 @@ class DummyParser < Ripper Node.new('binary', a, b, c) end - def on_block_var(a) - Node.new('block_var', a) + def on_block_var(a, b) + Node.new('block_var', a, b) end def on_bodystmt(a, b, c, d) @@ -346,8 +363,8 @@ class DummyParser < Ripper Node.new('param_error', a) end - def on_params(a, b, c, d) - Node.new('params', a, b, c, d) + def on_params(a, b, c, d, e) + Node.new('params', a, b, c, d, e) end def on_paren(a) @@ -370,8 +387,8 @@ class DummyParser < Ripper Node.new('redo') end - def on_regexp_literal(a) - Node.new('regexp_literal', a) + def on_regexp_literal(a, b) + Node.new('regexp_literal', a, b) end def on_rescue(a, b, c, d) -- cgit v1.2.3