Skip to content

Commit 56ae4f0

Browse files
committed
[p5regex] implement \A, \z and \Z
also add some basic tests
1 parent 5a60f40 commit 56ae4f0

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

src/QRegex/P5Regex/Actions.nqp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ class QRegex::P5Regex::Actions is HLL::Actions {
168168
QAST::Regex.new( :rxtype<altseq>, |@alts );
169169
make $qast;
170170
}
171+
172+
method p5backslash:sym<A>($/) {
173+
make QAST::Regex.new( :rxtype<anchor>, :subtype<bos>, :node($/) );
174+
175+
}
171176

172177
method p5backslash:sym<s>($/) {
173178
make QAST::Regex.new(:rxtype<cclass>, '.CCLASS_WHITESPACE',
@@ -181,6 +186,21 @@ class QRegex::P5Regex::Actions is HLL::Actions {
181186
QAST::Node.new( QAST::SVal.new( :value('wb') ) ));
182187
}
183188

189+
method p5backslash:sym<z>($/) {
190+
make QAST::Regex.new( :rxtype<anchor>, :subtype<eos>, :node($/) );
191+
}
192+
193+
method p5backslash:sym<Z>($/) {
194+
make QAST::Regex.new(
195+
:rxtype('concat'),
196+
QAST::Regex.new(
197+
:rxtype('quant'), :min(0), :max(1),
198+
QAST::Regex.new( :rxtype('literal'), "\n" )
199+
),
200+
QAST::Regex.new( :rxtype<anchor>, :subtype('eos'), :node($/) )
201+
);
202+
}
203+
184204
method p5backslash:sym<misc>($/) {
185205
if $<litchar> {
186206
make QAST::Regex.new( ~$<litchar> , :rxtype('literal'), :node($/) );

src/QRegex/P5Regex/Grammar.nqp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ grammar QRegex::P5Regex::Grammar is HLL::Grammar {
8181

8282
proto token p5backslash { <...> }
8383

84+
token p5backslash:sym<A> { <sym> }
85+
token p5backslash:sym<z> { <sym> }
86+
token p5backslash:sym<Z> { <sym> }
8487
token p5backslash:sym<b> { $<sym>=[<[bB]>] }
8588
token p5backslash:sym<s> { $<sym>=[<[dDnNsSwW]>] }
8689
token p5backslash:sym<misc> { $<litchar>=(\W) | $<number>=(\d+) }

t/p5regex/rx_metachars

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,10 @@ ab\d+cdef ab42cdef y digit
4747
a\D+f abcdef y not digit
4848
a\D+f ab0cdef n not digit
4949
\Ba\B a- n not boundary
50+
a\Z a\n y basic \Z + (1)
51+
a\Z a y basic \Z + (2)
52+
a\Z ab n basic \Z - (1)
53+
a\Z a\nb n basic \Z - (2)
54+
a\z a y basic \z +
55+
a\z a\n n basic \z - (1)
56+
a\z a\nb n basic \z - (2)

0 commit comments

Comments
 (0)