/
test2.pl
42 lines (35 loc) · 974 Bytes
/
test2.pl
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
# vim: ft=perl6
use Test;
# maybe should take a method name?
sub _rxcall($C, $fun) {
my @list := $fun($C);
sub () { @list ?? @list.shift !! Any; }
}
# A call to a subrule could return a cursor of a different type, or with
# unwanted subcaptures that need to be cleared for <.foo>
sub _rxunbind($C, $fun) {
my $it = $fun($C);
sub {
if my $v = $it() { #OK
Q:CgOp {
(box (@ (l $C)) (rawcall (unbox Cursor (@ (l $v)))
SetCaps (getfield captures (unbox Cursor (@ (l $C))))))
}
} else {
Any
}
}
}
my grammar G1 {
regex TOP { <.foo> }
regex foo { x }
}
ok G1.parse("x"), "subrules work (positive)";
ok !G1.parse("y"), "subrules work (negative)";
my grammar G2 {
regex TOP { y <.foo> <.foo> y }
regex foo { x }
}
ok G2.parse("yxxy"), "subrule position tracking works";
ok !G2.parse("yxy"), "subrule position tracking works (2)";
done-testing;