Skip to content

Commit e83cf47

Browse files
committed
Create all and any operators
As these only permit `any BLOCK LIST` and not the deferred-expression form like `grep EXPR, LIST`, we create a whole new token type, BLKLSTOP, to represent these. The parser then only accepts the block form and not the expression form when parsing these.
1 parent 3e90908 commit e83cf47

29 files changed

+2260
-1951
lines changed

MANIFEST

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6256,6 +6256,7 @@ t/op/aassign.t test list assign
62566256
t/op/alarm.t See if alarm works
62576257
t/op/anonconst.t See if :const works
62586258
t/op/anonsub.t See if anonymous subroutines work
6259+
t/op/any_all.t See if feature 'any' and 'all' work
62596260
t/op/append.t See if . works
62606261
t/op/args.t See if operations on @_ work
62616262
t/op/arith2.t See if arithmetic works

embed.fnc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5911,7 +5911,8 @@ S |int |intuit_method |NN char *s \
59115911
|NULLOK NOCHECK CV *cv
59125912
S |int |intuit_more |NN char *s \
59135913
|NN char *e
5914-
S |I32 |lop |I32 f \
5914+
S |I32 |lop |enum yytokentype t \
5915+
|I32 f \
59155916
|U8 x \
59165917
|NN char *s
59175918
Sr |void |missingterm |NULLOK char *s \

embed.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1704,7 +1704,7 @@
17041704
# define incline(a,b) S_incline(aTHX_ a,b)
17051705
# define intuit_method(a,b,c) S_intuit_method(aTHX_ a,b,c)
17061706
# define intuit_more(a,b) S_intuit_more(aTHX_ a,b)
1707-
# define lop(a,b,c) S_lop(aTHX_ a,b,c)
1707+
# define lop(a,b,c,d) S_lop(aTHX_ a,b,c,d)
17081708
# define missingterm(a,b) S_missingterm(aTHX_ a,b)
17091709
# define parse_ident(a,b,c,d,e,f) S_parse_ident(aTHX_ a,b,c,d,e,f)
17101710
# define pending_ident() S_pending_ident(aTHX)

ext/Opcode/Opcode.pm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package Opcode 1.66;
1+
package Opcode 1.67;
22

33
use strict;
44

@@ -377,6 +377,7 @@ used to implement a resource attack (e.g., consume all available CPU time).
377377
378378
grepstart grepwhile
379379
mapstart mapwhile
380+
anystart allstart anywhile
380381
enteriter iter
381382
enterloop leaveloop unstack
382383
last next redo

gv.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,8 @@ S_maybe_add_coresub(pTHX_ HV * const stash, GV *gv,
610610
case KEY___DATA__: case KEY___END__ :
611611
case KEY_ADJUST : case KEY_AUTOLOAD: case KEY_BEGIN : case KEY_CHECK :
612612
case KEY_DESTROY : case KEY_END : case KEY_INIT : case KEY_UNITCHECK:
613-
case KEY_and : case KEY_catch : case KEY_class :
613+
case KEY_all : case KEY_and : case KEY_any :
614+
case KEY_catch : case KEY_class :
614615
case KEY_continue: case KEY_cmp : case KEY_defer :
615616
case KEY_do : case KEY_dump : case KEY_else : case KEY_elsif :
616617
case KEY_eq : case KEY_eval : case KEY_field :

lib/B/Deparse-core.t

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ sub testit {
9191
else {
9292
package test;
9393
use subs ();
94+
no warnings qw( experimental::any experimental::all );
9495
import subs $keyword;
9596
$code = "no warnings 'syntax'; no strict 'vars'; sub { ${vars}() = $expr }";
9697
$code = "use feature 'isa';\n$code" if $keyword eq "isa";
@@ -232,6 +233,9 @@ while (<DATA>) {
232233

233234
# Special cases
234235

236+
testit any => 'CORE::any { $a } $b, $c', 'CORE::any({$a;} $b, $c);';
237+
testit all => 'CORE::all { $a } $b, $c', 'CORE::all({$a;} $b, $c);';
238+
235239
testit dbmopen => 'CORE::dbmopen(%foo, $bar, $baz);';
236240
testit dbmclose => 'CORE::dbmclose %foo;';
237241

lib/B/Deparse.pm

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# This is based on the module of the same name by Malcolm Beattie,
88
# but essentially none of his code remains.
99

10-
package B::Deparse 1.80;
10+
package B::Deparse 1.81;
1111
use strict;
1212
use Carp;
1313
use B qw(class main_root main_start main_cv svref_2object opnumber perlstring
@@ -2334,6 +2334,8 @@ my %feature_keywords = (
23342334
finally => 'try',
23352335
defer => 'defer',
23362336
signatures => 'signatures',
2337+
any => 'any',
2338+
all => 'all',
23372339
);
23382340

23392341
# keywords that are strong and also have a prototype
@@ -3637,9 +3639,10 @@ sub pp_sort { indirop(@_, "sort") }
36373639

36383640
sub mapop {
36393641
my $self = shift;
3640-
my($op, $cx, $name) = @_;
3642+
my($op, $cx) = @_;
36413643
my($expr, @exprs);
3642-
my $kid = $op->first; # this is the (map|grep)start
3644+
my $kid = $op->first; # this is the (map|grep|any|all)start
3645+
my ( $name ) = $kid->name =~ m/(.*)start/; # anystart and allstart share anywhile
36433646
$kid = $kid->first->sibling; # skip a pushmark
36443647
my $code = $kid->first; # skip a null
36453648
if (is_scope $code) {
@@ -3657,8 +3660,9 @@ sub mapop {
36573660
$code . join(", ", @exprs), $cx, 5);
36583661
}
36593662

3660-
sub pp_mapwhile { mapop(@_, "map") }
3661-
sub pp_grepwhile { mapop(@_, "grep") }
3663+
sub pp_mapwhile { mapop(@_) }
3664+
sub pp_grepwhile { mapop(@_) }
3665+
sub pp_anywhile { mapop(@_) }
36623666
sub pp_mapstart { baseop(@_, "map") }
36633667
sub pp_grepstart { baseop(@_, "grep") }
36643668

lib/B/Op_private.pm

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)