fglock / Perlito

"Perlito" Perl programming language compiler
http://fglock.github.io/Perlito/
Other
414 stars 47 forks source link

split (//, $s) is not handled well - results in a JS with a comment #22

Closed shlomif closed 10 years ago

shlomif commented 10 years ago

The code is taken from this branch:

https://github.com/shlomif/fc-solve/tree/Games-Solitaire-Verify--for-Perlito--Get-Rid-of-Getopt-Long

shlomif@telaviv1:~/Download/unpack/perl/Perlito/Perlito$ perl perlito5.pl -Cjs -I src5/lib/ -I/home/shlomif/progs/freecell/git/fc-solve/cpan/Games-Solitaire-Verify/Games-Solitaire-Verify/lib /home/shlomif/progs/freecell/git/fc-solve/cpan/Games-Solitaire-Verify/Games-Solitaire-Verify/script/expand-solitaire-multi-card-moves > ~/e.js
shlomif@telaviv1:~/Download/unpack/perl/Perlito/Perlito$ node ~/e.js 

/home/shlomif/e.js:5144
                                                var tmp276 = tmp275.slice(0);
                                                ^^^
SyntaxError: Unexpected token var
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:906:3
shlomif@telaviv1:~/Download/unpack/perl/Perlito/Perlito$ perl -lane 'print if 5140..5150' ~/e.js 
                                        var v_rank;
                                        var v_suit;
                                        (function () {
                                                var tmp275 = p5list_to_a(p5pkg["Games::Solitaire::Verify::Card"].split(p5list_to_a((p5str(p5pkg["Games::Solitaire::Verify::Card"]["v__"]).match(//) ? 1 : 0), v_str), 1));
                                                var tmp276 = tmp275.slice(0);
                                                v_rank = tmp275.shift();
                                                v_suit = tmp275.shift();
                                                return tmp276
                                        })();
                                        if ( !( (p5call(v_self, "rank", p5list_to_a(p5call(v_self, "calc_rank", [v_rank], 1)), 0) != null)) ) {
                                                p5call(p5pkg["Games::Solitaire::Verify::Exception::Parse::Card::UnknownRank"], "throw", ['error', 'unknown rank'], null);
shlomif@telaviv1:~/Download/unpack/perl/Perlito/Perlito$ 
fglock commented 10 years ago

The problem is that the js regex emitter doesn't know about list context.

I've committed a4f5c34c006ca1d0bd1f99230edae448a65fd550 which propagates "wantarray" context into the regex emitter. But the regex emitter doesn't do anything with it just yet.

fglock commented 10 years ago

this should be fixed with:

commit 997461ef0408b34bcbf717f7250d2f197af573f8 Perlito5 - js - implement special syntax "PATTERN" for split() commit 491ce2e4461f495c174bc07cd8de0b0c6959dbcf Perlito5 - js - split() runtime accepts regex as first argument