seattlerb / ruby_parser

ruby_parser is a ruby parser written in pure ruby. It outputs s-expressions which can be manipulated and converted back to ruby via the ruby2ruby gem.
http://www.zenspider.com/projects/ruby_parser.html
475 stars 102 forks source link

masgn w/ multiple splats doesn't parse #296

Closed zenspider closed 4 years ago

zenspider commented 5 years ago
a, b, c, d, e, f, g, h, i, j = 1, *[p1, p2, p3], *[p1, p2, p3], *[p4, p5, p6]
zenspider commented 5 years ago
9995 % rake debug R='a = 1, *[]'
s(:lasgn, :a, s(:svalue, s(:array, s(:lit, 1), s(:splat, s(:array)))))
9996 % rake debug R='a = *[], *[]'
s(:lasgn, :a, s(:svalue, s(:array, s(:splat, s(:array)), s(:splat, s(:array)))))
9997 % rake debug R='a = 1, *[], *[]'
#<Racc::ParseError: env:1 :: parse error on value "," (tCOMMA)>
eightbitraptor commented 4 years ago

I've just bumped into a variation of this when attempting to run flog over code that contains a splatted array in a list of exceptions passed to rescue

so something like

rescue FirstException, *EXCEPTIONS, ThirdException => e

I've got a failing test on my fork of ruby_parser here https://github.com/eightbitraptor/ruby_parser/commit/08ba65638dd93f7900422905a9797f32602d0d37 and a repro script here: https://gist.github.com/eightbitraptor/f30b6a2c10f174f0f1fbdd0e23617f5c but it's not clear to me yet how to fix this.

stevendaniels commented 4 years ago

I bumped into another variation of this error:

RubyParser.new.parse("a = 1, *[:b,:c,:d], {}")

zenspider commented 4 years ago

I believe this is entirely fixed