Permalink
Browse files

Perlito5 - cleanup parenthesis

  • Loading branch information...
1 parent 1cb513e commit 4b15a006c35aaf6659f1c3afdcdcd75103d666e0 @fglock committed Feb 1, 2012
View
@@ -16,13 +16,6 @@ TODO list for Perlito5
-- add "require"
-* source code - remove Perl 6 code
-
--- "token"
-
--- for @x {...} --> for (@x) {...}
-
-
* libraries
-- these should probably go into namespace Perlito5X::*
@@ -51,6 +44,8 @@ TODO list for Perlito5
-- TODO move "CallSub" to last argument in order to get some more compatibility with native js
+-- in the browser: implement "use" with XMLHttpRequest
+
* Python backend
@@ -77,5 +72,7 @@ TODO list for Perlito5
-- finish "overload" implementation
+-- source code - remove Perl 6 code such as "token"
+
-- much more!
View

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -88,18 +88,18 @@ package main;
sub emit_perl5 {
my $List__ = bless \@_, "ARRAY";
((my $self) = $List__->[0]);
- if ((((($self->{('quant')} eq '')) && (($self->{('greedy')} eq ''))))) {
+ if (((($self->{('quant')} eq '') && ($self->{('greedy')} eq '')))) {
return ($self->{('term')}->emit_perl5())
};
- if ((((($self->{('quant')} eq '+')) && (($self->{('greedy')} eq ''))))) {
+ if (((($self->{('quant')} eq '+') && ($self->{('greedy')} eq '')))) {
$self->{('term')}->set_captures_to_array();
return (('(do ' . chr(123) . ' ' . 'my ' . chr(36) . 'last_match_null ' . chr(61) . ' 0' . chr(59) . ' ' . 'my ' . chr(36) . 'last_pos ' . chr(61) . ' ' . chr(36) . 'MATCH->to' . chr(59) . ' ' . 'my ' . chr(36) . 'count ' . chr(61) . ' 0' . chr(59) . ' ' . 'while (' . $self->{('term')}->emit_perl5() . ' ' . chr(38) . chr(38) . ' (' . chr(36) . 'last_match_null < 2)) ' . chr(123) . ' ' . 'if (' . chr(36) . 'last_pos ' . chr(61) . chr(61) . ' ' . chr(36) . 'MATCH->to()) ' . chr(123) . ' ' . chr(36) . 'last_match_null ' . chr(61) . ' ' . chr(36) . 'last_match_null + 1' . chr(59) . ' ' . chr(125) . ' ' . 'else ' . chr(123) . ' ' . chr(36) . 'last_match_null ' . chr(61) . ' 0' . chr(59) . ' ' . chr(125) . chr(59) . ' ' . chr(36) . 'last_pos ' . chr(61) . ' ' . chr(36) . 'MATCH->to' . chr(59) . ' ' . chr(36) . 'count ' . chr(61) . ' ' . chr(36) . 'count + 1' . chr(59) . ' ' . chr(125) . chr(59) . ' ' . chr(36) . 'MATCH->' . chr(123) . chr(34) . 'to' . chr(34) . chr(125) . ' ' . chr(61) . ' ' . chr(36) . 'last_pos' . chr(59) . ' ' . chr(36) . 'count > 0' . chr(59) . ' ' . chr(125) . ')'))
};
- if ((((($self->{('quant')} eq '*')) && (($self->{('greedy')} eq ''))))) {
+ if (((($self->{('quant')} eq '*') && ($self->{('greedy')} eq '')))) {
$self->{('term')}->set_captures_to_array();
return (('(do ' . chr(123) . ' ' . 'my ' . chr(36) . 'last_match_null ' . chr(61) . ' 0' . chr(59) . ' ' . 'my ' . chr(36) . 'last_pos ' . chr(61) . ' ' . chr(36) . 'MATCH->to' . chr(59) . ' ' . 'while (' . $self->{('term')}->emit_perl5() . ' ' . chr(38) . chr(38) . ' (' . chr(36) . 'last_match_null < 2)) ' . chr(123) . ' ' . 'if (' . chr(36) . 'last_pos ' . chr(61) . chr(61) . ' ' . chr(36) . 'MATCH->to()) ' . chr(123) . ' ' . chr(36) . 'last_match_null ' . chr(61) . ' ' . chr(36) . 'last_match_null + 1' . chr(59) . ' ' . chr(125) . ' ' . 'else ' . chr(123) . ' ' . chr(36) . 'last_match_null ' . chr(61) . ' 0' . chr(59) . ' ' . chr(125) . chr(59) . ' ' . chr(36) . 'last_pos ' . chr(61) . ' ' . chr(36) . 'MATCH->to' . chr(59) . ' ' . chr(125) . chr(59) . ' ' . chr(36) . 'MATCH->' . chr(123) . chr(34) . 'to' . chr(34) . chr(125) . ' ' . chr(61) . ' ' . chr(36) . 'last_pos' . chr(59) . ' ' . '1 ' . chr(125) . ')'))
};
- if ((((($self->{('quant')} eq chr(63))) && (($self->{('greedy')} eq ''))))) {
+ if (((($self->{('quant')} eq chr(63)) && ($self->{('greedy')} eq '')))) {
$self->{('term')}->set_captures_to_array();
return (('(do ' . chr(123) . ' ' . 'my ' . chr(36) . 'last_pos ' . chr(61) . ' ' . chr(36) . 'MATCH->to' . chr(59) . ' ' . 'if (' . chr(33) . '(do ' . chr(123) . $self->{('term')}->emit_perl5() . chr(125) . ')) ' . chr(123) . ' ' . chr(36) . 'MATCH->' . chr(123) . chr(34) . 'to' . chr(34) . chr(125) . ' ' . chr(61) . ' ' . chr(36) . 'last_pos' . chr(59) . ' ' . chr(125) . chr(59) . ' ' . '1 ' . chr(125) . ')'))
};
@@ -65,30 +65,30 @@ package main;
return ($o)
};
((my $stmt) = $stmts->[0]);
- if ((((ref($stmt) eq 'Var')))) {
+ if (((ref($stmt) eq 'Var'))) {
return (Lit::Hash->new(('hash1' => (do {
(my $List_a = bless [], 'ARRAY');
(my $List_v = bless [], 'ARRAY');
push( @{$List_a}, $stmt );
$List_a
}))))
};
- if ((!((((ref($stmt) eq 'Apply')))))) {
+ if (((ref($stmt) ne 'Apply'))) {
return ($o)
};
- if ((($stmt->code()) eq 'infix:<' . chr(61) . '>>')) {
+ if ((($stmt->code() eq 'infix:<' . chr(61) . '>>'))) {
return (Lit::Hash->new(('hash1' => (do {
(my $List_a = bless [], 'ARRAY');
(my $List_v = bless [], 'ARRAY');
push( @{$List_a}, $stmt );
$List_a
}))))
};
- if ((($stmt->code()) ne 'list:<,>')) {
+ if ((($stmt->code() ne 'list:<,>'))) {
return ($o)
};
for my $item ( @{($stmt->arguments())} ) {
- if (((((ref($item) eq 'Apply')) && (($item->code()) eq 'infix:<' . chr(61) . '>>')))) {
+ if ((((ref($item) eq 'Apply') && ($item->code() eq 'infix:<' . chr(61) . '>>')))) {
return (Lit::Hash->new(('hash1' => expand_list($stmt))))
}
};
@@ -181,7 +181,7 @@ package main;
return ($v)
};
if ((($v->[1] eq 'methcall'))) {
- ((my $param_list) = expand_list(($v->[3])->{'exp'}));
+ ((my $param_list) = expand_list($v->[3]->{'exp'}));
($v = Call->new(('invocant' => $value), ('method' => $v->[2]), ('arguments' => $param_list)));
return ($v)
};
@@ -291,7 +291,7 @@ package main;
$List_a
}))
};
- if ((((((ref($arg->[0]) eq 'Apply')) && (($last_op->[0] eq 'infix'))) && ((($arg->[0])->code() eq (('list:<' . $last_op->[1] . '>'))))))) {
+ if (((((ref($arg->[0]) eq 'Apply') && ($last_op->[0] eq 'infix')) && (($arg->[0]->code() eq ('list:<' . $last_op->[1] . '>')))))) {
push( @{($num_stack)}, Apply->new(('namespace' => ''), ('code' => ($arg->[0])->code()), ('arguments' => (do {
(my $List_a = bless [], 'ARRAY');
(my $List_v = bless [], 'ARRAY');
@@ -1401,7 +1401,7 @@ package main;
($last_pos = $m->to())
}
};
- if (((((($v->[0]) eq 'postfix_or_term')) && ((($v->[1]) eq 'block'))) && $last_token_was_space)) {
+ if ((((($v->[0] eq 'postfix_or_term') && ($v->[1] eq 'block')) && $last_token_was_space))) {
if (($self->has_newline_after($str, $last_pos)->bool())) {
($terminated = 1);
push( @{($lexer_stack)}, (do {
@@ -1588,7 +1588,7 @@ package main;
($last_pos = $m->to())
}
};
- if (((((((((($v->[0]) eq 'postfix_or_term')) && ((($v->[1]) eq 'block')))) || ((((($v->[0]) eq 'term')) && (ref($v->[1]) eq 'Sub')))) || ((((($v->[0]) eq 'term')) && (ref($v->[1]) eq 'Do')))) || ((((($v->[0]) eq 'term')) && (ref($v->[1]) eq 'CompUnit')))))) {
+ if (((((((($v->[0] eq 'postfix_or_term') && ($v->[1] eq 'block'))) || ((($v->[0] eq 'term') && (ref($v->[1]) eq 'Sub')))) || ((($v->[0] eq 'term') && (ref($v->[1]) eq 'Do')))) || ((($v->[0] eq 'term') && (ref($v->[1]) eq 'CompUnit')))))) {
if (($self->has_newline_after($str, $last_pos)->bool())) {
($terminated = 1);
push( @{($lexer_stack)}, (do {
@@ -1888,7 +1888,7 @@ package main;
return ($res)
};
((my $modifier_exp) = $self->exp_parse($str, $modifier->to()));
- if ((!(($modifier_exp->bool())))) {
+ if ((!($modifier_exp->bool()))) {
die(('Expected expression after ' . chr(39)), $modifier->flat(), (chr(39)))
};
if (($modifier_exp->flat())->{'end_block'}) {
@@ -39,11 +39,11 @@ package main;
0
}
}))) && ((do {
- ((my $body) = ($MATCH->{('exp')}->flat())->{'end_block'});
- if ((!((defined($body))))) {
+ ((my $body) = $MATCH->{('exp')}->flat()->{'end_block'});
+ if ((!(defined($body)))) {
die(('Missing code block in ' . chr(39) . 'unless' . chr(39)))
};
- ($MATCH->{('capture')} = If->new(('cond' => ($MATCH->{('exp')}->flat())->{'exp'}), ('body' => Lit::Block->new(('stmts' => (do {
+ ($MATCH->{('capture')} = If->new(('cond' => $MATCH->{('exp')}->flat()->{'exp'}), ('body' => Lit::Block->new(('stmts' => (do {
(my $List_a = bless [], 'ARRAY');
(my $List_v = bless [], 'ARRAY');
$List_a
@@ -105,9 +105,9 @@ package main;
0
}
}))) && ((do {
- ((my $body) = ($MATCH->{('exp')}->flat())->{'end_block'});
+ ((my $body) = $MATCH->{('exp')}->flat()->{'end_block'});
((my $otherwise) = ($MATCH->{('exp2')}->flat())->{'exp'});
- if ((!((defined($body))))) {
+ if ((!(defined($body)))) {
die(('Missing code block in ' . chr(39) . 'if' . chr(39)))
};
if ((!((defined($otherwise))))) {
@@ -116,7 +116,7 @@ package main;
if (((ref($otherwise) eq 'Lit::Hash'))) {
($otherwise = Lit::Block->new(('stmts' => $otherwise->hash1())))
};
- ($MATCH->{('capture')} = If->new(('cond' => ($MATCH->{('exp')}->flat())->{'exp'}), ('body' => $body), ('otherwise' => $otherwise)));
+ ($MATCH->{('capture')} = If->new(('cond' => $MATCH->{('exp')}->flat()->{'exp'}), ('body' => $body), ('otherwise' => $otherwise)));
1
})))
})) || ((do {
@@ -141,11 +141,11 @@ package main;
0
}
}))) && ((do {
- ((my $body) = ($MATCH->{('exp')}->flat())->{'end_block'});
- if ((!((defined($body))))) {
+ ((my $body) = $MATCH->{('exp')}->flat()->{'end_block'});
+ if ((!(defined($body)))) {
die(('Missing code block in ' . chr(39) . 'if' . chr(39)))
};
- ($MATCH->{('capture')} = If->new(('cond' => ($MATCH->{('exp')}->flat())->{'exp'}), ('body' => $body), ('otherwise' => Lit::Block->new(('stmts' => (do {
+ ($MATCH->{('capture')} = If->new(('cond' => $MATCH->{('exp')}->flat()->{'exp'}), ('body' => $body), ('otherwise' => Lit::Block->new(('stmts' => (do {
(my $List_a = bless [], 'ARRAY');
(my $List_v = bless [], 'ARRAY');
push( @{$List_a}, $MATCH->{('if')}->flat() );
@@ -156,11 +156,11 @@ package main;
}))) || ((do {
($MATCH->{('to')} = $pos1);
(((do {
- ((my $body) = ($MATCH->{('exp')}->flat())->{'end_block'});
- if ((!((defined($body))))) {
+ ((my $body) = $MATCH->{('exp')}->flat()->{'end_block'});
+ if ((!(defined($body)))) {
die(('Missing code block in ' . chr(39) . 'if' . chr(39)))
};
- ($MATCH->{('capture')} = If->new(('cond' => ($MATCH->{('exp')}->flat())->{'exp'}), ('body' => $body), ('otherwise' => Lit::Block->new(('stmts' => (do {
+ ($MATCH->{('capture')} = If->new(('cond' => $MATCH->{('exp')}->flat()->{'exp'}), ('body' => $body), ('otherwise' => Lit::Block->new(('stmts' => (do {
(my $List_a = bless [], 'ARRAY');
(my $List_v = bless [], 'ARRAY');
$List_a
@@ -202,11 +202,11 @@ package main;
0
}
}))) && ((do {
- ((my $body) = ($MATCH->{('exp')}->flat())->{'end_block'});
- if ((!((defined($body))))) {
+ ((my $body) = $MATCH->{('exp')}->flat()->{'end_block'});
+ if ((!(defined($body)))) {
die(('Missing code block in ' . chr(39) . 'when' . chr(39)))
};
- ($MATCH->{('capture')} = When->new(('parameters' => ($MATCH->{('exp')}->flat())->{'exp'}), ('body' => $body)));
+ ($MATCH->{('capture')} = When->new(('parameters' => $MATCH->{('exp')}->flat()->{'exp'}), ('body' => $body)));
1
})))
}))
@@ -334,11 +334,11 @@ package main;
0
}
})) && ((do {
- ((my $body) = ($MATCH->{('exp')}->flat())->{'end_block'});
- if ((!((defined($body))))) {
+ ((my $body) = $MATCH->{('exp')}->flat()->{'end_block'});
+ if ((!(defined($body)))) {
die(('Missing code block in ' . chr(39) . 'when' . chr(39)))
};
- ($MATCH->{('capture')} = For->new(('cond' => ($MATCH->{('exp')}->flat())->{'exp'}), ('topic' => undef()), ('body' => $body)));
+ ($MATCH->{('capture')} = For->new(('cond' => $MATCH->{('exp')}->flat()->{'exp'}), ('topic' => undef()), ('body' => $body)));
1
}))))
})))
@@ -376,11 +376,11 @@ package main;
0
}
}))) && ((do {
- ((my $body) = ($MATCH->{('exp')}->flat())->{'end_block'});
- if ((!((defined($body))))) {
+ ((my $body) = $MATCH->{('exp')}->flat()->{'end_block'});
+ if ((!(defined($body)))) {
die(('Missing code block in ' . chr(39) . 'while' . chr(39)))
};
- ($MATCH->{('capture')} = While->new(('cond' => ($MATCH->{('exp')}->flat())->{'exp'}), ('body' => $body)));
+ ($MATCH->{('capture')} = While->new(('cond' => $MATCH->{('exp')}->flat()->{'exp'}), ('body' => $body)));
1
})))
}))
@@ -36,10 +36,10 @@ sub ws3 { $_[0]->{'ws3'} }
sub emit_perl5 {
my $self = $_[0];
- if (($self->{"quant"} eq '') && ($self->{"greedy"} eq '')) {
+ if ($self->{"quant"} eq '' && $self->{"greedy"} eq '') {
return $self->{"term"}->emit_perl5;
}
- if (($self->{"quant"} eq '+') && ($self->{"greedy"} eq '')) {
+ if ($self->{"quant"} eq '+' && $self->{"greedy"} eq '') {
$self->{"term"}->set_captures_to_array;
return
'(do { '
@@ -61,7 +61,7 @@ sub emit_perl5 {
. '$count > 0; '
. '})';
}
- if (($self->{"quant"} eq '*') && ($self->{"greedy"} eq '')) {
+ if ($self->{"quant"} eq '*' && $self->{"greedy"} eq '') {
$self->{"term"}->set_captures_to_array;
return
'(do { '
@@ -81,7 +81,7 @@ sub emit_perl5 {
. '1 '
. '})';
}
- if (($self->{"quant"} eq '?') && ($self->{"greedy"} eq '')) {
+ if ($self->{"quant"} eq '?' && $self->{"greedy"} eq '') {
$self->{"term"}->set_captures_to_array;
return
'(do { '
@@ -41,28 +41,28 @@ package Perlito5::Expression;
return $o
}
my $stmt = $stmts->[0];
- if (( ref($stmt) eq 'Var' )) {
+ if ( ref($stmt) eq 'Var' ) {
# the argument is a single variable
# say "# single var -- is hash";
return Lit::Hash->new(hash1 => [ $stmt ])
}
- if (!(( ref($stmt) eq 'Apply' ))) {
+ if ( ref($stmt) ne 'Apply' ) {
# say "# not Apply -- not hash";
return $o
}
- if ($stmt->code) eq 'infix:<=>>' {
+ if ($stmt->code eq 'infix:<=>>') {
# the argument is a single pair
# say "# single pair -- is hash";
return Lit::Hash->new(hash1 => [ $stmt ])
}
- if ($stmt->code) ne 'list:<,>' {
+ if ($stmt->code ne 'list:<,>') {
# say "# not a list -- not hash";
return $o
}
# the argument is a list -- check that it contains a pair
for my $item ( @{$stmt->arguments} ) {
# say "# item: ", $item->perl;
- if (( ref($item) eq 'Apply' ) && ($item->code) eq 'infix:<=>>') {
+ if ( ref($item) eq 'Apply' && $item->code eq 'infix:<=>>' ) {
# argument is a pair
# say "# block: ", $o->perl;
# say "# hash with args: ", ( expand_list($stmt->arguments) )->perl;
@@ -182,7 +182,7 @@ package Perlito5::Expression;
}
if ($v->[1] eq 'methcall') {
# say "# Call ", ($v->[2])->perl;
- my $param_list = expand_list(($v->[3]){'exp'});
+ my $param_list = expand_list($v->[3]{'exp'});
$v = Call->new( invocant => $value, method => $v->[2], arguments => $param_list );
return $v;
}
@@ -287,9 +287,9 @@ package Perlito5::Expression;
my $v2 = pop_term($num_stack);
$arg = [ pop_term($num_stack), $v2 ];
}
- if ( ( ref($arg->[0]) eq 'Apply' )
- && ($last_op->[0] eq 'infix')
- && (($arg->[0])->code eq ('list:<' . $last_op->[1] . '>'))
+ if ( ref($arg->[0]) eq 'Apply'
+ && $last_op->[0] eq 'infix'
+ && ($arg->[0]->code eq 'list:<' . $last_op->[1] . '>')
)
{
push @$num_stack,
@@ -531,8 +531,10 @@ package Perlito5::Expression;
# say "# list_lexer " . $v->perl;
- if (($v->[0]) eq 'postfix_or_term') && (($v->[1]) eq 'block')
+ if ( $v->[0] eq 'postfix_or_term'
+ && $v->[1] eq 'block'
&& $last_token_was_space
+ )
{
if ($self->has_newline_after($str, $last_pos)->bool) {
# a block followed by newline terminates the expression
@@ -677,10 +679,10 @@ package Perlito5::Expression;
}
# say "# exp_lexer got " . $v->perl;
- if ( ( (($v->[0]) eq 'postfix_or_term') && (($v->[1]) eq 'block') )
- || ( (($v->[0]) eq 'term') && ref($v->[1]) eq 'Sub' )
- || ( (($v->[0]) eq 'term') && ref($v->[1]) eq 'Do' )
- || ( (($v->[0]) eq 'term') && ref($v->[1]) eq 'CompUnit' )
+ if ( ( $v->[0] eq 'postfix_or_term' && $v->[1] eq 'block' )
+ || ( $v->[0] eq 'term' && ref($v->[1]) eq 'Sub' )
+ || ( $v->[0] eq 'term' && ref($v->[1]) eq 'Do' )
+ || ( $v->[0] eq 'term' && ref($v->[1]) eq 'CompUnit' )
)
{
# a block followed by newline terminates the expression
@@ -772,7 +774,7 @@ package Perlito5::Expression;
($res->flat()){'exp'} = Do->new(block => ($res->flat()){'exp'});
}
if ($res->flat()){'end_block'} {
- # warn "Block: ", (($res->flat()){'end_block'})->perl;
+ # warn "Block: ", $res->flat()->{'end_block'}->perl;
die "Unexpected block after expression near ", $pos;
}
if ($res->flat()){'terminated'} {
@@ -790,11 +792,11 @@ package Perlito5::Expression;
}
my $modifier_exp = $self->exp_parse($str, $modifier->to);
# say "# statement modifier [", $modifier->flat(), "] exp: ", $modifier_exp->perl;
- if (!($modifier_exp->bool)) {
+ if (!$modifier_exp->bool) {
die "Expected expression after '", $modifier->flat(), "'";
}
if ($modifier_exp->flat()){'end_block'} {
- # warn "Block: ", (($modifier_exp->flat()){'end_block'})->perl;
+ # warn "Block: ", $modifier_exp->flat()->{'end_block'}->perl;
die "Unexpected block after expression near ", $modifier->to;
}
# TODO - require a statement terminator
Oops, something went wrong.

0 comments on commit 4b15a00

Please sign in to comment.