Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Perlito5 - add more "use strict"

  • Loading branch information...
commit daea592131d330771a8e4595b34cf6535f89f39e 1 parent e107c18
@fglock authored
View
3  TODO-perlito5
@@ -88,6 +88,9 @@ TODO list for Perlito5
$ perl -e ' use strict; my $x = X; print $x '
Bareword "X" not allowed while "strict subs" in use
+ $ perl perlito5.pl -MO=Deparse -e ' ::X::x::y '
+ join("", ::{'main::X::'} x main::y);
+
-- clean up:
the several "end_tables" in Expression.pm are duplicating the function of
$Precedence in Precedence.pm - Expression.pm should use $Precedence directly.
View
64 html/perlito5.js
@@ -2115,6 +2115,7 @@ var p5100 = p5pkg['main'];
p5make_sub("Perlito5::AST::Use", "code", function (List__, p5want) {
return (List__.p5aget_hash(0)._hash_.p5hget('code'));
});
+ 1;
})()
;
(function () {
@@ -2173,6 +2174,8 @@ var p5100 = p5pkg['main'];
;
// use Perlito5::Dumper
;
+ // use strict
+;
var p5127 = p5make_package("Perlito5::Javascript2");
p5for_lex(function () {
var v_label_count;
@@ -3384,6 +3387,8 @@ var p5100 = p5pkg['main'];
}, [0], false, "");
var p5140 = p5make_package("Perlito5::AST::Apply");
p5for_lex(function () {
+ // no strict
+;
p5make_sub("Perlito5::AST::Apply", "emit_regex_javascript2", function (List__, p5want) {
try {
var v_op;
@@ -3536,13 +3541,17 @@ var p5100 = p5pkg['main'];
}, 'require', function (List__, p5want) {
var v_self;
(v_self = (List__.p5aget(0)));
+ var v_level;
+ (v_level = (List__.p5aget(1)));
return (p5context([('p5pkg["Perlito5::Grammar::Use"]["require"]([' + p5str(p5pkg["Perlito5::Javascript2"].to_str(p5list_to_a((v_self || (v_self = new p5HashRef({})))._hash_.p5hget_array('arguments')._array_.p5aget(0)), 0)) + ', ' + p5str(( p5bool((v_self || (v_self = new p5HashRef({})))._hash_.p5hget_array('arguments')._array_.p5aget_hash(0)._hash_.p5hget('bareword')) ? 1 : 0)) + '])')], p5want));
}, 'prefix:<$>', function (List__, p5want) {
var v_self;
(v_self = (List__.p5aget(0)));
+ var v_level;
+ (v_level = (List__.p5aget(1)));
var v_arg;
(v_arg = ((v_self || (v_self = new p5HashRef({})))._hash_.p5hget_array('arguments')._array_.p5aget(0)));
- return (p5context([(p5str(p5pkg["Perlito5::Javascript2"].emit_javascript2_autovivify([v_arg, p5pkg["Perlito5::AST::Apply"]["v_level"], 'scalar'], 0)) + '._scalar_')], p5want));
+ return (p5context([(p5str(p5pkg["Perlito5::Javascript2"].emit_javascript2_autovivify([v_arg, v_level, 'scalar'], 0)) + '._scalar_')], p5want));
}, 'prefix:<@>', function (List__, p5want) {
var v_self;
(v_self = (List__.p5aget(0)));
@@ -3578,11 +3587,15 @@ var p5100 = p5pkg['main'];
}, 'circumfix:<[ ]>', function (List__, p5want) {
var v_self;
(v_self = (List__.p5aget(0)));
+ var v_level;
+ (v_level = (List__.p5aget(1)));
return (p5context([('(new p5ArrayRef(' + p5str(p5pkg["Perlito5::Javascript2"].to_list(p5list_to_a((v_self || (v_self = new p5HashRef({})))._hash_.p5hget('arguments')), 0)) + '))')], p5want));
}, 'circumfix:<{ }>', function (List__, p5want) {
var v_self;
(v_self = (List__.p5aget(0)));
- return (p5context([('(new p5HashRef(' + p5str(p5pkg["Perlito5::Javascript2"].to_list(p5list_to_a((v_self || (v_self = new p5HashRef({})))._hash_.p5hget('arguments'), p5pkg["Perlito5::AST::Apply"]["v_level"], 'hash'), 0)) + '))')], p5want));
+ var v_level;
+ (v_level = (List__.p5aget(1)));
+ return (p5context([('(new p5HashRef(' + p5str(p5pkg["Perlito5::Javascript2"].to_list(p5list_to_a((v_self || (v_self = new p5HashRef({})))._hash_.p5hget('arguments'), v_level, 'hash'), 0)) + '))')], p5want));
}, 'prefix:<' + String.fromCharCode(92) + '>', function (List__, p5want) {
try {
var v_self;
@@ -3731,15 +3744,21 @@ var p5100 = p5pkg['main'];
}, 'infix:<..>', function (List__, p5want) {
var v_self;
(v_self = (List__.p5aget(0)));
+ var v_level;
+ (v_level = (List__.p5aget(1)));
return (p5context([('(function (a) { ' + 'for (var i=' + p5str(p5call((v_self || (v_self = new p5HashRef({})))._hash_.p5hget_array('arguments')._array_.p5aget(0), "emit_javascript2", [], 0)) + ', l=' + p5str(p5call((v_self || (v_self = new p5HashRef({})))._hash_.p5hget_array('arguments')._array_.p5aget(1), "emit_javascript2", [], 0)) + '; ' + 'i<=l; ++i)' + '{ ' + 'a.push(i) ' + '}; ' + 'return a ' + '})([])')], p5want));
}, 'delete', function (List__, p5want) {
var v_self;
(v_self = (List__.p5aget(0)));
+ var v_level;
+ (v_level = (List__.p5aget(1)));
return (p5context([('(delete ' + p5str(p5call((v_self || (v_self = new p5HashRef({})))._hash_.p5hget_array('arguments')._array_.p5aget(0), "emit_javascript2", [], 0)) + ')')], p5want));
}, 'scalar', function (List__, p5want) {
var v_self;
(v_self = (List__.p5aget(0)));
- return (p5pkg["Perlito5::Javascript2"].to_scalar(p5list_to_a((v_self || (v_self = new p5HashRef({})))._hash_.p5hget('arguments'), (p5num(p5pkg["Perlito5::AST::Apply"]["v_level"]) + 1)), p5want));
+ var v_level;
+ (v_level = (List__.p5aget(1)));
+ return (p5pkg["Perlito5::Javascript2"].to_scalar(p5list_to_a((v_self || (v_self = new p5HashRef({})))._hash_.p5hget('arguments'), (p5num(v_level) + 1)), p5want));
}, 'ternary:<? :>', function (List__, p5want) {
var v_self;
(v_self = (List__.shift()));
@@ -4395,8 +4414,10 @@ var p5100 = p5pkg['main'];
(v_body = (p5call(p5pkg["Perlito5::Javascript2::LexicalBlock"], "new", p5list_to_a('block', p5call((v_self || (v_self = new p5HashRef({})))._hash_.p5hget('body'), "stmts", [], 1), 'needs_return', 0, 'create_context', 1), 0)));
var v_expr;
(v_expr = (p5call(p5pkg["Perlito5::AST::Apply"], "new", p5list_to_a('code', 'infix:<==>', 'arguments', (new p5ArrayRef(p5list_to_a(p5call(p5pkg["Perlito5::AST::Var"], "new", ['sigil', '$', 'namespace', '', 'name', '_'], 1), v_cond)))), 0)));
+ var v_label;
+ (v_label = (''));
var v_s;
- (v_s = (('if ( ' + p5str(p5pkg["Perlito5::Javascript2"].to_bool([v_expr, (p5num(v_level) + 1)], 0)) + ' ) {' + String.fromCharCode(10) + p5str(p5call(v_body, "emit_javascript2", [(p5num(v_level) + 1)], 0)) + String.fromCharCode(10) + p5str(p5pkg["Perlito5::Javascript2"].tab([(p5num(v_level) + 1)], 0)) + 'throw(new p5_error("next", "' + p5str(p5pkg["Perlito5::AST::When"]["v_label"]) + '"))' + p5str(p5pkg["Perlito5::Javascript2"].tab([v_level], 0)) + '}')));
+ (v_s = (('if ( ' + p5str(p5pkg["Perlito5::Javascript2"].to_bool([v_expr, (p5num(v_level) + 1)], 0)) + ' ) {' + String.fromCharCode(10) + p5str(p5call(v_body, "emit_javascript2", [(p5num(v_level) + 1)], 0)) + String.fromCharCode(10) + p5str(p5pkg["Perlito5::Javascript2"].tab([(p5num(v_level) + 1)], 0)) + 'throw(new p5_error("next", "' + p5str(v_label) + '"))' + p5str(p5pkg["Perlito5::Javascript2"].tab([v_level], 0)) + '}')));
return (p5context([v_s], p5want));
});
}, [0], false, "");
@@ -4511,6 +4532,8 @@ var p5100 = p5pkg['main'];
;
(function () {
var p5148 = p5make_package("Perlito5::Precedence");
+ // use feature
+;
p5make_sub("Perlito5::Precedence", "new", function (List__, p5want) {
var v_class;
(v_class = (List__.shift()));
@@ -4881,7 +4904,7 @@ var p5100 = p5pkg['main'];
(v_op_stack || (v_op_stack = new p5ArrayRef([])))._array_.p5unshift([v_token]);
}
else {
- if ( (p5bool((p5context([(v_Operator || (v_Operator = new p5HashRef({})))._hash_.p5hget('postfix')], 0) || (p5context([(v_Operator || (v_Operator = new p5HashRef({})))._hash_.p5hget('postfix')], 0) = new p5HashRef({})))._hash_.p5hget(p5str((v_token || (v_token = new p5ArrayRef([])))._array_.p5aget(1)))) && p5bool(v_last_is_term)) ) {
+ if ( (p5bool((v_Operator || (v_Operator = new p5HashRef({})))._hash_.p5hget_hash('postfix')._hash_.p5hget(p5str((v_token || (v_token = new p5ArrayRef([])))._array_.p5aget(1)))) && p5bool(v_last_is_term)) ) {
(function () {
var v_pr;
(v_pr = ((v_Precedence || (v_Precedence = new p5HashRef({})))._hash_.p5hget(p5str((v_token || (v_token = new p5ArrayRef([])))._array_.p5aget(1)))));
@@ -4957,6 +4980,8 @@ var p5100 = p5pkg['main'];
;
(function () {
var p5149 = p5make_package("Perlito5::Grammar::Bareword");
+ // use strict
+;
p5make_sub("Perlito5::Grammar::Bareword", "term_bareword", function (List__, p5want) {
try {
var v_self;
@@ -4981,9 +5006,14 @@ var p5100 = p5pkg['main'];
};
throw(p5context([], p5want));
};
- (v_p = ((v_m_name || (v_m_name = new p5HashRef({})))._hash_.p5hget('to')));
var v_name;
(v_name = (p5pkg["Perlito5::Match"].flat([v_m_name], 0)));
+ (v_p = ((v_m_name || (v_m_name = new p5HashRef({})))._hash_.p5hget('to')));
+ if ( (p5pkg["Perlito5::Grammar::Bareword"].substr([v_str, v_p, 2], 0) == '::') ) {
+ (v_m_name || (v_m_name = new p5HashRef({})))._hash_.p5hset('to', ((p5num(v_p) + 2)));
+ (v_m_name || (v_m_name = new p5HashRef({})))._hash_.p5hset('capture', ((new p5ArrayRef(p5list_to_a('term', p5call(p5pkg["Perlito5::AST::Var"], "new", ['sigil', '::', 'name', '', 'namespace', (p5str(v_namespace) + '::' + p5str(v_name))], 1))))));
+ throw(p5context([v_m_name], p5want));
+ };
var v_full_name;
(v_full_name = (v_name));
if ( p5bool(v_namespace) ) {
@@ -9940,6 +9970,8 @@ var p5100 = p5pkg['main'];
;
// use Perlito5::Grammar
;
+ // use strict
+;
p5pkg["Perlito5::Precedence"].add_term(['no', function (List__, p5want) {
return (p5call(p5pkg["Perlito5::Grammar::Use"], "term_use", p5list_to_a(List__.p5aget(0), List__.p5aget(1)), p5want));
}], null);
@@ -10345,11 +10377,12 @@ return r;
if ( (p5str(p5pkg["Perlito5::Grammar::Use"].filename_lookup([v_filename], 0)) == 'done') ) {
throw(p5context([], p5want));
};
- (p5pkg["Perlito5::Grammar::Use"]["v_result"] = ((function (p5want) {
+ var v_result;
+ (v_result = ((function (p5want) {
var r;
p5pkg["main"]["v_@"] = "";
try {
-r = eval(perl5_to_js(p5str(p5pkg["Perlito5::IO"].slurp(p5list_to_a(p5pkg["main"]["Hash_INC"].p5hget(p5str(v_filename))), 0)), "Perlito5::Grammar::Use", (new p5ArrayRef(p5list_to_a((new p5HashRef(p5a_to_h(p5list_to_a('$filename', (new p5HashRef({'decl' : 'my'})), '$is_bareword', (new p5HashRef({'decl' : 'my'})))))), (new p5HashRef(p5a_to_h(p5list_to_a('$AUTOLOAD', (new p5HashRef({'decl' : 'our', 'namespace' : 'Perlito5::Grammar::Use'})), '$_', (new p5HashRef({'decl' : 'our', 'namespace' : 'Perlito5::Grammar::Use'})), '$a', (new p5HashRef({'decl' : 'our', 'namespace' : 'Perlito5::Grammar::Use'})), '$b', (new p5HashRef({'decl' : 'our', 'namespace' : 'Perlito5::Grammar::Use'})), '%Perlito_internal_module', (new p5HashRef({'decl' : 'my'})))))), (new p5HashRef(p5a_to_h(p5list_to_a('$AUTOLOAD', (new p5HashRef({'decl' : 'our', 'namespace' : 'Perlito5'})), '$_', (new p5HashRef({'decl' : 'our', 'namespace' : 'Perlito5'})), '$a', (new p5HashRef({'decl' : 'our', 'namespace' : 'Perlito5'})), '$b', (new p5HashRef({'decl' : 'our', 'namespace' : 'Perlito5'})))))), (new p5HashRef(p5a_to_h(p5list_to_a('$@', (new p5HashRef({'decl' : 'our', 'namespace' : 'main'})), '$AUTOLOAD', (new p5HashRef({'decl' : 'our', 'namespace' : 'main'})), '$^O', (new p5HashRef({'decl' : 'our', 'namespace' : 'main'})), '$_', (new p5HashRef({'decl' : 'our', 'namespace' : 'main'})), '$a', (new p5HashRef({'decl' : 'our', 'namespace' : 'main'})), '$b', (new p5HashRef({'decl' : 'our', 'namespace' : 'main'})), '$|', (new p5HashRef({'decl' : 'our', 'namespace' : 'main'})), '%ENV', (new p5HashRef({'decl' : 'our', 'namespace' : 'main'})), '%INC', (new p5HashRef({'decl' : 'our', 'namespace' : 'main'})), '@#', (new p5HashRef({'decl' : 'our', 'namespace' : 'main'})), '@ARGV', (new p5HashRef({'decl' : 'our', 'namespace' : 'main'})), '@INC', (new p5HashRef({'decl' : 'our', 'namespace' : 'main'})), '@_', (new p5HashRef({'decl' : 'my'}))))))))), ""))
+r = eval(perl5_to_js(p5str(p5pkg["Perlito5::IO"].slurp(p5list_to_a(p5pkg["main"]["Hash_INC"].p5hget(p5str(v_filename))), 0)), "Perlito5::Grammar::Use", (new p5ArrayRef(p5list_to_a((new p5HashRef(p5a_to_h(p5list_to_a('$filename', (new p5HashRef({'decl' : 'my'})), '$is_bareword', (new p5HashRef({'decl' : 'my'})), '$result', (new p5HashRef({'decl' : 'my'})))))), (new p5HashRef(p5a_to_h(p5list_to_a('$AUTOLOAD', (new p5HashRef({'decl' : 'our', 'namespace' : 'Perlito5::Grammar::Use'})), '$_', (new p5HashRef({'decl' : 'our', 'namespace' : 'Perlito5::Grammar::Use'})), '$a', (new p5HashRef({'decl' : 'our', 'namespace' : 'Perlito5::Grammar::Use'})), '$b', (new p5HashRef({'decl' : 'our', 'namespace' : 'Perlito5::Grammar::Use'})), '%Perlito_internal_module', (new p5HashRef({'decl' : 'my'})))))), (new p5HashRef(p5a_to_h(p5list_to_a('$AUTOLOAD', (new p5HashRef({'decl' : 'our', 'namespace' : 'Perlito5'})), '$_', (new p5HashRef({'decl' : 'our', 'namespace' : 'Perlito5'})), '$a', (new p5HashRef({'decl' : 'our', 'namespace' : 'Perlito5'})), '$b', (new p5HashRef({'decl' : 'our', 'namespace' : 'Perlito5'})))))), (new p5HashRef(p5a_to_h(p5list_to_a('$@', (new p5HashRef({'decl' : 'our', 'namespace' : 'main'})), '$AUTOLOAD', (new p5HashRef({'decl' : 'our', 'namespace' : 'main'})), '$^O', (new p5HashRef({'decl' : 'our', 'namespace' : 'main'})), '$_', (new p5HashRef({'decl' : 'our', 'namespace' : 'main'})), '$a', (new p5HashRef({'decl' : 'our', 'namespace' : 'main'})), '$b', (new p5HashRef({'decl' : 'our', 'namespace' : 'main'})), '$|', (new p5HashRef({'decl' : 'our', 'namespace' : 'main'})), '%ENV', (new p5HashRef({'decl' : 'our', 'namespace' : 'main'})), '%INC', (new p5HashRef({'decl' : 'our', 'namespace' : 'main'})), '@#', (new p5HashRef({'decl' : 'our', 'namespace' : 'main'})), '@ARGV', (new p5HashRef({'decl' : 'our', 'namespace' : 'main'})), '@INC', (new p5HashRef({'decl' : 'our', 'namespace' : 'main'})), '@_', (new p5HashRef({'decl' : 'my'}))))))))), ""))
}
catch(err) {
if ( err instanceof p5_error || err instanceof Error ) {
@@ -10371,7 +10404,7 @@ return r;
}
else {
- if ( !( p5bool(p5pkg["Perlito5::Grammar::Use"]["v_result"])) ) {
+ if ( !( p5bool(v_result)) ) {
(delete p5pkg["main"]["Hash_INC"].p5hget(p5str(v_filename)));
if ( p5bool(p5pkg["main"]["v_@"]) ) {
p5pkg["Perlito5::Grammar::Use"].warn([[p5pkg["main"]["v_@"]]], null);
@@ -10380,7 +10413,7 @@ return r;
}
else {
- throw(p5context([p5pkg["Perlito5::Grammar::Use"]["v_result"]], p5want))
+ throw(p5context([v_result], p5want))
}
}
}
@@ -10400,6 +10433,8 @@ return r;
var p5155 = p5make_package("Perlito5::Grammar::Block");
// use Perlito5::Expression
;
+ // use strict
+;
// our p5pkg["Perlito5::Grammar::Block"]["Hash_Named_block"]
(p5pkg["Perlito5::Grammar::Block"]["Hash_Named_block"] = {'BEGIN' : 1, 'UNITCHECK' : 1, 'CHECK' : 1, 'INIT' : 1, 'END' : 1});
p5pkg["Perlito5::Expression"].add_statement(['{', function (List__, p5want) {
@@ -10687,9 +10722,10 @@ return r;
else {
throw(p5context([], p5want));
};
- (p5pkg["Perlito5::Grammar::Block"]["v_p"] = ((v_ws || (v_ws = new p5HashRef({})))._hash_.p5hget('to')));
+ var v_p;
+ (v_p = ((v_ws || (v_ws = new p5HashRef({})))._hash_.p5hget('to')));
var v_m_name;
- (v_m_name = (p5call(p5pkg["Perlito5::Grammar"], "ident", [v_str, p5pkg["Perlito5::Grammar::Block"]["v_p"]], 0)));
+ (v_m_name = (p5call(p5pkg["Perlito5::Grammar"], "ident", [v_str, v_p], 0)));
if ( p5bool(v_m_name) ) {
null;
}
@@ -10699,9 +10735,9 @@ return r;
var v_block_name;
(v_block_name = (p5pkg["Perlito5::Match"].flat([v_m_name], 0)));
if ( (p5pkg["Perlito5::Grammar::Block"]["Hash_Named_block"]).hasOwnProperty(v_block_name) ) {
- throw(p5call(p5pkg["Perlito5::Grammar::Block"], "term_block", [v_str, p5pkg["Perlito5::Grammar::Block"]["v_p"]], p5want));
+ throw(p5call(p5pkg["Perlito5::Grammar::Block"], "term_block", [v_str, v_p], p5want));
};
- return (p5call(p5pkg["Perlito5::Grammar::Block"], "named_sub_def", [v_str, p5pkg["Perlito5::Grammar::Block"]["v_p"]], p5want));
+ return (p5call(p5pkg["Perlito5::Grammar::Block"], "named_sub_def", [v_str, v_p], p5want));
}
catch(err) {
if ( err instanceof Error ) {
View
56 perlito5.pl
@@ -270,6 +270,9 @@ sub Rul::NotBefore::set_captures_to_array {
;
package main;
package Perlito5::Precedence;
+
+# use feature
+;
sub Perlito5::Precedence::new {
((my $class) = shift());
bless({@_}, $class)
@@ -572,7 +575,7 @@ sub Perlito5::Precedence::precedence_parse {
unshift(@{$op_stack}, $token)
}
else {
- if ((($Operator->{'postfix'})->{$token->[1]} && $last_is_term)) {
+ if (($Operator->{'postfix'}->{$token->[1]} && $last_is_term)) {
((my $pr) = $Precedence->{$token->[1]});
for ( ; (scalar(@{$op_stack}) && (($pr <= $Precedence->{($op_stack->[0])->[1]}))); do {{
@@ -650,6 +653,9 @@ sub Perlito5::Precedence::precedence_parse {
;
package main;
package Perlito5::Grammar::Bareword;
+
+# use strict
+;
sub Perlito5::Grammar::Bareword::term_bareword {
((my $self) = $_[0]);
((my $str) = $_[1]);
@@ -666,8 +672,13 @@ sub Perlito5::Grammar::Bareword::term_bareword {
};
return ()
};
- ($p = $m_name->{'to'});
((my $name) = Perlito5::Match::flat($m_name));
+ ($p = $m_name->{'to'});
+ if ((substr($str, $p, 2) eq '::')) {
+ ($m_name->{'to'} = ($p + 2));
+ ($m_name->{'capture'} = ['term', Perlito5::AST::Var->new('sigil', '::', 'name', '', 'namespace', ($namespace . '::' . $name))]);
+ return ($m_name)
+ };
((my $full_name) = $name);
if ($namespace) {
($full_name = ($namespace . '::' . $name))
@@ -5360,6 +5371,9 @@ package Perlito5::Grammar::Use;
# use Perlito5::Grammar
;
+
+# use strict
+;
Perlito5::Precedence::add_term('no', sub {
Perlito5::Grammar::Use->term_use($_[0], $_[1])
});
@@ -5630,7 +5644,7 @@ sub Perlito5::Grammar::Use::require {
if ((filename_lookup($filename) eq 'done')) {
return ()
};
- ($result = (do { my $m = Perlito5::Grammar->exp_stmts( Perlito5::IO::slurp($INC{$filename}), 0);my $source; $source .= (defined $_ ? $_->emit_perl5(0, "scalar") : "") . ";\n" for @{ Perlito5::Match::flat($m) }; eval $source;}));
+ ((my $result) = (do { my $m = Perlito5::Grammar->exp_stmts( Perlito5::IO::slurp($INC{$filename}), 0);my $source; $source .= (defined $_ ? $_->emit_perl5(0, "scalar") : "") . ";\n" for @{ Perlito5::Match::flat($m) }; eval $source;}));
if (${'@'}) {
($INC{$filename} = undef());
die(${'@'})
@@ -5656,6 +5670,9 @@ package Perlito5::Grammar::Block;
# use Perlito5::Expression
;
+
+# use strict
+;
((our %Named_block) = ('BEGIN', 1, 'UNITCHECK', 1, 'CHECK', 1, 'INIT', 1, 'END', 1));
Perlito5::Expression::add_statement('{', sub {
Perlito5::Grammar::Block->term_block($_[0], $_[1])
@@ -5863,7 +5880,7 @@ sub Perlito5::Grammar::Block::named_sub {
else {
return ()
};
- ($p = $ws->{'to'});
+ ((my $p) = $ws->{'to'});
((my $m_name) = Perlito5::Grammar->ident($str, $p));
if ($m_name) {
@@ -7808,6 +7825,7 @@ sub Perlito5::AST::Use::mod {
sub Perlito5::AST::Use::code {
$_[0]->{ 'code'}
};
+1;
;
package main;
@@ -7847,6 +7865,9 @@ package main;
# use Perlito5::Dumper
;
+
+# use strict
+;
package Perlito5::Javascript2;
do {{
((my $label_count) = 100);
@@ -8630,6 +8651,9 @@ package Perlito5::AST::Call;
}};
package Perlito5::AST::Apply;
do {{
+
+ # no strict
+;
sub Perlito5::AST::Apply::emit_regex_javascript2 {
((my $op) = shift());
((my $var) = shift());
@@ -8731,9 +8755,11 @@ package Perlito5::AST::Apply;
('(' . $self->{'arguments'}->[0]->emit_javascript2($level, $wantarray) . ')')
}, 'require', sub {
((my $self) = $_[0]);
+ ((my $level) = $_[1]);
('p5pkg["Perlito5::Grammar::Use"]["require"]([' . Perlito5::Javascript2::to_str($self->{'arguments'}->[0]) . ', ' . (($self->{'arguments'}->[0]->{'bareword'} ? 1 : 0)) . '])')
}, 'prefix:<$>', sub {
((my $self) = $_[0]);
+ ((my $level) = $_[1]);
((my $arg) = $self->{'arguments'}->[0]);
(Perlito5::Javascript2::emit_javascript2_autovivify($arg, $level, 'scalar') . '._scalar_')
}, 'prefix:<@>', sub {
@@ -8758,9 +8784,11 @@ package Perlito5::AST::Apply;
('p5code_lookup_by_name("' . $Perlito5::PKG_NAME . '", ' . $arg->emit_javascript2($level) . ')')
}, 'circumfix:<[ ]>', sub {
((my $self) = $_[0]);
+ ((my $level) = $_[1]);
('(new p5ArrayRef(' . Perlito5::Javascript2::to_list($self->{'arguments'}) . '))')
}, 'circumfix:<{ }>', sub {
((my $self) = $_[0]);
+ ((my $level) = $_[1]);
('(new p5HashRef(' . Perlito5::Javascript2::to_list($self->{'arguments'}, $level, 'hash') . '))')
}, 'prefix:<' . chr(92) . '>', sub {
((my $self) = $_[0]);
@@ -8829,12 +8857,15 @@ package Perlito5::AST::Apply;
Perlito5::Javascript2::to_list($self->{'arguments'})
}, 'infix:<..>', sub {
((my $self) = $_[0]);
+ ((my $level) = $_[1]);
('(function (a) { ' . 'for (var i=' . $self->{'arguments'}->[0]->emit_javascript2() . ', l=' . $self->{'arguments'}->[1]->emit_javascript2() . '; ' . 'i<=l; ++i)' . '{ ' . 'a.push(i) ' . '}; ' . 'return a ' . '})([])')
}, 'delete', sub {
((my $self) = $_[0]);
+ ((my $level) = $_[1]);
('(delete ' . $self->{'arguments'}->[0]->emit_javascript2() . ')')
}, 'scalar', sub {
((my $self) = $_[0]);
+ ((my $level) = $_[1]);
Perlito5::Javascript2::to_scalar($self->{'arguments'}, ($level + 1))
}, 'ternary:<? :>', sub {
((my $self) = shift());
@@ -9269,6 +9300,7 @@ package Perlito5::AST::When;
((my $cond) = $self->{'cond'});
((my $body) = Perlito5::Javascript2::LexicalBlock->new('block', $self->{'body'}->stmts(), 'needs_return', 0, 'create_context', 1));
((my $expr) = Perlito5::AST::Apply->new('code', 'infix:<==>', 'arguments', [Perlito5::AST::Var->new('sigil', '$', 'namespace', '', 'name', '_'), $cond]));
+ ((my $label) = '');
((my $s) = ('if ( ' . Perlito5::Javascript2::to_bool($expr, ($level + 1)) . ' ) {' . chr(10) . $body->emit_javascript2(($level + 1)) . chr(10) . Perlito5::Javascript2::tab(($level + 1)) . 'throw(new p5_error("next", "' . $label . '"))' . Perlito5::Javascript2::tab($level) . '}'));
return ($s)
}
@@ -9409,6 +9441,9 @@ package main;
# use Perlito5::Dumper
;
+
+# use feature
+;
package Perlito5::Javascript3;
do {{
((my $label_count) = 100);
@@ -10224,6 +10259,7 @@ package Perlito5::AST::Apply;
('(' . $self->{'arguments'}->[0]->emit_javascript3($level, $wantarray) . ')')
}, 'require', sub {
((my $self) = $_[0]);
+ ((my $level) = $_[1]);
((my $arg) = $self->{'arguments'}->[0]);
if ($arg->isa('Perlito5::AST::Val::Num')) {
return ('1')
@@ -10231,6 +10267,7 @@ package Perlito5::AST::Apply;
('p5pkg["Perlito5::Grammar::Use"].require([' . Perlito5::Javascript3::to_str($self->{'arguments'}->[0]) . ', ' . (($self->{'arguments'}->[0]->{'bareword'} ? 1 : 0)) . '])')
}, 'prefix:<$>', sub {
((my $self) = $_[0]);
+ ((my $level) = $_[1]);
((my $arg) = $self->{'arguments'}->[0]);
(Perlito5::Javascript3::emit_javascript3_autovivify($arg, $level, 'scalar') . '.sderef()')
}, 'prefix:<@>', sub {
@@ -10255,9 +10292,11 @@ package Perlito5::AST::Apply;
('p5code_lookup_by_name("' . $Perlito5::PKG_NAME . '", ' . $arg->emit_javascript3($level) . ')')
}, 'circumfix:<[ ]>', sub {
((my $self) = $_[0]);
+ ((my $level) = $_[1]);
('(new p5ArrayRef(new p5Array(' . Perlito5::Javascript3::to_list($self->{'arguments'}) . ')))')
}, 'circumfix:<{ }>', sub {
((my $self) = $_[0]);
+ ((my $level) = $_[1]);
('(new p5HashRef(new p5Hash(' . Perlito5::Javascript3::to_list($self->{'arguments'}, $level, 'hash') . ')))')
}, 'prefix:<' . chr(92) . '>', sub {
((my $self) = $_[0]);
@@ -11205,7 +11244,7 @@ package Perlito5::AST::Apply;
((my $arg) = $self->{'arguments'}->[0]);
(my $eval);
if ($arg->isa('Perlito5::AST::Do')) {
- ($eval = $arg->emit_perl5(($level + 1), $wantarray))
+ ($eval = $arg->emit_perl5(($level + 1)))
}
else {
($eval = ('(do { ' . 'my $m = Perlito5::Grammar->exp_stmts(' . $arg->emit_perl5(($level + 1), 'scalar') . ', 0);' . 'my $source; ' . '$source .= (defined $_ ? $_->emit_perl5(0, "scalar") : "") . ";' . chr(92) . 'n" ' . 'for @{ Perlito5::Match::flat($m) }; ' . 'eval $source;' . '})'))
@@ -11887,6 +11926,9 @@ package Perlito5::Runtime;
# use Perlito5::Dumper
;
+
+# use strict
+;
((my $_V5_COMPILER_NAME) = 'Perlito5');
((my $_V5_COMPILER_VERSION) = '9.0');
((my $source) = '');
@@ -11910,12 +11952,12 @@ package Perlito5::Runtime;
else {
if (($ARGV[0] eq '-I')) {
shift(@ARGV);
- ($lib = shift(@ARGV));
+ ((my $lib) = shift(@ARGV));
unshift(@INC, $lib)
}
else {
if ((substr($ARGV[0], 0, 2) eq '-I')) {
- ($lib = substr($ARGV[0], 2));
+ ((my $lib) = substr($ARGV[0], 2));
unshift(@INC, $lib);
shift(@ARGV)
}
View
2  src5/lib/Perlito5/AST.pm
@@ -180,7 +180,7 @@ sub new { my $class = shift; bless {@_}, $class }
sub mod { $_[0]->{mod} }
sub code { $_[0]->{code} }
-
+1;
=begin
View
16 src5/lib/Perlito5/Grammar/Bareword.pm
@@ -1,5 +1,6 @@
package Perlito5::Grammar::Bareword;
+use strict;
sub term_bareword {
my $self = $_[0];
@@ -27,9 +28,22 @@ package Perlito5::Grammar::Bareword;
return;
}
+ my $name = Perlito5::Match::flat($m_name);
$p = $m_name->{to};
- my $name = Perlito5::Match::flat($m_name);
+ if ( substr( $str, $p, 2) eq '::' ) {
+ # ::X::y::
+ $m_name->{to} = $p + 2;
+ $m_name->{capture} = [ 'term',
+ Perlito5::AST::Var->new(
+ sigil => '::',
+ name => '',
+ namespace => $namespace . '::' . $name,
+ )
+ ];
+ return $m_name;
+ }
+
my $full_name = $name;
$full_name = $namespace . '::' . $name if $namespace;
View
3  src5/lib/Perlito5/Grammar/Block.pm
@@ -2,6 +2,7 @@
package Perlito5::Grammar::Block;
use Perlito5::Expression;
+use strict;
our %Named_block = (
BEGIN => 1,
@@ -139,7 +140,7 @@ sub named_sub {
my $ws = Perlito5::Grammar::Space->ws( $str, $pos + 3 );
return
unless $ws;
- $p = $ws->{to};
+ my $p = $ws->{to};
my $m_name = Perlito5::Grammar->ident( $str, $p );
return
View
3  src5/lib/Perlito5/Grammar/Use.pm
@@ -3,6 +3,7 @@ package Perlito5::Grammar::Use;
use Perlito5::Precedence;
use Perlito5::Grammar;
+use strict;
Perlito5::Precedence::add_term( 'no' => sub { Perlito5::Grammar::Use->term_use($_[0], $_[1]) } );
Perlito5::Precedence::add_term( 'use' => sub { Perlito5::Grammar::Use->term_use($_[0], $_[1]) } );
@@ -234,7 +235,7 @@ sub require {
return
if filename_lookup($filename) eq "done";
- $result = do $INC{$filename};
+ my $result = do $INC{$filename};
if ($@) {
$INC{$filename} = undef;
View
19 src5/lib/Perlito5/Javascript2/Emitter.pm
@@ -2,6 +2,7 @@ use v5;
use Perlito5::AST;
use Perlito5::Dumper;
+use strict;
package Perlito5::Javascript2;
{
@@ -467,7 +468,7 @@ package Perlito5::Javascript2::LexicalBlock;
return 1;
}
if ($decl->isa( 'Perlito5::AST::Apply' ) && $decl->code eq 'infix:<=>') {
- my $var = $decl->arguments[0];
+ my $var = $decl->arguments()->[0];
if ( $var->isa( 'Perlito5::AST::Decl' ) && $var->decl eq $type
|| $decl->isa( 'Perlito5::AST::Apply' ) && $decl->code eq $type
)
@@ -1255,6 +1256,9 @@ package Perlito5::AST::Call;
package Perlito5::AST::Apply;
{
+ no strict; # TODO - FIXME:
+ # Global symbol "$level" requires explicit package name
+ # make: *** [build-5js]
sub emit_regex_javascript2 {
my $op = shift;
@@ -1316,7 +1320,6 @@ package Perlito5::AST::Apply;
}
-
my %emit_js = (
'infix:<=~>' => sub {
my $self = $_[0];
@@ -1397,6 +1400,7 @@ package Perlito5::AST::Apply;
},
'require' => sub {
my $self = $_[0];
+ my $level = $_[1];
'p5pkg["Perlito5::Grammar::Use"]["require"](['
. Perlito5::Javascript2::to_str( $self->{arguments}[0] ) . ', '
. ($self->{arguments}[0]{bareword} ? 1 : 0)
@@ -1405,6 +1409,7 @@ package Perlito5::AST::Apply;
'prefix:<$>' => sub {
my $self = $_[0];
+ my $level = $_[1];
my $arg = $self->{arguments}->[0];
Perlito5::Javascript2::emit_javascript2_autovivify( $arg, $level, 'scalar' ) . '._scalar_';
},
@@ -1434,10 +1439,12 @@ package Perlito5::AST::Apply;
},
'circumfix:<[ ]>' => sub {
my $self = $_[0];
+ my $level = $_[1];
'(new p5ArrayRef(' . Perlito5::Javascript2::to_list( $self->{arguments} ) . '))';
},
'circumfix:<{ }>' => sub {
my $self = $_[0];
+ my $level = $_[1];
'(new p5HashRef(' . Perlito5::Javascript2::to_list( $self->{arguments}, $level, 'hash' ) . '))';
},
'prefix:<\\>' => sub {
@@ -1543,16 +1550,19 @@ package Perlito5::AST::Apply;
'infix:<..>' => sub {
my $self = $_[0];
+ my $level = $_[1];
'(function (a) { ' . 'for (var i=' . $self->{arguments}->[0]->emit_javascript2() . ', l=' . $self->{arguments}->[1]->emit_javascript2() . '; ' . 'i<=l; ++i)' . '{ ' . 'a.push(i) ' . '}; ' . 'return a ' . '})([])';
},
'delete' => sub {
my $self = $_[0];
+ my $level = $_[1];
'(delete ' . $self->{arguments}[0]->emit_javascript2() . ')';
},
'scalar' => sub {
- my $self = $_[0];
+ my $self = $_[0];
+ my $level = $_[1];
Perlito5::Javascript2::to_scalar($self->{arguments}, $level+1);
},
@@ -1981,7 +1991,6 @@ package Perlito5::AST::Apply;
);
-
sub emit_javascript2 {
my $self = shift;
my $level = shift;
@@ -2231,6 +2240,8 @@ package Perlito5::AST::When;
# TODO - use a "next" exception inside a "for", but use a "break" exception inside a "given"
+ my $label = ''; # TODO
+
my $s = 'if ( ' . Perlito5::Javascript2::to_bool($expr, $level + 1) . ' ) {' . "\n"
. $body->emit_javascript2( $level + 1 ) . "\n"
View
7 src5/lib/Perlito5/Javascript3/Emitter.pm
@@ -2,6 +2,7 @@ use v5;
use Perlito5::AST;
use Perlito5::Dumper;
+use feature 'say';
package Perlito5::Javascript3;
{
@@ -463,7 +464,7 @@ package Perlito5::Javascript3::LexicalBlock;
return 1;
}
if ($decl->isa( 'Perlito5::AST::Apply' ) && $decl->code eq 'infix:<=>') {
- my $var = $decl->arguments[0];
+ my $var = $decl->arguments()->[0];
if ( $var->isa( 'Perlito5::AST::Decl' ) && $var->decl eq $type
|| $decl->isa( 'Perlito5::AST::Apply' ) && $decl->code eq $type
)
@@ -1347,6 +1348,7 @@ package Perlito5::AST::Apply;
},
'require' => sub {
my $self = $_[0];
+ my $level = $_[1];
my $arg = $self->{arguments}->[0];
if ($arg->isa('Perlito5::AST::Val::Num')) {
# "use 5.006" -- XXX this should be tested at parse time instead
@@ -1360,6 +1362,7 @@ package Perlito5::AST::Apply;
'prefix:<$>' => sub {
my $self = $_[0];
+ my $level = $_[1];
my $arg = $self->{arguments}->[0];
Perlito5::Javascript3::emit_javascript3_autovivify( $arg, $level, 'scalar' ) . '.sderef()';
},
@@ -1389,10 +1392,12 @@ package Perlito5::AST::Apply;
},
'circumfix:<[ ]>' => sub {
my $self = $_[0];
+ my $level = $_[1];
'(new p5ArrayRef(new p5Array(' . Perlito5::Javascript3::to_list( $self->{arguments} ) . ')))';
},
'circumfix:<{ }>' => sub {
my $self = $_[0];
+ my $level = $_[1];
'(new p5HashRef(new p5Hash(' . Perlito5::Javascript3::to_list( $self->{arguments}, $level, 'hash' ) . ')))';
},
'prefix:<\\>' => sub {
View
2  src5/lib/Perlito5/Perl5/Emitter.pm
@@ -497,7 +497,7 @@ package Perlito5::AST::Apply;
my $arg = $self->{arguments}->[0];
my $eval;
if ($arg->isa( "Perlito5::AST::Do" )) {
- $eval = $arg->emit_perl5( $level + 1, $wantarray );
+ $eval = $arg->emit_perl5( $level + 1 ); # TODO -, $wantarray );
}
else {
$eval =
View
4 src5/lib/Perlito5/Perl6/Emitter.pm
@@ -127,7 +127,7 @@ package Perlito5::Perl6::LexicalBlock;
push @str, Perlito5::Perl6::tab($level) . $decl->emit_perl6_init;
}
if ($decl->isa( 'Perlito5::AST::Apply' ) && $decl->code eq 'infix:<=>') {
- my $var = $decl->arguments[0];
+ my $var = $decl->arguments->[0];
if ($var->isa( 'Perlito5::AST::Decl' ) && $var->decl eq 'my') {
push @str, Perlito5::Perl6::tab($level) . $var->emit_perl6_init;
}
@@ -182,7 +182,7 @@ package Perlito5::AST::CompUnit;
$str = $str . ' ' . $decl->emit_perl6_init;
}
if ($decl->isa( 'Perlito5::AST::Apply' ) && $decl->code eq 'infix:<=>') {
- my $var = $decl->arguments[0];
+ my $var = $decl->arguments->[0];
if ($var->isa( 'Perlito5::AST::Decl' ) && $var->decl eq 'my') {
$str = $str . ' ' . $var->emit_perl6_init;
}
View
4 src5/lib/Perlito5/Precedence.pm
@@ -1,6 +1,8 @@
package Perlito5::Precedence;
+use feature 'say';
+
# Perlito5::Precedence attributes:
# get_token - code ref
# reduce - code ref
@@ -419,7 +421,7 @@ sub precedence_parse {
$token->[0] = 'prefix';
unshift( @$op_stack, $token);
}
- elsif ( ($Operator->{postfix}){$token->[1]} && $last_is_term )
+ elsif ( $Operator->{postfix}{$token->[1]} && $last_is_term )
{
my $pr = $Precedence->{$token->[1]};
while (scalar(@$op_stack) && ($pr <= $Precedence->{ ($op_stack->[0])[1] })) {
View
6 src5/util/perlito5.pl
@@ -31,6 +31,8 @@ package Perlito;
use Perlito5::Runtime;
use Perlito5::Dumper;
+use strict;
+
my $_V5_COMPILER_NAME = 'Perlito5';
my $_V5_COMPILER_VERSION = '9.0';
my $source = '';
@@ -82,11 +84,11 @@ package Perlito;
}
elsif ($ARGV[0] eq '-I') {
shift @ARGV;
- $lib = shift @ARGV;
+ my $lib = shift @ARGV;
unshift @INC, $lib;
}
elsif (substr($ARGV[0], 0, 2) eq '-I') {
- $lib = substr($ARGV[0], 2);
+ my $lib = substr($ARGV[0], 2);
unshift @INC, $lib;
shift @ARGV;
}
Please sign in to comment.
Something went wrong with that request. Please try again.