Skip to content

Commit bc80c8f

Browse files
committed
improve error on range with backslash cclass
1 parent 1434468 commit bc80c8f

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

STD_P5.pm6

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2550,15 +2550,30 @@ grammar Regex is STD {
25502550
# "normal" metachars
25512551

25522552
token p5metachar:sym<[ ]> {
2553+
# Unix-style character classes are quite metafiddly. Don't blame me.
25532554
'[' {} $<neg> = [ '^' ]?
2555+
[
25542556
$<cclass> = [
25552557
[
2556-
[ \\ <p5ccback> || . ]
2557-
[ '-' [ \\ <p5ccback> || . ]]?
2558-
]+?
2559-
[<?before ']'> || '-' <?before ']'>]
2558+
$<ccelem>=[
2559+
[ \\ <p5ccback> || . ]
2560+
[ '-' [ \\ <p5ccback> || <-[ \] ]> ]]?
2561+
]
2562+
{
2563+
given $<ccelem>.Str {
2564+
if /\-/ {
2565+
for split('-', $_) {
2566+
if /\\(d|w|s|D|W|S)/ {
2567+
.panic("Illegal use of $_ in range");
2568+
}
2569+
}
2570+
}
2571+
}
2572+
}
2573+
]+? <?before ']'>
25602574
]
2561-
']'
2575+
]
2576+
']' || <.panic: "Unable to parse character class; couldn't find final ']'">
25622577
}
25632578

25642579
proto token p5ccback {*}

0 commit comments

Comments
 (0)