From ea7247ddd3818520915b0b11d79c5baca500bfee Mon Sep 17 00:00:00 2001 From: Alexander Lisachenko Date: Sun, 18 Feb 2024 12:17:29 +0200 Subject: [PATCH 01/28] Fork package to the goaop organization to keep all dependencies under control --- composer.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index eddf129..2654e06 100644 --- a/composer.json +++ b/composer.json @@ -1,9 +1,9 @@ { - "name": "walterwoshid/dissect", - "description": "A set of tools for lexical and syntactical analysis written in pure PHP - Fork by WalterWoshid", + "name": "goaop/dissect", + "description": "A set of tools for lexical and syntactical analysis written in pure PHP", "version": "2.0.0", "type": "library", - "homepage": "https://github.com/jakubledl/dissect", + "homepage": "https://github.com/goaop/dissect", "license": "MIT", "authors": [ { @@ -32,7 +32,7 @@ "test-coverage": "phpunit --coverage-html tests/coverage" }, "require": { - "php": ">=8.0" + "php": "^8.2.0" }, "require-dev": { "symfony/console": ">=6.0", From 8d2a3c7372e2a7de14342bfd2dcf16a15b8cc2df Mon Sep 17 00:00:00 2001 From: Alexander Lisachenko Date: Sun, 18 Feb 2024 12:18:10 +0200 Subject: [PATCH 02/28] Migrate phpunit configuration to newer scheme --- phpunit.xml | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index 747b9e0..33dcfdb 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,19 +1,13 @@ - + tests/ - - + src/ - + From 181edd0cd6bc2c6ff032b6c5b1bdcc66f78aefea Mon Sep 17 00:00:00 2001 From: Alexander Lisachenko Date: Sun, 18 Feb 2024 12:26:38 +0200 Subject: [PATCH 03/28] Remove deprecated utf8_decode() call https://php.watch/versions/8.2/utf8_encode-utf8_decode-deprecated --- src/Dissect/Util/Util.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Dissect/Util/Util.php b/src/Dissect/Util/Util.php index 1715bee..a28cfe4 100644 --- a/src/Dissect/Util/Util.php +++ b/src/Dissect/Util/Util.php @@ -43,7 +43,7 @@ public static function different(array $first, array $second): bool */ public static function stringLength(string $str): int { - return strlen(utf8_decode($str)); + return mb_strlen($str); } /** From 713e8f90bbe6e7dc1c43b6688ffed5b4a4da4390 Mon Sep 17 00:00:00 2001 From: Alexander Lisachenko Date: Sun, 18 Feb 2024 12:27:10 +0200 Subject: [PATCH 04/28] Updated Licene file --- LICENSE | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/LICENSE b/LICENSE index c715a84..965cc61 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,4 @@ -MIT License - -Copyright (c) 2023 Okapi +Copyright (c) 2024 Lisachenko Alexander Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 3ef4ffa8f01079bcb7794ff394261f987bcd85af Mon Sep 17 00:00:00 2001 From: Alexander Lisachenko Date: Sun, 18 Feb 2024 12:30:22 +0200 Subject: [PATCH 05/28] Bump to the version 3.0, add some meta --- composer.json | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 2654e06..ee442df 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "goaop/dissect", "description": "A set of tools for lexical and syntactical analysis written in pure PHP", - "version": "2.0.0", + "version": "3.0.0", "type": "library", "homepage": "https://github.com/goaop/dissect", "license": "MIT", @@ -36,7 +36,7 @@ }, "require-dev": { "symfony/console": ">=6.0", - "phpunit/phpunit": ">=9" + "phpunit/phpunit": "^11.0.3" }, "suggest": { "symfony/console": "for the command-line tool" @@ -54,5 +54,14 @@ "tests/" ] } + }, + "minimum-stability": "stable", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "config": { + "sort-packages": true } } From 8acd964b15b27b89bc8a0ff6274338a4c548e857 Mon Sep 17 00:00:00 2001 From: Alexander Lisachenko Date: Sun, 18 Feb 2024 12:39:45 +0200 Subject: [PATCH 06/28] Adjust README.md to general information --- README.md | 71 ++++++++++--------------------------------------------- 1 file changed, 13 insertions(+), 58 deletions(-) diff --git a/README.md b/README.md index ef05388..8c7dd93 100644 --- a/README.md +++ b/README.md @@ -1,67 +1,24 @@ - -

PHP Dissect

- - -

- - - License: MIT - - - - - Twitter: @WalterWoshid - - - - - PHP: >=8.0 - - - - - Packagist - - - - - - Build - -

- - -

- - - Coverage - PHP 8.0 - - - - - Coverage - PHP 8.1 - - - - - Coverage - PHP 8.2 - -

- -

Dissect is a set of tools for lexical and syntactical analysis written in pure PHP.

-

This library is forked from https://github.com/jakubledl/dissect

-
+Dissect +----------------- +This library is based on @jakubledl and @WalterWoshid work. +Dissect library provides a set of tools to create and use lexical parsers. Read more at /docs folder. +For the goaop/framework it is responsible for parsing pointcut DSL expressions into AST tree, which might be then +processed. + +[![Total Downloads](https://img.shields.io/packagist/dt/goaop/dissect.svg)](https://packagist.org/packages/goaop/dissect) +[![Daily Downloads](https://img.shields.io/packagist/dd/goaop/dissect.svg)](https://packagist.org/packages/goaop/dissect) +[![PHP Version](https://img.shields.io/badge/php-%3E%3D%208.2-8892BF.svg)](https://php.net/) +[![License](https://img.shields.io/packagist/l/goaop/dissect.svg)](https://packagist.org/packages/goaop/dissect) ## Installation ```bash -composer require walterwoshid/dissect +composer require goaop/dissect ``` - # Documentation? [Here](docs/index.md). @@ -81,8 +38,6 @@ composer require walterwoshid/dissect Give a ⭐ if this project helped you! - ## 📝 License -Copyright © 2023 [Valentin Wotschel](https://github.com/WalterWoshid).
-This project is [MIT](https://opensource.org/licenses/MIT) licensed. +This project is [MIT](https://opensource.org/licenses/MIT) licensed. \ No newline at end of file From b07bd44b30cab0986cc928d9013ba6b814487ce0 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sun, 18 Feb 2024 18:38:16 +0700 Subject: [PATCH 07/28] Use mb_convert_encoding() instead of utf8_decode() --- src/Dissect/Util/Util.php | 2 +- tests/Dissect/Lexer/StubLexer.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Dissect/Util/Util.php b/src/Dissect/Util/Util.php index a28cfe4..facd6d7 100644 --- a/src/Dissect/Util/Util.php +++ b/src/Dissect/Util/Util.php @@ -43,7 +43,7 @@ public static function different(array $first, array $second): bool */ public static function stringLength(string $str): int { - return mb_strlen($str); + return mb_strlen(mb_convert_encoding($str, 'ISO-8859-1')); } /** diff --git a/tests/Dissect/Lexer/StubLexer.php b/tests/Dissect/Lexer/StubLexer.php index 573c7f3..5843e43 100644 --- a/tests/Dissect/Lexer/StubLexer.php +++ b/tests/Dissect/Lexer/StubLexer.php @@ -6,7 +6,7 @@ class StubLexer extends AbstractLexer { protected function extractToken(string $string): ?Token { - if (strlen(utf8_decode($string)) === 0) { + if (strlen(mb_convert_encoding($string, 'ISO-8859-1')) === 0) { return null; } From d5994ff0099c2d628359576cc3a6d83b0ed980fb Mon Sep 17 00:00:00 2001 From: Alexander Lisachenko Date: Mon, 19 Feb 2024 23:07:05 +0200 Subject: [PATCH 08/28] Add rector as a dev-dependency to the project --- composer.json | 5 +++-- rector.php | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 rector.php diff --git a/composer.json b/composer.json index ee442df..02368fd 100644 --- a/composer.json +++ b/composer.json @@ -35,8 +35,9 @@ "php": "^8.2.0" }, "require-dev": { - "symfony/console": ">=6.0", - "phpunit/phpunit": "^11.0.3" + "phpunit/phpunit": "^11.0.3", + "rector/rector": "^1.0", + "symfony/console": ">=6.0" }, "suggest": { "symfony/console": "for the command-line tool" diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..e1178b7 --- /dev/null +++ b/rector.php @@ -0,0 +1,19 @@ +withPaths([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]) + // uncomment to reach your current PHP version + // ->withPhpSets() + ->withRules([ + // Dead-code + RemoveUselessVarTagRector::class, + //AddVoidReturnTypeWhereNoReturnRector::class, + ]); From d460a184b72e4a93821bf305511059bc23d88a03 Mon Sep 17 00:00:00 2001 From: Alexander Lisachenko Date: Mon, 19 Feb 2024 23:07:05 +0200 Subject: [PATCH 09/28] Apply the RemoveUselessVarTagRector rector --- src/Dissect/Lexer/AbstractLexer.php | 3 --- src/Dissect/Lexer/SimpleLexer.php | 3 --- src/Dissect/Lexer/TokenStream/ArrayTokenStream.php | 3 --- .../Parser/Exception/UnexpectedTokenException.php | 3 --- src/Dissect/Parser/LALR1/Analysis/AnalysisResult.php | 9 --------- src/Dissect/Parser/LALR1/Analysis/Automaton.php | 6 ------ .../Exception/ReduceReduceConflictException.php | 9 --------- .../Exception/ShiftReduceConflictException.php | 6 ------ src/Dissect/Parser/LALR1/Analysis/Item.php | 12 ------------ src/Dissect/Parser/LALR1/Analysis/State.php | 9 --------- src/Dissect/Parser/LALR1/Dumper/DebugTableDumper.php | 9 --------- src/Dissect/Parser/LALR1/Parser.php | 6 ------ 12 files changed, 78 deletions(-) diff --git a/src/Dissect/Lexer/AbstractLexer.php b/src/Dissect/Lexer/AbstractLexer.php index ac48423..4f88419 100644 --- a/src/Dissect/Lexer/AbstractLexer.php +++ b/src/Dissect/Lexer/AbstractLexer.php @@ -16,9 +16,6 @@ */ abstract class AbstractLexer implements Lexer { - /** - * @var int - */ private int $line = 1; /** diff --git a/src/Dissect/Lexer/SimpleLexer.php b/src/Dissect/Lexer/SimpleLexer.php index 735e835..6d9ecff 100644 --- a/src/Dissect/Lexer/SimpleLexer.php +++ b/src/Dissect/Lexer/SimpleLexer.php @@ -14,9 +14,6 @@ */ class SimpleLexer extends AbstractLexer { - /** - * @var array - */ protected array $skipTokens = []; /** diff --git a/src/Dissect/Lexer/TokenStream/ArrayTokenStream.php b/src/Dissect/Lexer/TokenStream/ArrayTokenStream.php index 610a1bf..f7d760b 100644 --- a/src/Dissect/Lexer/TokenStream/ArrayTokenStream.php +++ b/src/Dissect/Lexer/TokenStream/ArrayTokenStream.php @@ -18,9 +18,6 @@ class ArrayTokenStream implements TokenStream */ protected array $tokens; - /** - * @var int - */ protected int $position = 0; /** diff --git a/src/Dissect/Parser/Exception/UnexpectedTokenException.php b/src/Dissect/Parser/Exception/UnexpectedTokenException.php index a7de046..84c72cf 100644 --- a/src/Dissect/Parser/Exception/UnexpectedTokenException.php +++ b/src/Dissect/Parser/Exception/UnexpectedTokenException.php @@ -18,9 +18,6 @@ class UnexpectedTokenException extends RuntimeException Expected one of %s. EOT; - /** - * @var Token - */ protected Token $token; /** diff --git a/src/Dissect/Parser/LALR1/Analysis/AnalysisResult.php b/src/Dissect/Parser/LALR1/Analysis/AnalysisResult.php index 59f0909..dbba050 100644 --- a/src/Dissect/Parser/LALR1/Analysis/AnalysisResult.php +++ b/src/Dissect/Parser/LALR1/Analysis/AnalysisResult.php @@ -9,19 +9,10 @@ */ class AnalysisResult { - /** - * @var Automaton - */ protected Automaton $automaton; - /** - * @var array - */ protected array $parseTable; - /** - * @var array - */ protected array $resolvedConflicts; /** diff --git a/src/Dissect/Parser/LALR1/Analysis/Automaton.php b/src/Dissect/Parser/LALR1/Analysis/Automaton.php index 992d1dc..728f600 100644 --- a/src/Dissect/Parser/LALR1/Analysis/Automaton.php +++ b/src/Dissect/Parser/LALR1/Analysis/Automaton.php @@ -10,14 +10,8 @@ */ class Automaton { - /** - * @var array - */ protected array $states = []; - /** - * @var array - */ protected array $transitionTable = []; /** diff --git a/src/Dissect/Parser/LALR1/Analysis/Exception/ReduceReduceConflictException.php b/src/Dissect/Parser/LALR1/Analysis/Exception/ReduceReduceConflictException.php index b1a8395..5348beb 100644 --- a/src/Dissect/Parser/LALR1/Analysis/Exception/ReduceReduceConflictException.php +++ b/src/Dissect/Parser/LALR1/Analysis/Exception/ReduceReduceConflictException.php @@ -28,19 +28,10 @@ class ReduceReduceConflictException extends ConflictException (on lookahead "%s" in state %d). Restructure your grammar or choose a conflict resolution mode. EOT; - /** - * @var Rule - */ protected Rule $firstRule; - /** - * @var Rule - */ protected Rule $secondRule; - /** - * @var string - */ protected string $lookahead; /** diff --git a/src/Dissect/Parser/LALR1/Analysis/Exception/ShiftReduceConflictException.php b/src/Dissect/Parser/LALR1/Analysis/Exception/ShiftReduceConflictException.php index 0e095ff..59288cf 100644 --- a/src/Dissect/Parser/LALR1/Analysis/Exception/ShiftReduceConflictException.php +++ b/src/Dissect/Parser/LALR1/Analysis/Exception/ShiftReduceConflictException.php @@ -24,14 +24,8 @@ class ShiftReduceConflictException extends ConflictException (on lookahead "%s" in state %d). Restructure your grammar or choose a conflict resolution mode. EOT; - /** - * @var Rule - */ protected Rule $rule; - /** - * @var string - */ protected string $lookahead; /** diff --git a/src/Dissect/Parser/LALR1/Analysis/Item.php b/src/Dissect/Parser/LALR1/Analysis/Item.php index 79ada81..f176413 100644 --- a/src/Dissect/Parser/LALR1/Analysis/Item.php +++ b/src/Dissect/Parser/LALR1/Analysis/Item.php @@ -30,24 +30,12 @@ */ class Item { - /** - * @var Rule - */ protected Rule $rule; - /** - * @var int - */ protected int $dotIndex; - /** - * @var array - */ protected array $lookahead = []; - /** - * @var array - */ protected array $connected = []; /** diff --git a/src/Dissect/Parser/LALR1/Analysis/State.php b/src/Dissect/Parser/LALR1/Analysis/State.php index 8ba6f0e..57a535c 100644 --- a/src/Dissect/Parser/LALR1/Analysis/State.php +++ b/src/Dissect/Parser/LALR1/Analysis/State.php @@ -9,19 +9,10 @@ */ class State { - /** - * @var array - */ protected array $items = []; - /** - * @var array - */ protected array $itemMap = []; - /** - * @var int - */ protected int $number; /** diff --git a/src/Dissect/Parser/LALR1/Dumper/DebugTableDumper.php b/src/Dissect/Parser/LALR1/Dumper/DebugTableDumper.php index 99ae424..c59b350 100644 --- a/src/Dissect/Parser/LALR1/Dumper/DebugTableDumper.php +++ b/src/Dissect/Parser/LALR1/Dumper/DebugTableDumper.php @@ -13,19 +13,10 @@ */ class DebugTableDumper implements TableDumper { - /** - * @var Grammar - */ protected Grammar $grammar; - /** - * @var StringWriter - */ protected StringWriter $writer; - /** - * @var boolean - */ protected bool $written = false; /** diff --git a/src/Dissect/Parser/LALR1/Parser.php b/src/Dissect/Parser/LALR1/Parser.php index 72e1696..0d5ad35 100644 --- a/src/Dissect/Parser/LALR1/Parser.php +++ b/src/Dissect/Parser/LALR1/Parser.php @@ -15,14 +15,8 @@ */ class Parser implements P\Parser { - /** - * @var Grammar - */ protected Grammar $grammar; - /** - * @var array - */ protected array $parseTable; /** From 34dc3c3fa026871fcc99ea75adbb584d45257398 Mon Sep 17 00:00:00 2001 From: Alexander Lisachenko Date: Mon, 19 Feb 2024 23:07:05 +0200 Subject: [PATCH 10/28] Apply the RemoveUselessReturnTagRector rector --- rector.php | 2 ++ src/Dissect/Lexer/RegexLexer.php | 4 ---- src/Dissect/Lexer/TokenStream/ArrayTokenStream.php | 6 ------ src/Dissect/Parser/Grammar.php | 4 ---- src/Dissect/Parser/LALR1/Analysis/AnalysisResult.php | 2 -- src/Dissect/Parser/LALR1/Analysis/Automaton.php | 2 -- .../Parser/LALR1/Analysis/Exception/ConflictException.php | 4 ---- src/Dissect/Parser/LALR1/Analysis/State.php | 2 -- 8 files changed, 2 insertions(+), 24 deletions(-) diff --git a/rector.php b/rector.php index e1178b7..a41724a 100644 --- a/rector.php +++ b/rector.php @@ -3,6 +3,7 @@ declare(strict_types=1); use Rector\Config\RectorConfig; +use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector; use Rector\DeadCode\Rector\Property\RemoveUselessVarTagRector; return RectorConfig::configure() @@ -14,6 +15,7 @@ // ->withPhpSets() ->withRules([ // Dead-code + RemoveUselessReturnTagRector::class, RemoveUselessVarTagRector::class, //AddVoidReturnTypeWhereNoReturnRector::class, ]); diff --git a/src/Dissect/Lexer/RegexLexer.php b/src/Dissect/Lexer/RegexLexer.php index 808b1ea..8c3b13a 100644 --- a/src/Dissect/Lexer/RegexLexer.php +++ b/src/Dissect/Lexer/RegexLexer.php @@ -57,15 +57,11 @@ public function lex(string $string): TokenStream /** * The patterns corresponding to tokens. - * - * @return array */ abstract protected function getCatchablePatterns(): array; /** * The patterns corresponding to tokens to be skipped. - * - * @return array */ abstract protected function getNonCatchablePatterns(): array; diff --git a/src/Dissect/Lexer/TokenStream/ArrayTokenStream.php b/src/Dissect/Lexer/TokenStream/ArrayTokenStream.php index f7d760b..96a232e 100644 --- a/src/Dissect/Lexer/TokenStream/ArrayTokenStream.php +++ b/src/Dissect/Lexer/TokenStream/ArrayTokenStream.php @@ -106,17 +106,11 @@ public function next() $this->position++; } - /** - * @return int - */ public function count(): int { return count($this->tokens); } - /** - * @return ArrayIterator - */ public function getIterator(): ArrayIterator { return new ArrayIterator($this->tokens); diff --git a/src/Dissect/Parser/Grammar.php b/src/Dissect/Parser/Grammar.php index 2d30d24..3c751c7 100644 --- a/src/Dissect/Parser/Grammar.php +++ b/src/Dissect/Parser/Grammar.php @@ -240,8 +240,6 @@ public function getConflictsMode(): int * Does a nonterminal $name exist in the grammar? * * @param string $name The name of the nonterminal. - * - * @return boolean */ public function hasNonterminal(string $name): bool { @@ -351,8 +349,6 @@ public function prec(int $i): static * Is the passed token an operator? * * @param string $token The token type. - * - * @return boolean */ public function hasOperator(string $token): bool { diff --git a/src/Dissect/Parser/LALR1/Analysis/AnalysisResult.php b/src/Dissect/Parser/LALR1/Analysis/AnalysisResult.php index dbba050..6e09a27 100644 --- a/src/Dissect/Parser/LALR1/Analysis/AnalysisResult.php +++ b/src/Dissect/Parser/LALR1/Analysis/AnalysisResult.php @@ -32,8 +32,6 @@ public function __construct(array $parseTable, Automaton $automaton, array $conf /** * Returns the handle-finding FSA. - * - * @return Automaton */ public function getAutomaton(): Automaton { diff --git a/src/Dissect/Parser/LALR1/Analysis/Automaton.php b/src/Dissect/Parser/LALR1/Analysis/Automaton.php index 728f600..b9ae5de 100644 --- a/src/Dissect/Parser/LALR1/Analysis/Automaton.php +++ b/src/Dissect/Parser/LALR1/Analysis/Automaton.php @@ -52,8 +52,6 @@ public function getState(int $number): State * Does this automaton have a state identified by $number? * * @param $number - * - * @return boolean */ public function hasState($number): bool { diff --git a/src/Dissect/Parser/LALR1/Analysis/Exception/ConflictException.php b/src/Dissect/Parser/LALR1/Analysis/Exception/ConflictException.php index 157a11b..c74cb12 100644 --- a/src/Dissect/Parser/LALR1/Analysis/Exception/ConflictException.php +++ b/src/Dissect/Parser/LALR1/Analysis/Exception/ConflictException.php @@ -23,8 +23,6 @@ public function __construct( /** * Returns the number of the inadequate state. - * - * @return int */ public function getStateNumber(): int { @@ -33,8 +31,6 @@ public function getStateNumber(): int /** * Returns the faulty automaton. - * - * @return Automaton */ public function getAutomaton(): Automaton { diff --git a/src/Dissect/Parser/LALR1/Analysis/State.php b/src/Dissect/Parser/LALR1/Analysis/State.php index 57a535c..79342b3 100644 --- a/src/Dissect/Parser/LALR1/Analysis/State.php +++ b/src/Dissect/Parser/LALR1/Analysis/State.php @@ -57,8 +57,6 @@ public function get(int $ruleNumber, int $dotIndex): Item /** * Returns the number identifying this state. - * - * @return int */ public function getNumber(): int { From 6d76a53205a7ad015ae9f0ea61f4fd718aa1c64e Mon Sep 17 00:00:00 2001 From: Alexander Lisachenko Date: Mon, 19 Feb 2024 23:07:06 +0200 Subject: [PATCH 11/28] Apply the RemoveUselessParamTagRector rector --- rector.php | 2 ++ src/Dissect/Lexer/RegexLexer.php | 1 - src/Dissect/Parser/LALR1/Analysis/AnalysisResult.php | 1 - src/Dissect/Parser/LALR1/Analysis/Analyzer.php | 2 -- src/Dissect/Parser/LALR1/Dumper/AutomatonDumper.php | 2 -- 5 files changed, 2 insertions(+), 6 deletions(-) diff --git a/rector.php b/rector.php index a41724a..8d00d2e 100644 --- a/rector.php +++ b/rector.php @@ -3,6 +3,7 @@ declare(strict_types=1); use Rector\Config\RectorConfig; +use Rector\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector; use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector; use Rector\DeadCode\Rector\Property\RemoveUselessVarTagRector; @@ -15,6 +16,7 @@ // ->withPhpSets() ->withRules([ // Dead-code + RemoveUselessParamTagRector::class, RemoveUselessReturnTagRector::class, RemoveUselessVarTagRector::class, //AddVoidReturnTypeWhereNoReturnRector::class, diff --git a/src/Dissect/Lexer/RegexLexer.php b/src/Dissect/Lexer/RegexLexer.php index 8c3b13a..5a430a6 100644 --- a/src/Dissect/Lexer/RegexLexer.php +++ b/src/Dissect/Lexer/RegexLexer.php @@ -68,7 +68,6 @@ abstract protected function getNonCatchablePatterns(): array; /** * Retrieves the token type. * - * @param string $value * * @return string $type */ diff --git a/src/Dissect/Parser/LALR1/Analysis/AnalysisResult.php b/src/Dissect/Parser/LALR1/Analysis/AnalysisResult.php index 6e09a27..6052521 100644 --- a/src/Dissect/Parser/LALR1/Analysis/AnalysisResult.php +++ b/src/Dissect/Parser/LALR1/Analysis/AnalysisResult.php @@ -19,7 +19,6 @@ class AnalysisResult * Constructor. * * @param array $parseTable The parse table. - * @param Automaton $automaton * @param array $conflicts An array of conflicts resolved during parse table * construction. */ diff --git a/src/Dissect/Parser/LALR1/Analysis/Analyzer.php b/src/Dissect/Parser/LALR1/Analysis/Analyzer.php index fcc8094..145d9c5 100644 --- a/src/Dissect/Parser/LALR1/Analysis/Analyzer.php +++ b/src/Dissect/Parser/LALR1/Analysis/Analyzer.php @@ -240,8 +240,6 @@ protected function buildAutomaton(Grammar $grammar): Automaton /** * Encodes the handle-finding FSA as a LR parse table. * - * @param Automaton $automaton - * @param Grammar $grammar * * @return array The parse table. */ diff --git a/src/Dissect/Parser/LALR1/Dumper/AutomatonDumper.php b/src/Dissect/Parser/LALR1/Dumper/AutomatonDumper.php index b0184a0..cf2c85c 100644 --- a/src/Dissect/Parser/LALR1/Dumper/AutomatonDumper.php +++ b/src/Dissect/Parser/LALR1/Dumper/AutomatonDumper.php @@ -18,8 +18,6 @@ class AutomatonDumper /** * Constructor. - * - * @param Automaton $automaton */ public function __construct(Automaton $automaton) { From d8965d15a14303397b6d7c07be90731fc62ddea5 Mon Sep 17 00:00:00 2001 From: Alexander Lisachenko Date: Mon, 19 Feb 2024 23:07:06 +0200 Subject: [PATCH 12/28] Apply the PublicConstantVisibilityRector rector --- rector.php | 2 ++ src/Dissect/Lexer/StatefulLexer.php | 4 ++-- .../Exception/UnexpectedTokenException.php | 2 +- src/Dissect/Parser/Grammar.php | 22 +++++++++---------- .../ReduceReduceConflictException.php | 2 +- .../ShiftReduceConflictException.php | 2 +- src/Dissect/Parser/Parser.php | 2 +- 7 files changed, 19 insertions(+), 17 deletions(-) diff --git a/rector.php b/rector.php index 8d00d2e..0a0bf67 100644 --- a/rector.php +++ b/rector.php @@ -6,6 +6,7 @@ use Rector\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector; use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector; use Rector\DeadCode\Rector\Property\RemoveUselessVarTagRector; +use Rector\Php71\Rector\ClassConst\PublicConstantVisibilityRector; return RectorConfig::configure() ->withPaths([ @@ -19,5 +20,6 @@ RemoveUselessParamTagRector::class, RemoveUselessReturnTagRector::class, RemoveUselessVarTagRector::class, + PublicConstantVisibilityRector::class, //AddVoidReturnTypeWhereNoReturnRector::class, ]); diff --git a/src/Dissect/Lexer/StatefulLexer.php b/src/Dissect/Lexer/StatefulLexer.php index 7bbb073..76b6589 100644 --- a/src/Dissect/Lexer/StatefulLexer.php +++ b/src/Dissect/Lexer/StatefulLexer.php @@ -23,13 +23,13 @@ class StatefulLexer extends AbstractLexer /** * Signifies that no action should be taken on encountering a token. */ - const NO_ACTION = 0; + public const NO_ACTION = 0; /** * Indicates that a state should be popped of the state stack on * encountering a token. */ - const POP_STATE = 1; + public const POP_STATE = 1; /** * Adds a new token definition. If given only one argument, diff --git a/src/Dissect/Parser/Exception/UnexpectedTokenException.php b/src/Dissect/Parser/Exception/UnexpectedTokenException.php index 84c72cf..0ced75e 100644 --- a/src/Dissect/Parser/Exception/UnexpectedTokenException.php +++ b/src/Dissect/Parser/Exception/UnexpectedTokenException.php @@ -12,7 +12,7 @@ */ class UnexpectedTokenException extends RuntimeException { - const MESSAGE = << %s diff --git a/src/Dissect/Parser/LALR1/Analysis/Exception/ShiftReduceConflictException.php b/src/Dissect/Parser/LALR1/Analysis/Exception/ShiftReduceConflictException.php index 59288cf..a0f0606 100644 --- a/src/Dissect/Parser/LALR1/Analysis/Exception/ShiftReduceConflictException.php +++ b/src/Dissect/Parser/LALR1/Analysis/Exception/ShiftReduceConflictException.php @@ -16,7 +16,7 @@ class ShiftReduceConflictException extends ConflictException /** * The exception message template. */ - const MESSAGE = << %s diff --git a/src/Dissect/Parser/Parser.php b/src/Dissect/Parser/Parser.php index 1b7a8d4..5f08f04 100644 --- a/src/Dissect/Parser/Parser.php +++ b/src/Dissect/Parser/Parser.php @@ -14,7 +14,7 @@ interface Parser /** * The token type that represents an EOF. */ - const EOF_TOKEN_TYPE = '$eof'; + public const EOF_TOKEN_TYPE = '$eof'; /** * Parses a token stream and returns the semantical value From 45a48465db6d37db1adb4bdc643663317344d220 Mon Sep 17 00:00:00 2001 From: Alexander Lisachenko Date: Mon, 19 Feb 2024 23:07:06 +0200 Subject: [PATCH 13/28] Apply the ClosureToArrowFunctionRector rector --- rector.php | 2 ++ tests/Dissect/Parser/LALR1/ArithGrammar.php | 32 ++++++--------------- 2 files changed, 10 insertions(+), 24 deletions(-) diff --git a/rector.php b/rector.php index 0a0bf67..6ef5615 100644 --- a/rector.php +++ b/rector.php @@ -7,6 +7,7 @@ use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector; use Rector\DeadCode\Rector\Property\RemoveUselessVarTagRector; use Rector\Php71\Rector\ClassConst\PublicConstantVisibilityRector; +use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector; return RectorConfig::configure() ->withPaths([ @@ -21,5 +22,6 @@ RemoveUselessReturnTagRector::class, RemoveUselessVarTagRector::class, PublicConstantVisibilityRector::class, + ClosureToArrowFunctionRector::class, //AddVoidReturnTypeWhereNoReturnRector::class, ]); diff --git a/tests/Dissect/Parser/LALR1/ArithGrammar.php b/tests/Dissect/Parser/LALR1/ArithGrammar.php index 9d0b527..5a528d2 100644 --- a/tests/Dissect/Parser/LALR1/ArithGrammar.php +++ b/tests/Dissect/Parser/LALR1/ArithGrammar.php @@ -11,44 +11,28 @@ public function __construct() { $this('Expr') ->is('Expr', '+', 'Expr') - ->call(function ($l, $_, $r) { - return $l + $r; - }) + ->call(fn($l, $_, $r) => $l + $r) ->is('Expr', '-', 'Expr') - ->call(function ($l, $_, $r) { - return $l - $r; - }) + ->call(fn($l, $_, $r) => $l - $r) ->is('Expr', '*', 'Expr') - ->call(function ($l, $_, $r) { - return $l * $r; - }) + ->call(fn($l, $_, $r) => $l * $r) ->is('Expr', '/', 'Expr') - ->call(function ($l, $_, $r) { - return $l / $r; - }) + ->call(fn($l, $_, $r) => $l / $r) ->is('Expr', '**', 'Expr') - ->call(function ($l, $_, $r) { - return pow($l, $r); - }) + ->call(fn($l, $_, $r) => pow($l, $r)) ->is('(', 'Expr', ')') - ->call(function ($r, $e, $_) { - return $e; - }) + ->call(fn($r, $e, $_) => $e) ->is('-', 'Expr')->prec(4) - ->call(function ($_, $e) { - return -$e; - }) + ->call(fn($_, $e) => -$e) ->is('INT') - ->call(function ($i) { - return (int)$i->getValue(); - }); + ->call(fn($i) => (int)$i->getValue()); $this->operators('+', '-')->left()->prec(1); $this->operators('*', '/')->left()->prec(2); From 07889a22daa4fd314a7f2188572de103756f6ed5 Mon Sep 17 00:00:00 2001 From: Alexander Lisachenko Date: Mon, 19 Feb 2024 23:07:06 +0200 Subject: [PATCH 14/28] Apply the AddTestsVoidReturnTypeWhereNoReturnRector rector --- rector.php | 2 ++ tests/Dissect/Lexer/AbstractLexerTest.php | 10 ++++---- .../Lexer/Recognizer/RegexRecognizerTest.php | 6 ++--- .../Lexer/Recognizer/SimpleRecognizerTest.php | 4 ++-- tests/Dissect/Lexer/RegexLexerTest.php | 4 ++-- tests/Dissect/Lexer/SimpleLexerTest.php | 6 ++--- tests/Dissect/Lexer/StatefulLexerTest.php | 8 +++---- .../TokenStream/ArrayTokenStreamTest.php | 24 +++++++++---------- tests/Dissect/Parser/GrammarTest.php | 8 +++---- .../Parser/LALR1/Analysis/AnalyzerTest.php | 10 ++++---- .../Parser/LALR1/Analysis/AutomatonTest.php | 4 ++-- .../Parser/LALR1/Analysis/ItemTest.php | 10 ++++---- .../Analysis/KernelSet/KernelSetTest.php | 4 ++-- .../Parser/LALR1/Analysis/StateTest.php | 2 +- .../LALR1/Dumper/AutomatonDumperTest.php | 4 ++-- .../LALR1/Dumper/DebugTableDumperTest.php | 2 +- .../Dumper/ProductionTableDumperTest.php | 2 +- tests/Dissect/Parser/LALR1/ParserTest.php | 4 ++-- tests/Dissect/Parser/RuleTest.php | 2 +- 19 files changed, 59 insertions(+), 57 deletions(-) diff --git a/rector.php b/rector.php index 6ef5615..b6749bd 100644 --- a/rector.php +++ b/rector.php @@ -8,6 +8,7 @@ use Rector\DeadCode\Rector\Property\RemoveUselessVarTagRector; use Rector\Php71\Rector\ClassConst\PublicConstantVisibilityRector; use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector; +use Rector\TypeDeclaration\Rector\Class_\AddTestsVoidReturnTypeWhereNoReturnRector; return RectorConfig::configure() ->withPaths([ @@ -24,4 +25,5 @@ PublicConstantVisibilityRector::class, ClosureToArrowFunctionRector::class, //AddVoidReturnTypeWhereNoReturnRector::class, + AddTestsVoidReturnTypeWhereNoReturnRector::class ]); diff --git a/tests/Dissect/Lexer/AbstractLexerTest.php b/tests/Dissect/Lexer/AbstractLexerTest.php index 4fdb417..043c011 100644 --- a/tests/Dissect/Lexer/AbstractLexerTest.php +++ b/tests/Dissect/Lexer/AbstractLexerTest.php @@ -18,7 +18,7 @@ public function setUp(): void /** * @test */ - public function lexShouldDelegateToExtractTokenUpdatingTheLineAndOffsetAccordingly() + public function lexShouldDelegateToExtractTokenUpdatingTheLineAndOffsetAccordingly(): void { $stream = $this->lexer->lex("ab\nc"); @@ -41,7 +41,7 @@ public function lexShouldDelegateToExtractTokenUpdatingTheLineAndOffsetAccording /** * @test */ - public function lexShouldAppendAnEofTokenAutomatically() + public function lexShouldAppendAnEofTokenAutomatically(): void { $stream = $this->lexer->lex("abc"); $stream->seek(3); @@ -53,7 +53,7 @@ public function lexShouldAppendAnEofTokenAutomatically() /** * @test */ - public function lexShouldThrowAnExceptionOnAnUnrecognizableToken() + public function lexShouldThrowAnExceptionOnAnUnrecognizableToken(): void { try { $this->lexer->lex("abcd"); @@ -66,7 +66,7 @@ public function lexShouldThrowAnExceptionOnAnUnrecognizableToken() /** * @test */ - public function lexShouldNormalizeLineEndingsBeforeLexing() + public function lexShouldNormalizeLineEndingsBeforeLexing(): void { $stream = $this->lexer->lex("a\r\nb"); $this->assertEquals("\n", $stream->get(1)->getValue()); @@ -75,7 +75,7 @@ public function lexShouldNormalizeLineEndingsBeforeLexing() /** * @test */ - public function lexShouldSkipTokensIfToldToDoSo() + public function lexShouldSkipTokensIfToldToDoSo(): void { $stream = $this->lexer->lex('aeb'); $this->assertNotEquals('e', $stream->get(1)->getType()); diff --git a/tests/Dissect/Lexer/Recognizer/RegexRecognizerTest.php b/tests/Dissect/Lexer/Recognizer/RegexRecognizerTest.php index 1790221..67aecc4 100644 --- a/tests/Dissect/Lexer/Recognizer/RegexRecognizerTest.php +++ b/tests/Dissect/Lexer/Recognizer/RegexRecognizerTest.php @@ -9,7 +9,7 @@ class RegexRecognizerTest extends TestCase /** * @test */ - public function recognizerShouldMatchAndPassTheValueByReference() + public function recognizerShouldMatchAndPassTheValueByReference(): void { $recognizer = new RegexRecognizer('/[a-z]+/'); $result = $recognizer->match('lorem ipsum', $value); @@ -22,7 +22,7 @@ public function recognizerShouldMatchAndPassTheValueByReference() /** * @test */ - public function recognizerShouldFailAndTheValueShouldStayNull() + public function recognizerShouldFailAndTheValueShouldStayNull(): void { $recognizer = new RegexRecognizer('/[a-z]+/'); $result = $recognizer->match('123 456', $value); @@ -34,7 +34,7 @@ public function recognizerShouldFailAndTheValueShouldStayNull() /** * @test */ - public function recognizerShouldFailIfTheMatchIsNotAtTheBeginningOfTheString() + public function recognizerShouldFailIfTheMatchIsNotAtTheBeginningOfTheString(): void { $recognizer = new RegexRecognizer('/[a-z]+/'); $result = $recognizer->match('234 class', $value); diff --git a/tests/Dissect/Lexer/Recognizer/SimpleRecognizerTest.php b/tests/Dissect/Lexer/Recognizer/SimpleRecognizerTest.php index 1981715..5206f94 100644 --- a/tests/Dissect/Lexer/Recognizer/SimpleRecognizerTest.php +++ b/tests/Dissect/Lexer/Recognizer/SimpleRecognizerTest.php @@ -9,7 +9,7 @@ class SimpleRecognizerTest extends TestCase /** * @test */ - public function recognizerShouldMatchAndPassTheValueByReference() + public function recognizerShouldMatchAndPassTheValueByReference(): void { $recognizer = new SimpleRecognizer('class'); $result = $recognizer->match('class lorem ipsum', $value); @@ -22,7 +22,7 @@ public function recognizerShouldMatchAndPassTheValueByReference() /** * @test */ - public function recognizerShouldFailAndTheValueShouldStayNull() + public function recognizerShouldFailAndTheValueShouldStayNull(): void { $recognizer = new SimpleRecognizer('class'); $result = $recognizer->match('lorem ipsum', $value); diff --git a/tests/Dissect/Lexer/RegexLexerTest.php b/tests/Dissect/Lexer/RegexLexerTest.php index 487dc35..d7740ff 100644 --- a/tests/Dissect/Lexer/RegexLexerTest.php +++ b/tests/Dissect/Lexer/RegexLexerTest.php @@ -17,7 +17,7 @@ protected function setUp(): void /** * @test */ - public function itShouldCallGetTypeToRetrieveTokenType() + public function itShouldCallGetTypeToRetrieveTokenType(): void { $stream = $this->lexer->lex('5 + 6'); @@ -30,7 +30,7 @@ public function itShouldCallGetTypeToRetrieveTokenType() /** * @test */ - public function itShouldTrackLineNumbers() + public function itShouldTrackLineNumbers(): void { $stream = $this->lexer->lex("5\n+\n\n5"); diff --git a/tests/Dissect/Lexer/SimpleLexerTest.php b/tests/Dissect/Lexer/SimpleLexerTest.php index 73db207..9779bbf 100644 --- a/tests/Dissect/Lexer/SimpleLexerTest.php +++ b/tests/Dissect/Lexer/SimpleLexerTest.php @@ -26,7 +26,7 @@ public function setUp(): void /** * @test */ - public function simpleLexerShouldWalkThroughTheRecognizers() + public function simpleLexerShouldWalkThroughTheRecognizers(): void { $stream = $this->lexer->lex('a (b) c'); @@ -39,7 +39,7 @@ public function simpleLexerShouldWalkThroughTheRecognizers() /** * @test */ - public function simpleLexerShouldSkipSpecifiedTokens() + public function simpleLexerShouldSkipSpecifiedTokens(): void { $stream = $this->lexer->lex('a (b) c'); @@ -51,7 +51,7 @@ public function simpleLexerShouldSkipSpecifiedTokens() /** * @test */ - public function simpleLexerShouldReturnTheBestMatch() + public function simpleLexerShouldReturnTheBestMatch(): void { $this->lexer->token('CLASS', 'class'); $this->lexer->regex('WORD', '/[a-z]+/'); diff --git a/tests/Dissect/Lexer/StatefulLexerTest.php b/tests/Dissect/Lexer/StatefulLexerTest.php index f7517c5..efc02ab 100644 --- a/tests/Dissect/Lexer/StatefulLexerTest.php +++ b/tests/Dissect/Lexer/StatefulLexerTest.php @@ -17,7 +17,7 @@ protected function setUp(): void /** * @test */ - public function addingNewTokenShouldThrowAnExceptionWhenNoStateIsBeingBuilt() + public function addingNewTokenShouldThrowAnExceptionWhenNoStateIsBeingBuilt(): void { $this->expectExceptionMessage("Define a lexer state first."); $this->expectException(LogicException::class); @@ -27,7 +27,7 @@ public function addingNewTokenShouldThrowAnExceptionWhenNoStateIsBeingBuilt() /** * @test */ - public function anExceptionShouldBeThrownOnLexingWithoutAStartingState() + public function anExceptionShouldBeThrownOnLexingWithoutAStartingState(): void { $this->expectException(LogicException::class); $this->lexer->state('root'); @@ -37,7 +37,7 @@ public function anExceptionShouldBeThrownOnLexingWithoutAStartingState() /** * @test */ - public function theStateMechanismShouldCorrectlyPushAndPopStatesFromTheStack() + public function theStateMechanismShouldCorrectlyPushAndPopStatesFromTheStack(): void { /** @noinspection PhpPossiblePolymorphicInvocationInspection */ $this->lexer->state('root') @@ -64,7 +64,7 @@ public function theStateMechanismShouldCorrectlyPushAndPopStatesFromTheStack() /** * @test */ - public function defaultActionShouldBeNop() + public function defaultActionShouldBeNop(): void { $this->lexer->state('root') ->regex('WORD', '/[a-z]+/') diff --git a/tests/Dissect/Lexer/TokenStream/ArrayTokenStreamTest.php b/tests/Dissect/Lexer/TokenStream/ArrayTokenStreamTest.php index 2109980..0a4b2ef 100644 --- a/tests/Dissect/Lexer/TokenStream/ArrayTokenStreamTest.php +++ b/tests/Dissect/Lexer/TokenStream/ArrayTokenStreamTest.php @@ -24,7 +24,7 @@ protected function setUp(): void /** * @test */ - public function theCursorShouldBeOnFirstTokenByDefault() + public function theCursorShouldBeOnFirstTokenByDefault(): void { $this->assertEquals('6', $this->stream->getCurrentToken()->getValue()); } @@ -32,7 +32,7 @@ public function theCursorShouldBeOnFirstTokenByDefault() /** * @test */ - public function getPositionShouldReturnCurrentPosition() + public function getPositionShouldReturnCurrentPosition(): void { $this->stream->seek(2); $this->stream->next(); @@ -43,7 +43,7 @@ public function getPositionShouldReturnCurrentPosition() /** * @test */ - public function lookAheadShouldReturnTheCorrectToken() + public function lookAheadShouldReturnTheCorrectToken(): void { $this->assertEquals('5', $this->stream->lookAhead(2)->getValue()); } @@ -51,7 +51,7 @@ public function lookAheadShouldReturnTheCorrectToken() /** * @test */ - public function lookAheadShouldThrowAnExceptionWhenInvalid() + public function lookAheadShouldThrowAnExceptionWhenInvalid(): void { $this->expectException(OutOfBoundsException::class); $this->stream->lookAhead(15); @@ -60,7 +60,7 @@ public function lookAheadShouldThrowAnExceptionWhenInvalid() /** * @test */ - public function getShouldReturnATokenByAbsolutePosition() + public function getShouldReturnATokenByAbsolutePosition(): void { $this->assertEquals('3', $this->stream->get(4)->getValue()); } @@ -68,7 +68,7 @@ public function getShouldReturnATokenByAbsolutePosition() /** * @test */ - public function getShouldThrowAnExceptionWhenInvalid() + public function getShouldThrowAnExceptionWhenInvalid(): void { $this->expectException(OutOfBoundsException::class); $this->stream->get(15); @@ -77,7 +77,7 @@ public function getShouldThrowAnExceptionWhenInvalid() /** * @test */ - public function moveShouldMoveTheCursorByToAnAbsolutePosition() + public function moveShouldMoveTheCursorByToAnAbsolutePosition(): void { $this->stream->move(2); $this->assertEquals('5', $this->stream->getCurrentToken()->getValue()); @@ -86,7 +86,7 @@ public function moveShouldMoveTheCursorByToAnAbsolutePosition() /** * @test */ - public function moveShouldThrowAnExceptionWhenInvalid() + public function moveShouldThrowAnExceptionWhenInvalid(): void { $this->expectException(OutOfBoundsException::class); $this->stream->move(15); @@ -95,7 +95,7 @@ public function moveShouldThrowAnExceptionWhenInvalid() /** * @test */ - public function seekShouldMoveTheCursorByRelativeOffset() + public function seekShouldMoveTheCursorByRelativeOffset(): void { $this->stream->seek(4); $this->assertEquals('3', $this->stream->getCurrentToken()->getValue()); @@ -104,7 +104,7 @@ public function seekShouldMoveTheCursorByRelativeOffset() /** * @test */ - public function seekShouldThrowAnExceptionWhenInvalid() + public function seekShouldThrowAnExceptionWhenInvalid(): void { $this->expectException(OutOfBoundsException::class); $this->stream->seek(15); @@ -113,7 +113,7 @@ public function seekShouldThrowAnExceptionWhenInvalid() /** * @test */ - public function nextShouldMoveTheCursorOneTokenAhead() + public function nextShouldMoveTheCursorOneTokenAhead(): void { $this->stream->next(); $this->assertEquals('PLUS', $this->stream->getCurrentToken()->getType()); @@ -125,7 +125,7 @@ public function nextShouldMoveTheCursorOneTokenAhead() /** * @test */ - public function nextShouldThrowAnExceptionWhenAtTheEndOfTheStream() + public function nextShouldThrowAnExceptionWhenAtTheEndOfTheStream(): void { $this->expectException(OutOfBoundsException::class); $this->stream->seek(4); diff --git a/tests/Dissect/Parser/GrammarTest.php b/tests/Dissect/Parser/GrammarTest.php index 31c3428..dccc4c2 100644 --- a/tests/Dissect/Parser/GrammarTest.php +++ b/tests/Dissect/Parser/GrammarTest.php @@ -16,7 +16,7 @@ protected function setUp(): void /** * @test */ - public function ruleAlternativesShouldHaveTheSameName() + public function ruleAlternativesShouldHaveTheSameName(): void { $rules = $this->grammar->getRules(); @@ -27,7 +27,7 @@ public function ruleAlternativesShouldHaveTheSameName() /** * @test */ - public function theGrammarShouldBeAugmentedWithAStartRule() + public function theGrammarShouldBeAugmentedWithAStartRule(): void { $this->assertEquals( Grammar::START_RULE_NAME, @@ -43,7 +43,7 @@ public function theGrammarShouldBeAugmentedWithAStartRule() /** * @test */ - public function shouldReturnAlternativesGroupedByName() + public function shouldReturnAlternativesGroupedByName(): void { $rules = $this->grammar->getGroupedRules(); $this->assertCount(2, $rules['Foo']); @@ -52,7 +52,7 @@ public function shouldReturnAlternativesGroupedByName() /** * @test */ - public function nonterminalsShouldBeDetectedFromRuleNames() + public function nonterminalsShouldBeDetectedFromRuleNames(): void { $this->assertTrue($this->grammar->hasNonterminal('Foo')); } diff --git a/tests/Dissect/Parser/LALR1/Analysis/AnalyzerTest.php b/tests/Dissect/Parser/LALR1/Analysis/AnalyzerTest.php index 89092ba..5405598 100644 --- a/tests/Dissect/Parser/LALR1/Analysis/AnalyzerTest.php +++ b/tests/Dissect/Parser/LALR1/Analysis/AnalyzerTest.php @@ -14,7 +14,7 @@ class AnalyzerTest extends TestCase /** * @test */ - public function automatonShouldBeCorrectlyBuilt() + public function automatonShouldBeCorrectlyBuilt(): void { $grammar = new Grammar(); @@ -37,7 +37,7 @@ public function automatonShouldBeCorrectlyBuilt() /** * @test */ - public function lookaheadShouldBeCorrectlyPumped() + public function lookaheadShouldBeCorrectlyPumped(): void { $grammar = new Grammar(); @@ -94,7 +94,7 @@ public function lookaheadShouldBeCorrectlyPumped() /** * @test */ - public function parseTableShouldBeCorrectlyBuilt() + public function parseTableShouldBeCorrectlyBuilt(): void { $grammar = new Grammar(); @@ -135,7 +135,7 @@ public function parseTableShouldBeCorrectlyBuilt() /** * @test */ - public function unexpectedConflictsShouldThrowAnException() + public function unexpectedConflictsShouldThrowAnException(): void { $grammar = new Grammar(); @@ -165,7 +165,7 @@ public function unexpectedConflictsShouldThrowAnException() /** * @test */ - public function expectedConflictsShouldBeRecorded() + public function expectedConflictsShouldBeRecorded(): void { $grammar = new Grammar(); diff --git a/tests/Dissect/Parser/LALR1/Analysis/AutomatonTest.php b/tests/Dissect/Parser/LALR1/Analysis/AutomatonTest.php index 15d7908..0399f69 100644 --- a/tests/Dissect/Parser/LALR1/Analysis/AutomatonTest.php +++ b/tests/Dissect/Parser/LALR1/Analysis/AutomatonTest.php @@ -18,7 +18,7 @@ protected function setUp(): void /** * @test */ - public function addingATransitionShouldBeVisibleInTheTransitionTable() + public function addingATransitionShouldBeVisibleInTheTransitionTable(): void { $this->automaton->addTransition(0, 'a', 1); $table = $this->automaton->getTransitionTable(); @@ -29,7 +29,7 @@ public function addingATransitionShouldBeVisibleInTheTransitionTable() /** * @test */ - public function aNewStateShouldBeIdentifiedByItsNumber() + public function aNewStateShouldBeIdentifiedByItsNumber(): void { $state = new State(2, []); $this->automaton->addState($state); diff --git a/tests/Dissect/Parser/LALR1/Analysis/ItemTest.php b/tests/Dissect/Parser/LALR1/Analysis/ItemTest.php index 5c269f2..f67a90e 100644 --- a/tests/Dissect/Parser/LALR1/Analysis/ItemTest.php +++ b/tests/Dissect/Parser/LALR1/Analysis/ItemTest.php @@ -10,7 +10,7 @@ class ItemTest extends TestCase /** * @test */ - public function getActiveComponentShouldReturnTheComponentAboutToBeEncountered() + public function getActiveComponentShouldReturnTheComponentAboutToBeEncountered(): void { $item = new Item(new Rule(1, 'A', ['a', 'b', 'c']), 1); @@ -20,7 +20,7 @@ public function getActiveComponentShouldReturnTheComponentAboutToBeEncountered() /** * @test */ - public function itemShouldBeAReduceItemIfAllComponentsHaveBeenEncountered() + public function itemShouldBeAReduceItemIfAllComponentsHaveBeenEncountered(): void { $item = new Item(new Rule(1, 'A', ['a', 'b', 'c']), 1); $this->assertFalse($item->isReduceItem()); @@ -32,7 +32,7 @@ public function itemShouldBeAReduceItemIfAllComponentsHaveBeenEncountered() /** * @test */ - public function itemShouldPumpLookaheadIntoConnectedItems() + public function itemShouldPumpLookaheadIntoConnectedItems(): void { $item1 = new Item(new Rule(1, 'A', ['a', 'b', 'c']), 1); $item2 = new Item(new Rule(1, 'A', ['a', 'b', 'c']), 2); @@ -46,7 +46,7 @@ public function itemShouldPumpLookaheadIntoConnectedItems() /** * @test */ - public function itemShouldPumpTheSameLookaheadOnlyOnce() + public function itemShouldPumpTheSameLookaheadOnlyOnce(): void { $item1 = new Item(new Rule(1, 'A', ['a', 'b', 'c']), 1); @@ -71,7 +71,7 @@ public function itemShouldPumpTheSameLookaheadOnlyOnce() /** * @test */ - public function getUnrecognizedComponentsShouldReturnAllComponentAfterTheDottedOne() + public function getUnrecognizedComponentsShouldReturnAllComponentAfterTheDottedOne(): void { $item = new Item(new Rule(1, 'A', ['a', 'b', 'c']), 1); diff --git a/tests/Dissect/Parser/LALR1/Analysis/KernelSet/KernelSetTest.php b/tests/Dissect/Parser/LALR1/Analysis/KernelSet/KernelSetTest.php index 644dab2..478533c 100644 --- a/tests/Dissect/Parser/LALR1/Analysis/KernelSet/KernelSetTest.php +++ b/tests/Dissect/Parser/LALR1/Analysis/KernelSet/KernelSetTest.php @@ -9,7 +9,7 @@ class KernelSetTest extends TestCase /** * @test */ - public function kernelsShouldBeProperlyHashedAndOrdered() + public function kernelsShouldBeProperlyHashedAndOrdered(): void { $this->assertEquals(array(1, 3, 6, 7), KernelSet::hashKernel(array( array(2, 1), @@ -22,7 +22,7 @@ public function kernelsShouldBeProperlyHashedAndOrdered() /** * @test */ - public function insertShouldInsertANewNodeIfNoIdenticalKernelExists() + public function insertShouldInsertANewNodeIfNoIdenticalKernelExists(): void { $set = new KernelSet(); diff --git a/tests/Dissect/Parser/LALR1/Analysis/StateTest.php b/tests/Dissect/Parser/LALR1/Analysis/StateTest.php index f208be5..832c998 100644 --- a/tests/Dissect/Parser/LALR1/Analysis/StateTest.php +++ b/tests/Dissect/Parser/LALR1/Analysis/StateTest.php @@ -10,7 +10,7 @@ class StateTest extends TestCase /** * @test */ - public function stateShouldKeepItemsByRuleNumberAndPosition() + public function stateShouldKeepItemsByRuleNumberAndPosition(): void { $item1 = new Item(new Rule(1, 'E', ['E', '+', 'T']), 0); $state = new State(0, array($item1)); diff --git a/tests/Dissect/Parser/LALR1/Dumper/AutomatonDumperTest.php b/tests/Dissect/Parser/LALR1/Dumper/AutomatonDumperTest.php index ac3dae6..83d2cd6 100644 --- a/tests/Dissect/Parser/LALR1/Dumper/AutomatonDumperTest.php +++ b/tests/Dissect/Parser/LALR1/Dumper/AutomatonDumperTest.php @@ -19,7 +19,7 @@ protected function setUp(): void /** * @test */ - public function dumpDumpsTheEntireAutomaton() + public function dumpDumpsTheEntireAutomaton(): void { $this->assertStringEqualsFile( __DIR__ . '/res/graphviz/automaton.dot', @@ -30,7 +30,7 @@ public function dumpDumpsTheEntireAutomaton() /** * @test */ - public function dumpStateDumpsOnlyTheSpecifiedStateAndTransitions() + public function dumpStateDumpsOnlyTheSpecifiedStateAndTransitions(): void { $this->assertStringEqualsFile( __DIR__ . '/res/graphviz/state.dot', diff --git a/tests/Dissect/Parser/LALR1/Dumper/DebugTableDumperTest.php b/tests/Dissect/Parser/LALR1/Dumper/DebugTableDumperTest.php index 94faa71..01c2eaf 100644 --- a/tests/Dissect/Parser/LALR1/Dumper/DebugTableDumperTest.php +++ b/tests/Dissect/Parser/LALR1/Dumper/DebugTableDumperTest.php @@ -10,7 +10,7 @@ class DebugTableDumperTest extends TestCase /** * @test */ - public function itDumpsAHumanReadableParseTableWithExplainingComments() + public function itDumpsAHumanReadableParseTableWithExplainingComments(): void { $grammar = new ExampleGrammar(); $analyzer = new Analyzer(); diff --git a/tests/Dissect/Parser/LALR1/Dumper/ProductionTableDumperTest.php b/tests/Dissect/Parser/LALR1/Dumper/ProductionTableDumperTest.php index 3c4caa6..eacb08e 100644 --- a/tests/Dissect/Parser/LALR1/Dumper/ProductionTableDumperTest.php +++ b/tests/Dissect/Parser/LALR1/Dumper/ProductionTableDumperTest.php @@ -10,7 +10,7 @@ class ProductionTableDumperTest extends TestCase /** * @test */ - public function theWrittenTableShouldBeAsCompactAsPossible() + public function theWrittenTableShouldBeAsCompactAsPossible(): void { $grammar = new ExampleGrammar(); $analyzer = new Analyzer(); diff --git a/tests/Dissect/Parser/LALR1/ParserTest.php b/tests/Dissect/Parser/LALR1/ParserTest.php index ab71085..e032603 100644 --- a/tests/Dissect/Parser/LALR1/ParserTest.php +++ b/tests/Dissect/Parser/LALR1/ParserTest.php @@ -19,7 +19,7 @@ protected function setUp(): void /** * @test */ - public function parserShouldProcessTheTokenStreamAndUseGrammarCallbacksForReductions() + public function parserShouldProcessTheTokenStreamAndUseGrammarCallbacksForReductions(): void { $this->assertEquals(-2, $this->parser->parse($this->lexer->lex( '-1 - 1'))); @@ -37,7 +37,7 @@ public function parserShouldProcessTheTokenStreamAndUseGrammarCallbacksForReduct /** * @test */ - public function parserShouldThrowAnExceptionOnInvalidInput() + public function parserShouldThrowAnExceptionOnInvalidInput(): void { try { $this->parser->parse($this->lexer->lex('6 ** 5 3')); diff --git a/tests/Dissect/Parser/RuleTest.php b/tests/Dissect/Parser/RuleTest.php index 1b7f5e9..3c1f18d 100644 --- a/tests/Dissect/Parser/RuleTest.php +++ b/tests/Dissect/Parser/RuleTest.php @@ -9,7 +9,7 @@ class RuleTest extends TestCase /** * @test */ - public function getComponentShouldReturnNullIfAskedForComponentOutOfRange() + public function getComponentShouldReturnNullIfAskedForComponentOutOfRange(): void { $r = new Rule(1, 'Foo', ['x', 'y']); $this->assertEquals('y', $r->getComponent(1)); From 08037a1d88fd47925bf55d9648a08e17f3d29b69 Mon Sep 17 00:00:00 2001 From: Alexander Lisachenko Date: Mon, 19 Feb 2024 23:07:06 +0200 Subject: [PATCH 15/28] Apply the AddVoidReturnTypeWhereNoReturnRector rector --- rector.php | 3 ++- src/Dissect/Lexer/TokenStream/ArrayTokenStream.php | 6 +++--- src/Dissect/Node/CommonNode.php | 8 ++++---- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/rector.php b/rector.php index b6749bd..1e23306 100644 --- a/rector.php +++ b/rector.php @@ -9,6 +9,7 @@ use Rector\Php71\Rector\ClassConst\PublicConstantVisibilityRector; use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector; use Rector\TypeDeclaration\Rector\Class_\AddTestsVoidReturnTypeWhereNoReturnRector; +use Rector\TypeDeclaration\Rector\ClassMethod\AddVoidReturnTypeWhereNoReturnRector; return RectorConfig::configure() ->withPaths([ @@ -24,6 +25,6 @@ RemoveUselessVarTagRector::class, PublicConstantVisibilityRector::class, ClosureToArrowFunctionRector::class, - //AddVoidReturnTypeWhereNoReturnRector::class, + AddVoidReturnTypeWhereNoReturnRector::class, AddTestsVoidReturnTypeWhereNoReturnRector::class ]); diff --git a/src/Dissect/Lexer/TokenStream/ArrayTokenStream.php b/src/Dissect/Lexer/TokenStream/ArrayTokenStream.php index 96a232e..6c8a46a 100644 --- a/src/Dissect/Lexer/TokenStream/ArrayTokenStream.php +++ b/src/Dissect/Lexer/TokenStream/ArrayTokenStream.php @@ -73,7 +73,7 @@ public function get($n): Token /** * {@inheritDoc} */ - public function move($n) + public function move($n): void { if (!isset($this->tokens[$n])) { throw new OutOfBoundsException('Invalid index to move to.'); @@ -85,7 +85,7 @@ public function move($n) /** * {@inheritDoc} */ - public function seek($n) + public function seek($n): void { if (!isset($this->tokens[$this->position + $n])) { throw new OutOfBoundsException('Invalid seek.'); @@ -97,7 +97,7 @@ public function seek($n) /** * {@inheritDoc} */ - public function next() + public function next(): void { if (!isset($this->tokens[$this->position + 1])) { throw new OutOfBoundsException('Attempting to move beyond the end of the stream.'); diff --git a/src/Dissect/Node/CommonNode.php b/src/Dissect/Node/CommonNode.php index d9f086b..ad66606 100644 --- a/src/Dissect/Node/CommonNode.php +++ b/src/Dissect/Node/CommonNode.php @@ -59,7 +59,7 @@ public function getNode(int|string $name): Node /** * {@inheritDoc} */ - public function setNode(string $name, Node $child) + public function setNode(string $name, Node $child): void { $this->children[$name] = $child; } @@ -67,7 +67,7 @@ public function setNode(string $name, Node $child) /** * {@inheritDoc} */ - public function removeNode(string $name) + public function removeNode(string $name): void { unset($this->children[$name]); } @@ -103,7 +103,7 @@ public function getAttribute(string $key): mixed /** * {@inheritDoc} */ - public function setAttribute(string $key, mixed $value) + public function setAttribute(string $key, mixed $value): void { $this->attributes[$key] = $value; } @@ -111,7 +111,7 @@ public function setAttribute(string $key, mixed $value) /** * {@inheritDoc} */ - public function removeAttribute(string $key) + public function removeAttribute(string $key): void { unset($this->attributes[$key]); } From d9532c255422d42edf93eeba5ef68a778f5927c0 Mon Sep 17 00:00:00 2001 From: Alexander Lisachenko Date: Mon, 19 Feb 2024 23:07:06 +0200 Subject: [PATCH 16/28] Apply PSR-4 Autoloading Standard --- composer.json | 4 ++-- docs/lexing.md | 2 +- src/{Dissect => }/Console/Application.php | 0 src/{Dissect => }/Console/Command/DissectCommand.php | 0 src/{Dissect => }/Lexer/AbstractLexer.php | 0 src/{Dissect => }/Lexer/CommonToken.php | 0 src/{Dissect => }/Lexer/Exception/RecognitionException.php | 0 src/{Dissect => }/Lexer/Lexer.php | 0 src/{Dissect => }/Lexer/Recognizer/Recognizer.php | 0 src/{Dissect => }/Lexer/Recognizer/RegexRecognizer.php | 0 src/{Dissect => }/Lexer/Recognizer/SimpleRecognizer.php | 0 src/{Dissect => }/Lexer/RegexLexer.php | 0 src/{Dissect => }/Lexer/SimpleLexer.php | 0 src/{Dissect => }/Lexer/StatefulLexer.php | 0 src/{Dissect => }/Lexer/Token.php | 0 src/{Dissect => }/Lexer/TokenStream/ArrayTokenStream.php | 0 src/{Dissect => }/Lexer/TokenStream/TokenStream.php | 0 src/{Dissect => }/Node/CommonNode.php | 0 src/{Dissect => }/Node/Node.php | 0 .../Parser/Exception/UnexpectedTokenException.php | 0 src/{Dissect => }/Parser/Grammar.php | 0 src/{Dissect => }/Parser/LALR1/Analysis/AnalysisResult.php | 0 src/{Dissect => }/Parser/LALR1/Analysis/Analyzer.php | 0 src/{Dissect => }/Parser/LALR1/Analysis/Automaton.php | 0 .../Parser/LALR1/Analysis/Exception/ConflictException.php | 0 .../Analysis/Exception/ReduceReduceConflictException.php | 0 .../LALR1/Analysis/Exception/ShiftReduceConflictException.php | 0 src/{Dissect => }/Parser/LALR1/Analysis/Item.php | 0 .../Parser/LALR1/Analysis/KernelSet/KernelSet.php | 0 src/{Dissect => }/Parser/LALR1/Analysis/KernelSet/Node.php | 0 src/{Dissect => }/Parser/LALR1/Analysis/State.php | 0 src/{Dissect => }/Parser/LALR1/Dumper/AutomatonDumper.php | 0 src/{Dissect => }/Parser/LALR1/Dumper/DebugTableDumper.php | 0 .../Parser/LALR1/Dumper/ProductionTableDumper.php | 0 src/{Dissect => }/Parser/LALR1/Dumper/StringWriter.php | 0 src/{Dissect => }/Parser/LALR1/Dumper/TableDumper.php | 0 src/{Dissect => }/Parser/LALR1/Parser.php | 0 src/{Dissect => }/Parser/Parser.php | 0 src/{Dissect => }/Parser/Rule.php | 0 src/{Dissect => }/Util/Util.php | 0 tests/{Dissect => }/Lexer/AbstractLexerTest.php | 0 tests/{Dissect => }/Lexer/Recognizer/RegexRecognizerTest.php | 0 tests/{Dissect => }/Lexer/Recognizer/SimpleRecognizerTest.php | 0 tests/{Dissect => }/Lexer/RegexLexerTest.php | 0 tests/{Dissect => }/Lexer/SimpleLexerTest.php | 0 tests/{Dissect => }/Lexer/StatefulLexerTest.php | 0 tests/{Dissect => }/Lexer/StubLexer.php | 0 tests/{Dissect => }/Lexer/StubRegexLexer.php | 0 .../{Dissect => }/Lexer/TokenStream/ArrayTokenStreamTest.php | 0 tests/{Dissect => }/Parser/ExampleGrammar.php | 0 tests/{Dissect => }/Parser/GrammarTest.php | 0 tests/{Dissect => }/Parser/LALR1/Analysis/AnalyzerTest.php | 0 tests/{Dissect => }/Parser/LALR1/Analysis/AutomatonTest.php | 0 tests/{Dissect => }/Parser/LALR1/Analysis/ItemTest.php | 0 .../Parser/LALR1/Analysis/KernelSet/KernelSetTest.php | 0 tests/{Dissect => }/Parser/LALR1/Analysis/StateTest.php | 0 tests/{Dissect => }/Parser/LALR1/ArithGrammar.php | 0 tests/{Dissect => }/Parser/LALR1/ArithLexer.php | 0 .../{Dissect => }/Parser/LALR1/Dumper/AutomatonDumperTest.php | 0 .../Parser/LALR1/Dumper/DebugTableDumperTest.php | 0 tests/{Dissect => }/Parser/LALR1/Dumper/ExampleGrammar.php | 0 .../Parser/LALR1/Dumper/ProductionTableDumperTest.php | 0 .../Parser/LALR1/Dumper/res/graphviz/automaton.dot | 0 .../{Dissect => }/Parser/LALR1/Dumper/res/graphviz/state.dot | 0 tests/{Dissect => }/Parser/LALR1/Dumper/res/table/debug.php | 0 .../Parser/LALR1/Dumper/res/table/production.php | 0 tests/{Dissect => }/Parser/LALR1/ParserTest.php | 0 tests/{Dissect => }/Parser/RuleTest.php | 0 68 files changed, 3 insertions(+), 3 deletions(-) rename src/{Dissect => }/Console/Application.php (100%) rename src/{Dissect => }/Console/Command/DissectCommand.php (100%) rename src/{Dissect => }/Lexer/AbstractLexer.php (100%) rename src/{Dissect => }/Lexer/CommonToken.php (100%) rename src/{Dissect => }/Lexer/Exception/RecognitionException.php (100%) rename src/{Dissect => }/Lexer/Lexer.php (100%) rename src/{Dissect => }/Lexer/Recognizer/Recognizer.php (100%) rename src/{Dissect => }/Lexer/Recognizer/RegexRecognizer.php (100%) rename src/{Dissect => }/Lexer/Recognizer/SimpleRecognizer.php (100%) rename src/{Dissect => }/Lexer/RegexLexer.php (100%) rename src/{Dissect => }/Lexer/SimpleLexer.php (100%) rename src/{Dissect => }/Lexer/StatefulLexer.php (100%) rename src/{Dissect => }/Lexer/Token.php (100%) rename src/{Dissect => }/Lexer/TokenStream/ArrayTokenStream.php (100%) rename src/{Dissect => }/Lexer/TokenStream/TokenStream.php (100%) rename src/{Dissect => }/Node/CommonNode.php (100%) rename src/{Dissect => }/Node/Node.php (100%) rename src/{Dissect => }/Parser/Exception/UnexpectedTokenException.php (100%) rename src/{Dissect => }/Parser/Grammar.php (100%) rename src/{Dissect => }/Parser/LALR1/Analysis/AnalysisResult.php (100%) rename src/{Dissect => }/Parser/LALR1/Analysis/Analyzer.php (100%) rename src/{Dissect => }/Parser/LALR1/Analysis/Automaton.php (100%) rename src/{Dissect => }/Parser/LALR1/Analysis/Exception/ConflictException.php (100%) rename src/{Dissect => }/Parser/LALR1/Analysis/Exception/ReduceReduceConflictException.php (100%) rename src/{Dissect => }/Parser/LALR1/Analysis/Exception/ShiftReduceConflictException.php (100%) rename src/{Dissect => }/Parser/LALR1/Analysis/Item.php (100%) rename src/{Dissect => }/Parser/LALR1/Analysis/KernelSet/KernelSet.php (100%) rename src/{Dissect => }/Parser/LALR1/Analysis/KernelSet/Node.php (100%) rename src/{Dissect => }/Parser/LALR1/Analysis/State.php (100%) rename src/{Dissect => }/Parser/LALR1/Dumper/AutomatonDumper.php (100%) rename src/{Dissect => }/Parser/LALR1/Dumper/DebugTableDumper.php (100%) rename src/{Dissect => }/Parser/LALR1/Dumper/ProductionTableDumper.php (100%) rename src/{Dissect => }/Parser/LALR1/Dumper/StringWriter.php (100%) rename src/{Dissect => }/Parser/LALR1/Dumper/TableDumper.php (100%) rename src/{Dissect => }/Parser/LALR1/Parser.php (100%) rename src/{Dissect => }/Parser/Parser.php (100%) rename src/{Dissect => }/Parser/Rule.php (100%) rename src/{Dissect => }/Util/Util.php (100%) rename tests/{Dissect => }/Lexer/AbstractLexerTest.php (100%) rename tests/{Dissect => }/Lexer/Recognizer/RegexRecognizerTest.php (100%) rename tests/{Dissect => }/Lexer/Recognizer/SimpleRecognizerTest.php (100%) rename tests/{Dissect => }/Lexer/RegexLexerTest.php (100%) rename tests/{Dissect => }/Lexer/SimpleLexerTest.php (100%) rename tests/{Dissect => }/Lexer/StatefulLexerTest.php (100%) rename tests/{Dissect => }/Lexer/StubLexer.php (100%) rename tests/{Dissect => }/Lexer/StubRegexLexer.php (100%) rename tests/{Dissect => }/Lexer/TokenStream/ArrayTokenStreamTest.php (100%) rename tests/{Dissect => }/Parser/ExampleGrammar.php (100%) rename tests/{Dissect => }/Parser/GrammarTest.php (100%) rename tests/{Dissect => }/Parser/LALR1/Analysis/AnalyzerTest.php (100%) rename tests/{Dissect => }/Parser/LALR1/Analysis/AutomatonTest.php (100%) rename tests/{Dissect => }/Parser/LALR1/Analysis/ItemTest.php (100%) rename tests/{Dissect => }/Parser/LALR1/Analysis/KernelSet/KernelSetTest.php (100%) rename tests/{Dissect => }/Parser/LALR1/Analysis/StateTest.php (100%) rename tests/{Dissect => }/Parser/LALR1/ArithGrammar.php (100%) rename tests/{Dissect => }/Parser/LALR1/ArithLexer.php (100%) rename tests/{Dissect => }/Parser/LALR1/Dumper/AutomatonDumperTest.php (100%) rename tests/{Dissect => }/Parser/LALR1/Dumper/DebugTableDumperTest.php (100%) rename tests/{Dissect => }/Parser/LALR1/Dumper/ExampleGrammar.php (100%) rename tests/{Dissect => }/Parser/LALR1/Dumper/ProductionTableDumperTest.php (100%) rename tests/{Dissect => }/Parser/LALR1/Dumper/res/graphviz/automaton.dot (100%) rename tests/{Dissect => }/Parser/LALR1/Dumper/res/graphviz/state.dot (100%) rename tests/{Dissect => }/Parser/LALR1/Dumper/res/table/debug.php (100%) rename tests/{Dissect => }/Parser/LALR1/Dumper/res/table/production.php (100%) rename tests/{Dissect => }/Parser/LALR1/ParserTest.php (100%) rename tests/{Dissect => }/Parser/RuleTest.php (100%) diff --git a/composer.json b/composer.json index 02368fd..7020aaf 100644 --- a/composer.json +++ b/composer.json @@ -43,14 +43,14 @@ "symfony/console": "for the command-line tool" }, "autoload": { - "psr-0": { + "psr-4": { "Dissect\\": [ "src/" ] } }, "autoload-dev": { - "psr-0": { + "psr-4": { "Dissect\\": [ "tests/" ] diff --git a/docs/lexing.md b/docs/lexing.md index 53000e5..e99dbb4 100644 --- a/docs/lexing.md +++ b/docs/lexing.md @@ -236,7 +236,7 @@ Now that we've demonstrated how to perform lexical analysis with Dissect, we can move onto syntactical analysis, commonly known as [parsing][parsing]. -[tokenstream]: ../src/Dissect/Lexer/TokenStream/TokenStream.php +[tokenstream]: ../src/Lexer/TokenStream/TokenStream.php [parsing]: parsing.md [doctrinelexer]: https://github.com/doctrine/lexer/blob/master/lib/Doctrine/Common/Lexer/AbstractLexer.php [doctrine]: https://github.com/doctrine/lexer diff --git a/src/Dissect/Console/Application.php b/src/Console/Application.php similarity index 100% rename from src/Dissect/Console/Application.php rename to src/Console/Application.php diff --git a/src/Dissect/Console/Command/DissectCommand.php b/src/Console/Command/DissectCommand.php similarity index 100% rename from src/Dissect/Console/Command/DissectCommand.php rename to src/Console/Command/DissectCommand.php diff --git a/src/Dissect/Lexer/AbstractLexer.php b/src/Lexer/AbstractLexer.php similarity index 100% rename from src/Dissect/Lexer/AbstractLexer.php rename to src/Lexer/AbstractLexer.php diff --git a/src/Dissect/Lexer/CommonToken.php b/src/Lexer/CommonToken.php similarity index 100% rename from src/Dissect/Lexer/CommonToken.php rename to src/Lexer/CommonToken.php diff --git a/src/Dissect/Lexer/Exception/RecognitionException.php b/src/Lexer/Exception/RecognitionException.php similarity index 100% rename from src/Dissect/Lexer/Exception/RecognitionException.php rename to src/Lexer/Exception/RecognitionException.php diff --git a/src/Dissect/Lexer/Lexer.php b/src/Lexer/Lexer.php similarity index 100% rename from src/Dissect/Lexer/Lexer.php rename to src/Lexer/Lexer.php diff --git a/src/Dissect/Lexer/Recognizer/Recognizer.php b/src/Lexer/Recognizer/Recognizer.php similarity index 100% rename from src/Dissect/Lexer/Recognizer/Recognizer.php rename to src/Lexer/Recognizer/Recognizer.php diff --git a/src/Dissect/Lexer/Recognizer/RegexRecognizer.php b/src/Lexer/Recognizer/RegexRecognizer.php similarity index 100% rename from src/Dissect/Lexer/Recognizer/RegexRecognizer.php rename to src/Lexer/Recognizer/RegexRecognizer.php diff --git a/src/Dissect/Lexer/Recognizer/SimpleRecognizer.php b/src/Lexer/Recognizer/SimpleRecognizer.php similarity index 100% rename from src/Dissect/Lexer/Recognizer/SimpleRecognizer.php rename to src/Lexer/Recognizer/SimpleRecognizer.php diff --git a/src/Dissect/Lexer/RegexLexer.php b/src/Lexer/RegexLexer.php similarity index 100% rename from src/Dissect/Lexer/RegexLexer.php rename to src/Lexer/RegexLexer.php diff --git a/src/Dissect/Lexer/SimpleLexer.php b/src/Lexer/SimpleLexer.php similarity index 100% rename from src/Dissect/Lexer/SimpleLexer.php rename to src/Lexer/SimpleLexer.php diff --git a/src/Dissect/Lexer/StatefulLexer.php b/src/Lexer/StatefulLexer.php similarity index 100% rename from src/Dissect/Lexer/StatefulLexer.php rename to src/Lexer/StatefulLexer.php diff --git a/src/Dissect/Lexer/Token.php b/src/Lexer/Token.php similarity index 100% rename from src/Dissect/Lexer/Token.php rename to src/Lexer/Token.php diff --git a/src/Dissect/Lexer/TokenStream/ArrayTokenStream.php b/src/Lexer/TokenStream/ArrayTokenStream.php similarity index 100% rename from src/Dissect/Lexer/TokenStream/ArrayTokenStream.php rename to src/Lexer/TokenStream/ArrayTokenStream.php diff --git a/src/Dissect/Lexer/TokenStream/TokenStream.php b/src/Lexer/TokenStream/TokenStream.php similarity index 100% rename from src/Dissect/Lexer/TokenStream/TokenStream.php rename to src/Lexer/TokenStream/TokenStream.php diff --git a/src/Dissect/Node/CommonNode.php b/src/Node/CommonNode.php similarity index 100% rename from src/Dissect/Node/CommonNode.php rename to src/Node/CommonNode.php diff --git a/src/Dissect/Node/Node.php b/src/Node/Node.php similarity index 100% rename from src/Dissect/Node/Node.php rename to src/Node/Node.php diff --git a/src/Dissect/Parser/Exception/UnexpectedTokenException.php b/src/Parser/Exception/UnexpectedTokenException.php similarity index 100% rename from src/Dissect/Parser/Exception/UnexpectedTokenException.php rename to src/Parser/Exception/UnexpectedTokenException.php diff --git a/src/Dissect/Parser/Grammar.php b/src/Parser/Grammar.php similarity index 100% rename from src/Dissect/Parser/Grammar.php rename to src/Parser/Grammar.php diff --git a/src/Dissect/Parser/LALR1/Analysis/AnalysisResult.php b/src/Parser/LALR1/Analysis/AnalysisResult.php similarity index 100% rename from src/Dissect/Parser/LALR1/Analysis/AnalysisResult.php rename to src/Parser/LALR1/Analysis/AnalysisResult.php diff --git a/src/Dissect/Parser/LALR1/Analysis/Analyzer.php b/src/Parser/LALR1/Analysis/Analyzer.php similarity index 100% rename from src/Dissect/Parser/LALR1/Analysis/Analyzer.php rename to src/Parser/LALR1/Analysis/Analyzer.php diff --git a/src/Dissect/Parser/LALR1/Analysis/Automaton.php b/src/Parser/LALR1/Analysis/Automaton.php similarity index 100% rename from src/Dissect/Parser/LALR1/Analysis/Automaton.php rename to src/Parser/LALR1/Analysis/Automaton.php diff --git a/src/Dissect/Parser/LALR1/Analysis/Exception/ConflictException.php b/src/Parser/LALR1/Analysis/Exception/ConflictException.php similarity index 100% rename from src/Dissect/Parser/LALR1/Analysis/Exception/ConflictException.php rename to src/Parser/LALR1/Analysis/Exception/ConflictException.php diff --git a/src/Dissect/Parser/LALR1/Analysis/Exception/ReduceReduceConflictException.php b/src/Parser/LALR1/Analysis/Exception/ReduceReduceConflictException.php similarity index 100% rename from src/Dissect/Parser/LALR1/Analysis/Exception/ReduceReduceConflictException.php rename to src/Parser/LALR1/Analysis/Exception/ReduceReduceConflictException.php diff --git a/src/Dissect/Parser/LALR1/Analysis/Exception/ShiftReduceConflictException.php b/src/Parser/LALR1/Analysis/Exception/ShiftReduceConflictException.php similarity index 100% rename from src/Dissect/Parser/LALR1/Analysis/Exception/ShiftReduceConflictException.php rename to src/Parser/LALR1/Analysis/Exception/ShiftReduceConflictException.php diff --git a/src/Dissect/Parser/LALR1/Analysis/Item.php b/src/Parser/LALR1/Analysis/Item.php similarity index 100% rename from src/Dissect/Parser/LALR1/Analysis/Item.php rename to src/Parser/LALR1/Analysis/Item.php diff --git a/src/Dissect/Parser/LALR1/Analysis/KernelSet/KernelSet.php b/src/Parser/LALR1/Analysis/KernelSet/KernelSet.php similarity index 100% rename from src/Dissect/Parser/LALR1/Analysis/KernelSet/KernelSet.php rename to src/Parser/LALR1/Analysis/KernelSet/KernelSet.php diff --git a/src/Dissect/Parser/LALR1/Analysis/KernelSet/Node.php b/src/Parser/LALR1/Analysis/KernelSet/Node.php similarity index 100% rename from src/Dissect/Parser/LALR1/Analysis/KernelSet/Node.php rename to src/Parser/LALR1/Analysis/KernelSet/Node.php diff --git a/src/Dissect/Parser/LALR1/Analysis/State.php b/src/Parser/LALR1/Analysis/State.php similarity index 100% rename from src/Dissect/Parser/LALR1/Analysis/State.php rename to src/Parser/LALR1/Analysis/State.php diff --git a/src/Dissect/Parser/LALR1/Dumper/AutomatonDumper.php b/src/Parser/LALR1/Dumper/AutomatonDumper.php similarity index 100% rename from src/Dissect/Parser/LALR1/Dumper/AutomatonDumper.php rename to src/Parser/LALR1/Dumper/AutomatonDumper.php diff --git a/src/Dissect/Parser/LALR1/Dumper/DebugTableDumper.php b/src/Parser/LALR1/Dumper/DebugTableDumper.php similarity index 100% rename from src/Dissect/Parser/LALR1/Dumper/DebugTableDumper.php rename to src/Parser/LALR1/Dumper/DebugTableDumper.php diff --git a/src/Dissect/Parser/LALR1/Dumper/ProductionTableDumper.php b/src/Parser/LALR1/Dumper/ProductionTableDumper.php similarity index 100% rename from src/Dissect/Parser/LALR1/Dumper/ProductionTableDumper.php rename to src/Parser/LALR1/Dumper/ProductionTableDumper.php diff --git a/src/Dissect/Parser/LALR1/Dumper/StringWriter.php b/src/Parser/LALR1/Dumper/StringWriter.php similarity index 100% rename from src/Dissect/Parser/LALR1/Dumper/StringWriter.php rename to src/Parser/LALR1/Dumper/StringWriter.php diff --git a/src/Dissect/Parser/LALR1/Dumper/TableDumper.php b/src/Parser/LALR1/Dumper/TableDumper.php similarity index 100% rename from src/Dissect/Parser/LALR1/Dumper/TableDumper.php rename to src/Parser/LALR1/Dumper/TableDumper.php diff --git a/src/Dissect/Parser/LALR1/Parser.php b/src/Parser/LALR1/Parser.php similarity index 100% rename from src/Dissect/Parser/LALR1/Parser.php rename to src/Parser/LALR1/Parser.php diff --git a/src/Dissect/Parser/Parser.php b/src/Parser/Parser.php similarity index 100% rename from src/Dissect/Parser/Parser.php rename to src/Parser/Parser.php diff --git a/src/Dissect/Parser/Rule.php b/src/Parser/Rule.php similarity index 100% rename from src/Dissect/Parser/Rule.php rename to src/Parser/Rule.php diff --git a/src/Dissect/Util/Util.php b/src/Util/Util.php similarity index 100% rename from src/Dissect/Util/Util.php rename to src/Util/Util.php diff --git a/tests/Dissect/Lexer/AbstractLexerTest.php b/tests/Lexer/AbstractLexerTest.php similarity index 100% rename from tests/Dissect/Lexer/AbstractLexerTest.php rename to tests/Lexer/AbstractLexerTest.php diff --git a/tests/Dissect/Lexer/Recognizer/RegexRecognizerTest.php b/tests/Lexer/Recognizer/RegexRecognizerTest.php similarity index 100% rename from tests/Dissect/Lexer/Recognizer/RegexRecognizerTest.php rename to tests/Lexer/Recognizer/RegexRecognizerTest.php diff --git a/tests/Dissect/Lexer/Recognizer/SimpleRecognizerTest.php b/tests/Lexer/Recognizer/SimpleRecognizerTest.php similarity index 100% rename from tests/Dissect/Lexer/Recognizer/SimpleRecognizerTest.php rename to tests/Lexer/Recognizer/SimpleRecognizerTest.php diff --git a/tests/Dissect/Lexer/RegexLexerTest.php b/tests/Lexer/RegexLexerTest.php similarity index 100% rename from tests/Dissect/Lexer/RegexLexerTest.php rename to tests/Lexer/RegexLexerTest.php diff --git a/tests/Dissect/Lexer/SimpleLexerTest.php b/tests/Lexer/SimpleLexerTest.php similarity index 100% rename from tests/Dissect/Lexer/SimpleLexerTest.php rename to tests/Lexer/SimpleLexerTest.php diff --git a/tests/Dissect/Lexer/StatefulLexerTest.php b/tests/Lexer/StatefulLexerTest.php similarity index 100% rename from tests/Dissect/Lexer/StatefulLexerTest.php rename to tests/Lexer/StatefulLexerTest.php diff --git a/tests/Dissect/Lexer/StubLexer.php b/tests/Lexer/StubLexer.php similarity index 100% rename from tests/Dissect/Lexer/StubLexer.php rename to tests/Lexer/StubLexer.php diff --git a/tests/Dissect/Lexer/StubRegexLexer.php b/tests/Lexer/StubRegexLexer.php similarity index 100% rename from tests/Dissect/Lexer/StubRegexLexer.php rename to tests/Lexer/StubRegexLexer.php diff --git a/tests/Dissect/Lexer/TokenStream/ArrayTokenStreamTest.php b/tests/Lexer/TokenStream/ArrayTokenStreamTest.php similarity index 100% rename from tests/Dissect/Lexer/TokenStream/ArrayTokenStreamTest.php rename to tests/Lexer/TokenStream/ArrayTokenStreamTest.php diff --git a/tests/Dissect/Parser/ExampleGrammar.php b/tests/Parser/ExampleGrammar.php similarity index 100% rename from tests/Dissect/Parser/ExampleGrammar.php rename to tests/Parser/ExampleGrammar.php diff --git a/tests/Dissect/Parser/GrammarTest.php b/tests/Parser/GrammarTest.php similarity index 100% rename from tests/Dissect/Parser/GrammarTest.php rename to tests/Parser/GrammarTest.php diff --git a/tests/Dissect/Parser/LALR1/Analysis/AnalyzerTest.php b/tests/Parser/LALR1/Analysis/AnalyzerTest.php similarity index 100% rename from tests/Dissect/Parser/LALR1/Analysis/AnalyzerTest.php rename to tests/Parser/LALR1/Analysis/AnalyzerTest.php diff --git a/tests/Dissect/Parser/LALR1/Analysis/AutomatonTest.php b/tests/Parser/LALR1/Analysis/AutomatonTest.php similarity index 100% rename from tests/Dissect/Parser/LALR1/Analysis/AutomatonTest.php rename to tests/Parser/LALR1/Analysis/AutomatonTest.php diff --git a/tests/Dissect/Parser/LALR1/Analysis/ItemTest.php b/tests/Parser/LALR1/Analysis/ItemTest.php similarity index 100% rename from tests/Dissect/Parser/LALR1/Analysis/ItemTest.php rename to tests/Parser/LALR1/Analysis/ItemTest.php diff --git a/tests/Dissect/Parser/LALR1/Analysis/KernelSet/KernelSetTest.php b/tests/Parser/LALR1/Analysis/KernelSet/KernelSetTest.php similarity index 100% rename from tests/Dissect/Parser/LALR1/Analysis/KernelSet/KernelSetTest.php rename to tests/Parser/LALR1/Analysis/KernelSet/KernelSetTest.php diff --git a/tests/Dissect/Parser/LALR1/Analysis/StateTest.php b/tests/Parser/LALR1/Analysis/StateTest.php similarity index 100% rename from tests/Dissect/Parser/LALR1/Analysis/StateTest.php rename to tests/Parser/LALR1/Analysis/StateTest.php diff --git a/tests/Dissect/Parser/LALR1/ArithGrammar.php b/tests/Parser/LALR1/ArithGrammar.php similarity index 100% rename from tests/Dissect/Parser/LALR1/ArithGrammar.php rename to tests/Parser/LALR1/ArithGrammar.php diff --git a/tests/Dissect/Parser/LALR1/ArithLexer.php b/tests/Parser/LALR1/ArithLexer.php similarity index 100% rename from tests/Dissect/Parser/LALR1/ArithLexer.php rename to tests/Parser/LALR1/ArithLexer.php diff --git a/tests/Dissect/Parser/LALR1/Dumper/AutomatonDumperTest.php b/tests/Parser/LALR1/Dumper/AutomatonDumperTest.php similarity index 100% rename from tests/Dissect/Parser/LALR1/Dumper/AutomatonDumperTest.php rename to tests/Parser/LALR1/Dumper/AutomatonDumperTest.php diff --git a/tests/Dissect/Parser/LALR1/Dumper/DebugTableDumperTest.php b/tests/Parser/LALR1/Dumper/DebugTableDumperTest.php similarity index 100% rename from tests/Dissect/Parser/LALR1/Dumper/DebugTableDumperTest.php rename to tests/Parser/LALR1/Dumper/DebugTableDumperTest.php diff --git a/tests/Dissect/Parser/LALR1/Dumper/ExampleGrammar.php b/tests/Parser/LALR1/Dumper/ExampleGrammar.php similarity index 100% rename from tests/Dissect/Parser/LALR1/Dumper/ExampleGrammar.php rename to tests/Parser/LALR1/Dumper/ExampleGrammar.php diff --git a/tests/Dissect/Parser/LALR1/Dumper/ProductionTableDumperTest.php b/tests/Parser/LALR1/Dumper/ProductionTableDumperTest.php similarity index 100% rename from tests/Dissect/Parser/LALR1/Dumper/ProductionTableDumperTest.php rename to tests/Parser/LALR1/Dumper/ProductionTableDumperTest.php diff --git a/tests/Dissect/Parser/LALR1/Dumper/res/graphviz/automaton.dot b/tests/Parser/LALR1/Dumper/res/graphviz/automaton.dot similarity index 100% rename from tests/Dissect/Parser/LALR1/Dumper/res/graphviz/automaton.dot rename to tests/Parser/LALR1/Dumper/res/graphviz/automaton.dot diff --git a/tests/Dissect/Parser/LALR1/Dumper/res/graphviz/state.dot b/tests/Parser/LALR1/Dumper/res/graphviz/state.dot similarity index 100% rename from tests/Dissect/Parser/LALR1/Dumper/res/graphviz/state.dot rename to tests/Parser/LALR1/Dumper/res/graphviz/state.dot diff --git a/tests/Dissect/Parser/LALR1/Dumper/res/table/debug.php b/tests/Parser/LALR1/Dumper/res/table/debug.php similarity index 100% rename from tests/Dissect/Parser/LALR1/Dumper/res/table/debug.php rename to tests/Parser/LALR1/Dumper/res/table/debug.php diff --git a/tests/Dissect/Parser/LALR1/Dumper/res/table/production.php b/tests/Parser/LALR1/Dumper/res/table/production.php similarity index 100% rename from tests/Dissect/Parser/LALR1/Dumper/res/table/production.php rename to tests/Parser/LALR1/Dumper/res/table/production.php diff --git a/tests/Dissect/Parser/LALR1/ParserTest.php b/tests/Parser/LALR1/ParserTest.php similarity index 100% rename from tests/Dissect/Parser/LALR1/ParserTest.php rename to tests/Parser/LALR1/ParserTest.php diff --git a/tests/Dissect/Parser/RuleTest.php b/tests/Parser/RuleTest.php similarity index 100% rename from tests/Dissect/Parser/RuleTest.php rename to tests/Parser/RuleTest.php From d0073b176d9a79dcfc1ada5235583eeecd4e691b Mon Sep 17 00:00:00 2001 From: Alexander Lisachenko Date: Mon, 19 Feb 2024 23:07:06 +0200 Subject: [PATCH 17/28] Apply the DeclareStrictTypesRector rector --- rector.php | 4 +++- src/Console/Application.php | 2 ++ src/Console/Command/DissectCommand.php | 2 ++ src/Lexer/AbstractLexer.php | 2 ++ src/Lexer/CommonToken.php | 2 ++ src/Lexer/Exception/RecognitionException.php | 2 ++ src/Lexer/Lexer.php | 2 ++ src/Lexer/Recognizer/Recognizer.php | 2 ++ src/Lexer/Recognizer/RegexRecognizer.php | 2 ++ src/Lexer/Recognizer/SimpleRecognizer.php | 2 ++ src/Lexer/RegexLexer.php | 2 ++ src/Lexer/SimpleLexer.php | 2 ++ src/Lexer/StatefulLexer.php | 2 ++ src/Lexer/Token.php | 2 ++ src/Lexer/TokenStream/ArrayTokenStream.php | 2 ++ src/Lexer/TokenStream/TokenStream.php | 2 ++ src/Node/CommonNode.php | 2 ++ src/Node/Node.php | 2 ++ src/Parser/Exception/UnexpectedTokenException.php | 2 ++ src/Parser/Grammar.php | 2 ++ src/Parser/LALR1/Analysis/AnalysisResult.php | 2 ++ src/Parser/LALR1/Analysis/Analyzer.php | 2 ++ src/Parser/LALR1/Analysis/Automaton.php | 2 ++ src/Parser/LALR1/Analysis/Exception/ConflictException.php | 2 ++ .../Analysis/Exception/ReduceReduceConflictException.php | 2 ++ .../Analysis/Exception/ShiftReduceConflictException.php | 2 ++ src/Parser/LALR1/Analysis/Item.php | 2 ++ src/Parser/LALR1/Analysis/KernelSet/KernelSet.php | 2 ++ src/Parser/LALR1/Analysis/KernelSet/Node.php | 2 ++ src/Parser/LALR1/Analysis/State.php | 2 ++ src/Parser/LALR1/Dumper/AutomatonDumper.php | 2 ++ src/Parser/LALR1/Dumper/DebugTableDumper.php | 2 ++ src/Parser/LALR1/Dumper/ProductionTableDumper.php | 2 ++ src/Parser/LALR1/Dumper/StringWriter.php | 2 ++ src/Parser/LALR1/Dumper/TableDumper.php | 2 ++ src/Parser/LALR1/Parser.php | 2 ++ src/Parser/Parser.php | 2 ++ src/Parser/Rule.php | 2 ++ src/Util/Util.php | 2 ++ tests/Lexer/AbstractLexerTest.php | 2 ++ tests/Lexer/Recognizer/RegexRecognizerTest.php | 2 ++ tests/Lexer/Recognizer/SimpleRecognizerTest.php | 2 ++ tests/Lexer/RegexLexerTest.php | 2 ++ tests/Lexer/SimpleLexerTest.php | 2 ++ tests/Lexer/StatefulLexerTest.php | 2 ++ tests/Lexer/StubLexer.php | 2 ++ tests/Lexer/StubRegexLexer.php | 2 ++ tests/Lexer/TokenStream/ArrayTokenStreamTest.php | 2 ++ tests/Parser/ExampleGrammar.php | 2 ++ tests/Parser/GrammarTest.php | 2 ++ tests/Parser/LALR1/Analysis/AnalyzerTest.php | 2 ++ tests/Parser/LALR1/Analysis/AutomatonTest.php | 2 ++ tests/Parser/LALR1/Analysis/ItemTest.php | 2 ++ tests/Parser/LALR1/Analysis/KernelSet/KernelSetTest.php | 2 ++ tests/Parser/LALR1/Analysis/StateTest.php | 2 ++ tests/Parser/LALR1/ArithGrammar.php | 2 ++ tests/Parser/LALR1/ArithLexer.php | 2 ++ tests/Parser/LALR1/Dumper/AutomatonDumperTest.php | 2 ++ tests/Parser/LALR1/Dumper/DebugTableDumperTest.php | 2 ++ tests/Parser/LALR1/Dumper/ExampleGrammar.php | 2 ++ tests/Parser/LALR1/Dumper/ProductionTableDumperTest.php | 2 ++ tests/Parser/LALR1/Dumper/res/table/debug.php | 2 ++ tests/Parser/LALR1/Dumper/res/table/production.php | 6 +++++- tests/Parser/LALR1/ParserTest.php | 2 ++ tests/Parser/RuleTest.php | 2 ++ tests/bootstrap.php | 2 ++ 66 files changed, 136 insertions(+), 2 deletions(-) diff --git a/rector.php b/rector.php index 1e23306..8929c4e 100644 --- a/rector.php +++ b/rector.php @@ -10,6 +10,7 @@ use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector; use Rector\TypeDeclaration\Rector\Class_\AddTestsVoidReturnTypeWhereNoReturnRector; use Rector\TypeDeclaration\Rector\ClassMethod\AddVoidReturnTypeWhereNoReturnRector; +use Rector\TypeDeclaration\Rector\StmtsAwareInterface\DeclareStrictTypesRector; return RectorConfig::configure() ->withPaths([ @@ -26,5 +27,6 @@ PublicConstantVisibilityRector::class, ClosureToArrowFunctionRector::class, AddVoidReturnTypeWhereNoReturnRector::class, - AddTestsVoidReturnTypeWhereNoReturnRector::class + AddTestsVoidReturnTypeWhereNoReturnRector::class, + DeclareStrictTypesRector::class, ]); diff --git a/src/Console/Application.php b/src/Console/Application.php index 04d1d87..44cef20 100644 --- a/src/Console/Application.php +++ b/src/Console/Application.php @@ -1,5 +1,7 @@ [ 0 => [ diff --git a/tests/Parser/LALR1/Dumper/res/table/production.php b/tests/Parser/LALR1/Dumper/res/table/production.php index 607d708..a078ab2 100644 --- a/tests/Parser/LALR1/Dumper/res/table/production.php +++ b/tests/Parser/LALR1/Dumper/res/table/production.php @@ -1 +1,5 @@ -[0=>['a'=>2,'$eof'=>-2,],2=>['a'=>2,'b'=>-2,],3=>['b'=>4,],1=>['$eof'=>0,],4=>['$eof'=>-1,'b'=>-1,],],'goto'=>[0=>['S'=>1,],2=>['S'=>3,],]]; +[0=>['a'=>2,'$eof'=>-2,],2=>['a'=>2,'b'=>-2,],3=>['b'=>4,],1=>['$eof'=>0,],4=>['$eof'=>-1,'b'=>-1,],],'goto'=>[0=>['S'=>1,],2=>['S'=>3,],]]; diff --git a/tests/Parser/LALR1/ParserTest.php b/tests/Parser/LALR1/ParserTest.php index e032603..8261dec 100644 --- a/tests/Parser/LALR1/ParserTest.php +++ b/tests/Parser/LALR1/ParserTest.php @@ -1,5 +1,7 @@ Date: Mon, 19 Feb 2024 23:07:06 +0200 Subject: [PATCH 18/28] Identation of help description adjusted --- src/Console/Command/DissectCommand.php | 44 +++++++++++++------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/Console/Command/DissectCommand.php b/src/Console/Command/DissectCommand.php index b0b1af5..b1cd169 100644 --- a/src/Console/Command/DissectCommand.php +++ b/src/Console/Command/DissectCommand.php @@ -29,28 +29,28 @@ protected function configure() ->addOption('state', 's', InputOption::VALUE_REQUIRED, 'Exports only the specified state instead of the entire DFA.') ->addOption('output-dir', 'o', InputOption::VALUE_REQUIRED, 'Overrides the default output directory.') ->setHelp(<<--output-dir option: - - --output-dir=../some/other/dir - -The parse table is by default written with minimal whitespace to make it compact. -If you wish to inspect the table manually, you can export it in a readable and -well-commented way with the --debug option. - -If you wish to inspect the handle-finding automaton for your grammar (perhaps -to aid with grammar debugging), use the --dfa option. When in use, Dissect -will create a file with the automaton exported as a Graphviz graph -in the output directory. - -Additionally, you can use the --state option to export only the specified -state and any relevant transitions: - - --dfa --state=5 -EOT + Analyzes the given grammar and, if successful, exports the parse table to a PHP + file. + + By default, the output directory is taken to be the one in which the grammar is + defined. You can change that with the --output-dir option: + + --output-dir=../some/other/dir + + The parse table is by default written with minimal whitespace to make it compact. + If you wish to inspect the table manually, you can export it in a readable and + well-commented way with the --debug option. + + If you wish to inspect the handle-finding automaton for your grammar (perhaps + to aid with grammar debugging), use the --dfa option. When in use, Dissect + will create a file with the automaton exported as a Graphviz graph + in the output directory. + + Additionally, you can use the --state option to export only the specified + state and any relevant transitions: + + --dfa --state=5 + EOT ); } From cfb122151284d48f949c6766d5ac6e1db046a5fd Mon Sep 17 00:00:00 2001 From: Alexander Lisachenko Date: Mon, 19 Feb 2024 23:07:07 +0200 Subject: [PATCH 19/28] Use Variadic syntax For ArrayTokenStream to ensure type checks --- src/Lexer/AbstractLexer.php | 2 +- src/Lexer/RegexLexer.php | 2 +- src/Lexer/TokenStream/ArrayTokenStream.php | 4 +--- tests/Lexer/TokenStream/ArrayTokenStreamTest.php | 4 ++-- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Lexer/AbstractLexer.php b/src/Lexer/AbstractLexer.php index 23f66ea..37d583a 100644 --- a/src/Lexer/AbstractLexer.php +++ b/src/Lexer/AbstractLexer.php @@ -91,6 +91,6 @@ public function lex(string $string): TokenStream\TokenStream|ArrayTokenStream $tokens[] = new CommonToken(Parser::EOF_TOKEN_TYPE, '', $this->line); - return new ArrayTokenStream($tokens); + return new ArrayTokenStream(...$tokens); } } diff --git a/src/Lexer/RegexLexer.php b/src/Lexer/RegexLexer.php index 9b55c33..ca90677 100644 --- a/src/Lexer/RegexLexer.php +++ b/src/Lexer/RegexLexer.php @@ -54,7 +54,7 @@ public function lex(string $string): TokenStream $tokens[] = new CommonToken(Parser::EOF_TOKEN_TYPE, '', $line); - return new ArrayTokenStream($tokens); + return new ArrayTokenStream(...$tokens); } /** diff --git a/src/Lexer/TokenStream/ArrayTokenStream.php b/src/Lexer/TokenStream/ArrayTokenStream.php index c064713..ec55572 100644 --- a/src/Lexer/TokenStream/ArrayTokenStream.php +++ b/src/Lexer/TokenStream/ArrayTokenStream.php @@ -24,10 +24,8 @@ class ArrayTokenStream implements TokenStream /** * Constructor. - * - * @param Token[] $tokens The tokens in this stream. */ - public function __construct(array $tokens) + public function __construct(Token ...$tokens) { $this->tokens = $tokens; } diff --git a/tests/Lexer/TokenStream/ArrayTokenStreamTest.php b/tests/Lexer/TokenStream/ArrayTokenStreamTest.php index b01c6f0..9b15a25 100644 --- a/tests/Lexer/TokenStream/ArrayTokenStreamTest.php +++ b/tests/Lexer/TokenStream/ArrayTokenStreamTest.php @@ -14,13 +14,13 @@ class ArrayTokenStreamTest extends TestCase protected function setUp(): void { - $this->stream = new ArrayTokenStream([ + $this->stream = new ArrayTokenStream( new CommonToken('INT', '6', 1), new CommonToken('PLUS', '+', 1), new CommonToken('INT', '5', 1), new CommonToken('MINUS', '-', 1), new CommonToken('INT', '3', 1), - ]); + ); } /** From fc17752e4d93a70e95c22dba92b242b9c80b6cbe Mon Sep 17 00:00:00 2001 From: Alexander Lisachenko Date: Mon, 19 Feb 2024 23:07:07 +0200 Subject: [PATCH 20/28] Miscelanous cleaning --- src/Lexer/AbstractLexer.php | 11 ++-------- src/Lexer/Lexer.php | 2 -- src/Lexer/RegexLexer.php | 3 --- src/Lexer/SimpleLexer.php | 6 ------ src/Lexer/StatefulLexer.php | 12 ----------- src/Lexer/Token.php | 6 ------ src/Lexer/TokenStream/TokenStream.php | 20 +++---------------- .../Exception/UnexpectedTokenException.php | 8 +++----- 8 files changed, 8 insertions(+), 60 deletions(-) diff --git a/src/Lexer/AbstractLexer.php b/src/Lexer/AbstractLexer.php index 37d583a..97fdd4a 100644 --- a/src/Lexer/AbstractLexer.php +++ b/src/Lexer/AbstractLexer.php @@ -6,6 +6,7 @@ use Dissect\Lexer\Exception\RecognitionException; use Dissect\Lexer\TokenStream\ArrayTokenStream; +use Dissect\Lexer\TokenStream\TokenStream; use Dissect\Parser\Parser; use Dissect\Util\Util; @@ -22,8 +23,6 @@ abstract class AbstractLexer implements Lexer /** * Returns the current line. - * - * @return int The current line. */ protected function getCurrentLine(): int { @@ -35,24 +34,18 @@ protected function getCurrentLine(): int * Returns the token on success or null on failure. * * @param string $string The string to extract the token from. - * - * @return Token|null The extracted token or null. */ abstract protected function extractToken(string $string): ?Token; /** * Should given token be skipped? - * - * @param Token $token The token to evaluate. - * - * @return boolean Whether to skip the token. */ abstract protected function shouldSkipToken(Token $token): bool; /** * {@inheritDoc} */ - public function lex(string $string): TokenStream\TokenStream|ArrayTokenStream + public function lex(string $string): TokenStream { // normalize line endings $string = strtr($string, ["\r\n" => "\n", "\r" => "\n"]); diff --git a/src/Lexer/Lexer.php b/src/Lexer/Lexer.php index 0a72446..119c291 100644 --- a/src/Lexer/Lexer.php +++ b/src/Lexer/Lexer.php @@ -21,8 +21,6 @@ interface Lexer * @param string $string The string to lex. * * @throws RecognitionException When unable to extract more tokens from the string. - * - * @return TokenStream The resulting token stream. */ public function lex(string $string): TokenStream; } diff --git a/src/Lexer/RegexLexer.php b/src/Lexer/RegexLexer.php index ca90677..759feac 100644 --- a/src/Lexer/RegexLexer.php +++ b/src/Lexer/RegexLexer.php @@ -69,9 +69,6 @@ abstract protected function getNonCatchablePatterns(): array; /** * Retrieves the token type. - * - * - * @return string $type */ abstract protected function getType(string &$value): string; } diff --git a/src/Lexer/SimpleLexer.php b/src/Lexer/SimpleLexer.php index 3fe2316..3168b1e 100644 --- a/src/Lexer/SimpleLexer.php +++ b/src/Lexer/SimpleLexer.php @@ -30,8 +30,6 @@ class SimpleLexer extends AbstractLexer * * @param string $type The token type. * @param string|null $value The value to be recognized. - * - * @return SimpleLexer This instance for fluent interface. */ public function token(string $type, string $value = null): self { @@ -49,8 +47,6 @@ public function token(string $type, string $value = null): self * * @param string $type The token type. * @param string $regex The regular expression used to match the token. - * - * @return SimpleLexer This instance for fluent interface. */ public function regex(string $type, string $regex): static { @@ -63,8 +59,6 @@ public function regex(string $type, string $regex): static * Marks the token types given as arguments to be skipped. * * @param mixed $types Unlimited number of token types. - * - * @return SimpleLexer This instance for fluent interface. */ public function skip(mixed ...$types): static { diff --git a/src/Lexer/StatefulLexer.php b/src/Lexer/StatefulLexer.php index e340205..da12872 100644 --- a/src/Lexer/StatefulLexer.php +++ b/src/Lexer/StatefulLexer.php @@ -40,8 +40,6 @@ class StatefulLexer extends AbstractLexer * * @param string $type The token type. * @param string|null $value The value to be recognized. - * - * @return StatefulLexer This instance for fluent interface. */ public function token(string $type, string $value = null): StatefulLexer { @@ -68,8 +66,6 @@ public function token(string $type, string $value = null): StatefulLexer * * @param string $type The token type. * @param string $regex The regular expression used to match the token. - * - * @return SimpleLexer This instance for fluent interface. */ public function regex(string $type, string $regex): AbstractLexer { @@ -91,8 +87,6 @@ public function regex(string $type, string $regex): AbstractLexer * Marks the token types given as arguments to be skipped. * * @param mixed $types Unlimited number of token types. - * - * @return StatefulLexer This instance for fluent interface. */ public function skip(mixed ...$types): StatefulLexer { @@ -109,8 +103,6 @@ public function skip(mixed ...$types): StatefulLexer * Registers a new lexer state. * * @param string $state The new state name. - * - * @return StatefulLexer This instance for fluent interface. */ public function state(string $state): StatefulLexer { @@ -129,8 +121,6 @@ public function state(string $state): StatefulLexer * Sets the starting state for the lexer. * * @param string $state The name of the starting state. - * - * @return StatefulLexer This instance for fluent interface. */ public function start(string $state): StatefulLexer { @@ -143,8 +133,6 @@ public function start(string $state): StatefulLexer * Sets an action for the token type that is currently being built. * * @param mixed $action The action to take. - * - * @return StatefulLexer This instance for fluent interface. */ public function action(mixed $action): StatefulLexer { diff --git a/src/Lexer/Token.php b/src/Lexer/Token.php index c36faba..975c544 100644 --- a/src/Lexer/Token.php +++ b/src/Lexer/Token.php @@ -13,22 +13,16 @@ interface Token { /** * Returns the token type. - * - * @return mixed The token type. */ public function getType(): mixed; /** * Returns the token value. - * - * @return string The token value. */ public function getValue(): string; /** * Returns the line on which the token was found. - * - * @return int The line. */ public function getLine(): int; } diff --git a/src/Lexer/TokenStream/TokenStream.php b/src/Lexer/TokenStream/TokenStream.php index f0df479..da47d2b 100644 --- a/src/Lexer/TokenStream/TokenStream.php +++ b/src/Lexer/TokenStream/TokenStream.php @@ -18,8 +18,6 @@ interface TokenStream extends Countable, IteratorAggregate { /** * Returns the current position in the stream. - * - * @return int The current position in the stream. */ public function getPosition(): int; @@ -34,47 +32,35 @@ public function getCurrentToken(): Token; * Returns a look-ahead token. Negative values are allowed * and serve as look-behind. * - * @param int $n The look-ahead. - * * @throws OutOfBoundsException If current position + $n is out of range. - * - * @return Token The lookahead token. */ public function lookAhead(int $n): Token; /** * Returns the token at absolute position $n. * - * @param int $n The position. - * * @throws OutOfBoundsException If $n is out of range. - * - * @return Token The token at position $n. */ public function get(int $n): Token; /** * Moves the cursor to the absolute position $n. * - * @param int $n The position. - * * @throws OutOfBoundsException If $n is out of range. */ - public function move(int $n); + public function move(int $n): void; /** * Moves the cursor by $n, relative to the current position. * - * @param int $n The seek. - * * @throws OutOfBoundsException If current position + $n is out of range. */ - public function seek(int $n); + public function seek(int $n): void; /** * Moves the cursor to the next token. * * @throws OutOfBoundsException If at the end of the stream. */ - public function next(); + public function next(): void; } diff --git a/src/Parser/Exception/UnexpectedTokenException.php b/src/Parser/Exception/UnexpectedTokenException.php index 2857d5c..4e46ca0 100644 --- a/src/Parser/Exception/UnexpectedTokenException.php +++ b/src/Parser/Exception/UnexpectedTokenException.php @@ -15,10 +15,10 @@ class UnexpectedTokenException extends RuntimeException { public const MESSAGE = << Date: Mon, 19 Feb 2024 23:07:07 +0200 Subject: [PATCH 21/28] Remove PHP8.1 and PHP8.2 from build matrix, add PHP8.3 --- .github/workflows/php-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/php-tests.yml b/.github/workflows/php-tests.yml index fa7b6ba..4beb673 100644 --- a/.github/workflows/php-tests.yml +++ b/.github/workflows/php-tests.yml @@ -14,7 +14,7 @@ jobs: strategy: matrix: operating-system: [ ubuntu-latest ] - php-version: [ '8.0', '8.1', '8.2' ] + php-version: ['8.2', '8.3'] name: PHP ${{ matrix.php-version }} test on ${{ matrix.operating-system }} From fde344ee73743b514e048199fd8314a2cf8969a7 Mon Sep 17 00:00:00 2001 From: Alexander Lisachenko Date: Mon, 19 Feb 2024 23:07:07 +0200 Subject: [PATCH 22/28] Fix broken tests --- tests/Parser/LALR1/Dumper/res/table/debug.php | 2 -- tests/Parser/LALR1/Dumper/res/table/production.php | 6 +----- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/tests/Parser/LALR1/Dumper/res/table/debug.php b/tests/Parser/LALR1/Dumper/res/table/debug.php index 794e878..870256e 100644 --- a/tests/Parser/LALR1/Dumper/res/table/debug.php +++ b/tests/Parser/LALR1/Dumper/res/table/debug.php @@ -1,7 +1,5 @@ [ 0 => [ diff --git a/tests/Parser/LALR1/Dumper/res/table/production.php b/tests/Parser/LALR1/Dumper/res/table/production.php index a078ab2..607d708 100644 --- a/tests/Parser/LALR1/Dumper/res/table/production.php +++ b/tests/Parser/LALR1/Dumper/res/table/production.php @@ -1,5 +1 @@ -[0=>['a'=>2,'$eof'=>-2,],2=>['a'=>2,'b'=>-2,],3=>['b'=>4,],1=>['$eof'=>0,],4=>['$eof'=>-1,'b'=>-1,],],'goto'=>[0=>['S'=>1,],2=>['S'=>3,],]]; +[0=>['a'=>2,'$eof'=>-2,],2=>['a'=>2,'b'=>-2,],3=>['b'=>4,],1=>['$eof'=>0,],4=>['$eof'=>-1,'b'=>-1,],],'goto'=>[0=>['S'=>1,],2=>['S'=>3,],]]; From 49c4ce059f1219c1ce4ec9170a648c8560cebdc0 Mon Sep 17 00:00:00 2001 From: Alexander Lisachenko Date: Mon, 19 Feb 2024 23:07:07 +0200 Subject: [PATCH 23/28] Fix an error that value might be integer too (from tests + strict types enabled) --- src/Lexer/CommonToken.php | 6 +++--- src/Lexer/Token.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Lexer/CommonToken.php b/src/Lexer/CommonToken.php index b099a0d..7f5f17e 100644 --- a/src/Lexer/CommonToken.php +++ b/src/Lexer/CommonToken.php @@ -15,12 +15,12 @@ class CommonToken implements Token * Constructor. * * @param mixed $type The type of the token. - * @param string $value The token value. + * @param int|string $value The token value. * @param int $line The line. */ public function __construct( protected mixed $type, - protected string $value, + protected int|string $value, protected int $line ) {} @@ -35,7 +35,7 @@ public function getType(): mixed /** * {@inheritDoc} */ - public function getValue(): string + public function getValue(): int|string { return $this->value; } diff --git a/src/Lexer/Token.php b/src/Lexer/Token.php index 975c544..21c04da 100644 --- a/src/Lexer/Token.php +++ b/src/Lexer/Token.php @@ -19,7 +19,7 @@ public function getType(): mixed; /** * Returns the token value. */ - public function getValue(): string; + public function getValue(): int|string; /** * Returns the line on which the token was found. From 6e30ac632170c0efdbfc979602ab3139aa8903f8 Mon Sep 17 00:00:00 2001 From: Alexander Lisachenko Date: Mon, 19 Feb 2024 23:07:07 +0200 Subject: [PATCH 24/28] Apply the PHPUnitSetList set of rules --- rector.php | 6 ++- tests/Lexer/AbstractLexerTest.php | 20 ++------ .../Lexer/Recognizer/RegexRecognizerTest.php | 12 ++--- .../Lexer/Recognizer/SimpleRecognizerTest.php | 8 +--- tests/Lexer/RegexLexerTest.php | 8 +--- tests/Lexer/SimpleLexerTest.php | 12 ++--- tests/Lexer/StatefulLexerTest.php | 16 ++----- .../TokenStream/ArrayTokenStreamTest.php | 48 +++++-------------- tests/Parser/GrammarTest.php | 16 ++----- tests/Parser/LALR1/Analysis/AnalyzerTest.php | 20 ++------ tests/Parser/LALR1/Analysis/AutomatonTest.php | 8 +--- tests/Parser/LALR1/Analysis/ItemTest.php | 20 ++------ .../Analysis/KernelSet/KernelSetTest.php | 8 +--- tests/Parser/LALR1/Analysis/StateTest.php | 4 +- .../LALR1/Dumper/AutomatonDumperTest.php | 8 +--- .../LALR1/Dumper/DebugTableDumperTest.php | 4 +- .../Dumper/ProductionTableDumperTest.php | 4 +- tests/Parser/LALR1/ParserTest.php | 8 +--- tests/Parser/RuleTest.php | 4 +- 19 files changed, 62 insertions(+), 172 deletions(-) diff --git a/rector.php b/rector.php index 8929c4e..2ea5420 100644 --- a/rector.php +++ b/rector.php @@ -8,6 +8,7 @@ use Rector\DeadCode\Rector\Property\RemoveUselessVarTagRector; use Rector\Php71\Rector\ClassConst\PublicConstantVisibilityRector; use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector; +use Rector\PHPUnit\Set\PHPUnitSetList; use Rector\TypeDeclaration\Rector\Class_\AddTestsVoidReturnTypeWhereNoReturnRector; use Rector\TypeDeclaration\Rector\ClassMethod\AddVoidReturnTypeWhereNoReturnRector; use Rector\TypeDeclaration\Rector\StmtsAwareInterface\DeclareStrictTypesRector; @@ -28,5 +29,8 @@ ClosureToArrowFunctionRector::class, AddVoidReturnTypeWhereNoReturnRector::class, AddTestsVoidReturnTypeWhereNoReturnRector::class, - DeclareStrictTypesRector::class, + // DeclareStrictTypesRector::class, + ]) + ->withSets([ + PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES ]); diff --git a/tests/Lexer/AbstractLexerTest.php b/tests/Lexer/AbstractLexerTest.php index 4d6ae96..d0b5819 100644 --- a/tests/Lexer/AbstractLexerTest.php +++ b/tests/Lexer/AbstractLexerTest.php @@ -17,9 +17,7 @@ public function setUp(): void $this->lexer = new StubLexer(); } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function lexShouldDelegateToExtractTokenUpdatingTheLineAndOffsetAccordingly(): void { $stream = $this->lexer->lex("ab\nc"); @@ -40,9 +38,7 @@ public function lexShouldDelegateToExtractTokenUpdatingTheLineAndOffsetAccording $this->assertEquals(2, $stream->getCurrentToken()->getLine()); } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function lexShouldAppendAnEofTokenAutomatically(): void { $stream = $this->lexer->lex("abc"); @@ -52,9 +48,7 @@ public function lexShouldAppendAnEofTokenAutomatically(): void $this->assertEquals(1, $stream->getCurrentToken()->getLine()); } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function lexShouldThrowAnExceptionOnAnUnrecognizableToken(): void { try { @@ -65,18 +59,14 @@ public function lexShouldThrowAnExceptionOnAnUnrecognizableToken(): void } } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function lexShouldNormalizeLineEndingsBeforeLexing(): void { $stream = $this->lexer->lex("a\r\nb"); $this->assertEquals("\n", $stream->get(1)->getValue()); } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function lexShouldSkipTokensIfToldToDoSo(): void { $stream = $this->lexer->lex('aeb'); diff --git a/tests/Lexer/Recognizer/RegexRecognizerTest.php b/tests/Lexer/Recognizer/RegexRecognizerTest.php index 166d2d8..8517e0f 100644 --- a/tests/Lexer/Recognizer/RegexRecognizerTest.php +++ b/tests/Lexer/Recognizer/RegexRecognizerTest.php @@ -8,9 +8,7 @@ class RegexRecognizerTest extends TestCase { - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function recognizerShouldMatchAndPassTheValueByReference(): void { $recognizer = new RegexRecognizer('/[a-z]+/'); @@ -21,9 +19,7 @@ public function recognizerShouldMatchAndPassTheValueByReference(): void $this->assertEquals('lorem', $value); } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function recognizerShouldFailAndTheValueShouldStayNull(): void { $recognizer = new RegexRecognizer('/[a-z]+/'); @@ -33,9 +29,7 @@ public function recognizerShouldFailAndTheValueShouldStayNull(): void $this->assertNull($value); } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function recognizerShouldFailIfTheMatchIsNotAtTheBeginningOfTheString(): void { $recognizer = new RegexRecognizer('/[a-z]+/'); diff --git a/tests/Lexer/Recognizer/SimpleRecognizerTest.php b/tests/Lexer/Recognizer/SimpleRecognizerTest.php index f5c9260..095cb4e 100644 --- a/tests/Lexer/Recognizer/SimpleRecognizerTest.php +++ b/tests/Lexer/Recognizer/SimpleRecognizerTest.php @@ -8,9 +8,7 @@ class SimpleRecognizerTest extends TestCase { - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function recognizerShouldMatchAndPassTheValueByReference(): void { $recognizer = new SimpleRecognizer('class'); @@ -21,9 +19,7 @@ public function recognizerShouldMatchAndPassTheValueByReference(): void $this->assertEquals('class', $value); } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function recognizerShouldFailAndTheValueShouldStayNull(): void { $recognizer = new SimpleRecognizer('class'); diff --git a/tests/Lexer/RegexLexerTest.php b/tests/Lexer/RegexLexerTest.php index 3542200..83e8535 100644 --- a/tests/Lexer/RegexLexerTest.php +++ b/tests/Lexer/RegexLexerTest.php @@ -16,9 +16,7 @@ protected function setUp(): void $this->lexer = new StubRegexLexer(); } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function itShouldCallGetTypeToRetrieveTokenType(): void { $stream = $this->lexer->lex('5 + 6'); @@ -29,9 +27,7 @@ public function itShouldCallGetTypeToRetrieveTokenType(): void $this->assertEquals(Parser::EOF_TOKEN_TYPE, $stream->get(3)->getType()); } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function itShouldTrackLineNumbers(): void { $stream = $this->lexer->lex("5\n+\n\n5"); diff --git a/tests/Lexer/SimpleLexerTest.php b/tests/Lexer/SimpleLexerTest.php index dff589d..07ef9fd 100644 --- a/tests/Lexer/SimpleLexerTest.php +++ b/tests/Lexer/SimpleLexerTest.php @@ -25,9 +25,7 @@ public function setUp(): void ->skip('WS'); } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function simpleLexerShouldWalkThroughTheRecognizers(): void { $stream = $this->lexer->lex('a (b) c'); @@ -38,9 +36,7 @@ public function simpleLexerShouldWalkThroughTheRecognizers(): void $this->assertEquals('C', $stream->get(4)->getType()); } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function simpleLexerShouldSkipSpecifiedTokens(): void { $stream = $this->lexer->lex('a (b) c'); @@ -50,9 +46,7 @@ public function simpleLexerShouldSkipSpecifiedTokens(): void } } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function simpleLexerShouldReturnTheBestMatch(): void { $this->lexer->token('CLASS', 'class'); diff --git a/tests/Lexer/StatefulLexerTest.php b/tests/Lexer/StatefulLexerTest.php index d52932f..7d1cfde 100644 --- a/tests/Lexer/StatefulLexerTest.php +++ b/tests/Lexer/StatefulLexerTest.php @@ -16,9 +16,7 @@ protected function setUp(): void $this->lexer = new StatefulLexer(); } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function addingNewTokenShouldThrowAnExceptionWhenNoStateIsBeingBuilt(): void { $this->expectExceptionMessage("Define a lexer state first."); @@ -26,9 +24,7 @@ public function addingNewTokenShouldThrowAnExceptionWhenNoStateIsBeingBuilt(): v $this->lexer->regex('WORD', '/[a-z]+/'); } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function anExceptionShouldBeThrownOnLexingWithoutAStartingState(): void { $this->expectException(LogicException::class); @@ -36,9 +32,7 @@ public function anExceptionShouldBeThrownOnLexingWithoutAStartingState(): void $this->lexer->lex('foo'); } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function theStateMechanismShouldCorrectlyPushAndPopStatesFromTheStack(): void { /** @noinspection PhpPossiblePolymorphicInvocationInspection */ @@ -63,9 +57,7 @@ public function theStateMechanismShouldCorrectlyPushAndPopStatesFromTheStack(): $this->assertEquals('quux', $stream->get(6)->getValue()); } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function defaultActionShouldBeNop(): void { $this->lexer->state('root') diff --git a/tests/Lexer/TokenStream/ArrayTokenStreamTest.php b/tests/Lexer/TokenStream/ArrayTokenStreamTest.php index 9b15a25..b9ae22b 100644 --- a/tests/Lexer/TokenStream/ArrayTokenStreamTest.php +++ b/tests/Lexer/TokenStream/ArrayTokenStreamTest.php @@ -23,17 +23,13 @@ protected function setUp(): void ); } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function theCursorShouldBeOnFirstTokenByDefault(): void { $this->assertEquals('6', $this->stream->getCurrentToken()->getValue()); } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function getPositionShouldReturnCurrentPosition(): void { $this->stream->seek(2); @@ -42,79 +38,61 @@ public function getPositionShouldReturnCurrentPosition(): void $this->assertEquals(3, $this->stream->getPosition()); } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function lookAheadShouldReturnTheCorrectToken(): void { $this->assertEquals('5', $this->stream->lookAhead(2)->getValue()); } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function lookAheadShouldThrowAnExceptionWhenInvalid(): void { $this->expectException(OutOfBoundsException::class); $this->stream->lookAhead(15); } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function getShouldReturnATokenByAbsolutePosition(): void { $this->assertEquals('3', $this->stream->get(4)->getValue()); } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function getShouldThrowAnExceptionWhenInvalid(): void { $this->expectException(OutOfBoundsException::class); $this->stream->get(15); } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function moveShouldMoveTheCursorByToAnAbsolutePosition(): void { $this->stream->move(2); $this->assertEquals('5', $this->stream->getCurrentToken()->getValue()); } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function moveShouldThrowAnExceptionWhenInvalid(): void { $this->expectException(OutOfBoundsException::class); $this->stream->move(15); } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function seekShouldMoveTheCursorByRelativeOffset(): void { $this->stream->seek(4); $this->assertEquals('3', $this->stream->getCurrentToken()->getValue()); } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function seekShouldThrowAnExceptionWhenInvalid(): void { $this->expectException(OutOfBoundsException::class); $this->stream->seek(15); } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function nextShouldMoveTheCursorOneTokenAhead(): void { $this->stream->next(); @@ -124,9 +102,7 @@ public function nextShouldMoveTheCursorOneTokenAhead(): void $this->assertEquals('5', $this->stream->getCurrentToken()->getValue()); } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function nextShouldThrowAnExceptionWhenAtTheEndOfTheStream(): void { $this->expectException(OutOfBoundsException::class); diff --git a/tests/Parser/GrammarTest.php b/tests/Parser/GrammarTest.php index d69bcec..fef6982 100644 --- a/tests/Parser/GrammarTest.php +++ b/tests/Parser/GrammarTest.php @@ -15,9 +15,7 @@ protected function setUp(): void $this->grammar = new ExampleGrammar(); } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function ruleAlternativesShouldHaveTheSameName(): void { $rules = $this->grammar->getRules(); @@ -26,9 +24,7 @@ public function ruleAlternativesShouldHaveTheSameName(): void $this->assertEquals('Foo', $rules[2]->getName()); } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function theGrammarShouldBeAugmentedWithAStartRule(): void { $this->assertEquals( @@ -42,18 +38,14 @@ public function theGrammarShouldBeAugmentedWithAStartRule(): void ); } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function shouldReturnAlternativesGroupedByName(): void { $rules = $this->grammar->getGroupedRules(); $this->assertCount(2, $rules['Foo']); } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function nonterminalsShouldBeDetectedFromRuleNames(): void { $this->assertTrue($this->grammar->hasNonterminal('Foo')); diff --git a/tests/Parser/LALR1/Analysis/AnalyzerTest.php b/tests/Parser/LALR1/Analysis/AnalyzerTest.php index 89121a3..7055ca3 100644 --- a/tests/Parser/LALR1/Analysis/AnalyzerTest.php +++ b/tests/Parser/LALR1/Analysis/AnalyzerTest.php @@ -13,9 +13,7 @@ class AnalyzerTest extends TestCase { protected ?Analyzer $analyzer = null; - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function automatonShouldBeCorrectlyBuilt(): void { $grammar = new Grammar(); @@ -36,9 +34,7 @@ public function automatonShouldBeCorrectlyBuilt(): void $this->assertEquals(4, $table[3]['b']); } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function lookaheadShouldBeCorrectlyPumped(): void { $grammar = new Grammar(); @@ -93,9 +89,7 @@ public function lookaheadShouldBeCorrectlyPumped(): void ); } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function parseTableShouldBeCorrectlyBuilt(): void { $grammar = new Grammar(); @@ -134,9 +128,7 @@ public function parseTableShouldBeCorrectlyBuilt(): void $this->assertEquals(3, $table['goto'][2]['S']); } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function unexpectedConflictsShouldThrowAnException(): void { $grammar = new Grammar(); @@ -164,9 +156,7 @@ public function unexpectedConflictsShouldThrowAnException(): void } } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function expectedConflictsShouldBeRecorded(): void { $grammar = new Grammar(); diff --git a/tests/Parser/LALR1/Analysis/AutomatonTest.php b/tests/Parser/LALR1/Analysis/AutomatonTest.php index da972d8..cfaebd5 100644 --- a/tests/Parser/LALR1/Analysis/AutomatonTest.php +++ b/tests/Parser/LALR1/Analysis/AutomatonTest.php @@ -17,9 +17,7 @@ protected function setUp(): void $this->automaton->addState(new State(1, [])); } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function addingATransitionShouldBeVisibleInTheTransitionTable(): void { $this->automaton->addTransition(0, 'a', 1); @@ -28,9 +26,7 @@ public function addingATransitionShouldBeVisibleInTheTransitionTable(): void $this->assertEquals(1, $table[0]['a']); } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function aNewStateShouldBeIdentifiedByItsNumber(): void { $state = new State(2, []); diff --git a/tests/Parser/LALR1/Analysis/ItemTest.php b/tests/Parser/LALR1/Analysis/ItemTest.php index 9c9aad7..7faf688 100644 --- a/tests/Parser/LALR1/Analysis/ItemTest.php +++ b/tests/Parser/LALR1/Analysis/ItemTest.php @@ -9,9 +9,7 @@ class ItemTest extends TestCase { - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function getActiveComponentShouldReturnTheComponentAboutToBeEncountered(): void { $item = new Item(new Rule(1, 'A', ['a', 'b', 'c']), 1); @@ -19,9 +17,7 @@ public function getActiveComponentShouldReturnTheComponentAboutToBeEncountered() $this->assertEquals('b', $item->getActiveComponent()); } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function itemShouldBeAReduceItemIfAllComponentsHaveBeenEncountered(): void { $item = new Item(new Rule(1, 'A', ['a', 'b', 'c']), 1); @@ -31,9 +27,7 @@ public function itemShouldBeAReduceItemIfAllComponentsHaveBeenEncountered(): voi $this->assertTrue($item->isReduceItem()); } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function itemShouldPumpLookaheadIntoConnectedItems(): void { $item1 = new Item(new Rule(1, 'A', ['a', 'b', 'c']), 1); @@ -45,9 +39,7 @@ public function itemShouldPumpLookaheadIntoConnectedItems(): void $this->assertContains('d', $item2->getLookahead()); } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function itemShouldPumpTheSameLookaheadOnlyOnce(): void { $item1 = new Item(new Rule(1, 'A', ['a', 'b', 'c']), 1); @@ -70,9 +62,7 @@ public function itemShouldPumpTheSameLookaheadOnlyOnce(): void $item1->pump('d'); } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function getUnrecognizedComponentsShouldReturnAllComponentAfterTheDottedOne(): void { $item = new Item(new Rule(1, 'A', ['a', 'b', 'c']), 1); diff --git a/tests/Parser/LALR1/Analysis/KernelSet/KernelSetTest.php b/tests/Parser/LALR1/Analysis/KernelSet/KernelSetTest.php index 79e51c9..825ecc3 100644 --- a/tests/Parser/LALR1/Analysis/KernelSet/KernelSetTest.php +++ b/tests/Parser/LALR1/Analysis/KernelSet/KernelSetTest.php @@ -8,9 +8,7 @@ class KernelSetTest extends TestCase { - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function kernelsShouldBeProperlyHashedAndOrdered(): void { $this->assertEquals(array(1, 3, 6, 7), KernelSet::hashKernel(array( @@ -21,9 +19,7 @@ public function kernelsShouldBeProperlyHashedAndOrdered(): void ))); } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function insertShouldInsertANewNodeIfNoIdenticalKernelExists(): void { $set = new KernelSet(); diff --git a/tests/Parser/LALR1/Analysis/StateTest.php b/tests/Parser/LALR1/Analysis/StateTest.php index 5531f2b..930ddaf 100644 --- a/tests/Parser/LALR1/Analysis/StateTest.php +++ b/tests/Parser/LALR1/Analysis/StateTest.php @@ -9,9 +9,7 @@ class StateTest extends TestCase { - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function stateShouldKeepItemsByRuleNumberAndPosition(): void { $item1 = new Item(new Rule(1, 'E', ['E', '+', 'T']), 0); diff --git a/tests/Parser/LALR1/Dumper/AutomatonDumperTest.php b/tests/Parser/LALR1/Dumper/AutomatonDumperTest.php index 7539e1b..b5c7ac2 100644 --- a/tests/Parser/LALR1/Dumper/AutomatonDumperTest.php +++ b/tests/Parser/LALR1/Dumper/AutomatonDumperTest.php @@ -18,9 +18,7 @@ protected function setUp(): void $this->dumper = new AutomatonDumper($automaton); } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function dumpDumpsTheEntireAutomaton(): void { $this->assertStringEqualsFile( @@ -29,9 +27,7 @@ public function dumpDumpsTheEntireAutomaton(): void ); } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function dumpStateDumpsOnlyTheSpecifiedStateAndTransitions(): void { $this->assertStringEqualsFile( diff --git a/tests/Parser/LALR1/Dumper/DebugTableDumperTest.php b/tests/Parser/LALR1/Dumper/DebugTableDumperTest.php index 11fb40d..2344d23 100644 --- a/tests/Parser/LALR1/Dumper/DebugTableDumperTest.php +++ b/tests/Parser/LALR1/Dumper/DebugTableDumperTest.php @@ -9,9 +9,7 @@ class DebugTableDumperTest extends TestCase { - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function itDumpsAHumanReadableParseTableWithExplainingComments(): void { $grammar = new ExampleGrammar(); diff --git a/tests/Parser/LALR1/Dumper/ProductionTableDumperTest.php b/tests/Parser/LALR1/Dumper/ProductionTableDumperTest.php index 8bd3a59..b6b1f5d 100644 --- a/tests/Parser/LALR1/Dumper/ProductionTableDumperTest.php +++ b/tests/Parser/LALR1/Dumper/ProductionTableDumperTest.php @@ -9,9 +9,7 @@ class ProductionTableDumperTest extends TestCase { - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function theWrittenTableShouldBeAsCompactAsPossible(): void { $grammar = new ExampleGrammar(); diff --git a/tests/Parser/LALR1/ParserTest.php b/tests/Parser/LALR1/ParserTest.php index 8261dec..cd5728e 100644 --- a/tests/Parser/LALR1/ParserTest.php +++ b/tests/Parser/LALR1/ParserTest.php @@ -18,9 +18,7 @@ protected function setUp(): void $this->parser = new Parser(new ArithGrammar()); } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function parserShouldProcessTheTokenStreamAndUseGrammarCallbacksForReductions(): void { $this->assertEquals(-2, $this->parser->parse($this->lexer->lex( @@ -36,9 +34,7 @@ public function parserShouldProcessTheTokenStreamAndUseGrammarCallbacksForReduct '4 ** 3 ** 2'))); } - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function parserShouldThrowAnExceptionOnInvalidInput(): void { try { diff --git a/tests/Parser/RuleTest.php b/tests/Parser/RuleTest.php index 3b36e6d..f7ae753 100644 --- a/tests/Parser/RuleTest.php +++ b/tests/Parser/RuleTest.php @@ -8,9 +8,7 @@ class RuleTest extends TestCase { - /** - * @test - */ + #[\PHPUnit\Framework\Attributes\Test] public function getComponentShouldReturnNullIfAskedForComponentOutOfRange(): void { $r = new Rule(1, 'Foo', ['x', 'y']); From c6768821918b97b4e9e4c507d2aa58b4f8eda271 Mon Sep 17 00:00:00 2001 From: Alexander Lisachenko Date: Mon, 19 Feb 2024 23:07:07 +0200 Subject: [PATCH 25/28] Apply the PHPUnitSetList::PHPUNIT_CODE_QUALITY set of rules --- rector.php | 3 +- src/Lexer/AbstractLexer.php | 1 + src/Lexer/Recognizer/RegexRecognizer.php | 1 + src/Lexer/Recognizer/SimpleRecognizer.php | 1 + src/Lexer/RegexLexer.php | 1 + src/Lexer/SimpleLexer.php | 1 + src/Lexer/StatefulLexer.php | 1 + src/Lexer/TokenStream/ArrayTokenStream.php | 1 + src/Parser/Grammar.php | 1 + src/Parser/LALR1/Analysis/Analyzer.php | 1 + src/Parser/LALR1/Analysis/Automaton.php | 1 + src/Parser/LALR1/Analysis/Item.php | 1 + .../LALR1/Analysis/KernelSet/KernelSet.php | 1 + src/Parser/LALR1/Analysis/State.php | 1 + src/Parser/LALR1/Dumper/AutomatonDumper.php | 1 + src/Parser/LALR1/Dumper/DebugTableDumper.php | 1 + .../LALR1/Dumper/ProductionTableDumper.php | 1 + src/Parser/LALR1/Parser.php | 1 + src/Parser/Rule.php | 1 + tests/Lexer/AbstractLexerTest.php | 26 +++--- .../Lexer/Recognizer/RegexRecognizerTest.php | 2 +- .../Lexer/Recognizer/SimpleRecognizerTest.php | 2 +- tests/Lexer/RegexLexerTest.php | 10 +-- tests/Lexer/SimpleLexerTest.php | 14 ++-- tests/Lexer/StatefulLexerTest.php | 8 +- .../TokenStream/ArrayTokenStreamTest.php | 16 ++-- tests/Parser/GrammarTest.php | 8 +- tests/Parser/LALR1/Analysis/AnalyzerTest.php | 84 +++++++++---------- tests/Parser/LALR1/Analysis/AutomatonTest.php | 2 +- tests/Parser/LALR1/Analysis/ItemTest.php | 6 +- .../Analysis/KernelSet/KernelSetTest.php | 10 +-- tests/Parser/LALR1/ParserTest.php | 14 ++-- tests/Parser/RuleTest.php | 2 +- 33 files changed, 122 insertions(+), 103 deletions(-) diff --git a/rector.php b/rector.php index 2ea5420..c216c38 100644 --- a/rector.php +++ b/rector.php @@ -32,5 +32,6 @@ // DeclareStrictTypesRector::class, ]) ->withSets([ - PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES + PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES, + PHPUnitSetList::PHPUNIT_CODE_QUALITY, ]); diff --git a/src/Lexer/AbstractLexer.php b/src/Lexer/AbstractLexer.php index 97fdd4a..9603914 100644 --- a/src/Lexer/AbstractLexer.php +++ b/src/Lexer/AbstractLexer.php @@ -16,6 +16,7 @@ * SimpleLexer and StatefulLexer extend this class. * * @author Jakub Lédl + * @see \Dissect\Lexer\AbstractLexerTest */ abstract class AbstractLexer implements Lexer { diff --git a/src/Lexer/Recognizer/RegexRecognizer.php b/src/Lexer/Recognizer/RegexRecognizer.php index 49d96cb..7956de2 100644 --- a/src/Lexer/Recognizer/RegexRecognizer.php +++ b/src/Lexer/Recognizer/RegexRecognizer.php @@ -9,6 +9,7 @@ * regular expression. * * @author Jakub Lédl + * @see \Dissect\Lexer\Recognizer\RegexRecognizerTest */ class RegexRecognizer implements Recognizer { diff --git a/src/Lexer/Recognizer/SimpleRecognizer.php b/src/Lexer/Recognizer/SimpleRecognizer.php index 43d1153..a03a5a7 100644 --- a/src/Lexer/Recognizer/SimpleRecognizer.php +++ b/src/Lexer/Recognizer/SimpleRecognizer.php @@ -9,6 +9,7 @@ * strpos match. * * @author Jakub Lédl + * @see \Dissect\Lexer\Recognizer\SimpleRecognizerTest */ class SimpleRecognizer implements Recognizer { diff --git a/src/Lexer/RegexLexer.php b/src/Lexer/RegexLexer.php index 759feac..673aacc 100644 --- a/src/Lexer/RegexLexer.php +++ b/src/Lexer/RegexLexer.php @@ -15,6 +15,7 @@ * @author Jonathan Wage * @author Roman Borschel * @author Jakub Lédl + * @see \Dissect\Lexer\RegexLexerTest */ abstract class RegexLexer implements Lexer { diff --git a/src/Lexer/SimpleLexer.php b/src/Lexer/SimpleLexer.php index 3168b1e..854ff6c 100644 --- a/src/Lexer/SimpleLexer.php +++ b/src/Lexer/SimpleLexer.php @@ -13,6 +13,7 @@ * without keeping track of state. * * @author Jakub Lédl + * @see \Dissect\Lexer\SimpleLexerTest */ class SimpleLexer extends AbstractLexer { diff --git a/src/Lexer/StatefulLexer.php b/src/Lexer/StatefulLexer.php index da12872..6a4ac5c 100644 --- a/src/Lexer/StatefulLexer.php +++ b/src/Lexer/StatefulLexer.php @@ -14,6 +14,7 @@ * but internally keeps notion of current lexer state. * * @author Jakub Lédl + * @see \Dissect\Lexer\StatefulLexerTest */ class StatefulLexer extends AbstractLexer { diff --git a/src/Lexer/TokenStream/ArrayTokenStream.php b/src/Lexer/TokenStream/ArrayTokenStream.php index ec55572..c31b631 100644 --- a/src/Lexer/TokenStream/ArrayTokenStream.php +++ b/src/Lexer/TokenStream/ArrayTokenStream.php @@ -12,6 +12,7 @@ * A simple array based implementation of a token stream. * * @author Jakub Lédl + * @see \Dissect\Lexer\TokenStream\ArrayTokenStreamTest */ class ArrayTokenStream implements TokenStream { diff --git a/src/Parser/Grammar.php b/src/Parser/Grammar.php index 116e50c..e795b36 100644 --- a/src/Parser/Grammar.php +++ b/src/Parser/Grammar.php @@ -10,6 +10,7 @@ * Represents a context-free grammar. * * @author Jakub Lédl + * @see \Dissect\Parser\GrammarTest */ class Grammar { diff --git a/src/Parser/LALR1/Analysis/Analyzer.php b/src/Parser/LALR1/Analysis/Analyzer.php index 63548d6..a6fefe4 100644 --- a/src/Parser/LALR1/Analysis/Analyzer.php +++ b/src/Parser/LALR1/Analysis/Analyzer.php @@ -17,6 +17,7 @@ * the result. * * @author Jakub Lédl + * @see \Dissect\Parser\LALR1\Analysis\AnalyzerTest */ class Analyzer { diff --git a/src/Parser/LALR1/Analysis/Automaton.php b/src/Parser/LALR1/Analysis/Automaton.php index 6bfba8a..03c4eb3 100644 --- a/src/Parser/LALR1/Analysis/Automaton.php +++ b/src/Parser/LALR1/Analysis/Automaton.php @@ -9,6 +9,7 @@ * grammar productions. * * @author Jakub Lédl + * @see \Dissect\Parser\LALR1\Analysis\AutomatonTest */ class Automaton { diff --git a/src/Parser/LALR1/Analysis/Item.php b/src/Parser/LALR1/Analysis/Item.php index 98dfbca..c517731 100644 --- a/src/Parser/LALR1/Analysis/Item.php +++ b/src/Parser/LALR1/Analysis/Item.php @@ -29,6 +29,7 @@ * can be reduced. * * @author Jakub Lédl + * @see \Dissect\Parser\LALR1\Analysis\ItemTest */ class Item { diff --git a/src/Parser/LALR1/Analysis/KernelSet/KernelSet.php b/src/Parser/LALR1/Analysis/KernelSet/KernelSet.php index 2bdb7f5..230f448 100644 --- a/src/Parser/LALR1/Analysis/KernelSet/KernelSet.php +++ b/src/Parser/LALR1/Analysis/KernelSet/KernelSet.php @@ -9,6 +9,7 @@ * of states by their kernel items. * * @author Jakub Lédl + * @see \Dissect\Parser\LALR1\Analysis\KernelSet\KernelSetTest */ class KernelSet { diff --git a/src/Parser/LALR1/Analysis/State.php b/src/Parser/LALR1/Analysis/State.php index 13a64ca..62e92b8 100644 --- a/src/Parser/LALR1/Analysis/State.php +++ b/src/Parser/LALR1/Analysis/State.php @@ -8,6 +8,7 @@ * A state in a handle-finding FSA. * * @author Jakub Lédl + * @see \Dissect\Parser\LALR1\Analysis\StateTest */ class State { diff --git a/src/Parser/LALR1/Dumper/AutomatonDumper.php b/src/Parser/LALR1/Dumper/AutomatonDumper.php index 30c77e2..2662a00 100644 --- a/src/Parser/LALR1/Dumper/AutomatonDumper.php +++ b/src/Parser/LALR1/Dumper/AutomatonDumper.php @@ -13,6 +13,7 @@ * format used by Graphviz. * * @author Jakub Lédl + * @see \Dissect\Parser\LALR1\Dumper\AutomatonDumperTest */ class AutomatonDumper { diff --git a/src/Parser/LALR1/Dumper/DebugTableDumper.php b/src/Parser/LALR1/Dumper/DebugTableDumper.php index 5116b15..7e49497 100644 --- a/src/Parser/LALR1/Dumper/DebugTableDumper.php +++ b/src/Parser/LALR1/Dumper/DebugTableDumper.php @@ -12,6 +12,7 @@ * parser. * * @author Jakub Lédl + * @see \Dissect\Parser\LALR1\Dumper\DebugTableDumperTest */ class DebugTableDumper implements TableDumper { diff --git a/src/Parser/LALR1/Dumper/ProductionTableDumper.php b/src/Parser/LALR1/Dumper/ProductionTableDumper.php index e678600..c4d288f 100644 --- a/src/Parser/LALR1/Dumper/ProductionTableDumper.php +++ b/src/Parser/LALR1/Dumper/ProductionTableDumper.php @@ -11,6 +11,7 @@ * without any comments. * * @author Jakub Lédl + * @see \Dissect\Parser\LALR1\Dumper\ProductionTableDumperTest */ class ProductionTableDumper implements TableDumper { diff --git a/src/Parser/LALR1/Parser.php b/src/Parser/LALR1/Parser.php index 1852b6b..2d5f71b 100644 --- a/src/Parser/LALR1/Parser.php +++ b/src/Parser/LALR1/Parser.php @@ -14,6 +14,7 @@ * A LR parser. * * @author Jakub Lédl + * @see \Dissect\Parser\LALR1\ParserTest */ class Parser implements P\Parser { diff --git a/src/Parser/Rule.php b/src/Parser/Rule.php index 631243a..6a7fde8 100644 --- a/src/Parser/Rule.php +++ b/src/Parser/Rule.php @@ -8,6 +8,7 @@ * Represents a rule in a context-free grammar. * * @author Jakub Lédl + * @see \Dissect\Parser\RuleTest */ class Rule { diff --git a/tests/Lexer/AbstractLexerTest.php b/tests/Lexer/AbstractLexerTest.php index d0b5819..eb33970 100644 --- a/tests/Lexer/AbstractLexerTest.php +++ b/tests/Lexer/AbstractLexerTest.php @@ -22,20 +22,20 @@ public function lexShouldDelegateToExtractTokenUpdatingTheLineAndOffsetAccording { $stream = $this->lexer->lex("ab\nc"); - $this->assertEquals('a', $stream->getCurrentToken()->getValue()); - $this->assertEquals(1, $stream->getCurrentToken()->getLine()); + $this->assertSame('a', $stream->getCurrentToken()->getValue()); + $this->assertSame(1, $stream->getCurrentToken()->getLine()); $stream->next(); - $this->assertEquals('b', $stream->getCurrentToken()->getValue()); - $this->assertEquals(1, $stream->getCurrentToken()->getLine()); + $this->assertSame('b', $stream->getCurrentToken()->getValue()); + $this->assertSame(1, $stream->getCurrentToken()->getLine()); $stream->next(); - $this->assertEquals("\n", $stream->getCurrentToken()->getValue()); - $this->assertEquals(1, $stream->getCurrentToken()->getLine()); + $this->assertSame("\n", $stream->getCurrentToken()->getValue()); + $this->assertSame(1, $stream->getCurrentToken()->getLine()); $stream->next(); - $this->assertEquals('c', $stream->getCurrentToken()->getValue()); - $this->assertEquals(2, $stream->getCurrentToken()->getLine()); + $this->assertSame('c', $stream->getCurrentToken()->getValue()); + $this->assertSame(2, $stream->getCurrentToken()->getLine()); } #[\PHPUnit\Framework\Attributes\Test] @@ -44,8 +44,8 @@ public function lexShouldAppendAnEofTokenAutomatically(): void $stream = $this->lexer->lex("abc"); $stream->seek(3); - $this->assertEquals(Parser::EOF_TOKEN_TYPE, $stream->getCurrentToken()->getType()); - $this->assertEquals(1, $stream->getCurrentToken()->getLine()); + $this->assertSame(Parser::EOF_TOKEN_TYPE, $stream->getCurrentToken()->getType()); + $this->assertSame(1, $stream->getCurrentToken()->getLine()); } #[\PHPUnit\Framework\Attributes\Test] @@ -55,7 +55,7 @@ public function lexShouldThrowAnExceptionOnAnUnrecognizableToken(): void $this->lexer->lex("abcd"); $this->fail('Expected a RecognitionException.'); } catch (RecognitionException $e) { - $this->assertEquals(1, $e->getSourceLine()); + $this->assertSame(1, $e->getSourceLine()); } } @@ -63,13 +63,13 @@ public function lexShouldThrowAnExceptionOnAnUnrecognizableToken(): void public function lexShouldNormalizeLineEndingsBeforeLexing(): void { $stream = $this->lexer->lex("a\r\nb"); - $this->assertEquals("\n", $stream->get(1)->getValue()); + $this->assertSame("\n", $stream->get(1)->getValue()); } #[\PHPUnit\Framework\Attributes\Test] public function lexShouldSkipTokensIfToldToDoSo(): void { $stream = $this->lexer->lex('aeb'); - $this->assertNotEquals('e', $stream->get(1)->getType()); + $this->assertNotSame('e', $stream->get(1)->getType()); } } diff --git a/tests/Lexer/Recognizer/RegexRecognizerTest.php b/tests/Lexer/Recognizer/RegexRecognizerTest.php index 8517e0f..26072d8 100644 --- a/tests/Lexer/Recognizer/RegexRecognizerTest.php +++ b/tests/Lexer/Recognizer/RegexRecognizerTest.php @@ -16,7 +16,7 @@ public function recognizerShouldMatchAndPassTheValueByReference(): void $this->assertTrue($result); $this->assertNotNull($value); - $this->assertEquals('lorem', $value); + $this->assertSame('lorem', $value); } #[\PHPUnit\Framework\Attributes\Test] diff --git a/tests/Lexer/Recognizer/SimpleRecognizerTest.php b/tests/Lexer/Recognizer/SimpleRecognizerTest.php index 095cb4e..da0212b 100644 --- a/tests/Lexer/Recognizer/SimpleRecognizerTest.php +++ b/tests/Lexer/Recognizer/SimpleRecognizerTest.php @@ -16,7 +16,7 @@ public function recognizerShouldMatchAndPassTheValueByReference(): void $this->assertTrue($result); $this->assertNotNull($value); - $this->assertEquals('class', $value); + $this->assertSame('class', $value); } #[\PHPUnit\Framework\Attributes\Test] diff --git a/tests/Lexer/RegexLexerTest.php b/tests/Lexer/RegexLexerTest.php index 83e8535..c70b6d9 100644 --- a/tests/Lexer/RegexLexerTest.php +++ b/tests/Lexer/RegexLexerTest.php @@ -22,9 +22,9 @@ public function itShouldCallGetTypeToRetrieveTokenType(): void $stream = $this->lexer->lex('5 + 6'); $this->assertCount(4, $stream); - $this->assertEquals('INT', $stream->get(0)->getType()); - $this->assertEquals('+', $stream->get(1)->getType()); - $this->assertEquals(Parser::EOF_TOKEN_TYPE, $stream->get(3)->getType()); + $this->assertSame('INT', $stream->get(0)->getType()); + $this->assertSame('+', $stream->get(1)->getType()); + $this->assertSame(Parser::EOF_TOKEN_TYPE, $stream->get(3)->getType()); } #[\PHPUnit\Framework\Attributes\Test] @@ -32,7 +32,7 @@ public function itShouldTrackLineNumbers(): void { $stream = $this->lexer->lex("5\n+\n\n5"); - $this->assertEquals(2, $stream->get(1)->getLine()); - $this->assertEquals(4, $stream->get(2)->getLine()); + $this->assertSame(2, $stream->get(1)->getLine()); + $this->assertSame(4, $stream->get(2)->getLine()); } } diff --git a/tests/Lexer/SimpleLexerTest.php b/tests/Lexer/SimpleLexerTest.php index 07ef9fd..1f920f4 100644 --- a/tests/Lexer/SimpleLexerTest.php +++ b/tests/Lexer/SimpleLexerTest.php @@ -30,10 +30,10 @@ public function simpleLexerShouldWalkThroughTheRecognizers(): void { $stream = $this->lexer->lex('a (b) c'); - $this->assertEquals(6, $stream->count()); // with EOF - $this->assertEquals('(', $stream->get(1)->getType()); - $this->assertEquals(1, $stream->get(3)->getLine()); - $this->assertEquals('C', $stream->get(4)->getType()); + $this->assertSame(6, $stream->count()); // with EOF + $this->assertSame('(', $stream->get(1)->getType()); + $this->assertSame(1, $stream->get(3)->getLine()); + $this->assertSame('C', $stream->get(4)->getType()); } #[\PHPUnit\Framework\Attributes\Test] @@ -42,7 +42,7 @@ public function simpleLexerShouldSkipSpecifiedTokens(): void $stream = $this->lexer->lex('a (b) c'); foreach ($stream as $token) { - $this->assertNotEquals('WS', $token->getType()); + $this->assertNotSame('WS', $token->getType()); } } @@ -54,7 +54,7 @@ public function simpleLexerShouldReturnTheBestMatch(): void $stream = $this->lexer->lex('class classloremipsum'); - $this->assertEquals('CLASS', $stream->getCurrentToken()->getType()); - $this->assertEquals('WORD', $stream->lookAhead(1)->getType()); + $this->assertSame('CLASS', $stream->getCurrentToken()->getType()); + $this->assertSame('WORD', $stream->lookAhead(1)->getType()); } } diff --git a/tests/Lexer/StatefulLexerTest.php b/tests/Lexer/StatefulLexerTest.php index 7d1cfde..a33798c 100644 --- a/tests/Lexer/StatefulLexerTest.php +++ b/tests/Lexer/StatefulLexerTest.php @@ -52,9 +52,9 @@ public function theStateMechanismShouldCorrectlyPushAndPopStatesFromTheStack(): $stream = $this->lexer->lex('foo bar "long \\" string" baz quux'); $this->assertCount(8, $stream); - $this->assertEquals('STRING_CONTENTS', $stream->get(3)->getType()); - $this->assertEquals('long \\" string', $stream->get(3)->getValue()); - $this->assertEquals('quux', $stream->get(6)->getValue()); + $this->assertSame('STRING_CONTENTS', $stream->get(3)->getType()); + $this->assertSame('long \\" string', $stream->get(3)->getValue()); + $this->assertSame('quux', $stream->get(6)->getValue()); } #[\PHPUnit\Framework\Attributes\Test] @@ -70,6 +70,6 @@ public function defaultActionShouldBeNop(): void $this->lexer->start('root'); $stream = $this->lexer->lex('foo bar'); - $this->assertEquals(3, $stream->count()); + $this->assertSame(3, $stream->count()); } } diff --git a/tests/Lexer/TokenStream/ArrayTokenStreamTest.php b/tests/Lexer/TokenStream/ArrayTokenStreamTest.php index b9ae22b..64c2ba7 100644 --- a/tests/Lexer/TokenStream/ArrayTokenStreamTest.php +++ b/tests/Lexer/TokenStream/ArrayTokenStreamTest.php @@ -26,7 +26,7 @@ protected function setUp(): void #[\PHPUnit\Framework\Attributes\Test] public function theCursorShouldBeOnFirstTokenByDefault(): void { - $this->assertEquals('6', $this->stream->getCurrentToken()->getValue()); + $this->assertSame('6', $this->stream->getCurrentToken()->getValue()); } #[\PHPUnit\Framework\Attributes\Test] @@ -35,13 +35,13 @@ public function getPositionShouldReturnCurrentPosition(): void $this->stream->seek(2); $this->stream->next(); - $this->assertEquals(3, $this->stream->getPosition()); + $this->assertSame(3, $this->stream->getPosition()); } #[\PHPUnit\Framework\Attributes\Test] public function lookAheadShouldReturnTheCorrectToken(): void { - $this->assertEquals('5', $this->stream->lookAhead(2)->getValue()); + $this->assertSame('5', $this->stream->lookAhead(2)->getValue()); } #[\PHPUnit\Framework\Attributes\Test] @@ -54,7 +54,7 @@ public function lookAheadShouldThrowAnExceptionWhenInvalid(): void #[\PHPUnit\Framework\Attributes\Test] public function getShouldReturnATokenByAbsolutePosition(): void { - $this->assertEquals('3', $this->stream->get(4)->getValue()); + $this->assertSame('3', $this->stream->get(4)->getValue()); } #[\PHPUnit\Framework\Attributes\Test] @@ -68,7 +68,7 @@ public function getShouldThrowAnExceptionWhenInvalid(): void public function moveShouldMoveTheCursorByToAnAbsolutePosition(): void { $this->stream->move(2); - $this->assertEquals('5', $this->stream->getCurrentToken()->getValue()); + $this->assertSame('5', $this->stream->getCurrentToken()->getValue()); } #[\PHPUnit\Framework\Attributes\Test] @@ -82,7 +82,7 @@ public function moveShouldThrowAnExceptionWhenInvalid(): void public function seekShouldMoveTheCursorByRelativeOffset(): void { $this->stream->seek(4); - $this->assertEquals('3', $this->stream->getCurrentToken()->getValue()); + $this->assertSame('3', $this->stream->getCurrentToken()->getValue()); } #[\PHPUnit\Framework\Attributes\Test] @@ -96,10 +96,10 @@ public function seekShouldThrowAnExceptionWhenInvalid(): void public function nextShouldMoveTheCursorOneTokenAhead(): void { $this->stream->next(); - $this->assertEquals('PLUS', $this->stream->getCurrentToken()->getType()); + $this->assertSame('PLUS', $this->stream->getCurrentToken()->getType()); $this->stream->next(); - $this->assertEquals('5', $this->stream->getCurrentToken()->getValue()); + $this->assertSame('5', $this->stream->getCurrentToken()->getValue()); } #[\PHPUnit\Framework\Attributes\Test] diff --git a/tests/Parser/GrammarTest.php b/tests/Parser/GrammarTest.php index fef6982..d890f5f 100644 --- a/tests/Parser/GrammarTest.php +++ b/tests/Parser/GrammarTest.php @@ -20,19 +20,19 @@ public function ruleAlternativesShouldHaveTheSameName(): void { $rules = $this->grammar->getRules(); - $this->assertEquals('Foo', $rules[1]->getName()); - $this->assertEquals('Foo', $rules[2]->getName()); + $this->assertSame('Foo', $rules[1]->getName()); + $this->assertSame('Foo', $rules[2]->getName()); } #[\PHPUnit\Framework\Attributes\Test] public function theGrammarShouldBeAugmentedWithAStartRule(): void { - $this->assertEquals( + $this->assertSame( Grammar::START_RULE_NAME, $this->grammar->getStartRule()->getName() ); - $this->assertEquals( + $this->assertSame( array('Foo'), $this->grammar->getStartRule()->getComponents() ); diff --git a/tests/Parser/LALR1/Analysis/AnalyzerTest.php b/tests/Parser/LALR1/Analysis/AnalyzerTest.php index 7055ca3..c48d997 100644 --- a/tests/Parser/LALR1/Analysis/AnalyzerTest.php +++ b/tests/Parser/LALR1/Analysis/AnalyzerTest.php @@ -27,11 +27,11 @@ public function automatonShouldBeCorrectlyBuilt(): void $result = $this->getAnalysisResult($grammar); $table = $result->getAutomaton()->getTransitionTable(); - $this->assertEquals(1, $table[0]['S']); - $this->assertEquals(2, $table[0]['a']); - $this->assertEquals(2, $table[2]['a']); - $this->assertEquals(3, $table[2]['S']); - $this->assertEquals(4, $table[3]['b']); + $this->assertSame(1, $table[0]['S']); + $this->assertSame(2, $table[0]['a']); + $this->assertSame(2, $table[2]['a']); + $this->assertSame(3, $table[2]['S']); + $this->assertSame(4, $table[3]['b']); } #[\PHPUnit\Framework\Attributes\Test] @@ -58,32 +58,32 @@ public function lookaheadShouldBeCorrectlyPumped(): void $automaton = $this->getAnalysisResult($grammar)->getAutomaton(); - $this->assertEquals( + $this->assertSame( array(Parser::EOF_TOKEN_TYPE), $automaton->getState(1)->get(0, 1)->getLookahead() ); - $this->assertEquals( + $this->assertSame( array('b'), $automaton->getState(3)->get(2, 1)->getLookahead() ); - $this->assertEquals( + $this->assertSame( array('d'), $automaton->getState(4)->get(4, 0)->getLookahead() ); - $this->assertEquals( + $this->assertSame( array('d'), $automaton->getState(5)->get(3, 1)->getLookahead() ); - $this->assertEquals( + $this->assertSame( array(Parser::EOF_TOKEN_TYPE), $automaton->getState(7)->get(1, 4)->getLookahead() ); - $this->assertEquals( + $this->assertSame( array(Parser::EOF_TOKEN_TYPE), $automaton->getState(8)->get(5, 1)->getLookahead() ); @@ -103,29 +103,29 @@ public function parseTableShouldBeCorrectlyBuilt(): void $table = $this->getAnalysisResult($grammar)->getParseTable(); // shift(2) - $this->assertEquals(2, $table['action'][0]['a']); + $this->assertSame(2, $table['action'][0]['a']); // reduce(S -> ) - $this->assertEquals(-2, $table['action'][0][Parser::EOF_TOKEN_TYPE]); + $this->assertSame(-2, $table['action'][0][Parser::EOF_TOKEN_TYPE]); // accept - $this->assertEquals(0, $table['action'][1][Parser::EOF_TOKEN_TYPE]); + $this->assertSame(0, $table['action'][1][Parser::EOF_TOKEN_TYPE]); // shift(2) - $this->assertEquals(2, $table['action'][2]['a']); + $this->assertSame(2, $table['action'][2]['a']); // reduce(S -> ) - $this->assertEquals(-2, $table['action'][2]['b']); + $this->assertSame(-2, $table['action'][2]['b']); // shift(4) - $this->assertEquals(4, $table['action'][3]['b']); + $this->assertSame(4, $table['action'][3]['b']); // reduce(S -> a S b) - $this->assertEquals(-1, $table['action'][4]['b']); - $this->assertEquals(-1, $table['action'][4][Parser::EOF_TOKEN_TYPE]); + $this->assertSame(-1, $table['action'][4]['b']); + $this->assertSame(-1, $table['action'][4][Parser::EOF_TOKEN_TYPE]); - $this->assertEquals(1, $table['goto'][0]['S']); - $this->assertEquals(3, $table['goto'][2]['S']); + $this->assertSame(1, $table['goto'][0]['S']); + $this->assertSame(3, $table['goto'][2]['S']); } #[\PHPUnit\Framework\Attributes\Test] @@ -149,10 +149,10 @@ public function unexpectedConflictsShouldThrowAnException(): void $this->getAnalysisResult($grammar); $this->fail('Expected an exception warning of a reduce/reduce conflict.'); } catch(ReduceReduceConflictException $e) { - $this->assertEquals(3, $e->getStateNumber()); - $this->assertEquals('d', $e->getLookahead()); - $this->assertEquals(3, $e->getFirstRule()->getNumber()); - $this->assertEquals(4, $e->getSecondRule()->getNumber()); + $this->assertSame(3, $e->getStateNumber()); + $this->assertSame('d', $e->getLookahead()); + $this->assertSame(3, $e->getFirstRule()->getNumber()); + $this->assertSame(4, $e->getSecondRule()->getNumber()); } } @@ -175,32 +175,32 @@ public function expectedConflictsShouldBeRecorded(): void $conflict = $conflicts[0]; - $this->assertEquals(3, $conflict['state']); - $this->assertEquals('b', $conflict['lookahead']); - $this->assertEquals(2, $conflict['rule']->getNumber()); - $this->assertEquals(Grammar::SHIFT, $conflict['resolution']); + $this->assertSame(3, $conflict['state']); + $this->assertSame('b', $conflict['lookahead']); + $this->assertSame(2, $conflict['rule']->getNumber()); + $this->assertSame(Grammar::SHIFT, $conflict['resolution']); $conflict = $conflicts[1]; - $this->assertEquals(4, $conflict['state']); - $this->assertEquals('b', $conflict['lookahead']); - $this->assertEquals(1, $conflict['rule']->getNumber()); - $this->assertEquals(Grammar::SHIFT, $conflict['resolution']); + $this->assertSame(4, $conflict['state']); + $this->assertSame('b', $conflict['lookahead']); + $this->assertSame(1, $conflict['rule']->getNumber()); + $this->assertSame(Grammar::SHIFT, $conflict['resolution']); $conflict = $conflicts[2]; - $this->assertEquals(4, $conflict['state']); - $this->assertEquals(Parser::EOF_TOKEN_TYPE, $conflict['lookahead']); - $this->assertEquals(1, $conflict['rules'][0]->getNumber()); - $this->assertEquals(2, $conflict['rules'][1]->getNumber()); - $this->assertEquals(Grammar::LONGER_REDUCE, $conflict['resolution']); + $this->assertSame(4, $conflict['state']); + $this->assertSame(Parser::EOF_TOKEN_TYPE, $conflict['lookahead']); + $this->assertSame(1, $conflict['rules'][0]->getNumber()); + $this->assertSame(2, $conflict['rules'][1]->getNumber()); + $this->assertSame(Grammar::LONGER_REDUCE, $conflict['resolution']); $conflict = $conflicts[3]; - $this->assertEquals(4, $conflict['state']); - $this->assertEquals('b', $conflict['lookahead']); - $this->assertEquals(2, $conflict['rule']->getNumber()); - $this->assertEquals(Grammar::SHIFT, $conflict['resolution']); + $this->assertSame(4, $conflict['state']); + $this->assertSame('b', $conflict['lookahead']); + $this->assertSame(2, $conflict['rule']->getNumber()); + $this->assertSame(Grammar::SHIFT, $conflict['resolution']); } protected function getAnalysisResult(Grammar $grammar): AnalysisResult diff --git a/tests/Parser/LALR1/Analysis/AutomatonTest.php b/tests/Parser/LALR1/Analysis/AutomatonTest.php index cfaebd5..7bafd0f 100644 --- a/tests/Parser/LALR1/Analysis/AutomatonTest.php +++ b/tests/Parser/LALR1/Analysis/AutomatonTest.php @@ -23,7 +23,7 @@ public function addingATransitionShouldBeVisibleInTheTransitionTable(): void $this->automaton->addTransition(0, 'a', 1); $table = $this->automaton->getTransitionTable(); - $this->assertEquals(1, $table[0]['a']); + $this->assertSame(1, $table[0]['a']); } #[\PHPUnit\Framework\Attributes\Test] diff --git a/tests/Parser/LALR1/Analysis/ItemTest.php b/tests/Parser/LALR1/Analysis/ItemTest.php index 7faf688..e0021e7 100644 --- a/tests/Parser/LALR1/Analysis/ItemTest.php +++ b/tests/Parser/LALR1/Analysis/ItemTest.php @@ -14,7 +14,7 @@ public function getActiveComponentShouldReturnTheComponentAboutToBeEncountered() { $item = new Item(new Rule(1, 'A', ['a', 'b', 'c']), 1); - $this->assertEquals('b', $item->getActiveComponent()); + $this->assertSame('b', $item->getActiveComponent()); } #[\PHPUnit\Framework\Attributes\Test] @@ -54,7 +54,7 @@ public function itemShouldPumpTheSameLookaheadOnlyOnce(): void $item2->expects($this->once()) ->method('pump') - ->with($this->equalTo('d')); + ->with('d'); $item1->connect($item2); @@ -67,6 +67,6 @@ public function getUnrecognizedComponentsShouldReturnAllComponentAfterTheDottedO { $item = new Item(new Rule(1, 'A', ['a', 'b', 'c']), 1); - $this->assertEquals(['c'], $item->getUnrecognizedComponents()); + $this->assertSame(['c'], $item->getUnrecognizedComponents()); } } diff --git a/tests/Parser/LALR1/Analysis/KernelSet/KernelSetTest.php b/tests/Parser/LALR1/Analysis/KernelSet/KernelSetTest.php index 825ecc3..7399ad1 100644 --- a/tests/Parser/LALR1/Analysis/KernelSet/KernelSetTest.php +++ b/tests/Parser/LALR1/Analysis/KernelSet/KernelSetTest.php @@ -11,7 +11,7 @@ class KernelSetTest extends TestCase #[\PHPUnit\Framework\Attributes\Test] public function kernelsShouldBeProperlyHashedAndOrdered(): void { - $this->assertEquals(array(1, 3, 6, 7), KernelSet::hashKernel(array( + $this->assertSame(array(1, 3, 6, 7), KernelSet::hashKernel(array( array(2, 1), array(1, 0), array(2, 0), @@ -24,19 +24,19 @@ public function insertShouldInsertANewNodeIfNoIdenticalKernelExists(): void { $set = new KernelSet(); - $this->assertEquals(0, $set->insert([ + $this->assertSame(0, $set->insert([ [2, 1], ])); - $this->assertEquals(1, $set->insert([ + $this->assertSame(1, $set->insert([ [2, 2], ])); - $this->assertEquals(2, $set->insert([ + $this->assertSame(2, $set->insert([ [1, 1], ])); - $this->assertEquals(0, $set->insert([ + $this->assertSame(0, $set->insert([ [2, 1], ])); } diff --git a/tests/Parser/LALR1/ParserTest.php b/tests/Parser/LALR1/ParserTest.php index cd5728e..5eaafb8 100644 --- a/tests/Parser/LALR1/ParserTest.php +++ b/tests/Parser/LALR1/ParserTest.php @@ -21,16 +21,16 @@ protected function setUp(): void #[\PHPUnit\Framework\Attributes\Test] public function parserShouldProcessTheTokenStreamAndUseGrammarCallbacksForReductions(): void { - $this->assertEquals(-2, $this->parser->parse($this->lexer->lex( + $this->assertSame(-2, $this->parser->parse($this->lexer->lex( '-1 - 1'))); - $this->assertEquals(11664, $this->parser->parse($this->lexer->lex( + $this->assertSame(11664, $this->parser->parse($this->lexer->lex( '6 ** (1 + 1) ** 2 * (5 + 4)'))); - $this->assertEquals(-4, $this->parser->parse($this->lexer->lex( + $this->assertSame(-4, $this->parser->parse($this->lexer->lex( '3 - 5 - 2'))); - $this->assertEquals(262144, $this->parser->parse($this->lexer->lex( + $this->assertSame(262144, $this->parser->parse($this->lexer->lex( '4 ** 3 ** 2'))); } @@ -41,9 +41,9 @@ public function parserShouldThrowAnExceptionOnInvalidInput(): void $this->parser->parse($this->lexer->lex('6 ** 5 3')); $this->fail('Expected an UnexpectedTokenException.'); } catch (UnexpectedTokenException $e) { - $this->assertEquals('INT', $e->getToken()->getType()); - $this->assertEquals(array('$eof', '+', '-', '*', '/', '**', ')'), $e->getExpected()); - $this->assertEquals(<<assertSame('INT', $e->getToken()->getType()); + $this->assertSame(array('$eof', '+', '-', '*', '/', '**', ')'), $e->getExpected()); + $this->assertSame(<<assertEquals('y', $r->getComponent(1)); + $this->assertSame('y', $r->getComponent(1)); $this->assertNull($r->getComponent(2)); } } From ff7acade6e0564d9623a3615f62dc0fdd0cd35fc Mon Sep 17 00:00:00 2001 From: Alexander Lisachenko Date: Mon, 19 Feb 2024 23:13:11 +0200 Subject: [PATCH 26/28] Enable test workflow pipeline for all branches and PRs --- .github/workflows/php-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/php-tests.yml b/.github/workflows/php-tests.yml index 4beb673..b53d88f 100644 --- a/.github/workflows/php-tests.yml +++ b/.github/workflows/php-tests.yml @@ -1,8 +1,8 @@ name: PHP Tests on: + pull_request: push: - branches: [ "master" ] permissions: contents: read From cb93025a1208dc466301bd396717790e2a0a2e6e Mon Sep 17 00:00:00 2001 From: Alexander Lisachenko <640114+lisachenko@users.noreply.github.com> Date: Mon, 19 Feb 2024 23:29:20 +0200 Subject: [PATCH 27/28] Update README.md badges --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8c7dd93..fc662ff 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,11 @@ Dissect library provides a set of tools to create and use lexical parsers. Read For the goaop/framework it is responsible for parsing pointcut DSL expressions into AST tree, which might be then processed. +![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/goaop/dissect/php-tests.yml?branch=master) [![Total Downloads](https://img.shields.io/packagist/dt/goaop/dissect.svg)](https://packagist.org/packages/goaop/dissect) [![Daily Downloads](https://img.shields.io/packagist/dd/goaop/dissect.svg)](https://packagist.org/packages/goaop/dissect) [![PHP Version](https://img.shields.io/badge/php-%3E%3D%208.2-8892BF.svg)](https://php.net/) -[![License](https://img.shields.io/packagist/l/goaop/dissect.svg)](https://packagist.org/packages/goaop/dissect) +![GitHub License](https://img.shields.io/github/license/goaop/dissect) ## Installation @@ -40,4 +41,4 @@ Give a ⭐ if this project helped you! ## 📝 License -This project is [MIT](https://opensource.org/licenses/MIT) licensed. \ No newline at end of file +This project is [MIT](https://opensource.org/licenses/MIT) licensed. From 5d4aeb87ee4aaf20fb3fbf08aa3e0b17bba37e09 Mon Sep 17 00:00:00 2001 From: Alexander Lisachenko <640114+lisachenko@users.noreply.github.com> Date: Mon, 19 Feb 2024 23:35:38 +0200 Subject: [PATCH 28/28] Create dependabot.yml --- .github/dependabot.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..c85b5e6 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,12 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file + +version: 2 +updates: + - package-ecosystem: "composer" + # Files stored in repository root + directory: "/" + schedule: + interval: "monthly"