Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Perlito5 - javascript: move more code to dispatch tables

  • Loading branch information...
commit a5dd90d8f1f775e5245207bf6516e72a736e0d68 1 parent 5067b7c
@fglock authored
View
224 html/perlito5.js
@@ -2327,6 +2327,130 @@ var p5100 = NAMESPACE['main'];
var v_self = null;
(v_self = (List__[0]));
return (p5context([('NAMESPACE["Perlito5::Grammar::Use"]["require"]([' + p5str(NAMESPACE["Perlito5::Javascript"].to_str(interpolate_array(((v_self || (v_self = new HashRef({})))._hash_['arguments'] || ((v_self || (v_self = new HashRef({})))._hash_['arguments'] = new ArrayRef([])))._array_[0]), 0)) + '])')], p5want));
+}, 'prefix:<$>', function (List__, p5want) {
+ var v_self = null;
+ (v_self = (List__[0]));
+ var v_arg = null;
+ (v_arg = (((v_self || (v_self = new HashRef({})))._hash_['arguments'] || ((v_self || (v_self = new HashRef({})))._hash_['arguments'] = new ArrayRef([])))._array_[0]));
+ return (p5context([('(' + p5str(_call_(v_arg, "emit_javascript", [], 0)) + ')._scalar_')], p5want));
+}, 'prefix:<@>', function (List__, p5want) {
+ var v_self = null;
+ (v_self = (List__[0]));
+ var v_level = null;
+ (v_level = (List__[1]));
+ var v_arg = null;
+ (v_arg = (((v_self || (v_self = new HashRef({})))._hash_['arguments'] || ((v_self || (v_self = new HashRef({})))._hash_['arguments'] = new ArrayRef([])))._array_[0]));
+ return (p5context([('(' + p5str(_call_(v_arg, "emit_javascript", interpolate_array(v_level), 0)) + ' || (' + p5str(_call_(v_arg, "emit_javascript", interpolate_array(v_level), 0)) + ' = new ArrayRef([]))' + ')._array_')], p5want));
+}, 'prefix:<$#>', function (List__, p5want) {
+ var v_self = null;
+ (v_self = (List__[0]));
+ var v_level = null;
+ (v_level = (List__[1]));
+ var v_arg = null;
+ (v_arg = (((v_self || (v_self = new HashRef({})))._hash_['arguments'] || ((v_self || (v_self = new HashRef({})))._hash_['arguments'] = new ArrayRef([])))._array_[0]));
+ return (p5context([('((' + p5str(_call_(v_arg, "emit_javascript", interpolate_array(v_level), 0)) + ' || (' + p5str(_call_(v_arg, "emit_javascript", interpolate_array(v_level), 0)) + ' = new ArrayRef([]))' + ')._array_.length - 1)')], p5want));
+}, 'prefix:<%>', function (List__, p5want) {
+ var v_self = null;
+ (v_self = (List__[0]));
+ var v_level = null;
+ (v_level = (List__[1]));
+ var v_arg = null;
+ (v_arg = (((v_self || (v_self = new HashRef({})))._hash_['arguments'] || ((v_self || (v_self = new HashRef({})))._hash_['arguments'] = new ArrayRef([])))._array_[0]));
+ return (p5context([('(' + p5str(_call_(v_arg, "emit_javascript", interpolate_array(v_level), 0)) + ')._hash_')], p5want));
+}, 'prefix:<&>', function (List__, p5want) {
+ var v_self = null;
+ (v_self = (List__[0]));
+ var v_level = null;
+ (v_level = (List__[1]));
+ var v_arg = null;
+ (v_arg = (((v_self || (v_self = new HashRef({})))._hash_['arguments'] || ((v_self || (v_self = new HashRef({})))._hash_['arguments'] = new ArrayRef([])))._array_[0]));
+ return (p5context([('p5code_lookup_by_name("' + p5str(NAMESPACE["Perlito5"]["v_PKG_NAME"]) + '", ' + p5str(_call_(v_arg, "emit_javascript", interpolate_array(v_level), 0)) + ')')], p5want));
+}, 'circumfix:<[ ]>', function (List__, p5want) {
+ var v_self = null;
+ (v_self = (List__[0]));
+ return (p5context([('(new ArrayRef(' + p5str(NAMESPACE["Perlito5::Javascript"].to_list(interpolate_array((v_self || (v_self = new HashRef({})))._hash_['arguments']), 0)) + '))')], p5want));
+}, 'circumfix:<{ }>', function (List__, p5want) {
+ var v_self = null;
+ (v_self = (List__[0]));
+ return (p5context([('(new HashRef(array_to_hash(' + p5str(NAMESPACE["Perlito5::Javascript"].to_list(interpolate_array((v_self || (v_self = new HashRef({})))._hash_['arguments']), 0)) + ')))')], p5want));
+}, 'prefix:<' + String.fromCharCode(92) + '>', function (List__, p5want) {
+ try {
+ var v_self = null;
+ (v_self = (List__[0]));
+ var v_level = null;
+ (v_level = (List__[1]));
+ var v_arg = null;
+ (v_arg = (((v_self || (v_self = new HashRef({})))._hash_['arguments'] || ((v_self || (v_self = new HashRef({})))._hash_['arguments'] = new ArrayRef([])))._array_[0]));
+ if ( bool(_call_(v_arg, "isa", interpolate_array('Perlito5::AST::Var'), 0)) ) {
+ if ( (p5str(_call_(v_arg, "sigil", [], 0)) == '@') ) {
+ throw(p5context([('(new ArrayRef(' + p5str(_call_(v_arg, "emit_javascript", interpolate_array(v_level), 0)) + '))')], p5want));
+ };
+ if ( (p5str(_call_(v_arg, "sigil", [], 0)) == '%') ) {
+ throw(p5context([('(new HashRef(' + p5str(_call_(v_arg, "emit_javascript", interpolate_array(v_level), 0)) + '))')], p5want));
+ };
+ if ( (p5str(_call_(v_arg, "sigil", [], 0)) == '&') ) {
+ if ( bool((v_arg || (v_arg = new HashRef({})))._hash_['namespace']) ) {
+ throw(p5context([('NAMESPACE["' + p5str((v_arg || (v_arg = new HashRef({})))._hash_['namespace']) + '"].' + p5str((v_arg || (v_arg = new HashRef({})))._hash_['name']))], p5want));
+ }
+ else {
+ throw(p5context([(p5str(NAMESPACE["Perlito5::Javascript"].pkg([], 0)) + '.' + p5str((v_arg || (v_arg = new HashRef({})))._hash_['name']))], p5want));
+ };
+ };
+ };
+ throw(p5context([('(new ScalarRef(' + p5str(_call_(v_arg, "emit_javascript", interpolate_array(v_level), 0)) + '))')], p5want))
+ }
+ catch(err) {
+ if ( err instanceof Error ) {
+ throw(err);
+ }
+ else {
+ return(err);
+ }
+ }
+}, 'postfix:<++>', function (List__, p5want) {
+ var v_self = null;
+ (v_self = (List__[0]));
+ return (p5context([('(' + p5115.join([' ', interpolate_array(p5map(p5115, function (p5want) {
+ return (p5context([_call_(NAMESPACE["Perlito5::AST::Apply"]["v__"], "emit_javascript", [], p5want)], p5want));
+}, interpolate_array(((v_self || (v_self = new HashRef({})))._hash_['arguments'] || ((v_self || (v_self = new HashRef({})))._hash_['arguments'] = new ArrayRef([])))._array_)))], 0) + ')++')], p5want));
+}, 'postfix:<-->', function (List__, p5want) {
+ var v_self = null;
+ (v_self = (List__[0]));
+ return (p5context([('(' + p5115.join([' ', interpolate_array(p5map(p5115, function (p5want) {
+ return (p5context([_call_(NAMESPACE["Perlito5::AST::Apply"]["v__"], "emit_javascript", [], p5want)], p5want));
+}, interpolate_array(((v_self || (v_self = new HashRef({})))._hash_['arguments'] || ((v_self || (v_self = new HashRef({})))._hash_['arguments'] = new ArrayRef([])))._array_)))], 0) + ')--')], p5want));
+}, 'prefix:<++>', function (List__, p5want) {
+ var v_self = null;
+ (v_self = (List__[0]));
+ return (p5context([('++(' + p5115.join([' ', interpolate_array(p5map(p5115, function (p5want) {
+ return (p5context([_call_(NAMESPACE["Perlito5::AST::Apply"]["v__"], "emit_javascript", [], p5want)], p5want));
+}, interpolate_array(((v_self || (v_self = new HashRef({})))._hash_['arguments'] || ((v_self || (v_self = new HashRef({})))._hash_['arguments'] = new ArrayRef([])))._array_)))], 0) + ')')], p5want));
+}, 'prefix:<-->', function (List__, p5want) {
+ var v_self = null;
+ (v_self = (List__[0]));
+ return (p5context([('--(' + p5115.join([' ', interpolate_array(p5map(p5115, function (p5want) {
+ return (p5context([_call_(NAMESPACE["Perlito5::AST::Apply"]["v__"], "emit_javascript", [], p5want)], p5want));
+}, interpolate_array(((v_self || (v_self = new HashRef({})))._hash_['arguments'] || ((v_self || (v_self = new HashRef({})))._hash_['arguments'] = new ArrayRef([])))._array_)))], 0) + ')')], p5want));
+}, 'infix:<x>', function (List__, p5want) {
+ var v_self = null;
+ (v_self = (List__[0]));
+ return (p5context([('str_replicate(' + p5115.join([', ', interpolate_array(p5map(p5115, function (p5want) {
+ return (p5context([_call_(NAMESPACE["Perlito5::AST::Apply"]["v__"], "emit_javascript", [], p5want)], p5want));
+}, interpolate_array(((v_self || (v_self = new HashRef({})))._hash_['arguments'] || ((v_self || (v_self = new HashRef({})))._hash_['arguments'] = new ArrayRef([])))._array_)))], 0) + ')')], p5want));
+}, 'list:<.>', function (List__, p5want) {
+ var v_self = null;
+ (v_self = (List__[0]));
+ return (p5context([('(' + p5115.join([' + ', interpolate_array(p5map(p5115, function (p5want) {
+ return (p5context([NAMESPACE["Perlito5::Javascript"].to_str(interpolate_array(NAMESPACE["Perlito5::AST::Apply"]["v__"]), p5want)], p5want));
+}, interpolate_array(((v_self || (v_self = new HashRef({})))._hash_['arguments'] || ((v_self || (v_self = new HashRef({})))._hash_['arguments'] = new ArrayRef([])))._array_)))], 0) + ')')], p5want));
+}, 'list:<,>', function (List__, p5want) {
+ var v_self = null;
+ (v_self = (List__[0]));
+ return (p5context([NAMESPACE["Perlito5::Javascript"].to_list(interpolate_array((v_self || (v_self = new HashRef({})))._hash_['arguments']), p5want)], p5want));
+}, 'infix:<..>', function (List__, p5want) {
+ var v_self = null;
+ (v_self = (List__[0]));
+ return (p5context([('(function (a) { ' + 'for (var i=' + p5str(_call_(((v_self || (v_self = new HashRef({})))._hash_['arguments'] || ((v_self || (v_self = new HashRef({})))._hash_['arguments'] = new ArrayRef([])))._array_[0], "emit_javascript", [], 0)) + ', l=' + p5str(_call_(((v_self || (v_self = new HashRef({})))._hash_['arguments'] || ((v_self || (v_self = new HashRef({})))._hash_['arguments'] = new ArrayRef([])))._array_[1], "emit_javascript", [], 0)) + '; ' + 'i<=l; ++i)' + '{ ' + 'a.push(i) ' + '}; ' + 'return a ' + '})([])')], p5want));
})));
make_sub("Perlito5::AST::Apply", "emit_javascript", function (List__, p5want) {
try {
@@ -2470,106 +2594,6 @@ var p5100 = NAMESPACE['main'];
throw(p5context([('p5sort(' + p5str(NAMESPACE["Perlito5::Javascript"].pkg([], 0)) + ', ' + p5str(v_fun) + ', ' + p5str(v_list) + ')')], p5want));
})();
};
- if ( (p5str(v_code) == 'prefix:<$>') ) {
- (function () {
- var v_arg = null;
- (v_arg = (((v_self || (v_self = new HashRef({})))._hash_['arguments'] || ((v_self || (v_self = new HashRef({})))._hash_['arguments'] = new ArrayRef([])))._array_[0]));
- throw(p5context([('(' + p5str(_call_(v_arg, "emit_javascript", [], 0)) + ')._scalar_')], p5want));
- })();
- };
- if ( (p5str(v_code) == 'prefix:<@>') ) {
- (function () {
- var v_arg = null;
- (v_arg = (((v_self || (v_self = new HashRef({})))._hash_['arguments'] || ((v_self || (v_self = new HashRef({})))._hash_['arguments'] = new ArrayRef([])))._array_[0]));
- throw(p5context([('(' + p5str(_call_(v_arg, "emit_javascript", interpolate_array(v_level), 0)) + ' || (' + p5str(_call_(v_arg, "emit_javascript", interpolate_array(v_level), 0)) + ' = new ArrayRef([]))' + ')._array_')], p5want));
- })();
- };
- if ( (p5str(v_code) == 'prefix:<$#>') ) {
- (function () {
- var v_arg = null;
- (v_arg = (((v_self || (v_self = new HashRef({})))._hash_['arguments'] || ((v_self || (v_self = new HashRef({})))._hash_['arguments'] = new ArrayRef([])))._array_[0]));
- throw(p5context([('((' + p5str(_call_(v_arg, "emit_javascript", interpolate_array(v_level), 0)) + ' || (' + p5str(_call_(v_arg, "emit_javascript", interpolate_array(v_level), 0)) + ' = new ArrayRef([]))' + ')._array_.length - 1)')], p5want));
- })();
- };
- if ( (p5str(v_code) == 'prefix:<%>') ) {
- (function () {
- var v_arg = null;
- (v_arg = (((v_self || (v_self = new HashRef({})))._hash_['arguments'] || ((v_self || (v_self = new HashRef({})))._hash_['arguments'] = new ArrayRef([])))._array_[0]));
- throw(p5context([('(' + p5str(_call_(v_arg, "emit_javascript", interpolate_array(v_level), 0)) + ')._hash_')], p5want));
- })();
- };
- if ( (p5str(v_code) == 'prefix:<&>') ) {
- (function () {
- var v_arg = null;
- (v_arg = (((v_self || (v_self = new HashRef({})))._hash_['arguments'] || ((v_self || (v_self = new HashRef({})))._hash_['arguments'] = new ArrayRef([])))._array_[0]));
- throw(p5context([('p5code_lookup_by_name("' + p5str(NAMESPACE["Perlito5"]["v_PKG_NAME"]) + '", ' + p5str(_call_(v_arg, "emit_javascript", interpolate_array(v_level), 0)) + ')')], p5want));
- })();
- };
- if ( (p5str(v_code) == 'circumfix:<[ ]>') ) {
- throw(p5context([('(new ArrayRef(' + p5str(NAMESPACE["Perlito5::Javascript"].to_list(interpolate_array((v_self || (v_self = new HashRef({})))._hash_['arguments']), 0)) + '))')], p5want));
- };
- if ( (p5str(v_code) == 'circumfix:<{ }>') ) {
- throw(p5context([('(new HashRef(array_to_hash(' + p5str(NAMESPACE["Perlito5::Javascript"].to_list(interpolate_array((v_self || (v_self = new HashRef({})))._hash_['arguments']), 0)) + ')))')], p5want));
- };
- if ( (p5str(v_code) == 'prefix:<' + String.fromCharCode(92) + '>') ) {
- (function () {
- var v_arg = null;
- (v_arg = (((v_self || (v_self = new HashRef({})))._hash_['arguments'] || ((v_self || (v_self = new HashRef({})))._hash_['arguments'] = new ArrayRef([])))._array_[0]));
- if ( bool(_call_(v_arg, "isa", interpolate_array('Perlito5::AST::Var'), 0)) ) {
- if ( (p5str(_call_(v_arg, "sigil", [], 0)) == '@') ) {
- throw(p5context([('(new ArrayRef(' + p5str(_call_(v_arg, "emit_javascript", interpolate_array(v_level), 0)) + '))')], p5want));
- };
- if ( (p5str(_call_(v_arg, "sigil", [], 0)) == '%') ) {
- throw(p5context([('(new HashRef(' + p5str(_call_(v_arg, "emit_javascript", interpolate_array(v_level), 0)) + '))')], p5want));
- };
- if ( (p5str(_call_(v_arg, "sigil", [], 0)) == '&') ) {
- if ( bool((v_arg || (v_arg = new HashRef({})))._hash_['namespace']) ) {
- throw(p5context([('NAMESPACE["' + p5str((v_arg || (v_arg = new HashRef({})))._hash_['namespace']) + '"].' + p5str((v_arg || (v_arg = new HashRef({})))._hash_['name']))], p5want));
- }
- else {
- throw(p5context([(p5str(NAMESPACE["Perlito5::Javascript"].pkg([], 0)) + '.' + p5str((v_arg || (v_arg = new HashRef({})))._hash_['name']))], p5want));
- };
- };
- };
- throw(p5context([('(new ScalarRef(' + p5str(_call_(v_arg, "emit_javascript", interpolate_array(v_level), 0)) + '))')], p5want));
- })();
- };
- if ( (p5str(v_code) == 'postfix:<++>') ) {
- throw(p5context([('(' + p5115.join([' ', interpolate_array(p5map(p5115, function (p5want) {
- return (p5context([_call_(NAMESPACE["Perlito5::AST::Apply"]["v__"], "emit_javascript", [], p5want)], p5want));
-}, interpolate_array(((v_self || (v_self = new HashRef({})))._hash_['arguments'] || ((v_self || (v_self = new HashRef({})))._hash_['arguments'] = new ArrayRef([])))._array_)))], 0) + ')++')], p5want));
- };
- if ( (p5str(v_code) == 'postfix:<-->') ) {
- throw(p5context([('(' + p5115.join([' ', interpolate_array(p5map(p5115, function (p5want) {
- return (p5context([_call_(NAMESPACE["Perlito5::AST::Apply"]["v__"], "emit_javascript", [], p5want)], p5want));
-}, interpolate_array(((v_self || (v_self = new HashRef({})))._hash_['arguments'] || ((v_self || (v_self = new HashRef({})))._hash_['arguments'] = new ArrayRef([])))._array_)))], 0) + ')--')], p5want));
- };
- if ( (p5str(v_code) == 'prefix:<++>') ) {
- throw(p5context([('++(' + p5115.join([' ', interpolate_array(p5map(p5115, function (p5want) {
- return (p5context([_call_(NAMESPACE["Perlito5::AST::Apply"]["v__"], "emit_javascript", [], p5want)], p5want));
-}, interpolate_array(((v_self || (v_self = new HashRef({})))._hash_['arguments'] || ((v_self || (v_self = new HashRef({})))._hash_['arguments'] = new ArrayRef([])))._array_)))], 0) + ')')], p5want));
- };
- if ( (p5str(v_code) == 'prefix:<-->') ) {
- throw(p5context([('--(' + p5115.join([' ', interpolate_array(p5map(p5115, function (p5want) {
- return (p5context([_call_(NAMESPACE["Perlito5::AST::Apply"]["v__"], "emit_javascript", [], p5want)], p5want));
-}, interpolate_array(((v_self || (v_self = new HashRef({})))._hash_['arguments'] || ((v_self || (v_self = new HashRef({})))._hash_['arguments'] = new ArrayRef([])))._array_)))], 0) + ')')], p5want));
- };
- if ( (p5str(v_code) == 'infix:<x>') ) {
- throw(p5context([('str_replicate(' + p5115.join([', ', interpolate_array(p5map(p5115, function (p5want) {
- return (p5context([_call_(NAMESPACE["Perlito5::AST::Apply"]["v__"], "emit_javascript", [], p5want)], p5want));
-}, interpolate_array(((v_self || (v_self = new HashRef({})))._hash_['arguments'] || ((v_self || (v_self = new HashRef({})))._hash_['arguments'] = new ArrayRef([])))._array_)))], 0) + ')')], p5want));
- };
- if ( (p5str(v_code) == 'list:<.>') ) {
- throw(p5context([('(' + p5115.join([' + ', interpolate_array(p5map(p5115, function (p5want) {
- return (p5context([NAMESPACE["Perlito5::Javascript"].to_str(interpolate_array(NAMESPACE["Perlito5::AST::Apply"]["v__"]), p5want)], p5want));
-}, interpolate_array(((v_self || (v_self = new HashRef({})))._hash_['arguments'] || ((v_self || (v_self = new HashRef({})))._hash_['arguments'] = new ArrayRef([])))._array_)))], 0) + ')')], p5want));
- };
- if ( (p5str(v_code) == 'list:<,>') ) {
- throw(p5context([NAMESPACE["Perlito5::Javascript"].to_list(interpolate_array((v_self || (v_self = new HashRef({})))._hash_['arguments']), p5want)], p5want));
- };
- if ( (p5str(v_code) == 'infix:<..>') ) {
- throw(p5context([('(function (a) { ' + 'for (var i=' + p5str(_call_(((v_self || (v_self = new HashRef({})))._hash_['arguments'] || ((v_self || (v_self = new HashRef({})))._hash_['arguments'] = new ArrayRef([])))._array_[0], "emit_javascript", [], 0)) + ', l=' + p5str(_call_(((v_self || (v_self = new HashRef({})))._hash_['arguments'] || ((v_self || (v_self = new HashRef({})))._hash_['arguments'] = new ArrayRef([])))._array_[1], "emit_javascript", [], 0)) + '; ' + 'i<=l; ++i)' + '{ ' + 'a.push(i) ' + '}; ' + 'return a ' + '})([])')], p5want));
- };
if ( ((p5str(v_code) == 'infix:<&&>') || (p5str(v_code) == 'infix:<and>')) ) {
throw(p5context([('and' + '(' + p5str(_call_(((v_self || (v_self = new HashRef({})))._hash_['arguments'] || ((v_self || (v_self = new HashRef({})))._hash_['arguments'] = new ArrayRef([])))._array_[0], "emit_javascript", interpolate_array(v_level, v_wantarray), 0)) + ', ' + p5str(_call_(v_self, "emit_function_javascript", interpolate_array(v_level, v_wantarray, ((v_self || (v_self = new HashRef({})))._hash_['arguments'] || ((v_self || (v_self = new HashRef({})))._hash_['arguments'] = new ArrayRef([])))._array_[1]), 0)) + ')')], p5want));
};
View
145 lib5/Perlito5/Javascript/Emitter.pm
@@ -668,6 +668,81 @@ for ($_) {
}), ('require' => sub {
((my $self) = $_[0]);
('NAMESPACE["Perlito5::Grammar::Use"]["require"]([' . Perlito5::Javascript::to_str($self->{'arguments'}->[0]) . '])')
+}), ('prefix:<$>' => sub {
+ ((my $self) = $_[0]);
+ ((my $arg) = $self->{'arguments'}->[0]);
+ ('(' . $arg->emit_javascript() . ')._scalar_')
+}), ('prefix:<@>' => sub {
+ ((my $self) = $_[0]);
+ ((my $level) = $_[1]);
+ ((my $arg) = $self->{'arguments'}->[0]);
+ ('(' . $arg->emit_javascript($level) . ' || (' . $arg->emit_javascript($level) . ' = new ArrayRef([]))' . ')._array_')
+}), ('prefix:<$#>' => sub {
+ ((my $self) = $_[0]);
+ ((my $level) = $_[1]);
+ ((my $arg) = $self->{'arguments'}->[0]);
+ ('((' . $arg->emit_javascript($level) . ' || (' . $arg->emit_javascript($level) . ' = new ArrayRef([]))' . ')._array_.length - 1)')
+}), ('prefix:<%>' => sub {
+ ((my $self) = $_[0]);
+ ((my $level) = $_[1]);
+ ((my $arg) = $self->{'arguments'}->[0]);
+ ('(' . $arg->emit_javascript($level) . ')._hash_')
+}), ('prefix:<&>' => sub {
+ ((my $self) = $_[0]);
+ ((my $level) = $_[1]);
+ ((my $arg) = $self->{'arguments'}->[0]);
+ ('p5code_lookup_by_name("' . $Perlito5::PKG_NAME . '", ' . $arg->emit_javascript($level) . ')')
+}), ('circumfix:<[ ]>' => sub {
+ ((my $self) = $_[0]);
+ ('(new ArrayRef(' . Perlito5::Javascript::to_list($self->{'arguments'}) . '))')
+}), ('circumfix:<{ }>' => sub {
+ ((my $self) = $_[0]);
+ ('(new HashRef(array_to_hash(' . Perlito5::Javascript::to_list($self->{'arguments'}) . ')))')
+}), ('prefix:<' . chr(92) . '>' => sub {
+ ((my $self) = $_[0]);
+ ((my $level) = $_[1]);
+ ((my $arg) = $self->{'arguments'}->[0]);
+ if ($arg->isa('Perlito5::AST::Var')) {
+ if (($arg->sigil() eq '@')) {
+ return (('(new ArrayRef(' . $arg->emit_javascript($level) . '))'))
+ };
+ if (($arg->sigil() eq '%')) {
+ return (('(new HashRef(' . $arg->emit_javascript($level) . '))'))
+ };
+ if (($arg->sigil() eq '&')) {
+ if ($arg->{'namespace'}) {
+ return (('NAMESPACE["' . $arg->{'namespace'} . '"].' . $arg->{'name'}))
+ }
+ else {
+ return ((Perlito5::Javascript::pkg() . '.' . $arg->{'name'}))
+ }
+ }
+ };
+ return (('(new ScalarRef(' . $arg->emit_javascript($level) . '))'))
+}), ('postfix:<++>' => sub {
+ ((my $self) = $_[0]);
+ ('(' . join(' ', map($_->emit_javascript(), @{$self->{'arguments'}})) . ')++')
+}), ('postfix:<-->' => sub {
+ ((my $self) = $_[0]);
+ ('(' . join(' ', map($_->emit_javascript(), @{$self->{'arguments'}})) . ')--')
+}), ('prefix:<++>' => sub {
+ ((my $self) = $_[0]);
+ ('++(' . join(' ', map($_->emit_javascript(), @{$self->{'arguments'}})) . ')')
+}), ('prefix:<-->' => sub {
+ ((my $self) = $_[0]);
+ ('--(' . join(' ', map($_->emit_javascript(), @{$self->{'arguments'}})) . ')')
+}), ('infix:<x>' => sub {
+ ((my $self) = $_[0]);
+ ('str_replicate(' . join(', ', map($_->emit_javascript(), @{$self->{'arguments'}})) . ')')
+}), ('list:<.>' => sub {
+ ((my $self) = $_[0]);
+ ('(' . join(' + ', map(Perlito5::Javascript::to_str($_), @{$self->{'arguments'}})) . ')')
+}), ('list:<,>' => sub {
+ ((my $self) = $_[0]);
+ Perlito5::Javascript::to_list($self->{'arguments'})
+}), ('infix:<..>' => sub {
+ ((my $self) = $_[0]);
+ ('(function (a) { ' . 'for (var i=' . $self->{'arguments'}->[0]->emit_javascript() . ', l=' . $self->{'arguments'}->[1]->emit_javascript() . '; ' . 'i<=l; ++i)' . '{ ' . 'a.push(i) ' . '}; ' . 'return a ' . '})([])')
})));
sub Perlito5::AST::Apply::emit_javascript {
((my $self) = shift());
@@ -770,76 +845,6 @@ for ($_) {
($list = Perlito5::Javascript::to_list(\@in));
return (('p5sort(' . Perlito5::Javascript::pkg() . ', ' . $fun . ', ' . $list . ')'))
};
- if (($code eq 'prefix:<$>')) {
- ((my $arg) = $self->{'arguments'}->[0]);
- return (('(' . $arg->emit_javascript() . ')._scalar_'))
- };
- if (($code eq 'prefix:<@>')) {
- ((my $arg) = $self->{'arguments'}->[0]);
- return (('(' . $arg->emit_javascript($level) . ' || (' . $arg->emit_javascript($level) . ' = new ArrayRef([]))' . ')._array_'))
- };
- if (($code eq 'prefix:<$#>')) {
- ((my $arg) = $self->{'arguments'}->[0]);
- return (('((' . $arg->emit_javascript($level) . ' || (' . $arg->emit_javascript($level) . ' = new ArrayRef([]))' . ')._array_.length - 1)'))
- };
- if (($code eq 'prefix:<%>')) {
- ((my $arg) = $self->{'arguments'}->[0]);
- return (('(' . $arg->emit_javascript($level) . ')._hash_'))
- };
- if (($code eq 'prefix:<&>')) {
- ((my $arg) = $self->{'arguments'}->[0]);
- return (('p5code_lookup_by_name("' . $Perlito5::PKG_NAME . '", ' . $arg->emit_javascript($level) . ')'))
- };
- if (($code eq 'circumfix:<[ ]>')) {
- return (('(new ArrayRef(' . Perlito5::Javascript::to_list($self->{'arguments'}) . '))'))
- };
- if (($code eq 'circumfix:<{ }>')) {
- return (('(new HashRef(array_to_hash(' . Perlito5::Javascript::to_list($self->{'arguments'}) . ')))'))
- };
- if (($code eq 'prefix:<' . chr(92) . '>')) {
- ((my $arg) = $self->{'arguments'}->[0]);
- if ($arg->isa('Perlito5::AST::Var')) {
- if (($arg->sigil() eq '@')) {
- return (('(new ArrayRef(' . $arg->emit_javascript($level) . '))'))
- };
- if (($arg->sigil() eq '%')) {
- return (('(new HashRef(' . $arg->emit_javascript($level) . '))'))
- };
- if (($arg->sigil() eq '&')) {
- if ($arg->{'namespace'}) {
- return (('NAMESPACE["' . $arg->{'namespace'} . '"].' . $arg->{'name'}))
- }
- else {
- return ((Perlito5::Javascript::pkg() . '.' . $arg->{'name'}))
- }
- }
- };
- return (('(new ScalarRef(' . $arg->emit_javascript($level) . '))'))
- };
- if (($code eq 'postfix:<++>')) {
- return (('(' . join(' ', map($_->emit_javascript(), @{$self->{'arguments'}})) . ')++'))
- };
- if (($code eq 'postfix:<-->')) {
- return (('(' . join(' ', map($_->emit_javascript(), @{$self->{'arguments'}})) . ')--'))
- };
- if (($code eq 'prefix:<++>')) {
- return (('++(' . join(' ', map($_->emit_javascript(), @{$self->{'arguments'}})) . ')'))
- };
- if (($code eq 'prefix:<-->')) {
- return (('--(' . join(' ', map($_->emit_javascript(), @{$self->{'arguments'}})) . ')'))
- };
- if (($code eq 'infix:<x>')) {
- return (('str_replicate(' . join(', ', map($_->emit_javascript(), @{$self->{'arguments'}})) . ')'))
- };
- if (($code eq 'list:<.>')) {
- return (('(' . join(' + ', map(Perlito5::Javascript::to_str($_), @{$self->{'arguments'}})) . ')'))
- };
- if (($code eq 'list:<,>')) {
- return (Perlito5::Javascript::to_list($self->{'arguments'}))
- };
- if (($code eq 'infix:<..>')) {
- return (('(function (a) { ' . 'for (var i=' . $self->{'arguments'}->[0]->emit_javascript() . ', l=' . $self->{'arguments'}->[1]->emit_javascript() . '; ' . 'i<=l; ++i)' . '{ ' . 'a.push(i) ' . '}; ' . 'return a ' . '})([])'))
- };
if ((($code eq 'infix:<&&>') || ($code eq 'infix:<and>'))) {
return (('and' . '(' . $self->{'arguments'}->[0]->emit_javascript($level, $wantarray) . ', ' . $self->emit_function_javascript($level, $wantarray, $self->{'arguments'}->[1]) . ')'))
};
View
181 src5/lib/Perlito5/Javascript/Emitter.pm
@@ -995,6 +995,102 @@ package Perlito5::AST::Apply;
'NAMESPACE["Perlito5::Grammar::Use"]["require"]([' . Perlito5::Javascript::to_str( $self->{"arguments"}[0] ) . '])';
},
+ 'prefix:<$>' => sub {
+ my $self = $_[0];
+ my $arg = $self->{"arguments"}->[0];
+ '(' . $arg->emit_javascript . ')._scalar_';
+ },
+ 'prefix:<@>' => sub {
+ my $self = $_[0];
+ my $level = $_[1];
+ my $arg = $self->{"arguments"}->[0];
+ '(' . $arg->emit_javascript($level) . ' || (' . $arg->emit_javascript($level) . ' = new ArrayRef([]))' . ')._array_';
+ },
+ 'prefix:<$#>' => sub {
+ my $self = $_[0];
+ my $level = $_[1];
+ my $arg = $self->{"arguments"}->[0];
+ '((' . $arg->emit_javascript($level) . ' || (' . $arg->emit_javascript($level) . ' = new ArrayRef([]))' . ')._array_.length - 1)';
+ },
+ 'prefix:<%>' => sub {
+ my $self = $_[0];
+ my $level = $_[1];
+ my $arg = $self->{"arguments"}->[0];
+ '(' . $arg->emit_javascript($level) . ')._hash_';
+ },
+ 'prefix:<&>' => sub {
+ my $self = $_[0];
+ my $level = $_[1];
+ my $arg = $self->{"arguments"}->[0];
+ 'p5code_lookup_by_name("' . $Perlito5::PKG_NAME . '", ' . $arg->emit_javascript($level) . ')';
+ },
+ 'circumfix:<[ ]>' => sub {
+ my $self = $_[0];
+ '(new ArrayRef(' . Perlito5::Javascript::to_list( $self->{"arguments"} ) . '))';
+ },
+ 'circumfix:<{ }>' => sub {
+ my $self = $_[0];
+ '(new HashRef(array_to_hash(' . Perlito5::Javascript::to_list( $self->{"arguments"} ) . ')))';
+ },
+ 'prefix:<\\>' => sub {
+ my $self = $_[0];
+ my $level = $_[1];
+ my $arg = $self->{"arguments"}->[0];
+ if ( $arg->isa('Perlito5::AST::Var') ) {
+ if ( $arg->sigil eq '@' ) {
+ return '(new ArrayRef(' . $arg->emit_javascript($level) . '))';
+ }
+ if ( $arg->sigil eq '%' ) {
+ return '(new HashRef(' . $arg->emit_javascript($level) . '))';
+ }
+ if ( $arg->sigil eq '&' ) {
+ if ( $arg->{"namespace"} ) {
+ return 'NAMESPACE["' . $arg->{"namespace"} . '"].' . $arg->{"name"};
+ }
+ else {
+ return Perlito5::Javascript::pkg() . '.' . $arg->{"name"};
+ }
+ }
+ }
+ return '(new ScalarRef(' . $arg->emit_javascript($level) . '))';
+ },
+
+ 'postfix:<++>' => sub {
+ my $self = $_[0];
+ '(' . join( ' ', map( $_->emit_javascript, @{ $self->{"arguments"} } ) ) . ')++';
+ },
+ 'postfix:<-->' => sub {
+ my $self = $_[0];
+ '(' . join( ' ', map( $_->emit_javascript, @{ $self->{"arguments"} } ) ) . ')--';
+ },
+ 'prefix:<++>' => sub {
+ my $self = $_[0];
+ '++(' . join( ' ', map( $_->emit_javascript, @{ $self->{"arguments"} } ) ) . ')';
+ },
+ 'prefix:<-->' => sub {
+ my $self = $_[0];
+ '--(' . join( ' ', map( $_->emit_javascript, @{ $self->{"arguments"} } ) ) . ')';
+ },
+
+ 'infix:<x>' => sub {
+ my $self = $_[0];
+ 'str_replicate(' . join( ', ', map( $_->emit_javascript, @{ $self->{"arguments"} } ) ) . ')';
+ },
+
+ 'list:<.>' => sub {
+ my $self = $_[0];
+ '(' . join( ' + ', map( Perlito5::Javascript::to_str($_), @{ $self->{"arguments"} } ) ) . ')';
+ },
+ 'list:<,>' => sub {
+ my $self = $_[0];
+ Perlito5::Javascript::to_list( $self->{"arguments"} );
+ },
+
+ 'infix:<..>' => sub {
+ my $self = $_[0];
+ '(function (a) { ' . 'for (var i=' . $self->{"arguments"}->[0]->emit_javascript() . ', l=' . $self->{"arguments"}->[1]->emit_javascript() . '; ' . 'i<=l; ++i)' . '{ ' . 'a.push(i) ' . '}; ' . 'return a ' . '})([])';
+ },
+
);
@@ -1181,91 +1277,6 @@ package Perlito5::AST::Apply;
. ')';
}
- if ( $code eq 'prefix:<$>' ) {
- my $arg = $self->{"arguments"}->[0];
- return '(' . $arg->emit_javascript . ')._scalar_';
- }
- if ( $code eq 'prefix:<@>' ) {
- my $arg = $self->{"arguments"}->[0];
- return
- '('
- . $arg->emit_javascript( $level )
- . ' || (' . $arg->emit_javascript( $level ) . ' = new ArrayRef([]))'
- . ')._array_';
- }
- if ( $code eq 'prefix:<$#>' ) {
- my $arg = $self->{"arguments"}->[0];
- return
- '(('
- . $arg->emit_javascript( $level )
- . ' || (' . $arg->emit_javascript( $level ) . ' = new ArrayRef([]))'
- . ')._array_.length - 1)';
- }
- if ( $code eq 'prefix:<%>' ) {
- my $arg = $self->{"arguments"}->[0];
- return '(' . $arg->emit_javascript( $level ) . ')._hash_';
- }
- if ( $code eq 'prefix:<&>' ) {
- my $arg = $self->{"arguments"}->[0];
- return 'p5code_lookup_by_name("' . $Perlito5::PKG_NAME . '", ' . $arg->emit_javascript( $level ) . ')';
- }
-
- if ( $code eq 'circumfix:<[ ]>' ) {
- return '(new ArrayRef(' . Perlito5::Javascript::to_list($self->{"arguments"}) . '))'
- }
- if ( $code eq 'circumfix:<{ }>' ) {
- return '(new HashRef(array_to_hash(' . Perlito5::Javascript::to_list($self->{"arguments"}) . ')))'
- }
- if ( $code eq 'prefix:<\\>' ) {
- my $arg = $self->{"arguments"}->[0];
- if ( $arg->isa('Perlito5::AST::Var') ) {
- if ( $arg->sigil eq '@' ) {
- return '(new ArrayRef(' . $arg->emit_javascript( $level ) . '))';
- }
- if ( $arg->sigil eq '%' ) {
- return '(new HashRef(' . $arg->emit_javascript( $level ) . '))';
- }
- if ( $arg->sigil eq '&' ) {
- if ($arg->{"namespace"}) {
- return 'NAMESPACE["' . $arg->{"namespace"} . '"].' . $arg->{"name"};
- }
- else {
- return Perlito5::Javascript::pkg() . '.' . $arg->{"name"};
- }
- }
- }
- return '(new ScalarRef(' . $arg->emit_javascript( $level ) . '))';
- }
-
- if ($code eq 'postfix:<++>') { return '(' . join(' ', map( $_->emit_javascript, @{$self->{"arguments"}} )) . ')++' }
- if ($code eq 'postfix:<-->') { return '(' . join(' ', map( $_->emit_javascript, @{$self->{"arguments"}} )) . ')--' }
- if ($code eq 'prefix:<++>') { return '++(' . join(' ', map( $_->emit_javascript, @{$self->{"arguments"}} )) . ')' }
- if ($code eq 'prefix:<-->') { return '--(' . join(' ', map( $_->emit_javascript, @{$self->{"arguments"}} )) . ')' }
-
- if ($code eq 'infix:<x>') { return 'str_replicate(' . join(', ', map( $_->emit_javascript, @{$self->{"arguments"}} )) . ')' }
-
- if ($code eq 'list:<.>') {
- return '('
- . join( ' + ',
- map( Perlito5::Javascript::to_str($_), @{$self->{"arguments"}} )
- )
- . ')'
- }
- if ($code eq 'list:<,>') {
- return Perlito5::Javascript::to_list($self->{"arguments"})
- }
-
- if ($code eq 'infix:<..>') {
- return '(function (a) { '
- . 'for (var i=' . $self->{"arguments"}->[0]->emit_javascript()
- . ', l=' . $self->{"arguments"}->[1]->emit_javascript() . '; '
- . 'i<=l; ++i)'
- . '{ '
- . 'a.push(i) '
- . '}; '
- . 'return a '
- . '})([])'
- }
if ( $code eq 'infix:<&&>'
|| $code eq 'infix:<and>'
Please sign in to comment.
Something went wrong with that request. Please try again.