Skip to content

Commit fa310ab

Browse files
committed
Use list<T> in ArrayBuffer instead of custom keys (possibly keys duplication fix).
1 parent 34fe09c commit fa310ab

22 files changed

+445
-69
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
strategy:
1717
fail-fast: false
1818
matrix:
19-
php: [ '7.4', '8.0', '8.1', '8.2', '8.3', '8.4' ]
19+
php: [ '8.1', '8.2', '8.3', '8.4' ]
2020
os: [ ubuntu-latest, macos-latest, windows-latest ]
2121
stability: [ prefer-lowest, prefer-stable ]
2222
steps:

composer.json

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717
],
1818
"require": {
1919
"php": "^8.1",
20-
"phplrt/source": "^4.0",
21-
"phplrt/buffer": "^4.0",
22-
"phplrt/exception": "^4.0",
23-
"phplrt/parser-contracts": "^4.0",
24-
"phplrt/lexer-contracts": "^4.0",
25-
"phplrt/ast-contracts": "^4.0"
20+
"phplrt/source": "^3.7",
21+
"phplrt/buffer": "^3.7",
22+
"phplrt/exception": "^3.7",
23+
"phplrt/parser-contracts": "^3.7",
24+
"phplrt/lexer-contracts": "^3.7",
25+
"phplrt/ast-contracts": "^3.7",
26+
"symfony/deprecation-contracts": "^2.5|^3.0"
2627
},
2728
"replace": {
2829
"phplrt/grammar": "<=3.1",
@@ -31,11 +32,14 @@
3132
"autoload": {
3233
"psr-4": {
3334
"Phplrt\\Parser\\": "src"
34-
}
35+
},
36+
"files": [
37+
"src/polyfill.php"
38+
]
3539
},
3640
"require-dev": {
37-
"phplrt/visitor": "^4.0",
38-
"phplrt/lexer": "^4.0",
41+
"phplrt/visitor": "^3.7",
42+
"phplrt/lexer": "^3.7",
3943
"phpunit/phpunit": "^10.5|^11.0",
4044
"phpstan/extension-installer": "^1.4",
4145
"phpstan/phpstan": "^1.11",
@@ -48,16 +52,19 @@
4852
}
4953
},
5054
"provide": {
51-
"phplrt/parser-contracts-implementation": "^4.0"
55+
"phplrt/parser-contracts-implementation": "^3.7"
5256
},
5357
"extra": {
5458
"branch-alias": {
55-
"dev-master": "4.x-dev",
56-
"dev-main": "4.x-dev"
59+
"dev-master": "3.x-dev",
60+
"dev-main": "3.x-dev"
5761
}
5862
},
5963
"config": {
60-
"sort-packages": true
64+
"sort-packages": true,
65+
"allow-plugins": {
66+
"phpstan/extension-installer": true
67+
}
6168
},
6269
"minimum-stability": "dev",
6370
"prefer-stable": true

