Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Perlito5 - js - autoquote special cases
  • Loading branch information
fglock committed Sep 11, 2013
1 parent 596ae83 commit 1fef5af
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 26 deletions.
21 changes: 12 additions & 9 deletions html/perlito5.js
Expand Up @@ -11405,6 +11405,17 @@ var p5100 = p5pkg['main'];
throw(p5call(p5pkg["Perlito5::AST::Val::Buf"], "new", ['buf', v_full_name], p5want));
};
})();
}
else {
if ( (p5bool(p5call(v_index, "isa", ['Perlito5::AST::Apply'], 0)) && ((p5str(p5call(v_index, "code", [], 0)) == 'prefix:<->') || (p5str(p5call(v_index, "code", [], 0)) == 'prefix:<+>'))) ) {
(function () {
var v_arg;
(v_arg = (p5call(v_index, "arguments", [], p5want)._array_.p5aget(0)));
if ( p5bool(v_arg) ) {
throw(p5call(p5pkg["Perlito5::AST::Apply"], "new", p5list_to_a('code', p5call(v_index, "code", [], 1), 'namespace', p5call(v_index, "namespace", [], 1), 'arguments', (new p5ArrayRef(p5list_to_a(p5call(v_self, "autoquote", [v_arg], 1))))), p5want));
};
})();
};
};
return (p5context([v_index], p5want));
}
Expand Down Expand Up @@ -12036,15 +12047,7 @@ var p5100 = p5pkg['main'];
(v_index = (List__.shift()));
var v_level;
(v_level = (List__.shift()));
if ( (p5bool(p5call(v_index, "isa", ['Perlito5::AST::Apply'], 0)) && p5bool((v_index || (v_index = new p5HashRef({})))._hash_.p5hget('bareword'))) ) {
(function () {
var v_full_name;
(v_full_name = ((p5str(( p5bool((v_index || (v_index = new p5HashRef({})))._hash_.p5hget('namespace')) ? (p5str((v_index || (v_index = new p5HashRef({})))._hash_.p5hget('namespace')) + '::') : '')) + p5str((v_index || (v_index = new p5HashRef({})))._hash_.p5hget('code')))));
if ( !( (p5make_package("Perlito5")["v_PROTO"])._hash_.hasOwnProperty(v_full_name)) ) {
(v_index = (p5call(p5pkg["Perlito5::AST::Val::Buf"], "new", ['buf', v_full_name], 0)));
};
})();
};
(v_index = (p5call(p5pkg["Perlito5::AST::Lookup"], "autoquote", [v_index], 0)));
return (p5pkg["Perlito5::Javascript2"].to_str([v_index, v_level], p5want));
});
p5typeglob_set("Perlito5::Javascript2", "emit_javascript2_autovivify", function (List__, p5want) {
Expand Down
15 changes: 9 additions & 6 deletions perlito5.pl
Expand Up @@ -8283,6 +8283,14 @@ sub Perlito5::AST::Lookup::autoquote {
if (!(exists($Perlito5::PROTO->{$full_name}))) {
return Perlito5::AST::Val::Buf->new('buf', $full_name)
}
}
else {
if (($index->isa('Perlito5::AST::Apply') && ((($index->code() eq 'prefix:<->') || ($index->code() eq 'prefix:<+>'))))) {
my $arg = $index->arguments()->[0];
if ($arg) {
return Perlito5::AST::Apply->new('code', $index->code(), 'namespace', $index->namespace(), 'arguments', [$self->autoquote($arg)])
}
}
};
$index
};
Expand Down Expand Up @@ -8733,12 +8741,7 @@ package Perlito5::Javascript2;
sub Perlito5::Javascript2::autoquote {
my $index = shift();
my $level = shift();
if (($index->isa('Perlito5::AST::Apply') && $index->{'bareword'})) {
my $full_name = ((($index->{'namespace'} ? ($index->{'namespace'} . '::') : '')) . $index->{'code'});
if (!(exists($Perlito5::PROTO->{$full_name}))) {
$index = Perlito5::AST::Val::Buf->new('buf', $full_name)
}
};
$index = Perlito5::AST::Lookup->autoquote($index);
return to_str($index, $level)
};
sub Perlito5::Javascript2::emit_javascript2_autovivify {
Expand Down
12 changes: 12 additions & 0 deletions src5/lib/Perlito5/AST.pm
Expand Up @@ -63,6 +63,18 @@ sub autoquote {
return Perlito5::AST::Val::Buf->new( buf => $full_name );
}
}
elsif ( $index->isa('Perlito5::AST::Apply')
&& ($index->code eq 'prefix:<->' || $index->code eq 'prefix:<+>')
)
{
my $arg = $index->arguments->[0];
return Perlito5::AST::Apply->new(
code => $index->code,
namespace => $index->namespace,
arguments => [ $self->autoquote($arg) ],
)
if $arg;
}

$index;
}
Expand Down
12 changes: 1 addition & 11 deletions src5/lib/Perlito5/Javascript2/Emitter.pm
Expand Up @@ -399,17 +399,7 @@ package Perlito5::Javascript2;
# TODO ' sub x () { 123 } $v{main::x} = 12; use Data::Dumper; print Dumper \%v ' # '123' => 12
# ok ' $v{main::x} = 12; use Data::Dumper; print Dumper \%v ' # 'main::x' => 12

if ($index->isa('Perlito5::AST::Apply')
&& $index->{bareword}
)
{
my $full_name = ($index->{namespace} ? $index->{namespace} . '::' : "") . $index->{code};
if ( !exists $Perlito5::PROTO->{$full_name} ) {
$index = Perlito5::AST::Val::Buf->new(
buf => $full_name
);
}
}
$index = Perlito5::AST::Lookup->autoquote($index);

return to_str($index, $level);
}
Expand Down

0 comments on commit 1fef5af

Please sign in to comment.