in reply to When would I want to use possessive quantifiers?
Suppose you want to parse something like Perl code, and you see
from /foo/
First you'd match an identifier, say with \w+, and then a regex. However if that parsing fails (for example because there's another line, and no semicolon), then instead of giving up, \w+ starts matching fro, and the regex parsing code matches m /foo/ (which is a valid regex too).
This is both slower than failing outright, and can lead to misparses in some situations. So you'd really want to match an identifier as \w++ instead of just \w+
The standard Perl 6 grammar uses Perl 6 regexes to parse Perl 6. Every time you see a token or a rule, it's a non-backtracking regex.
There backtracking control is crucial for getting good parse error messages, and for speed.
|
|---|