On Thu, Jun 20, 2002 at 11:19:28AM +0200, Marcel Gruenauer wrote:
> So it's really p5p or macosx-perl that need to be informed.
Apart from that, I've been playing around with the offending regex and
came up with something that seems to be faster and produces the same
results. That is, it passes 'make test'. However, it uses zero-width
negative lookbehind, so it may not work with earlier perls (when was
it introduced?)
The regex is in Template::Parser, starting around line 450. That's the
tokeniser that produces a list of tokens of various types. The part that
gives OS X perl grief is (sans comments)
(["'])((?:\\\\|\\\1|.|\n)*?)\2
This is the part that matches quoted strings.
Instead, I propose
(["'])((?:.|\n)*?)(?<!(?<!\\)\\)\2
which basically says match a single or double quote non-greedily up to
the next quote of the same type, but only if that quote isn't preceded
by a single backslash. Double backslashes are ok, though.
So here's a diff:
diff -ruN Template-Toolkit-2.07.orig/lib/Template/Parser.pm
Template-Toolkit-2.07/lib/Template/Parser.pm
--- Template-Toolkit-2.07.orig/lib/Template/Parser.pm Wed Apr 17 16:17:59 2002
+++ Template-Toolkit-2.07/lib/Template/Parser.pm Thu Jun 20 13:25:09 2002
@@ -459,15 +459,13 @@
(["']) # $2 - opening quote, " or '
( # $3 - quoted text buffer
(?: # repeat group (no backreference)
- \\\\ # an escaped backslash \\
- | # ...or...
- \\\2 # an escaped quote \" or \' (match $1)
- | # ...or...
- . # any other character
+ . # any character
| \n
)*? # non-greedy repeat
) # end of $3
- \2 # match opening quote
+ (?<!(?<!\\)\\) # match opening quote not preceded
+ \2 # by a single backslash (a double
+ # doesn't end the quote)
|
# an unquoted number matches in $4
(-?\d+(?:\.\d+)?) # numbers
One thing that has just occurred to me is what happens if there are three
or more backslashes? It will see more than two and refuse to recognise
the end quote. whereas it would really have to check for an odd number
of backslashes, wouldn't it?
Marcel
--
We are Perl. Your table will be assimilated. Your waiter will adapt to
service us. Surrender your beer. Resistance is futile.
-- London.pm strategy aka "embrace and extend" aka "mark and sweep"