Skip to content

Commit 05d1982

Browse files
committed
Add Cursor.ws .
1 parent 22b4fa8 commit 05d1982

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/QRegex/Cursor.nqp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ role QRegex::Cursor {
7777
nqp::elems($!cstack);
7878
}
7979

80-
method !cursor_pass($pos) {
80+
method !cursor_pass($pos, $name?) {
8181
$!match := 1;
8282
$!pos := $pos;
8383
$!regexsub := Q:PIR {
@@ -92,6 +92,21 @@ role QRegex::Cursor {
9292
$!pos := -3;
9393
}
9494

95+
method ws() {
96+
# skip over any whitespace, fail if between two word chars
97+
my $cur := self."!cursor_start"();
98+
$!pos >= nqp::chars($!target)
99+
?? $cur."!cursor_pass"($!pos, 'ws')
100+
!! ($!pos < 1
101+
|| !nqp::iscclass(pir::const::CCLASS_WORD, $!target, $!pos)
102+
|| !nqp::iscclass(pir::const::CCLASS_WORD, $!target, $!pos-1)
103+
) && $cur."!cursor_pass"(
104+
pir::find_not_cclass__Iisii(
105+
pir::const::CCLASS_WHITESPACE, $!target, $!pos, nqp::chars($!target)),
106+
'ws');
107+
$cur;
108+
}
109+
95110
method alpha() {
96111
my $cur := self."!cursor_start"();
97112
$cur."!cursor_pass"($!pos+1)

0 commit comments

Comments
 (0)