optimized macro parser for perl 5.10

This commit is contained in:
Graham Knop 2010-02-05 18:06:31 -06:00
parent a8e7ec090b
commit 1c27279d6b
2 changed files with 46 additions and 18 deletions

View file

@ -1,4 +1,5 @@
7.9.0 7.9.0
- added: Optimized macro parser for perl 5.10
7.8.13 7.8.13
- fixed #11418: confusing typ-o in gotcha - fixed #11418: confusing typ-o in gotcha

View file

@ -42,25 +42,52 @@ These functions are available from this package:
=cut =cut
#------------------------------------------------------------------- #-------------------------------------------------------------------
my $parenthesis; my $macro_re;
$parenthesis = qr{ BEGIN {
\( # Start with '(', if ( eval { require 5.010 } ) {
(?: # Followed by $macro_re = eval <<'END_REGEX';
(?>\\[()]) # Escaped parenthesis qr{
| # or ( # capture #1 - entire macro call
(?>[^()]) # Non-parenthesis \^ # start with carat
| # or ([-a-zA-Z0-9_@#/*]{1,64}) # capture #2 - macro name
(??{ $parenthesis }) # a balanced parenthesis block ( # capture #3 - parenthesis
)* # zero or more times \( # start with open parenthesis
\) # Ending with ')' (?: # followed by
}x; (?> [^()] ) # non-parenthesis
| # or
(?>\\[()]) # Escaped parenthesis
| # or
(?3) # a balanced parenthesis block (recursive)
)* # zero or more times
\) # ending with closing parenthesis
)?
; # End with a semicolon.
)
}msx;
END_REGEX
}
else {
my $parenthesis;
$parenthesis = qr{
\( # Start with '(',
(?: # Followed by
(?>\\[()]) # Escaped parenthesis
| # or
(?>[^()]) # Non-parenthesis
| # or
(??{ $parenthesis }) # a balanced parenthesis block
)* # zero or more times
\) # Ending with ')'
}x;
my $macro_re = qr{ $macro_re = qr{
(\^ # Start with carat (\^ # Start with carat
([-a-zA-Z0-9_@#/*]{1,64}) # And one or more non-macro characters -tagged- ([-a-zA-Z0-9_@#/*]{1,64}) # And one or more non-macro characters -tagged-
((??{ $parenthesis })?) # a balanced parenthesis block ((??{ $parenthesis })?) # a balanced parenthesis block
;) # End with a semicolon. ;) # End with a semicolon.
}msx; }msx;
}
}
=head2 filter ( html ) =head2 filter ( html )