-
-
Notifications
You must be signed in to change notification settings - Fork 373
/
Regex.pm
47 lines (43 loc) · 1.46 KB
/
Regex.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
my class Regex { # declared in BOOTSTRAP
# class Regex is Method {
# has Mu $!caps;
# has Mu $!nfa;
# has Mu $!alt_nfas
multi method ACCEPTS(Regex:D \SELF: Mu \topic) {
my $dollar_slash := nqp::getlexrelcaller(
nqp::ctxcallerskipthunks(nqp::ctx()),
'$/');
$dollar_slash = SELF.(Cursor."!cursor_init"(topic, :c(0))).MATCH_SAVE;
}
multi method ACCEPTS(Regex:D \SELF: @a) {
my $dollar_slash := nqp::getlexrelcaller(
nqp::ctxcallerskipthunks(nqp::ctx()),
'$/');
for @a {
$dollar_slash = SELF.(Cursor.'!cursor_init'($_, :c(0))).MATCH_SAVE;
return $dollar_slash if $dollar_slash;
}
Nil;
}
multi method ACCEPTS(Regex:D \SELF: %h) {
my $dollar_slash := nqp::getlexrelcaller(
nqp::ctxcallerskipthunks(nqp::ctx()),
'$/');
for %h.keys {
$dollar_slash = SELF.(Cursor.'!cursor_init'($_, :c(0))).MATCH_SAVE;
return $dollar_slash if $dollar_slash;
}
Nil;
}
multi method Bool(Regex:D:) {
my $dollar_slash := nqp::getlexrelcaller(
nqp::ctxcallerskipthunks(nqp::ctx()),
'$/');
my $dollar_underscore := nqp::getlexrelcaller(
nqp::ctxcallerskipthunks(nqp::ctx()),
'$_');
$dollar_slash = $dollar_underscore.match(self);
$dollar_slash.Bool()
}
}
# vim: ft=perl6 expandtab sw=4