Skip to content

Commit 725cfa8

Browse files
committed
[P5Regex] added \r, \R, \t and \x
1 parent 210cd15 commit 725cfa8

File tree

2 files changed

+41
-9
lines changed

2 files changed

+41
-9
lines changed

src/QRegex/P5Regex/Actions.nqp

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,21 +190,49 @@ class QRegex::P5Regex::Actions is HLL::Actions {
190190
}
191191

192192
method p5backslash:sym<A>($/) {
193-
make QAST::Regex.new( :rxtype<anchor>, :subtype<bos>, :node($/) );
193+
make QAST::Regex.new( :rxtype<anchor>, :subtype<bos>, :node($/) );
194+
}
194195

196+
method p5backslash:sym<b>($/) {
197+
make QAST::Regex.new(:rxtype<subrule>, :subtype<zerowidth>,
198+
:node($/), :negate($<sym> eq 'B'), :name(''),
199+
QAST::Node.new( QAST::SVal.new( :value('wb') ) ));
195200
}
196-
201+
202+
method p5backslash:sym<h>($/) {
203+
make QAST::Regex.new( "\x[09,20,a0,1680,180e,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,200a,202f,205f,3000]", :rxtype('enumcharlist'),
204+
:negate($<sym> eq 'H'), :node($/) );
205+
}
206+
207+
method p5backslash:sym<r>($/) {
208+
make QAST::Regex.new( "\r", :rxtype('enumcharlist'), :node($/) );
209+
}
210+
211+
method p5backslash:sym<R>($/) {
212+
make QAST::Regex.new( :rxtype<cclass>, :name( 'n' ), :node($/) );
213+
}
214+
197215
method p5backslash:sym<s>($/) {
198216
make QAST::Regex.new(:rxtype<cclass>, :name( nqp::lc(~$<sym>) ),
199217
:negate($<sym> le 'Z'), :node($/));
200218
}
201219

202-
method p5backslash:sym<b>($/) {
203-
make QAST::Regex.new(:rxtype<subrule>, :subtype<zerowidth>,
204-
:node($/), :negate($<sym> eq 'B'), :name(''),
205-
QAST::Node.new( QAST::SVal.new( :value('wb') ) ));
220+
method p5backslash:sym<t>($/) {
221+
make QAST::Regex.new( "\t", :rxtype('enumcharlist'),
222+
:negate($<sym> eq 'T'), :node($/) );
206223
}
207-
224+
225+
method p5backslash:sym<v>($/) {
226+
make QAST::Regex.new( "\x[0a,0b,0c,0d,85,2028,2029]",
227+
:rxtype('enumcharlist'),
228+
:negate($<sym> eq 'V'), :node($/) );
229+
}
230+
231+
method p5backslash:sym<x>($/) {
232+
my $hexlit := HLL::Actions.ints_to_string( $<hexint> );
233+
make QAST::Regex.new( $hexlit, :rxtype('literal'), :node($/) );
234+
}
235+
208236
method p5backslash:sym<z>($/) {
209237
make QAST::Regex.new( :rxtype<anchor>, :subtype<eos>, :node($/) );
210238
}

src/QRegex/P5Regex/Grammar.nqp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,14 @@ grammar QRegex::P5Regex::Grammar is HLL::Grammar {
130130
proto token p5backslash { <...> }
131131

132132
token p5backslash:sym<A> { <sym> }
133-
token p5backslash:sym<z> { <sym> }
134-
token p5backslash:sym<Z> { <sym> }
135133
token p5backslash:sym<b> { $<sym>=[<[bB]>] }
134+
token p5backslash:sym<r> { <sym> }
135+
token p5backslash:sym<R> { <sym> }
136136
token p5backslash:sym<s> { $<sym>=[<[dDnNsSwW]>] }
137+
token p5backslash:sym<t> { <sym> }
138+
token p5backslash:sym<x> { <sym> <hexint> }
139+
token p5backslash:sym<z> { <sym> }
140+
token p5backslash:sym<Z> { <sym> }
137141
token p5backslash:sym<misc> { $<litchar>=(\W) | $<number>=(\d+) }
138142
token p5backslash:sym<oops> { <.panic: "Unrecognized Perl 5 regex backslash sequence"> }
139143

0 commit comments

Comments
 (0)