summaryrefslogtreecommitdiffstats
path: root/test/ripper/dummyparser.rb
diff options
context:
space:
mode:
authoryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-12-05 02:36:42 +0000
committeryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-12-05 02:36:42 +0000
commit0989332d9ad78b354bda780f13bda1b79d2b0b95 (patch)
tree30b8ac4128c7b77f229658337a8c978066a76730 /test/ripper/dummyparser.rb
parentd3ce5dbd64b40b027e1e4ddbca16c8405e82cffb (diff)
merges r25187 from trunk into ruby_1_9_1.
-- * 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: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_9_1@26001 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ripper/dummyparser.rb')
-rw-r--r--test/ripper/dummyparser.rb35
1 files changed, 26 insertions, 9 deletions
diff --git a/test/ripper/dummyparser.rb b/test/ripper/dummyparser.rb
index 483ac0d01..a76632e46 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)