Browse files

+ Refactored 1.9 args handling

[git-p4: depot-paths = "//src/ruby_parser/dev/": change = 6727]
  • Loading branch information...
1 parent 7f69c73 commit 8c5456374f7016c005ff99968a16a7b7b4a0dc03 @zenspider zenspider committed Nov 3, 2011
Showing with 56 additions and 37 deletions.
  1. +18 −37 lib/ruby19_parser.y
  2. +38 −0 lib/ruby_parser_extras.rb
View
55 lib/ruby19_parser.y
@@ -1659,86 +1659,67 @@ xstring_contents: none
f_args: f_arg tCOMMA f_optarg tCOMMA f_rest_arg opt_f_block_arg
{
- result = args val[0], val[2], val[4], val[5]
+ result = args19 val
}
| f_arg tCOMMA f_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_f_block_arg
{
- result = val[0]
- val[2][1..-1].each do |lasgn| # FIX clean sexp iter
- raise "wtf? #{lasgn.inspect}" unless lasgn[0] == :lasgn
- result << lasgn[1]
- end
- result << val[4]
- result << val[6].last
- result << :"&#{val[7].last}" if val[7]
- result << val[2]
- result
+ result = args19 val
}
- | f_arg tCOMMA f_optarg opt_f_block_arg
+ | f_arg tCOMMA f_optarg opt_f_block_arg
{
- result = args val[0], val[2], nil, val[3]
+ result = args19 val
}
| f_arg tCOMMA f_optarg tCOMMA f_arg opt_f_block_arg
{
- result = args val[0], val[2], val[4].last, val[5]
+ result = args19 val
}
- | f_arg tCOMMA f_rest_arg opt_f_block_arg
+ | f_arg tCOMMA f_rest_arg opt_f_block_arg
{
- result = args val[0], nil, val[2], val[3]
+ result = args19 val
}
| f_arg opt_f_block_arg
{
- result = args val[0], nil, nil, val[1]
+ result = args19 val
}
| f_arg tCOMMA f_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_f_block_arg
{
- result = args val[0], val[2], val[4], val[7], val[6]
+ result = args19 val
}
| f_arg tCOMMA f_rest_arg tCOMMA f_arg opt_f_block_arg
{
- result = args val[0], nil, val[2], val[5], val[4]
+ result = args19 val
}
| f_optarg tCOMMA f_rest_arg opt_f_block_arg
{
- result = args nil, val[0], val[2], val[3]
+ result = args19 val
}
| f_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_f_block_arg
{
- result = s(:args)
- val[0][1..-1].each do |lasgn| # FIX clean sexp iter
- raise "wtf? #{lasgn.inspect}" unless lasgn[0] == :lasgn
- result << lasgn[1]
- end
-
- result << val[2]
- result << val[4].last
- result << :"&#{val[5].last}" if val[5]
- result << val[0]
- result
+ result = args19 val
}
| f_optarg opt_f_block_arg
{
- result = args nil, val[0], nil, val[1]
+ result = args19 val
}
| f_rest_arg opt_f_block_arg
{
- result = args nil, nil, val[0], val[1]
+ result = args19 val
}
| f_optarg tCOMMA f_arg opt_f_block_arg
{
- result = args nil, val[0], val[2].last, val[3]
+ result = args19 val
}
| f_rest_arg tCOMMA f_arg opt_f_block_arg
{
- result = args nil, nil, val[0], val[3], val[2]
+ result = args19 val
}
| f_block_arg
{
- result = args nil, nil, nil, val[0]
+ result = args19 val
}
|
{
- result = args nil, nil, nil, nil
+ result = args19 val
}
f_norm_arg: tCONSTANT
View
38 lib/ruby_parser_extras.rb
@@ -149,13 +149,51 @@ def args arg, optarg, rest_arg, block_arg, post_arg = nil
end
result << rest_arg if rest_arg
+
result << :"&#{block_arg.last}" if block_arg
result << optarg if optarg # TODO? huh - processed above as well
post_arg[1..-1].each {|pa| result << pa } if post_arg
result
end
+ def args19 vals # TODO: migrate to args once 1.8 tests pass as well
+ result = s(:args)
+ block = nil
+
+ vals.each do |val|
+ case val
+ when Sexp then
+ case val.first
+ when :args then
+ val[1..-1].each do |name|
+ result << name
+ end
+ when :block_arg then
+ result << :"&#{val.last}"
+ when :block then
+ block = val
+ val[1..-1].each do |lasgn| # FIX clean sexp iter
+ raise "wtf? #{val.inspect}" unless lasgn[0] == :lasgn
+ result << lasgn[1]
+ end
+ else
+ raise "unhandled sexp: #{val.inspect}"
+ end
+ when Symbol then
+ result << val
+ when ",", nil then
+ # ignore
+ else
+ raise "unhandled val: #{val.inspect} in #{vals.inspect}"
+ end
+ end
+
+ result << block if block
+
+ result
+ end
+
def aryset receiver, index
index[0] = :arglist if index[0] == :array
s(:attrasgn, receiver, :"[]=", index)

0 comments on commit 8c54563

Please sign in to comment.