From: Michael Edgar Date: 2011-02-04T06:57:55+09:00 Subject: [ruby-core:35078] [Ruby 1.9-Bug#4364][Open] Ripper loses MLHS variables in the presence of an LHS splat --mimepart_4d4b243bb001f_598959178fa3839 Content-Type: text/plain Content-Transfer-Encoding: Quoted-printable Content-Disposition: inline Bug #4364: Ripper loses MLHS variables in the presence of an LHS splat http://redmine.ruby-lang.org/issues/show/4364 Author: Michael Edgar Status: Open, Priority: Normal ruby -v: ruby 1.9.3dev (2011-02-04 trunk 30778) [x86_64-darwin10.6.0] Ripper.sexp currently mis-parses the following LHS forms: *b, c =3D ... *, a =3D ... a, *, b =3D ... Specifically, in all 3 cases, the variables after the splat are not prese= nt in the resulting AST. The cause is simply missing mlhs_add calls in pa= rse.y. Here is the output of the trunk Ripper.sexp: >> pp Ripper.sexp('*, b =3D 1, 2, 3') [:program, [[:massign, [:mlhs_add_star, [], nil], [:mrhs_new_from_args, [[:@int, "1", [1, 7]], [:@int, "2", [1, 10]]], [:@int, "3", [1, 13]]]]]] >> pp Ripper.sexp('*b, c =3D 1, 2, 3') [:program, [[:massign, [:mlhs_add_star, [], [:@ident, "b", [1, 1]]], [:mrhs_new_from_args, [[:@int, "1", [1, 8]], [:@int, "2", [1, 11]]], [:@int, "3", [1, 14]]]]]] >> pp Ripper.sexp('a, *, c =3D 1, 2, 3') [:program, [[:massign, [:mlhs_add_star, [[:@ident, "a", [1, 0]]], nil], [:mrhs_new_from_args, [[:@int, "1", [1, 10]], [:@int, "2", [1, 13]]], [:@int, "3", [1, 16]]]]]] And here is it after the patch I am including: require 'ripper' require 'pp' >> pp Ripper.sexp('*, b =3D 1, 2, 3') [:program, [[:massign, [:mlhs_add_star, [], nil, [[:@ident, "b", [1, 3]]]], [:mrhs_new_from_args, [[:@int, "1", [1, 7]], [:@int, "2", [1, 10]]], [:@int, "3", [1, 13]]]]]] >> pp Ripper.sexp('*b, c =3D 1, 2, 3, 4') [:program, [[:massign, [:mlhs_add_star, [], [:@ident, "b", [1, 1]], [[:@ident, "c", [1, 4]]]]= , [:mrhs_new_from_args, [[:@int, "1", [1, 8]], [:@int, "2", [1, 11]], [:@int, "3", [1, 14]]],= [:@int, "4", [1, 17]]]]]] >> pp Ripper.sexp('a, *, b, c =3D 1, 2, 3, 4') [:program, [[:massign, [:mlhs_add_star, [[:@ident, "a", [1, 0]]], nil, [[:@ident, "b", [1, 6]], [:@ident, "c", [1, 9]]]], [:mrhs_new_from_args, [[:@int, "1", [1, 13]], [:@int, "2", [1, 16]], [:@int, "3", [1, 19]]]= , [:@int, "4", [1, 22]]]]]] I based the new output on the results of the one case that does parse suc= cessfully (this is for both versions): >> pp Ripper.sexp('a, b, *c, d, e =3D 1, 2, 3, 4, 5, 6') [:program, [[:massign, [:mlhs_add_star, [[:@ident, "a", [1, 0]], [:@ident, "b", [1, 3]]], [:@ident, "c", [1, 7]], [[:@ident, "d", [1, 10]], [:@ident, "e", [1, 13]]]], [:mrhs_new_from_args, [[:@int, "1", [1, 17]], [:@int, "2", [1, 20]], [:@int, "3", [1, 23]], [:@int, "4", [1, 26]], [:@int, "5", [1, 29]]], [:@int, "6", [1, 32]]]]]] ---------------------------------------- http://redmine.ruby-lang.org --mimepart_4d4b243bb001f_598959178fa3839 Content-Type: application/octet-stream; name=ripper.splat.diff Content-Transfer-Encoding: Base64 Content-Disposition: attachment; filename=ripper.splat.diff SW5kZXg6IHBhcnNlLnkKPT09PT09PT09PT09PT09PT09PT09PT09PT09PT09 PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PQotLS0gcGFy c2UueQkocmV2aXNpb24gMzA3NzgpCisrKyBwYXJzZS55CSh3b3JraW5nIGNv cHkpCkBAIC0xNTE4LDcgKzE1MTgsOCBAQAogCQkgICAgLyolJSUqLwogCQkJ JCQgPSBORVdfTUFTR04oJDEsIE5FV19QT1NUQVJHKC0xLCAkNCkpOwogCQkg ICAgLyolCi0JCQkkJCA9IG1saHNfYWRkX3N0YXIoJDEsIFFuaWwpOworCQkJ JDEgPSBtbGhzX2FkZF9zdGFyKCQxLCBRbmlsKTsKKwkJCSQkID0gbWxoc19h ZGQoJDEsICQ0KTsKIAkJICAgICUqLwogCQkgICAgfQogCQl8IHRTVEFSIG1s aHNfbm9kZQpAQCAtMTUzNCw3ICsxNTM1LDggQEAKIAkJICAgIC8qJSUlKi8K IAkJCSQkID0gTkVXX01BU0dOKDAsIE5FV19QT1NUQVJHKCQyLCQ0KSk7CiAJ CSAgICAvKiUKLQkJCSQkID0gbWxoc19hZGRfc3RhcihtbGhzX25ldygpLCAk Mik7CisJCQkkMiA9IG1saHNfYWRkX3N0YXIobWxoc19uZXcoKSwgJDIpOwor CQkJJCQgPSBtbGhzX2FkZCgkMiwgJDQpOwogCQkgICAgJSovCiAJCSAgICB9 CiAJCXwgdFNUQVIKQEAgLTE1NTEsNiArMTU1Myw3IEBACiAJCQkkJCA9IE5F V19NQVNHTigwLCBORVdfUE9TVEFSRygtMSwgJDMpKTsKIAkJICAgIC8qJQog CQkJJCQgPSBtbGhzX2FkZF9zdGFyKG1saHNfbmV3KCksIFFuaWwpOworCQkJ JCQgPSBtbGhzX2FkZCgkJCwgJDMpOwogCQkgICAgJSovCiAJCSAgICB9CiAJ CTsK --mimepart_4d4b243bb001f_598959178fa3839--