Skip to content

Commit 0164c28

Browse files
committed
Merge branch 'master' into replito
2 parents 4660a57 + 657299a commit 0164c28

File tree

7 files changed

+411
-650
lines changed

7 files changed

+411
-650
lines changed

TODO-perlito5

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,19 @@ TODO list for Perlito5
233233
' $step++ < $steps '
234234
Can't find string terminator '>' anywhere before EOF
235235

236+
-- from moritz, Schwern and others at
237+
http://stackoverflow.com/questions/161872/hidden-features-of-perl
238+
239+
- you can use letters as delimiters
240+
241+
$ perl -Mstrict -wle 'print q bJet another perl hacker.b'
242+
Jet another perl hacker.
243+
244+
Likewise you can write regular expressions:
245+
246+
m xabcx
247+
# same as m/abc/
248+
236249

237250

238251
* Perl5 backend
@@ -464,17 +477,7 @@ TODO list for Perlito5
464477
$ perl -lwe '*4 = sub { print "yes" }; 4->()'
465478
yes
466479

467-
- you can use letters as delimiters
468-
469-
$ perl -Mstrict -wle 'print q bJet another perl hacker.b'
470-
Jet another perl hacker.
471-
472-
Likewise you can write regular expressions:
473-
474-
m xabcx
475-
# same as m/abc/
476-
477-
The "desperation mode" of Perl's loop control constructs which causes them to look up the stack to find a matching label allows some curious behaviors which Test::More takes advantage of, for better or worse.
480+
-- The "desperation mode" of Perl's loop control constructs which causes them to look up the stack to find a matching label allows some curious behaviors which Test::More takes advantage of, for better or worse.
478481