resources/.deprecations.php

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
3+
namespace Phplrt\Grammar {
4+
5+
/**
6+
* @deprecated since phplrt 3.2 and will be removed in 4.0, use {@see \Phplrt\Parser\Grammar\Terminal} instead.
7+
*/
8+
abstract class Terminal extends \Phplrt\Parser\Grammar\Terminal
9+
{
10+
}
11+
12+
/**
13+
* @deprecated since phplrt 3.2 and will be removed in 4.0, use {@see \Phplrt\Parser\Grammar\Repetition} instead.
14+
*/
15+
class Repetition extends \Phplrt\Parser\Grammar\Repetition
16+
{
17+
}
18+
19+
/**
20+
* @deprecated since phplrt 3.2 and will be removed in 4.0, use {@see \Phplrt\Parser\Grammar\Optional} instead.
21+
*/
22+
class Optional extends \Phplrt\Parser\Grammar\Optional
23+
{
24+
}
25+
26+
/**
27+
* @deprecated since phplrt 3.2 and will be removed in 4.0, use {@see \Phplrt\Parser\Grammar\Production} instead.
28+
*/
29+
abstract class Production extends \Phplrt\Parser\Grammar\Production
30+
{
31+
}
32+
33+
/**
34+
* @deprecated since phplrt 3.2 and will be removed in 4.0, use {@see \Phplrt\Parser\Grammar\Concatenation} instead.
35+
*/
36+
class Concatenation extends \Phplrt\Parser\Grammar\Concatenation
37+
{
38+
}
39+
40+
/**
41+
* @deprecated since phplrt 3.2 and will be removed in 4.0, use {@see \Phplrt\Parser\Grammar\Builder} instead.
42+
*/
43+
class Builder extends \Phplrt\Parser\Grammar\Builder
44+
{
45+
}
46+
47+
/**
48+
* @deprecated since phplrt 3.2 and will be removed in 4.0, use {@see \Phplrt\Parser\Grammar\Rule} instead.
49+
*/
50+
class Rule extends \Phplrt\Parser\Grammar\Rule
51+
{
52+
}
53+
54+
/**
55+
* @deprecated since phplrt 3.2 and will be removed in 4.0, use {@see \Phplrt\Parser\Grammar\Lexeme} instead.
56+
*/
57+
class Lexeme extends \Phplrt\Parser\Grammar\Lexeme
58+
{
59+
}
60+
61+
/**
62+
* @deprecated since phplrt 3.2 and will be removed in 4.0, use {@see \Phplrt\Parser\Grammar\Alternation} instead.
63+
*/
64+
class Alternation extends \Phplrt\Parser\Grammar\Alternation
65+
{
66+
}
67+
}
68+
69+
namespace Phplrt\Contracts\Grammar {
70+
71+
/**
72+
* @deprecated since phplrt 3.2 and will be removed in 4.0, use {@see \Phplrt\Parser\Grammar\ProductionInterface} instead.
73+
*/
74+
interface ProductionInterface extends \Phplrt\Parser\Grammar\ProductionInterface
75+
{
76+
}
77+
78+
/**
79+
* @deprecated since phplrt 3.2 and will be removed in 4.0, use {@see \Phplrt\Parser\Grammar\RuleInterface} instead.
80+
*/
81+
interface RuleInterface extends \Phplrt\Parser\Grammar\RuleInterface
82+
{
83+
}
84+
85+
/**
86+
* @deprecated since phplrt 3.2 and will be removed in 4.0, use {@see \Phplrt\Parser\Grammar\TerminalInterface} instead.
87+
*/
88+
interface TerminalInterface extends \Phplrt\Parser\Grammar\TerminalInterface
89+
{
90+
}
91+
}

src/BuilderInterface.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
interface BuilderInterface
1111
{
1212
/**
13+
* Note: Native type hints will be added in phplrt 4.0, as adding them
14+
* clearly breaks backward compatibility with inheritance.
15+
*
1316
* @param NodeInterface|TokenInterface|iterable<NodeInterface|TokenInterface> $result
1417
*/
15-
public function build(Context $context, mixed $result);
18+
public function build(Context $context, /* mixed */ $result)/* : mixed */;
1619
}

