summaryrefslogtreecommitdiff
path: root/test/ripper/dummyparser.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-10-02 11:37:44 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-10-02 11:37:44 +0000
commitaec8a4b0a4eb332140d363d5c81d00eae382ff6a (patch)
tree38f9e43771b03701117f13813eb81c419b216e79 /test/ripper/dummyparser.rb
parente9c728fea305bce19e712eeff9cc43d1994f069a (diff)
* 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
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 483ac0d..a76632e 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)