Skip to content

Commit 4a1f1e2

Browse files
committed
Bring regex nibbler closer to STD.
Means we'll be able to support user-picked stoppers in Rakudo. Should also deal with some over-eager backtracking bugs leading to bad errors. No NQP test regressions with this, but may well bust non-Q Rakudo, so in a branch for now.
1 parent 579f3d0 commit 4a1f1e2

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/NQP/Grammar.pm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,10 @@ grammar NQP::Grammar is HLL::Grammar {
784784
}
785785

786786
grammar NQP::Regex is QRegex::P6Regex::Grammar {
787+
token rxstopper {
788+
<[ } / ]>
789+
}
790+
787791
token metachar:sym<:my> {
788792
':' <?before 'my'> <statement=.LANG('MAIN', 'statement')> <.ws> ';'
789793
}

src/QRegex/P6Regex/Grammar.nqp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,25 @@ grammar QRegex::P6Regex::Grammar is HLL::Grammar {
7474
for $OLDRX { %*RX{$_.key} := $_.value; }
7575
}
7676
[ <.ws> ['||'|'|'|'&&'|'&'] ]?
77-
<termaltseq>
77+
<termaltseq> <.ws>
78+
[
79+
|| <?infixstopper>
80+
|| $$ <.panic: "Regex not terminated">
81+
|| (\W) { $/.CURSOR.panic("Unrecognized regex metacharacter " ~ $/[0].Str ~ " (must be quoted to match literally)") }
82+
|| <.panic: "Regex not terminated">
83+
]
7884
}
85+
86+
regex infixstopper {
87+
:dba('infix stopper')
88+
[
89+
| <?before <[\) \} \]]> >
90+
| <?before '>' <-[>]> >
91+
| <?before <rxstopper> >
92+
]
93+
}
94+
95+
token rxstopper { $ }
7996

8097
token termaltseq {
8198
<termconjseq>

0 commit comments

Comments
 (0)