src/Context.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@
1717
* The presence of public modifiers in fields is required only to speed up the
1818
* parser, since direct access is several times faster than using methods of
1919
* setting values or creating a new class at each step of the parser.
20+
*
21+
* @property-read ReadableInterface $source
22+
* @property-read BufferInterface $buffer
23+
*
24+
* @final marked as final since phplrt 3.4 and will be final since 4.0
2025
*/
21-
final class Context
26+
class Context implements ContextInterface
2227
{
2328
use ContextOptionsTrait;
2429

@@ -55,7 +60,6 @@ final class Context
5560
public ?RuleInterface $rule = null;
5661

5762
/**
58-
* @param array-key $state
5963
* @param array<non-empty-string, mixed> $options
6064
*/
6165
public function __construct(
@@ -73,9 +77,11 @@ public function __construct(
7377
* Note: This is a stateful data and may cause a race condition error. In
7478
* the future, it is necessary to delete this data with a replacement for
7579
* the stateless structure.
80+
*
81+
* @var array-key
7682
*/
77-
public string|int $state,
78-
array $options
83+
public int|string $state,
84+
array $options,
7985
) {
8086
$this->options = $options;
8187
$this->lastOrdinalToken = $this->lastProcessedToken = $this->buffer->current();

src/ContextInterface.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Phplrt\Parser;
6+
7+
use Phplrt\Buffer\BufferInterface;
8+
use Phplrt\Contracts\Lexer\TokenInterface;
9+
use Phplrt\Contracts\Source\ReadableInterface;
10+
use Phplrt\Parser\Grammar\RuleInterface;
11+
12+
/**
13+
* Interface provides full information about execution context.
14+
*
15+
* @deprecated since phplrt 3.4 and will be removed in 4.0, please use {@see Context} instead.
16+
*/
17+
interface ContextInterface extends ContextOptionsInterface
18+
{
19+
/**
20+
* Returns the source being processed.
21+
*/
22+
public function getSource(): ReadableInterface;
23+
24+
/**
25+
* Returns a lexer's buffer.
26+
*/
27+
public function getBuffer(): BufferInterface;
28+
29+
/**
30+
* Returns the parser's current state identifier.
31+
*
32+
* Note: Please note that this value is mutable and may change over time.
33+
*
34+
* @return array-key
35+
*/
36+
public function getState();
37+
38+
/**
39+
* Returns the parser's current state rule.
40+
*
41+
* Note: Please note that this value is mutable and may change over time.
42+
*/
43+
public function getRule(): ?RuleInterface;
44+
45+
/**
46+
* Returns the parser's current AST node.
47+
*
48+
* If the parser does not contain any nodes of the abstract syntax tree,
49+
* then the method will return NULL.
50+
*
51+
* Note: Please note that this value is mutable and may change over time.
52+
*/
53+
public function getNode(): ?object;
54+
55+
/**
56+
* Returns the current parsing token.
57+
*
58+
* Note: Please note that this value is mutable and may change over time.
59+
*/
60+
public function getToken(): TokenInterface;
61+
}

src/ContextOptionsInterface.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Phplrt\Parser;
6+
7+
use Phplrt\Parser\Context\ContextOptionsProviderInterface;
8+
9+
/**
10+
* @deprecated since phplrt 3.4 and will be removed in 4.0, please
11+
* use {@see ContextOptionsProviderInterface} instead.
12+
*/
13+
interface ContextOptionsInterface extends ContextOptionsProviderInterface {}

src/Environment/XdebugSelector.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ final class XdebugSelector implements SelectorInterface
3333
*/
3434
private readonly bool $enabled;
3535

36-
/**
37-
* @param int<0, max> $expectedRecursionDepth
38-
*/
3936
public function __construct(
40-
private readonly int $expectedRecursionDepth = self::DEFAULT_EXPECTED_RECURSION_DEPTH,
37+
/**
38+
* @var int<0, max>
39+
*/
40+
private readonly int $expectedRecursionDepth = self::DEFAULT_EXPECTED_RECURSION_DEPTH
4141
) {
4242
$this->enabled = \extension_loaded('xdebug');
4343
$this->actualRecursionDepth = (int) \ini_get('xdebug.max_nesting_level');
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Phplrt\Parser\Exception;
6+
7+
/**
8+
* @deprecated since phplrt 3.4 and will be removed in 4.0, please
9+
* use {@see UnexpectedTokenException} exception instead.
10+
*/
11+
class UnexpectedTokenWithHintsException extends UnexpectedTokenException {}

src/Grammar/Alternation.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
*/
1212
class Alternation extends Production
1313
{
14-
/**
15-
* @param list<array-key> $sequence
16-
*/
1714
public function __construct(
15+
/**
16+
* @var list<array-key>
17+
*/
1818
public readonly array $sequence,
1919
) {}
2020

@@ -31,7 +31,7 @@ public function getTerminals(array $rules): iterable
3131
return $result;
3232
}
3333

34-
public function reduce(BufferInterface $buffer, \Closure $reduce)
34+
public function reduce(BufferInterface $buffer, \Closure $reduce): mixed
3535
{
3636
$rollback = $buffer->key();
3737

0 commit comments

Comments
 (0)