Skip to content

Commit 8eb6810

Browse files
committed
Get various backslash sequences in place.
1 parent 6902f1d commit 8eb6810

File tree

2 files changed

+17
-39
lines changed

2 files changed

+17
-39
lines changed

src/QRegex/P5Regex/Actions.nqp

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,19 @@ class QRegex::P5Regex::Actions is HLL::Actions {
140140
QAST::Regex.new( :rxtype<altseq>, |@alts );
141141
make $qast;
142142
}
143+
144+
method p5backslash:sym<s>($/) {
145+
make QAST::Regex.new(:rxtype<cclass>, '.CCLASS_WHITESPACE',
146+
:subtype($<sym> eq 'n' ?? 'nl' !! ~$<sym>),
147+
:negate($<sym> le 'Z'), :node($/));
148+
}
143149

150+
method p5backslash:sym<b>($/) {
151+
make QAST::Regex.new(:rxtype<subrule>, :subtype<method>,
152+
:node($/), PAST::Node.new('wb'),
153+
:negate($<sym> eq 'B'), :name('') );
154+
}
155+
144156
method p5backslash:sym<misc>($/) {
145157
my $qast := QAST::Regex.new( ~$/ , :rxtype('literal'), :node($/) );
146158
make $qast;
@@ -262,18 +274,6 @@ class QRegex::P5Regex::Actions is HLL::Actions {
262274
make $qast;
263275
}
264276

265-
method backslash:sym<s>($/) {
266-
make QAST::Regex.new(:rxtype<cclass>, '.CCLASS_WHITESPACE',
267-
:subtype($<sym> eq 'n' ?? 'nl' !! ~$<sym>),
268-
:negate($<sym> le 'Z'), :node($/));
269-
}
270-
271-
method backslash:sym<b>($/) {
272-
my $qast := QAST::Regex.new( "\b", :rxtype('enumcharlist'),
273-
:negate($<sym> eq 'B'), :node($/) );
274-
make $qast;
275-
}
276-
277277
method backslash:sym<e>($/) {
278278
my $qast := QAST::Regex.new( "\c[27]", :rxtype('enumcharlist'),
279279
:negate($<sym> eq 'E'), :node($/) );
@@ -333,11 +333,6 @@ class QRegex::P5Regex::Actions is HLL::Actions {
333333
make QAST::Regex.new( $<charspec>.ast, :rxtype('literal'), :node($/) );
334334
}
335335

336-
method backslash:sym<misc>($/) {
337-
my $qast := QAST::Regex.new( ~$/ , :rxtype('literal'), :node($/) );
338-
make $qast;
339-
}
340-
341336
method assertion:sym<?>($/) {
342337
my $qast;
343338
if $<assertion> {
@@ -363,22 +358,6 @@ class QRegex::P5Regex::Actions is HLL::Actions {
363358
make $qast;
364359
}
365360

366-
method assertion:sym<|>($/) {
367-
my $qast;
368-
my $name := ~$<identifier>;
369-
if $name eq 'c' {
370-
# codepoint boundaries alway match in
371-
# our current Unicode abstraction level
372-
$qast := 0;
373-
}
374-
elsif $name eq 'w' {
375-
$qast := QAST::Regex.new(:rxtype<subrule>, :subtype<method>,
376-
:node($/), PAST::Node.new('wb'),
377-
:name('') );
378-
}
379-
make $qast;
380-
}
381-
382361
method assertion:sym<method>($/) {
383362
my $qast := $<assertion>.ast;
384363
$qast.subtype('method');

src/QRegex/P5Regex/Grammar.nqp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ grammar QRegex::P5Regex::Grammar is HLL::Grammar {
4040
[
4141
| \w
4242
| <metachar=p5metachar>
43-
| '\\' {} $<esc>=.
4443
]
4544
}
4645

@@ -50,7 +49,7 @@ grammar QRegex::P5Regex::Grammar is HLL::Grammar {
5049
<quantifier=p5quantifier>
5150
<.panic: "quantifier quantifies nothing">
5251
}
53-
token p5metachar:sym<bs> { <sym> <backslash=p5backslash> }
52+
token p5metachar:sym<bs> { \\ <backslash=p5backslash> }
5453
token p5metachar:sym<.> { <sym> }
5554
token p5metachar:sym<^> { <sym> }
5655
token p5metachar:sym<$> {
@@ -77,7 +76,11 @@ grammar QRegex::P5Regex::Grammar is HLL::Grammar {
7776
}
7877

7978
proto token p5backslash { <...> }
79+
80+
token p5backslash:sym<b> { $<sym>=[<[bB]>] }
81+
token p5backslash:sym<s> { $<sym>=[<[dDnNsSwW]>] }
8082
token p5backslash:sym<misc> { \W }
83+
token p5backslash:sym<oops> { <.panic: "Unrecognized Perl 5 regex backslash sequence"> }
8184

8285
proto token p5assertion { <...> }
8386

@@ -142,8 +145,6 @@ grammar QRegex::P5Regex::Grammar is HLL::Grammar {
142145
}
143146

144147
proto token backslash { <...> }
145-
token backslash:sym<s> { $<sym>=[<[dDnNsSwW]>] }
146-
token backslash:sym<b> { $<sym>=[<[bB]>] }
147148
token backslash:sym<e> { $<sym>=[<[eE]>] }
148149
token backslash:sym<f> { $<sym>=[<[fF]>] }
149150
token backslash:sym<h> { $<sym>=[<[hH]>] }
@@ -158,13 +159,11 @@ grammar QRegex::P5Regex::Grammar is HLL::Grammar {
158159
token backslash:sym<Z> { 'Z' <.obs: '\\Z as end-of-string matcher', '\\n?$'> }
159160
token backslash:sym<Q> { 'Q' <.obs: '\\Q as quotemeta', 'quotes or literal variable match'> }
160161
token backslash:sym<unrec> { {} \w <.panic: 'Unrecognized backslash sequence'> }
161-
token backslash:sym<misc> { \W }
162162

163163
proto token assertion { <...> }
164164

165165
token assertion:sym<?> { '?' [ <?before '>' > | <assertion> ] }
166166
token assertion:sym<!> { '!' [ <?before '>' > | <assertion> ] }
167-
token assertion:sym<|> { '|' <identifier> }
168167

169168
token assertion:sym<method> {
170169
'.' <assertion>

0 commit comments

Comments
 (0)