Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Perlito5 - parser - autoquote fix

  • Loading branch information...
commit 1aa5804f8d1ecb0d78b108af43c0ee7dcb248160 1 parent 376e088
@fglock authored
View
1  TODO-perlito5
@@ -61,7 +61,6 @@ TODO list for Perlito5
--- check signature in sort()
--- fix the prototype for 'stat(*)' (see t/test.pl in the perl test suite)
--- $v{x::y} autoquotes the index when x::y() exists
-- $v->{x} doesn't interpolate inside double quotes
-- deref inside double quotes:
$ node perlito5.js -Bjs -e ' my $x = "123"; my $y = \$x; print "[$$y]\n" '
View
16 html/perlito5.js
@@ -1892,7 +1892,13 @@ var p5100 = p5pkg['main'];
var v_index;
(v_index = (List__.shift()));
if ( (p5bool(p5call(v_index, "isa", ['Perlito5::AST::Apply'], 0)) && p5bool((v_index || (v_index = new p5HashRef({})))._hash_.p5hget('bareword'))) ) {
- throw(p5call(p5pkg["Perlito5::AST::Val::Buf"], "new", ['buf', (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')))], p5want));
+ (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 ( !( (p5pkg["Perlito5"]["v_PROTO"])._hash_.hasOwnProperty(v_full_name)) ) {
+ throw(p5call(p5pkg["Perlito5::AST::Val::Buf"], "new", ['buf', v_full_name], p5want));
+ };
+ })();
};
return (p5context([v_index], p5want));
}
@@ -2468,7 +2474,13 @@ var p5100 = p5pkg['main'];
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'))) ) {
- (v_index = (p5call(p5pkg["Perlito5::AST::Val::Buf"], "new", ['buf', (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')))], 0)));
+ (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 ( !( (p5pkg["Perlito5"]["v_PROTO"])._hash_.hasOwnProperty(v_full_name)) ) {
+ (v_index = (p5call(p5pkg["Perlito5::AST::Val::Buf"], "new", ['buf', v_full_name], 0)));
+ };
+ })();
};
return (p5pkg["Perlito5::Javascript2"].to_str([v_index, v_level], p5want));
});
View
15 perlito5.pl
@@ -7590,7 +7590,10 @@ sub Perlito5::AST::Lookup::autoquote {
((my $self) = shift());
((my $index) = shift());
if (($index->isa('Perlito5::AST::Apply') && $index->{'bareword'})) {
- return (Perlito5::AST::Val::Buf->new('buf', ((($index->{'namespace'} ? ($index->{'namespace'} . '::') : '')) . $index->{'code'})))
+ ((my $full_name) = ((($index->{'namespace'} ? ($index->{'namespace'} . '::') : '')) . $index->{'code'}));
+ if (!(exists($Perlito5::PROTO->{$full_name}))) {
+ return (Perlito5::AST::Val::Buf->new('buf', $full_name))
+ }
};
$index
};
@@ -7998,7 +8001,10 @@ package Perlito5::Javascript2;
((my $index) = shift());
((my $level) = shift());
if (($index->isa('Perlito5::AST::Apply') && $index->{'bareword'})) {
- ($index = Perlito5::AST::Val::Buf->new('buf', ((($index->{'namespace'} ? ($index->{'namespace'} . '::') : '')) . $index->{'code'})))
+ ((my $full_name) = ((($index->{'namespace'} ? ($index->{'namespace'} . '::') : '')) . $index->{'code'}));
+ if (!(exists($Perlito5::PROTO->{$full_name}))) {
+ ($index = Perlito5::AST::Val::Buf->new('buf', $full_name))
+ }
};
return (to_str($index, $level))
};
@@ -9563,7 +9569,10 @@ package Perlito5::Javascript3;
((my $index) = shift());
((my $level) = shift());
if (($index->isa('Perlito5::AST::Apply') && $index->{'bareword'})) {
- ($index = Perlito5::AST::Val::Buf->new('buf', ((($index->{'namespace'} ? ($index->{'namespace'} . '::') : '')) . $index->{'code'})))
+ ((my $full_name) = ((($index->{'namespace'} ? ($index->{'namespace'} . '::') : '')) . $index->{'code'}));
+ if (!(exists($Perlito5::PROTO->{$full_name}))) {
+ ($index = Perlito5::AST::Val::Buf->new('buf', $full_name))
+ }
};
return (to_str($index, $level))
};
View
5 src5/lib/Perlito5/AST.pm
@@ -58,7 +58,10 @@ sub autoquote {
&& $index->{bareword}
)
{
- return Perlito5::AST::Val::Buf->new( buf => ($index->{namespace} ? $index->{namespace} . '::' : "") . $index->{code} );
+ my $full_name = ($index->{namespace} ? $index->{namespace} . '::' : "") . $index->{code};
+ if ( !exists $Perlito5::PROTO->{$full_name} ) {
+ return Perlito5::AST::Val::Buf->new( buf => $full_name );
+ }
}
$index;
View
9 src5/lib/Perlito5/Javascript2/Emitter.pm
@@ -398,9 +398,12 @@ package Perlito5::Javascript2;
&& $index->{bareword}
)
{
- $index = Perlito5::AST::Val::Buf->new(
- buf => ($index->{namespace} ? $index->{namespace} . '::' : "") . $index->{code}
- );
+ my $full_name = ($index->{namespace} ? $index->{namespace} . '::' : "") . $index->{code};
+ if ( !exists $Perlito5::PROTO->{$full_name} ) {
+ $index = Perlito5::AST::Val::Buf->new(
+ buf => $full_name
+ );
+ }
}
return to_str($index, $level);
View
11 src5/lib/Perlito5/Javascript3/Emitter.pm
@@ -410,11 +410,14 @@ package Perlito5::Javascript3;
&& $index->{bareword}
)
{
- $index = Perlito5::AST::Val::Buf->new(
- buf => ($index->{namespace} ? $index->{namespace} . '::' : "") . $index->{code}
- );
+ my $full_name = ($index->{namespace} ? $index->{namespace} . '::' : "") . $index->{code};
+ if ( !exists $Perlito5::PROTO->{$full_name} ) {
+ $index = Perlito5::AST::Val::Buf->new(
+ buf => $full_name
+ );
+ }
}
-
+
return to_str($index, $level);
}
View
19 t5/01-perlito/05-hash.t
@@ -2,7 +2,7 @@ use v5;
use strict;
use feature 'say';
-say '1..11';
+say '1..15';
my %a;
say 'ok 1 - create hash';
$a{abc} = 3;
@@ -54,3 +54,20 @@ print 'not ' if !defined $c1->{c};
say "ok 11 - defined item";
+# autoquote
+
+my %v;
+sub x1 () { 1230 } $v{x1()} = 120; # '1230' => 120
+sub x2 () { 1231 } $v{x2} = 121; # 'x2' => 121
+sub x3 () { 1232 } $v{main::x3} = 122; # '1232' => 122
+
+{
+ no strict 'subs';
+ $v{main::x4} = 123; # 'main::x4' => 123
+}
+
+print 'not ' if $v{'1230'} != 120; say "ok 12 - no autoquote for function call with parenthesis";
+print 'not ' if $v{'x2'} != 121; say "ok 13 - autoquote for bareword without colons";
+print 'not ' if $v{'1232'} != 122; say "ok 14 - no autoquote for function call without parenthesis";
+print 'not ' if $v{'main::x4'} != 123; say "ok 15 - autoquote for bareword with colons";
+
Please sign in to comment.
Something went wrong with that request. Please try again.