Skip to content

Commit

Permalink
Fix GH actions
Browse files Browse the repository at this point in the history
  • Loading branch information
SerafimArts committed Aug 1, 2024
1 parent 0e28bf3 commit d744b5a
Show file tree
Hide file tree
Showing 18 changed files with 38 additions and 36 deletions.
14 changes: 6 additions & 8 deletions src/ConfigurableParserInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,23 @@

/**
* @template TNode of object
*
* @template-extends ParserInterface<TNode>
*/
interface ConfigurableParserInterface extends ParserInterface
{
/**
* Parses sources into an abstract source tree (AST) or list of AST nodes.
*
* @param array<non-empty-string, mixed> $options List of additional
* runtime options for the parser (parsing context).
* @param array<non-empty-string, mixed> $options list of additional
* runtime options for the parser (parsing context)
*
* @return iterable<array-key, TNode>
*
* @throws ParserExceptionInterface An error occurs before source processing
* @throws ParserExceptionInterface an error occurs before source processing
* starts, when the given source cannot be recognized or if the
* parser settings contain errors.
* @throws ParserRuntimeExceptionInterface An exception that occurs after
* parser settings contain errors
* @throws ParserRuntimeExceptionInterface an exception that occurs after
* starting the parsing and indicates problems in the analyzed
* source.
* source
*/
public function parse(ReadableInterface $source, array $options = []): iterable;
}
3 changes: 2 additions & 1 deletion src/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Phplrt\Parser;

use Phplrt\Buffer\BufferInterface;
use Phplrt\Contracts\Ast\NodeInterface;
use Phplrt\Contracts\Lexer\TokenInterface;
use Phplrt\Contracts\Source\ReadableInterface;
use Phplrt\Parser\Context\ContextOptionsTrait;
Expand Down Expand Up @@ -75,6 +74,7 @@ class Context implements ContextInterface
* Contains information about the processed source.
*
* @readonly marked as readonly since phplrt 3.4 and will be readonly since 4.0
*
* @psalm-readonly-allow-private-mutation
*/
public ReadableInterface $source;
Expand All @@ -83,6 +83,7 @@ class Context implements ContextInterface
* Contains a buffer of tokens that were collected from lexical analysis.
*
* @readonly marked as readonly since phplrt 3.4 and will be readonly since 4.0
*
* @psalm-readonly-allow-private-mutation
*/
public BufferInterface $buffer;
Expand Down
3 changes: 2 additions & 1 deletion src/Context/ContextOptionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
namespace Phplrt\Parser\Context;

