Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add "x" operator

  • Loading branch information...
commit 272cc87cb7c3504a94d92b32c996094ca50cb107 1 parent 74340cd
@fglock authored
View
1  ChangeLog
@@ -2,6 +2,7 @@ dev 2011-04-27
- fixed unicode IO, added unicode tests
- add some formatting to Perl5 and Javascript output
- methods: map, grep
+- operators: x
7.0 2011-04-20
- supported backends: Perl 5, Python 2.6, Javascript
View
32 html/perlito.js
@@ -472,6 +472,10 @@ chars = function(o) {
return o.length;
};
+str_replicate = function(o, num) {
+ return num ? Array(num + 1).join(o) : "";
+};
+
// regex primitives
if (typeof Perlito$Grammar !== 'object') {
Perlito$Grammar = function() {};
@@ -688,15 +692,7 @@ if (typeof Javascript !== 'object') {
// sub tab
Javascript.tab = function (v_level) {
try {
- var v_s = null;
-
- var v_count = null;
-
-(v_s = '');
-(v_count = v_level);
- for ( ; bool((v_count > 0)); ) { (function () { (v_s = (string(v_s) + string((string(' ')))));
-(v_count = (v_count - 1));; })() };
- throw(v_s);;
+ return(str_replicate((string(' ')), v_level));;
}
catch(err) {
if ( err instanceof Error ) {
@@ -2020,6 +2016,12 @@ if (typeof Apply !== 'object') {
else { (function () {
null;
})(); };
+ if ( bool((v_code == 'infix:<x>')) ) { (function () {
+ throw((string('str_replicate(') + string(((function (a_) { var out = []; if ( a_ == null ) { return out; }; for(var i = 0; i < a_.length; i++) { out.push( a_[i].emit_javascript() ) }; return out; })(v_self.v_arguments)).join(', ')) + string(')')));;
+ })(); }
+ else { (function () {
+ null;
+ })(); };
if ( bool((v_code == 'list:<' + String.fromCharCode(126) + '>')) ) { (function () {
throw((string('(') + string(Javascript.escape_function('string')) + string('(') + string(((function (a_) { var out = []; if ( a_ == null ) { return out; }; for(var i = 0; i < a_.length; i++) { out.push( a_[i].emit_javascript() ) }; return out; })(v_self.v_arguments)).join((string(') + ') + string(Javascript.escape_function('string')) + string('(')))) + string('))')));;
})(); }
@@ -3472,7 +3474,7 @@ v_op_stack.unshift(v_token);;
(function () { if (Hash_a == null) { Hash_a = {} }; return (Hash_a['assoc'] = 'right'); })();
return(Hash_a);
-})());(v_prec = (v_prec - 1)); v__NAMESPACE.add_op('prefix', '+', v_prec); v__NAMESPACE.add_op('prefix', '-', v_prec); v__NAMESPACE.add_op('prefix', String.fromCharCode(36), v_prec); v__NAMESPACE.add_op('prefix', String.fromCharCode(64), v_prec); v__NAMESPACE.add_op('prefix', String.fromCharCode(37), v_prec); v__NAMESPACE.add_op('prefix', String.fromCharCode(33), v_prec); v__NAMESPACE.add_op('prefix', String.fromCharCode(63), v_prec);(v_prec = (v_prec - 1)); v__NAMESPACE.add_op('infix', '*', v_prec); v__NAMESPACE.add_op('infix', String.fromCharCode(47), v_prec);(v_prec = (v_prec - 1)); v__NAMESPACE.add_op('infix', '+', v_prec); v__NAMESPACE.add_op('infix', '-', v_prec);(v_prec = (v_prec - 1)); v__NAMESPACE.add_op('infix', String.fromCharCode(126), v_prec, (function () {
+})());(v_prec = (v_prec - 1)); v__NAMESPACE.add_op('prefix', '+', v_prec); v__NAMESPACE.add_op('prefix', '-', v_prec); v__NAMESPACE.add_op('prefix', String.fromCharCode(36), v_prec); v__NAMESPACE.add_op('prefix', String.fromCharCode(64), v_prec); v__NAMESPACE.add_op('prefix', String.fromCharCode(37), v_prec); v__NAMESPACE.add_op('prefix', String.fromCharCode(33), v_prec); v__NAMESPACE.add_op('prefix', String.fromCharCode(63), v_prec);(v_prec = (v_prec - 1)); v__NAMESPACE.add_op('infix', '*', v_prec); v__NAMESPACE.add_op('infix', String.fromCharCode(47), v_prec);(v_prec = (v_prec - 1)); v__NAMESPACE.add_op('infix', '+', v_prec); v__NAMESPACE.add_op('infix', '-', v_prec);(v_prec = (v_prec - 1)); v__NAMESPACE.add_op('infix', 'x', v_prec); v__NAMESPACE.add_op('infix', 'xx', v_prec);(v_prec = (v_prec - 1)); v__NAMESPACE.add_op('infix', String.fromCharCode(126), v_prec, (function () {
var Hash_a = {};
(function () { if (Hash_a == null) { Hash_a = {} }; return (Hash_a['assoc'] = 'list'); })();
@@ -3637,15 +3639,7 @@ if (typeof Perl5 !== 'object') {
// sub tab
Perl5.tab = function (v_level) {
try {
- var v_s = null;
-
- var v_count = null;
-
-(v_s = '');
-(v_count = v_level);
- for ( ; bool((v_count > 0)); ) { (function () { (v_s = (string(v_s) + string((string(' ')))));
-(v_count = (v_count - 1));; })() };
- throw(v_s);;
+ return(str_replicate((string(' ')), v_level));;
}
catch(err) {
if ( err instanceof Error ) {
View
10 lib/Perlito/Javascript/Emitter.pm
@@ -2,13 +2,7 @@ use v6;
class Javascript {
sub tab($level) {
- my $s = '';
- my $count = $level;
- while $count > 0 {
- $s = $s ~ " ";
- $count = $count - 1;
- }
- return $s;
+ " " x $level
}
my %safe_char = (
@@ -542,6 +536,8 @@ class Apply {
if $code eq 'prefix:<++>' { return '++(' ~ (@.arguments.>>emit_javascript).join(' ') ~ ')' }
if $code eq 'prefix:<-->' { return '--(' ~ (@.arguments.>>emit_javascript).join(' ') ~ ')' }
+ if $code eq 'infix:<x>' { return 'str_replicate(' ~ (@.arguments.>>emit_javascript).join(', ') ~ ')' }
+
if $code eq 'list:<~>' { return '(' ~ Javascript::escape_function('string') ~ '(' ~ (@.arguments.>>emit_javascript()).join( ') + ' ~ Javascript::escape_function('string') ~ '(' ) ~ '))' }
if $code eq 'infix:<+>' { return Javascript::escape_function('add') ~ '(' ~ (@.arguments.>>emit_javascript).join(', ') ~ ')' }
View
4 lib/Perlito/Javascript/Runtime.js
@@ -471,6 +471,10 @@ chars = function(o) {
return o.length;
};
+str_replicate = function(o, num) {
+ return num ? Array(num + 1).join(o) : "";
+};
+
// regex primitives
if (typeof Perlito$Grammar !== 'object') {
Perlito$Grammar = function() {};
View
8 lib/Perlito/Perl5/Emitter.pm
@@ -2,13 +2,7 @@ use v6;
class Perl5 {
sub tab($level) {
- my $s = '';
- my $count = $level;
- while $count > 0 {
- $s ~= " ";
- $count = $count - 1;
- }
- return $s;
+ " " x $level
}
my %safe_char = (
View
3  lib/Perlito/Precedence.pm
@@ -200,6 +200,9 @@ class Perlito::Precedence {
add_op( 'infix', '+', $prec );
add_op( 'infix', '-', $prec );
$prec = $prec - 1;
+ add_op( 'infix', 'x', $prec );
+ add_op( 'infix', 'xx', $prec );
+ $prec = $prec - 1;
add_op( 'infix', '~', $prec, { assoc => 'list' } );
add_op( 'prefix', '~', $prec );
$prec = $prec - 1;
View
13 lib/Perlito/Python/Emitter.pm
@@ -2,13 +2,7 @@ use v6;
class Python {
sub tab($level) {
- my $s = '';
- my $count = $level;
- while $count > 0 {
- $s = $s ~ " ";
- $count = $count - 1;
- }
- return $s;
+ " " x $level
}
my %safe_char = (
@@ -590,6 +584,11 @@ class Apply {
if $code eq 'prefix:<@>' { return '(' ~ (@.arguments.>>emit_python).join(' ') ~ ')' };
if $code eq 'prefix:<%>' { return '%{' ~ (@.arguments.>>emit_python).join(' ') ~ '}' };
+ if $code eq 'infix:<x>' {
+ return '(unicode(' ~ @.arguments[0].emit_python() ~ ')'
+ ~ ' * mp6_to_num(' ~ @.arguments[1].emit_python() ~ '))'
+ };
+
if $code eq 'list:<~>' { return '(unicode(' ~ (@.arguments.>>emit_python).join(') + unicode(') ~ '))' };
if $code eq 'infix:<+>' { return '(mp6_to_num(' ~ (@.arguments.>>emit_python).join(') + mp6_to_num(') ~ '))' };
if $code eq 'infix:<->' { return '(' ~ (@.arguments.>>emit_python).join(' - ') ~ ')' };
View
11 lib5/Perlito/Javascript/Emitter.pm
@@ -18,13 +18,7 @@ package GLOBAL;
sub new { shift; bless { @_ }, "Javascript" }
sub tab {
my $level = $_[0];
- ((my $s) = '');
- ((my $count) = $level);
- for ( ; ($count > 0); ) {
- ($s = ($s . (' ')));
- ($count = ($count - 1))
- };
- return scalar ($s)
+ ((' ') x $level)
};
((my $Hash_safe_char = bless {}, 'HASH') = do {
(my $Hash_a = bless {}, 'HASH');
@@ -647,6 +641,9 @@ $self->emit_javascript_indented(0)
if (($code eq 'prefix:<-->')) {
return scalar (('--(' . Main::join(([ map { $_->emit_javascript() } @{( $self->{arguments} )} ]), ' ') . ')'))
};
+ if (($code eq 'infix:<x>')) {
+ return scalar (('str_replicate(' . Main::join(([ map { $_->emit_javascript() } @{( $self->{arguments} )} ]), ', ') . ')'))
+ };
if (($code eq 'list:<' . chr(126) . '>')) {
return scalar (('(' . Javascript::escape_function('string') . '(' . Main::join(([ map { $_->emit_javascript() } @{( $self->{arguments} )} ]), (') + ' . Javascript::escape_function('string') . '(')) . '))'))
};
View
4 lib5/Perlito/Javascript/Runtime.js
@@ -471,6 +471,10 @@ chars = function(o) {
return o.length;
};
+str_replicate = function(o, num) {
+ return num ? Array(num + 1).join(o) : "";
+};
+
// regex primitives
if (typeof Perlito$Grammar !== 'object') {
Perlito$Grammar = function() {};
View
8 lib5/Perlito/Perl5/Emitter.pm
@@ -18,13 +18,7 @@ package GLOBAL;
sub new { shift; bless { @_ }, "Perl5" }
sub tab {
my $level = $_[0];
- ((my $s) = '');
- ((my $count) = $level);
- for ( ; ($count > 0); ) {
- ($s = ($s . (' ')));
- ($count = ($count - 1))
- };
- return scalar ($s)
+ ((' ') x $level)
};
((my $Hash_safe_char = bless {}, 'HASH') = do {
(my $Hash_a = bless {}, 'HASH');
View
3  lib5/Perlito/Precedence.pm
@@ -324,6 +324,9 @@ package GLOBAL;
add_op('infix', '+', $prec);
add_op('infix', '-', $prec);
($prec = ($prec - 1));
+ add_op('infix', 'x', $prec);
+ add_op('infix', 'xx', $prec);
+ ($prec = ($prec - 1));
add_op('infix', chr(126), $prec, do {
(my $Hash_a = bless {}, 'HASH');
($Hash_a->{'assoc'} = 'list');
View
11 lib5/Perlito/Python/Emitter.pm
@@ -18,13 +18,7 @@ package GLOBAL;
sub new { shift; bless { @_ }, "Python" }
sub tab {
my $level = $_[0];
- ((my $s) = '');
- ((my $count) = $level);
- for ( ; ($count > 0); ) {
- ($s = ($s . (' ')));
- ($count = ($count - 1))
- };
- return scalar ($s)
+ ((' ') x $level)
};
((my $Hash_safe_char = bless {}, 'HASH') = do {
(my $Hash_a = bless {}, 'HASH');
@@ -706,6 +700,9 @@ $self->emit_python_indented(0)
if (($code eq 'prefix:<' . chr(37) . '>')) {
return scalar ((chr(37) . chr(123) . Main::join(([ map { $_->emit_python() } @{( $self->{arguments} )} ]), ' ') . chr(125)))
};
+ if (($code eq 'infix:<x>')) {
+ return scalar (('(unicode(' . $self->{arguments}->[0]->emit_python() . ')' . ' * mp6_to_num(' . $self->{arguments}->[1]->emit_python() . '))'))
+ };
if (($code eq 'list:<' . chr(126) . '>')) {
return scalar (('(unicode(' . Main::join(([ map { $_->emit_python() } @{( $self->{arguments} )} ]), ') + unicode(') . '))'))
};
Please sign in to comment.
Something went wrong with that request. Please try again.