Permalink
Browse files

[p5regex] implement \A, \z and \Z

also add some basic tests
  • Loading branch information...
moritz committed Oct 11, 2012
1 parent 5a60f40 commit 56ae4f0071899389b24e1b02b90f688744c67f29
Showing with 30 additions and 0 deletions.
  1. +20 −0 src/QRegex/P5Regex/Actions.nqp
  2. +3 −0 src/QRegex/P5Regex/Grammar.nqp
  3. +7 −0 t/p5regex/rx_metachars
@@ -168,6 +168,11 @@ class QRegex::P5Regex::Actions is HLL::Actions {
QAST::Regex.new( :rxtype<altseq>, |@alts );
make $qast;
}
+
+ method p5backslash:sym<A>($/) {
+ make QAST::Regex.new( :rxtype<anchor>, :subtype<bos>, :node($/) );
+
+ }
method p5backslash:sym<s>($/) {
make QAST::Regex.new(:rxtype<cclass>, '.CCLASS_WHITESPACE',
@@ -181,6 +186,21 @@ class QRegex::P5Regex::Actions is HLL::Actions {
QAST::Node.new( QAST::SVal.new( :value('wb') ) ));
}
+ method p5backslash:sym<z>($/) {
+ make QAST::Regex.new( :rxtype<anchor>, :subtype<eos>, :node($/) );
+ }
+
+ method p5backslash:sym<Z>($/) {
+ make QAST::Regex.new(
+ :rxtype('concat'),
+ QAST::Regex.new(
+ :rxtype('quant'), :min(0), :max(1),
+ QAST::Regex.new( :rxtype('literal'), "\n" )
+ ),
+ QAST::Regex.new( :rxtype<anchor>, :subtype('eos'), :node($/) )
+ );
+ }
+
method p5backslash:sym<misc>($/) {
if $<litchar> {
make QAST::Regex.new( ~$<litchar> , :rxtype('literal'), :node($/) );
@@ -81,6 +81,9 @@ grammar QRegex::P5Regex::Grammar is HLL::Grammar {
proto token p5backslash { <...> }
+ token p5backslash:sym<A> { <sym> }
+ token p5backslash:sym<z> { <sym> }
+ token p5backslash:sym<Z> { <sym> }
token p5backslash:sym<b> { $<sym>=[<[bB]>] }
token p5backslash:sym<s> { $<sym>=[<[dDnNsSwW]>] }
token p5backslash:sym<misc> { $<litchar>=(\W) | $<number>=(\d+) }
View
@@ -47,3 +47,10 @@ ab\d+cdef ab42cdef y digit
a\D+f abcdef y not digit
a\D+f ab0cdef n not digit
\Ba\B a- n not boundary
+a\Z a\n y basic \Z + (1)
+a\Z a y basic \Z + (2)
+a\Z ab n basic \Z - (1)
+a\Z a\nb n basic \Z - (2)
+a\z a y basic \z +
+a\z a\n n basic \z - (1)
+a\z a\nb n basic \z - (2)

0 comments on commit 56ae4f0

Please sign in to comment.