/**
* @mixin ContextOptionsProviderInterface
* @psalm-require-implements ContextOptionsProviderInterface
*
* @mixin ContextOptionsProviderInterface
*/
trait ContextOptionsTrait
{
Expand Down
2 changes: 1 addition & 1 deletion src/Context/TreeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Phplrt\Parser\Context;

/**
* @internal This is an internal library class, please do not use it in your code.
* @internal this is an internal library class, please do not use it in your code
* @psalm-internal Phplrt\Parser
*/
class TreeBuilder implements BuilderInterface
Expand Down
1 change: 1 addition & 0 deletions src/Environment/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ final class Factory implements SelectorInterface
{
/**
* @var list<SelectorInterface>
*
* @readonly
*/
private array $selectors;
Expand Down
1 change: 1 addition & 0 deletions src/Environment/XdebugSelector.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ final class XdebugSelector implements SelectorInterface

/**
* @var int<0, max>
*
* @readonly
*/
private int $expectedRecursionDepth;
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/ParserRuntimeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final public function __construct(
string $message,
ReadableInterface $src,
?TokenInterface $tok,
\Throwable $prev = null
?\Throwable $prev = null
) {
parent::__construct($message, 0, $prev);

Expand Down
2 changes: 1 addition & 1 deletion src/Exception/UnexpectedTokenException.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class UnexpectedTokenException extends UnrecognizedTokenException
public static function fromToken(
ReadableInterface $src,
TokenInterface $tok,
\Throwable $prev = null,
?\Throwable $prev = null,
array $expected = []
): self {
switch (\count($expected)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/UnrecognizedTokenException.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

class UnrecognizedTokenException extends ParserRuntimeException
{
public static function fromToken(ReadableInterface $src, TokenInterface $tok, \Throwable $prev = null): self
public static function fromToken(ReadableInterface $src, TokenInterface $tok, ?\Throwable $prev = null): self
{
$message = \sprintf('Syntax error, unrecognized %s', self::getTokenValue($tok));

Expand Down
1 change: 1 addition & 0 deletions src/Grammar/Alternation.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Alternation extends Production
* @var list<array-key>
*
* @readonly
*
* @psalm-readonly-allow-private-mutation
*/
public array $sequence = [];
Expand Down
5 changes: 3 additions & 2 deletions src/Grammar/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Builder implements \IteratorAggregate
/**
* @param \Closure():\Generator|null $generator
*/
public function __construct(\Closure $generator = null)
public function __construct(?\Closure $generator = null)
{
if ($generator !== null) {
$this->extend($generator);
Expand Down Expand Up @@ -48,7 +48,6 @@ public function extend(\Closure $rules): self
case \is_string($key) && $value instanceof RuleInterface:
$generator->send($this->add($value, $key));
continue 2;

case $value instanceof RuleInterface:
$generator->send($this->add($value));
continue 2;
Expand Down Expand Up @@ -94,6 +93,7 @@ public function maybe(...$of): Optional

/**
* @param non-empty-list<array-key> $args
*
* @return array-key
*/
private function unwrap(array $args)
Expand Down Expand Up @@ -126,6 +126,7 @@ private function read(\Closure $rules): \Generator

/**
* @param array-key|null $id
*
* @return array-key
*/
public function add(RuleInterface $rule, $id = null)
Expand Down
1 change: 1 addition & 0 deletions src/Grammar/Concatenation.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Concatenation extends Production
* @var list<array-key>
*
* @readonly
*
* @psalm-readonly-allow-private-mutation
*/
public array $sequence = [];
Expand Down
1 change: 1 addition & 0 deletions src/Grammar/Lexeme.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Lexeme extends Terminal
{
/**
* @var non-empty-string|int
*
* @readonly
*/
public $token;
Expand Down
1 change: 1 addition & 0 deletions src/Grammar/Optional.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Optional extends Production
* @var array-key
*
* @readonly
*
* @psalm-readonly-allow-private-mutation
*/
public $rule;
Expand Down
1 change: 1 addition & 0 deletions src/Grammar/Production.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ abstract class Production extends Rule implements ProductionInterface
/**
* @param list<NodeInterface|TokenInterface> $children
* @param NodeInterface|TokenInterface|array $result
*
* @return list<NodeInterface|TokenInterface>
*/
protected function mergeWith(array $children, $result): array
Expand Down
3 changes: 3 additions & 0 deletions src/Grammar/Repetition.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Repetition extends Production
* @var int<0, max>
*
* @readonly
*
* @psalm-readonly-allow-private-mutation
*/
public int $gte;
Expand All @@ -23,6 +24,7 @@ class Repetition extends Production
* @var int<0, max>|float
*
* @readonly
*
* @psalm-readonly-allow-private-mutation
*/
public $lte;
Expand All @@ -31,6 +33,7 @@ class Repetition extends Production
* @var array-key
*
* @readonly
*
* @psalm-readonly-allow-private-mutation
*/
public $rule;
Expand Down
30 changes: 11 additions & 19 deletions src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Phplrt\Parser;

use Phplrt\Buffer\BufferInterface;
use Phplrt\Contracts\Ast\NodeInterface;
use Phplrt\Contracts\Exception\RuntimeExceptionInterface;
use Phplrt\Contracts\Lexer\LexerInterface;
use Phplrt\Contracts\Lexer\LexerRuntimeExceptionInterface;
Expand All @@ -24,7 +23,6 @@
use Phplrt\Parser\Grammar\ProductionInterface;
use Phplrt\Parser\Grammar\RuleInterface;
use Phplrt\Parser\Grammar\TerminalInterface;
use Phplrt\Source\File;
use Phplrt\Source\SourceFactory;

/**
Expand Down Expand Up @@ -61,7 +59,6 @@
* </code>
*
* @template TNode of object
*
* @template-implements ConfigurableParserInterface<TNode>
*/
final class Parser implements ConfigurableParserInterface, ParserConfigsInterface
Expand Down Expand Up @@ -107,6 +104,7 @@ final class Parser implements ConfigurableParserInterface, ParserConfigsInterfac
* The initial state (initial rule identifier) of the parser.
*
* @var array-key
*
* @psalm-readonly-allow-private-mutation
*/
private $initial;
Expand All @@ -117,15 +115,16 @@ final class Parser implements ConfigurableParserInterface, ParserConfigsInterfac
* @var array<array-key, RuleInterface>
*
* @readonly
*
* @psalm-readonly-allow-private-mutation
*/
private array $rules = [];

private ?Context $context = null;

/**
* @param iterable<array-key, RuleInterface> $grammar An iterable of the
* transition rules for the parser.
* @param iterable<array-key, RuleInterface> $grammar an iterable of the
* transition rules for the parser
* @param array<ParserConfigsInterface::CONFIG_*, mixed> $options
*/
public function __construct(
Expand Down Expand Up @@ -245,18 +244,17 @@ public function buildUsing(BuilderInterface $builder): self
/**
* Parses sources into an abstract source tree (AST) or list of AST nodes.
*
* @param mixed $source Any source supported by the {@see SourceFactoryInterface::create()}.
* @param array<non-empty-string, mixed> $options List of additional
* runtime options for the parser (parsing context).
* @param mixed $source any source supported by the {@see SourceFactoryInterface::create()}
* @param array<non-empty-string, mixed> $options list of additional
* runtime options for the parser (parsing context)
*
* @return iterable<array-key, TNode>
*
* @throws ParserExceptionInterface An error occurs before source processing
* @throws ParserExceptionInterface an error occurs before source processing
* starts, when the given source cannot be recognized or if the
* parser settings contain errors.
* @throws ParserRuntimeExceptionInterface An exception that occurs after
* parser settings contain errors
* @throws ParserRuntimeExceptionInterface an exception that occurs after
* starting the parsing and indicates problems in the analyzed
* source.
* source
*/
public function parse($source, array $options = []): iterable
{
Expand Down Expand Up @@ -362,9 +360,6 @@ private function lookupExpectedTokens(Context $context): array
return \array_values($tokens);
}

/**
* @return mixed
*/
private function next(Context $context)
{
if ($this->step !== null) {
Expand All @@ -376,9 +371,6 @@ private function next(Context $context)
return $this->runNextStep($context);
}

/**
* @return mixed
*/
private function runNextStep(Context $context)
{
$rule = $context->rule = $this->rules[$context->state];
Expand Down
1 change: 0 additions & 1 deletion src/polyfill.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php

namespace Phplrt\Grammar {

if (
!\class_exists(Alternation::class, false)
&& \class_exists(\Phplrt\Parser\Grammar\Alternation::class)
Expand Down

0 comments on commit d744b5a

Please sign in to comment.