Skip to content

Commit

Permalink
TASK: Turn abstract Matcher class into interface
Browse files Browse the repository at this point in the history
...and move the (rule -> matcher) cache concern over to the Scanner
class.
  • Loading branch information
grebaldi committed Aug 18, 2023
1 parent f7e3382 commit 9b1d34d
Show file tree
Hide file tree
Showing 13 changed files with 219 additions and 226 deletions.
4 changes: 2 additions & 2 deletions src/Language/Lexer/Matcher/Characters/Characters.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
namespace PackageFactory\ComponentEngine\Language\Lexer\Matcher\Characters;

use PackageFactory\ComponentEngine\Language\Lexer\Matcher\Result;
use PackageFactory\ComponentEngine\Language\Lexer\Matcher\Matcher;
use PackageFactory\ComponentEngine\Language\Lexer\Matcher\MatcherInterface;

final class Characters extends Matcher
final class Characters implements MatcherInterface
{
public function __construct(
private readonly string $allowedCharacters,
Expand Down
4 changes: 2 additions & 2 deletions src/Language/Lexer/Matcher/Exact/Exact.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
namespace PackageFactory\ComponentEngine\Language\Lexer\Matcher\Exact;

use PackageFactory\ComponentEngine\Language\Lexer\Matcher\Result;
use PackageFactory\ComponentEngine\Language\Lexer\Matcher\Matcher;
use PackageFactory\ComponentEngine\Language\Lexer\Matcher\MatcherInterface;

final class Exact extends Matcher
final class Exact implements MatcherInterface
{
private int $length;

Expand Down
6 changes: 3 additions & 3 deletions src/Language/Lexer/Matcher/Fixed/Fixed.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
namespace PackageFactory\ComponentEngine\Language\Lexer\Matcher\Fixed;

use PackageFactory\ComponentEngine\Language\Lexer\Matcher\Result;
use PackageFactory\ComponentEngine\Language\Lexer\Matcher\Matcher;
use PackageFactory\ComponentEngine\Language\Lexer\Matcher\MatcherInterface;

final class Fixed extends Matcher
final class Fixed implements MatcherInterface
{
public function __construct(
private readonly int $fixedLength,
private readonly Matcher $innerMatcher
private readonly MatcherInterface $innerMatcher
) {
assert($this->fixedLength > 0);
}
Expand Down
190 changes: 0 additions & 190 deletions src/Language/Lexer/Matcher/Matcher.php

This file was deleted.

28 changes: 28 additions & 0 deletions src/Language/Lexer/Matcher/MatcherInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

/**
* PackageFactory.ComponentEngine - Universal View Components for PHP
* Copyright (C) 2023 Contributors of PackageFactory.ComponentEngine
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

declare(strict_types=1);

namespace PackageFactory\ComponentEngine\Language\Lexer\Matcher;

interface MatcherInterface
{
public function match(?string $character, int $offset): Result;
}
6 changes: 3 additions & 3 deletions src/Language/Lexer/Matcher/Not/Not.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
namespace PackageFactory\ComponentEngine\Language\Lexer\Matcher\Not;

use PackageFactory\ComponentEngine\Language\Lexer\Matcher\Result;
use PackageFactory\ComponentEngine\Language\Lexer\Matcher\Matcher;
use PackageFactory\ComponentEngine\Language\Lexer\Matcher\MatcherInterface;

final class Not extends Matcher
final class Not implements MatcherInterface
{
public function __construct(private readonly Matcher $innerMatcher)
public function __construct(private readonly MatcherInterface $innerMatcher)
{
}

Expand Down
6 changes: 3 additions & 3 deletions src/Language/Lexer/Matcher/Optional/Optional.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
namespace PackageFactory\ComponentEngine\Language\Lexer\Matcher\Optional;

use PackageFactory\ComponentEngine\Language\Lexer\Matcher\Result;
use PackageFactory\ComponentEngine\Language\Lexer\Matcher\Matcher;
use PackageFactory\ComponentEngine\Language\Lexer\Matcher\MatcherInterface;

final class Optional extends Matcher
final class Optional implements MatcherInterface
{
public function __construct(private readonly Matcher $innerMatcher)
public function __construct(private readonly MatcherInterface $innerMatcher)
{
}

Expand Down
8 changes: 4 additions & 4 deletions src/Language/Lexer/Matcher/Sequence/Sequence.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@
namespace PackageFactory\ComponentEngine\Language\Lexer\Matcher\Sequence;

use PackageFactory\ComponentEngine\Language\Lexer\Matcher\Result;
use PackageFactory\ComponentEngine\Language\Lexer\Matcher\Matcher;
use PackageFactory\ComponentEngine\Language\Lexer\Matcher\MatcherInterface;

final class Sequence extends Matcher
final class Sequence implements MatcherInterface
{
private int $lastStop = 0;
private int $matcherIndex = 0;
private int $numberOfMatchers;

/**
* @var Matcher[]
* @var MatcherInterface[]
*/
private readonly array $matchers;

public function __construct(Matcher ...$matchers)
public function __construct(MatcherInterface ...$matchers)
{
$this->matchers = $matchers;
$this->numberOfMatchers = count($matchers);
Expand Down
Loading

0 comments on commit 9b1d34d

Please sign in to comment.