479482
SKIP: {
480483
skip() if $something;

html/perlito5.js

Lines changed: 312 additions & 451 deletions
Large diffs are not rendered by default.

perlito5.pl

Lines changed: 27 additions & 159 deletions
Large diffs are not rendered by default.

src5/lib/Perlito5/Grammar/Statement.pm

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ token stmt_format {
2828
| { $MATCH->{'Perlito5::Grammar.full_ident'} = 'STDOUT' }
2929
]
3030
{
31-
# inject a here-doc request
32-
# see Perlito5::Grammar::String
31+
# inject a here-doc request - see Perlito5::Grammar::String
3332
my $placeholder = Perlito5::AST::Apply->new(
3433
code => 'list:<.>',
3534
namespace => '',
@@ -48,21 +47,12 @@ token stmt_format {
4847
$placeholder->{arguments}[0]{arguments},
4948
'.', # delimiter
5049
];
51-
# "FORMAT format_name = string"
5250
$MATCH->{capture} =
5351
Perlito5::AST::Apply->new(
54-
code => 'infix:<=>',
52+
code => 'p5:format',
5553
namespace => '',
5654
arguments => [
57-
Perlito5::AST::Decl->new(
58-
decl => 'FORMAT',
59-
type => undef,
60-
var => Perlito5::AST::Var->new(
61-
name => Perlito5::Match::flat($MATCH->{'Perlito5::Grammar.full_ident'}),
62-
namespace => '', # TODO - split namespace/name
63-
sigil => 'FORMAT', # ???
64-
),
65-
),
55+
Perlito5::Match::flat($MATCH->{'Perlito5::Grammar.full_ident'}),
6656
$placeholder,
6757
]
6858
);

src5/lib/Perlito5/Grammar/String.pm

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,26 @@ Perlito5::Grammar::Precedence::add_term( 'y' => sub { Perlito5::Grammar::String
2222

2323

2424
token term_q_quote {
25-
[ 'q' [ '#' | <.Perlito5::Grammar::Space.opt_ws> <!before <.Perlito5::Grammar.word> || '=>' > . ]
25+
[ 'q' [ '#' | <.Perlito5::Grammar::Space.opt_ws> <!before '=>' > . ]
2626
| \'
2727
]
2828
<q_quote_parse>
2929
{ $MATCH->{capture} = [ 'term', Perlito5::Match::flat($MATCH->{q_quote_parse}) ] }
3030
};
3131
token term_qq_quote {
32-
[ 'qq' [ '#' | <.Perlito5::Grammar::Space.opt_ws> <!before <.Perlito5::Grammar.word> || '=>' > . ]
32+
[ 'qq' [ '#' | <.Perlito5::Grammar::Space.opt_ws> <!before '=>' > . ]
3333
| '"'
3434
]
3535
<qq_quote_parse>
3636
{ $MATCH->{capture} = [ 'term', Perlito5::Match::flat($MATCH->{qq_quote_parse}) ] }
3737
};
3838
token term_qw_quote {
39-
'qw' [ '#' | <.Perlito5::Grammar::Space.opt_ws> <!before <.Perlito5::Grammar.word> || '=>' > . ]
39+
'qw' [ '#' | <.Perlito5::Grammar::Space.opt_ws> <!before '=>' > . ]
4040
<qw_quote_parse>
4141
{ $MATCH->{capture} = [ 'term', Perlito5::Match::flat($MATCH->{qw_quote_parse}) ] }
4242
};
4343
token term_m_quote {
44-
[ 'm' [ '#' | <.Perlito5::Grammar::Space.opt_ws> <!before <.Perlito5::Grammar.word> || '=>' > . ]
44+
[ 'm' [ '#' | <.Perlito5::Grammar::Space.opt_ws> <!before '=>' > . ]
4545
| '/'
4646
]
4747
<m_quote_parse>
@@ -50,14 +50,14 @@ token term_m_quote {
5050
}
5151
};
5252
token term_s_quote {
53-
's' [ '#' | <.Perlito5::Grammar::Space.opt_ws> <!before <.Perlito5::Grammar.word> || '=>' > . ]
53+
's' [ '#' | <.Perlito5::Grammar::Space.opt_ws> <!before '=>' > . ]
5454
<s_quote_parse>
5555
{
5656
$MATCH->{capture} = [ 'term', Perlito5::Match::flat($MATCH->{s_quote_parse}) ]
5757
}
5858
};
5959
token term_qx {
60-
[ 'qx' [ '#' | <.Perlito5::Grammar::Space.opt_ws> <!before <.Perlito5::Grammar.word> || '=>' > . ]
60+
[ 'qx' [ '#' | <.Perlito5::Grammar::Space.opt_ws> <!before '=>' > . ]
6161
| '`'
6262
]
6363
<qx_quote_parse>
@@ -68,14 +68,14 @@ token term_glob {
6868
{ $MATCH->{capture} = [ 'term', Perlito5::Match::flat($MATCH->{glob_quote_parse}) ] }
6969
};
7070
token term_tr_quote {
71-
[ 'tr' | 'y' ] [ '#' | <.Perlito5::Grammar::Space.opt_ws> <!before <.Perlito5::Grammar.word> || '=>' > . ]
71+
[ 'tr' | 'y' ] [ '#' | <.Perlito5::Grammar::Space.opt_ws> <!before '=>' > . ]
7272
<tr_quote_parse>
7373
{
7474
$MATCH->{capture} = [ 'term', Perlito5::Match::flat($MATCH->{tr_quote_parse}) ]
7575
}
7676
};
7777
token term_qr_quote {
78-
'qr' [ '#' | <.Perlito5::Grammar::Space.opt_ws> <!before <.Perlito5::Grammar.word> || '=>' > . ]
78+
'qr' [ '#' | <.Perlito5::Grammar::Space.opt_ws> <!before '=>' > . ]
7979
<qr_quote_parse>
8080
{
8181
$MATCH->{capture} = [ 'term', Perlito5::Match::flat($MATCH->{qr_quote_parse}) ]

src5/lib/Perlito5/Javascript2/Emitter.pm

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,17 @@ package Perlito5::Javascript2;
440440
return 'function () { return ' . $argument->emit_javascript2($level, $wantarray) . ' }';
441441
}
442442

443+
sub emit_wrap_statement_javascript2 {
444+
my $wantarray = shift;
445+
my $argument = shift;
446+
447+
# TODO - enable this optimization
448+
# if ($wantarray eq 'void') {
449+
# return $argument;
450+
# }
451+
return '(function () { ' . $argument . ' })()';
452+
}
453+
443454
}
444455

445456
package Perlito5::Javascript2::LexicalBlock;
@@ -1939,41 +1950,65 @@ package Perlito5::AST::Apply;
19391950
'break' => sub {
19401951
my $self = shift;
19411952
my $level = shift;
1953+
my $wantarray = shift;
19421954
$Perlito5::THROW = 1;
1943-
'throw(new p5_error("break", ""))'
1955+
Perlito5::Javascript2::emit_wrap_statement_javascript2(
1956+
$wantarray,
1957+
'throw(new p5_error("break", ""))'
1958+
);
19441959
},
19451960
'next' => sub {
19461961
my $self = shift;
19471962
my $level = shift;
1963+
my $wantarray = shift;
19481964
$Perlito5::THROW = 1;
19491965
my $label = $self->{arguments}[0]{code} || "";
1950-
'throw(new p5_error("next", "' . $label . '"))'
1966+
Perlito5::Javascript2::emit_wrap_statement_javascript2(
1967+
$wantarray,
1968+
'throw(new p5_error("next", "' . $label . '"))'
1969+
);
19511970
},
19521971
'last' => sub {
19531972
my $self = shift;
19541973
my $level = shift;
1974+
my $wantarray = shift;
19551975
$Perlito5::THROW = 1;
19561976
my $label = $self->{arguments}[0]{code} || "";
1957-
'throw(new p5_error("last", "' . $label . '"))'
1977+
Perlito5::Javascript2::emit_wrap_statement_javascript2(
1978+
$wantarray,
1979+
'throw(new p5_error("last", "' . $label . '"))'
1980+
);
19581981
},
19591982
'redo' => sub {
19601983
my $self = shift;
19611984
my $level = shift;
1985+
my $wantarray = shift;
19621986
$Perlito5::THROW = 1;
19631987
my $label = $self->{arguments}[0]{code} || "";
1964-
'throw(new p5_error("redo", "' . $label . '"))'
1988+
Perlito5::Javascript2::emit_wrap_statement_javascript2(
1989+
$wantarray,
1990+
'throw(new p5_error("redo", "' . $label . '"))'
1991+
);
19651992
},
1966-
19671993
'return' => sub {
19681994
my $self = shift;
19691995
my $level = shift;
1996+
my $wantarray = shift;
19701997
$Perlito5::THROW = 1;
1971-
'throw(' . Perlito5::Javascript2::to_runtime_context( $self->{arguments}, $level ) . ')';
1998+
Perlito5::Javascript2::emit_wrap_statement_javascript2(
1999+
$wantarray,
2000+
'throw(' . Perlito5::Javascript2::to_runtime_context( $self->{arguments}, $level ) . ')'
2001+
);
19722002
},
19732003
'goto' => sub {
19742004
my $self = $_[0];
2005+
my $level = shift;
2006+
my $wantarray = shift;
19752007
$Perlito5::THROW = 1;
1976-
'throw((' . $self->{arguments}->[0]->emit_javascript2() . ')([List__, p5want]))';
2008+
Perlito5::Javascript2::emit_wrap_statement_javascript2(
2009+
$wantarray,
2010+
'throw((' . $self->{arguments}->[0]->emit_javascript2() . ')([List__, p5want]))'
2011+
);
19772012
},
19782013

19792014
'do' => sub {

t5/01-perlito/030-num.t

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use strict;
33
use feature 'say';
44

55
package Main;
6-
say '1..8';
6+
say '1..9';
77
my $v = 1 + 0.3;
88
if (( $v < 1.29 ) || ( $v > 1.31 )) {
99
print 'not '
@@ -41,3 +41,7 @@ my $y;
4141
print 'not ' if defined $y;
4242
say 'ok 8 - undefined var';
4343

44+
$v = eval '013.4e2';
45+
print 'not ' if $v != 11400;
46+
say 'ok 9 - octal integer followed by dot # TODO';
47+

0 commit comments

Comments
 (0)