Skip to content
Browse files

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.
  • Loading branch information...
1 parent 579f3d0 commit 4a1f1e225954d41e1043c93a3da2dd3b1a590cf5 @jnthn jnthn committed Nov 1, 2012
Showing with 22 additions and 1 deletion.
  1. +4 −0 src/NQP/Grammar.pm
  2. +18 −1 src/QRegex/P6Regex/Grammar.nqp
View
4 src/NQP/Grammar.pm
@@ -784,6 +784,10 @@ grammar NQP::Grammar is HLL::Grammar {
}
grammar NQP::Regex is QRegex::P6Regex::Grammar {
+ token rxstopper {
+ <[ } / ]>
+ }
+
token metachar:sym<:my> {
':' <?before 'my'> <statement=.LANG('MAIN', 'statement')> <.ws> ';'
}
View
19 src/QRegex/P6Regex/Grammar.nqp
@@ -74,8 +74,25 @@ grammar QRegex::P6Regex::Grammar is HLL::Grammar {
for $OLDRX { %*RX{$_.key} := $_.value; }
}
[ <.ws> ['||'|'|'|'&&'|'&'] ]?
- <termaltseq>
+ <termaltseq> <.ws>
+ [
+ || <?infixstopper>
+ || $$ <.panic: "Regex not terminated">
+ || (\W) { $/.CURSOR.panic("Unrecognized regex metacharacter " ~ $/[0].Str ~ " (must be quoted to match literally)") }
+ || <.panic: "Regex not terminated">
+ ]
}
+
+ regex infixstopper {
+ :dba('infix stopper')
+ [
+ | <?before <[\) \} \]]> >
+ | <?before '>' <-[>]> >
+ | <?before <rxstopper> >
+ ]
+ }
+
+ token rxstopper { $ }
token termaltseq {
<termconjseq>

0 comments on commit 4a1f1e2

Please sign in to comment.
Something went wrong with that request. Please try again.