diff options
Diffstat (limited to 'inc/Parsing/Lexer')
-rw-r--r-- | inc/Parsing/Lexer/Lexer.php | 25 | ||||
-rw-r--r-- | inc/Parsing/Lexer/ParallelRegex.php | 15 | ||||
-rw-r--r-- | inc/Parsing/Lexer/StateStack.php | 4 |
3 files changed, 20 insertions, 24 deletions
diff --git a/inc/Parsing/Lexer/Lexer.php b/inc/Parsing/Lexer/Lexer.php index 20040938e..cf0a2138c 100644 --- a/inc/Parsing/Lexer/Lexer.php +++ b/inc/Parsing/Lexer/Lexer.php @@ -18,13 +18,13 @@ namespace dokuwiki\Parsing\Lexer; class Lexer { /** @var ParallelRegex[] */ - protected $regexes; + protected $regexes = []; /** @var \Doku_Handler */ protected $handler; /** @var StateStack */ protected $modeStack; /** @var array mode "rewrites" */ - protected $mode_handlers; + protected $mode_handlers = []; /** @var bool case sensitive? */ protected $case; @@ -38,10 +38,8 @@ class Lexer public function __construct($handler, $start = "accept", $case = false) { $this->case = $case; - $this->regexes = array(); $this->handler = $handler; $this->modeStack = new StateStack($start); - $this->mode_handlers = array(); } /** @@ -141,13 +139,13 @@ class Lexer $length = $initialLength; $pos = 0; while (is_array($parsed = $this->reduce($raw))) { - list($unmatched, $matched, $mode) = $parsed; + [$unmatched, $matched, $mode] = $parsed; $currentLength = strlen($raw); $matchPos = $initialLength - $currentLength - strlen($matched); if (! $this->dispatchTokens($unmatched, $matched, $mode, $pos, $matchPos)) { return false; } - if ($currentLength == $length) { + if ($currentLength === $length) { return false; } $length = $currentLength; @@ -266,7 +264,7 @@ class Lexer // modes starting with plugin_ are all handled by the same // handler but with an additional parameter if (substr($handler, 0, 7)=='plugin_') { - list($handler,$plugin) = sexplode('_', $handler, 2, ''); + [$handler, $plugin] = sexplode('_', $handler, 2, ''); return $this->handler->$handler($content, $is_match, $pos, $plugin); } @@ -291,8 +289,8 @@ class Lexer return true; } if ($action = $this->regexes[$this->modeStack->getCurrent()]->split($raw, $split)) { - list($unparsed, $match, $raw) = $split; - return array($unparsed, $match, $action); + [$unparsed, $match, $raw] = $split; + return [$unparsed, $match, $action]; } return true; } @@ -305,7 +303,7 @@ class Lexer */ public static function escape($str) { - $chars = array( + $chars = [ '/\\\\/', '/\./', '/\+/', @@ -323,9 +321,9 @@ class Lexer '/\>/', '/\|/', '/\:/' - ); + ]; - $escaped = array( + $escaped = [ '\\\\\\\\', '\.', '\+', @@ -343,7 +341,8 @@ class Lexer '\>', '\|', '\:' - ); + ]; + return preg_replace($chars, $escaped, $str); } } diff --git a/inc/Parsing/Lexer/ParallelRegex.php b/inc/Parsing/Lexer/ParallelRegex.php index bf1979950..cc47c2e9b 100644 --- a/inc/Parsing/Lexer/ParallelRegex.php +++ b/inc/Parsing/Lexer/ParallelRegex.php @@ -17,9 +17,9 @@ namespace dokuwiki\Parsing\Lexer; class ParallelRegex { /** @var string[] patterns to match */ - protected $patterns; + protected $patterns = []; /** @var string[] labels for above patterns */ - protected $labels; + protected $labels = []; /** @var string the compound regex matching all patterns */ protected $regex; /** @var bool case sensitive matching? */ @@ -34,9 +34,6 @@ class ParallelRegex public function __construct($case) { $this->case = $case; - $this->patterns = array(); - $this->labels = array(); - $this->regex = null; } /** @@ -121,15 +118,15 @@ class ParallelRegex } } - $split = array($subject, "", ""); + $split = [$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); + [$pre, $post] = preg_split($this->patterns[$idx].$this->getPerlMatchingFlags(), $subject, 2); + $split = [$pre, $matches[0], $post]; - return isset($this->labels[$idx]) ? $this->labels[$idx] : true; + return $this->labels[$idx] ?? true; } /** diff --git a/inc/Parsing/Lexer/StateStack.php b/inc/Parsing/Lexer/StateStack.php index 325412bb4..5ec065967 100644 --- a/inc/Parsing/Lexer/StateStack.php +++ b/inc/Parsing/Lexer/StateStack.php @@ -22,7 +22,7 @@ class StateStack */ public function __construct($start) { - $this->stack = array($start); + $this->stack = [$start]; } /** @@ -41,7 +41,7 @@ class StateStack */ public function enter($state) { - array_push($this->stack, $state); + $this->stack[] = $state; } /** |