File tree Expand file tree Collapse file tree 1 file changed +20
-5
lines changed Expand file tree Collapse file tree 1 file changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -2550,15 +2550,30 @@ grammar Regex is STD {
2550
2550
# "normal" metachars
2551
2551
2552
2552
token p5metachar :sym <[ ] > {
2553
+ # Unix-style character classes are quite metafiddly. Don't blame me.
2553
2554
'[' { } $ < neg > = [ '^' ]?
2555
+ [
2554
2556
$ < cclass > = [
2555
2557
[
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 ']' >
2560
2574
]
2561
- ']'
2575
+ ]
2576
+ ']' || <.panic : "Unable to parse character class; couldn't find final ']'" >
2562
2577
}
2563
2578
2564
2579
proto token p5ccback {* }
You can’t perform that action at this time.
0 commit comments