Skip to content
Snippets Groups Projects
Commit ff8e5c09 authored by stephane.chazelas's avatar stephane.chazelas
Browse files

parenthesis_escaper_fix

darcs-hash:20080104145301-3d17c-6ba186de4a2661f7d4f6b080e4cf74fed9ae1904.gz
parent 64daa86a
No related branches found
Tags develsnap_2008-01-01
No related merge requests found
...@@ -138,60 +138,49 @@ class Doku_LexerParallelRegex { ...@@ -138,60 +138,49 @@ class Doku_LexerParallelRegex {
$cnt = count($this->_patterns); $cnt = count($this->_patterns);
for ($i = 0; $i < $cnt; $i++) { for ($i = 0; $i < $cnt; $i++) {
// Replace lookaheads / lookbehinds with marker /*
$m = "\1\1"; * decompose the input pattern into "(", "(?", ")",
$pattern = preg_replace( * "[...]", "[]..]", "[^]..]", "[...[:...:]..]", "\x"...
array ( * elements.
'/\(\?(i|m|s|x|U)\)/U', */
'/\(\?(\-[i|m|s|x|U])\)/U', preg_match_all('/\\\\.|' .
'/\(\?\=(.*)\)/sU', '\(\?|' .
'/\(\?\!(.*)\)/sU', '[()]|' .
'/\(\?\<\=(.*)\)/sU', '\[\^?\]?(?:\\\\.|\[:[^]]*:\]|[^]\\\\])*\]|' .
'/\(\?\<\!(.*)\)/sU', '[^[()\\\\]+/', $this->_patterns[$i], $elts);
'/\(\?\:(.*)\)/sU',
), $pattern = "";
array ( $level = 0;
$m.'SO:\\1'.$m,
$m.'SOR:\\1'.$m, foreach ($elts[0] as $elt) {
$m.'LA:IS:\\1'.$m, /*
$m.'LA:NOT:\\1'.$m, * for "(", ")" remember the nesting level, add "\"
$m.'LB:IS:\\1'.$m, * only to the non-"(?" ones.
$m.'LB:NOT:\\1'.$m, */
$m.'GRP:\\1'.$m,
), switch($elt) {
$this->_patterns[$i] case '(':
); $pattern .= '\(';
// Quote the rest break;
$pattern = str_replace( case ')':
array('/', '(', ')'), if ($level > 0)
array('\/', '\(', '\)'), $level--; /* closing (? */
$pattern else
); $pattern .= '\\';
$pattern .= ')';
// Restore lookaheads / lookbehinds break;
$pattern = preg_replace( case '(?':
array ( $level++;
'/'.$m.'SO:(.{1})'.$m.'/', $pattern .= '(?';
'/'.$m.'SOR:(.{2})'.$m.'/', break;
'/'.$m.'LA:IS:(.*)'.$m.'/sU', default:
'/'.$m.'LA:NOT:(.*)'.$m.'/sU', if (substr($elt, 0, 1) == '\\')
'/'.$m.'LB:IS:(.*)'.$m.'/sU', $pattern .= $elt;
'/'.$m.'LB:NOT:(.*)'.$m.'/sU', else
'/'.$m.'GRP:(.*)'.$m.'/sU', $pattern .= str_replace('/', '\/', $elt);
), }
array ( }
'(?\\1)', $this->_patterns[$i] = "($pattern)";
'(?\\1)',
'(?=\\1)',
'(?!\\1)',
'(?<=\\1)',
'(?<!\\1)',
'(?:\\1)',
),
$pattern
);
$this->_patterns[$i] = '('.$pattern.')';
} }
$this->_regex = "/" . implode("|", $this->_patterns) . "/" . $this->_getPerlMatchingFlags(); $this->_regex = "/" . implode("|", $this->_patterns) . "/" . $this->_getPerlMatchingFlags();
} }
...@@ -591,4 +580,4 @@ function Doku_Lexer_Escape($str) { ...@@ -591,4 +580,4 @@ function Doku_Lexer_Escape($str) {
return preg_replace($chars, $escaped, $str); return preg_replace($chars, $escaped, $str);
} }
//Setup VIM: ex: et ts=4 enc=utf-8 : //Setup VIM: ex: et ts=4 sw=4 enc=utf-8 :
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment