TextMate-style syntax highlighting in PHP
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

37 lines
1016 B

<?php
/** @license MIT
* Copyright 2021 Dustin Wilson et al.
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace dW\Highlighter\Scope;
class PathMatcher extends Matcher {
protected string|null $prefix;
protected array $matchers;
public function __construct(string|null $prefix, Matcher ...$matchers) {
$this->prefix = ($prefix !== null) ? $prefix[0] : null;
$this->matchers = $matchers;
}
public function matches(string ...$scopes): bool {
$count = 0;
$matcher = $this->matchers[$count];
foreach ($scopes as $scope) {
if ($matcher->matches($scope)) {
$matcher = $this->matchers[++$count] ?? null;
}
if ($matcher === null) {
return true;
}
}
return false;
}
public function getPrefix(string ...$scopes): string|null|false {
if ($this->matches($scopes)) {
return $this->prefix;
}
}
}