From 4a02e07efe8d7be48fcd09ef543546eab1289223 Mon Sep 17 00:00:00 2001 From: Dustin Wilson Date: Fri, 11 Jun 2021 22:23:58 -0500 Subject: [PATCH] Fixed minor scope parsing bug --- lib/Scope/Matcher.php | 6 +----- lib/Scope/Matchers/GroupMatcher.php | 2 +- lib/Scope/Matchers/NegateMatcher.php | 2 +- lib/Scope/Matchers/ScopeMatcher.php | 2 +- lib/Scope/Matchers/SegmentMatcher.php | 4 ++++ lib/Scope/Matchers/TrueMatcher.php | 4 ++++ lib/Scope/Parser.php | 5 +++++ 7 files changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/Scope/Matcher.php b/lib/Scope/Matcher.php index be1eee5..de2d285 100644 --- a/lib/Scope/Matcher.php +++ b/lib/Scope/Matcher.php @@ -6,8 +6,4 @@ declare(strict_types=1); namespace dW\Highlighter\Scope; -abstract class Matcher { - public function getPrefix(string $scope): string|null|false { - return null; - } -} \ No newline at end of file +abstract class Matcher {} \ No newline at end of file diff --git a/lib/Scope/Matchers/GroupMatcher.php b/lib/Scope/Matchers/GroupMatcher.php index c9a622d..c00b2b2 100644 --- a/lib/Scope/Matchers/GroupMatcher.php +++ b/lib/Scope/Matchers/GroupMatcher.php @@ -16,7 +16,7 @@ class GroupMatcher extends Matcher { } public function matches(array $scopes): bool { - return $this->selector->matches($scope); + return $this->selector->matches($scopes); } public function getPrefix(array $scopes): string|null|false { diff --git a/lib/Scope/Matchers/NegateMatcher.php b/lib/Scope/Matchers/NegateMatcher.php index 2c8fefd..d478054 100644 --- a/lib/Scope/Matchers/NegateMatcher.php +++ b/lib/Scope/Matchers/NegateMatcher.php @@ -17,7 +17,7 @@ class NegateMatcher extends Matcher { return !($this->matcher->matches($scopes)); } - public function getPrefix(array $scopes): null { + public function getPrefix(array $scopes) { return null; } } diff --git a/lib/Scope/Matchers/ScopeMatcher.php b/lib/Scope/Matchers/ScopeMatcher.php index e1284b3..c5c7d80 100644 --- a/lib/Scope/Matchers/ScopeMatcher.php +++ b/lib/Scope/Matchers/ScopeMatcher.php @@ -17,7 +17,7 @@ class ScopeMatcher extends Matcher { $lastDotIndex = 0; $scopeLen = strlen($scope); foreach ($this->segments as $index => $segment) { - if ($lastIndex > $scopeLen) { + if ($lastDotIndex > $scopeLen) { break; } diff --git a/lib/Scope/Matchers/SegmentMatcher.php b/lib/Scope/Matchers/SegmentMatcher.php index 723668d..cf32a32 100644 --- a/lib/Scope/Matchers/SegmentMatcher.php +++ b/lib/Scope/Matchers/SegmentMatcher.php @@ -16,4 +16,8 @@ class SegmentMatcher extends Matcher { public function matches(string $scope): bool { return ($scope === $this->segment); } + + public function getPrefix(string $scope): string|null|false { + return null; + } } diff --git a/lib/Scope/Matchers/TrueMatcher.php b/lib/Scope/Matchers/TrueMatcher.php index 2c94c9d..e5228d3 100644 --- a/lib/Scope/Matchers/TrueMatcher.php +++ b/lib/Scope/Matchers/TrueMatcher.php @@ -16,4 +16,8 @@ class TrueMatcher extends Matcher { public function matches(string $scope): bool { return true; } + + public function getPrefix(string $scope): string|null|false { + return null; + } } diff --git a/lib/Scope/Parser.php b/lib/Scope/Parser.php index dc63731..0d60946 100644 --- a/lib/Scope/Parser.php +++ b/lib/Scope/Parser.php @@ -131,6 +131,7 @@ class Parser { $result = false; $prefix = null; + $position = self::$instance->data->position; $s2 = self::$instance->data->consumeIf('LRB'); if ($s2 === '' || $s2 === false) { @@ -167,6 +168,10 @@ class Parser { self::fail('('); } + if ($result === false) { + self::$instance->data->unconsumeTo($position); + } + if (self::$debug === true) { self::debugResult($result); }