summaryrefslogtreecommitdiff
path: root/inc/parser
diff options
context:
space:
mode:
authorchris <chris@jalakai.co.uk>2005-09-16 13:32:59 +0200
committerchris <chris@jalakai.co.uk>2005-09-16 13:32:59 +0200
commit032d6fd665158f6a7f048a07d44d7694b6704cea (patch)
tree9ccfd462896da259bf18286394e04a039ebe29a5 /inc/parser
parenta152721bf2269fb9e52a14248dcb53ff9a6217cf (diff)
downloadrpg-032d6fd665158f6a7f048a07d44d7694b6704cea.tar.gz
rpg-032d6fd665158f6a7f048a07d44d7694b6704cea.tar.bz2
lexer fix, corrects pattern match locating issues for patterns with look-ahead/look-behind assertions (e.g. acronyms per bug#538)
darcs-hash:20050916113259-9b6ab-47b502b4c7410d17229923d03c30ace76b7b1853.gz
Diffstat (limited to 'inc/parser')
-rw-r--r--inc/parser/lexer.php35
1 files changed, 30 insertions, 5 deletions
diff --git a/inc/parser/lexer.php b/inc/parser/lexer.php
index cc87df31a..394eae3f6 100644
--- a/inc/parser/lexer.php
+++ b/inc/parser/lexer.php
@@ -98,6 +98,34 @@ class Doku_LexerParallelRegex {
}
/**
+ * Attempts to split the string against all patterns at once
+ *
+ * @param string $subject String to match against.
+ * @param array $split The split result: array containing, pre-match, match & post-match strings
+ * @return boolean True on success.
+ * @access public
+ *
+ * @author Christopher Smith <chris@jalakai.co.uk>
+ */
+ function split($subject, &$split) {
+ if (count($this->_patterns) == 0) {
+ return false;
+ }
+
+ if (! preg_match($this->_getCompoundedRegex(), $subject, $matches)) {
+ $split = array($subject, "", "");
+ return false;
+ }
+
+ $idx = count($matches)-2;
+
+ list($pre, $post) = preg_split($this->_patterns[$idx].$this->_getPerlMatchingFlags(), $subject, 2);
+
+ $split = array($pre, $matches[0], $post);
+ return isset($this->_labels[$idx]) ? $this->_labels[$idx] : true;
+ }
+
+ /**
* Compounds the patterns into a single
* regular expression separated with the
* "or" operator. Caches the regex.
@@ -505,10 +533,8 @@ class Doku_Lexer {
if ($raw === "") {
return true;
}
- if ($action = $this->_regexes[$this->_mode->getCurrent()]->match($raw, $match)) {
- $unparsed_character_count = strpos($raw, $match);
- $unparsed = substr($raw, 0, $unparsed_character_count);
- $raw = substr($raw, $unparsed_character_count + strlen($match));
+ if ($action = $this->_regexes[$this->_mode->getCurrent()]->split($raw, $split)) {
+ list($unparsed, $match, $raw) = $split;
return array($unparsed, $match, $action);
}
return true;
@@ -563,5 +589,4 @@ function Doku_Lexer_Escape($str) {
return preg_replace($chars, $escaped, $str);
}
-
//Setup VIM: ex: et ts=4 enc=utf-8 :