Skip to content

Commit 336822d

Browse files
committed
Rename "Parser" to the "TypeParser"
1 parent 0115b1c commit 336822d

55 files changed

Lines changed: 119 additions & 123 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/Writerside/topics/parser.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ To create a parser instance, the `TypeLang\Parser\Parser` class is used.
2626
To run code analysis, you should use the `parse()` method.
2727

2828
```php
29-
$parser = new TypeLang\Parser\Parser();
29+
$parser = new TypeLang\Parser\TypeParser();
3030

3131
$result = $parser->parse('example');
3232
```
@@ -56,7 +56,7 @@ partial support of the functionality. Such a feature allows you to conveniently
5656
implement more strict functionality.
5757

5858
```php
59-
$parser = new TypeLang\Parser\Parser(
59+
$parser = new TypeLang\Parser\TypeParser(
6060
literals: false,
6161
);
6262

docs/Writerside/topics/parser/features.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ implement more strict functionality.
2020
To enable or disable literals, use the `literals: bool` flag.
2121

2222
```php
23-
$parser = new TypeLang\Parser\Parser(
23+
$parser = new TypeLang\Parser\TypeParser(
2424
literals: false,
2525
);
2626

@@ -38,7 +38,7 @@ To enable or disable template arguments (generics), use
3838
the `generics: bool` flag.
3939

4040
```php
41-
$parser = new TypeLang\Parser\Parser(
41+
$parser = new TypeLang\Parser\TypeParser(
4242
generics: false,
4343
);
4444

@@ -56,7 +56,7 @@ To enable or disable template argument hints (argument modifiers), use the
5656
`hints: bool` flag.
5757

5858
```php
59-
$parser = new TypeLang\Parser\Parser(
59+
$parser = new TypeLang\Parser\TypeParser(
6060
hints: false,
6161
);
6262

@@ -74,7 +74,7 @@ To enable or disable type lists (legacy/short syntax for iterable types), use
7474
the `list: bool` flag.
7575

7676
```php
77-
$parser = new TypeLang\Parser\Parser(
77+
$parser = new TypeLang\Parser\TypeParser(
7878
list: false,
7979
);
8080

@@ -93,7 +93,7 @@ Square bracket list types not allowed in "Example[]"
9393
To enable or disable type offsets, use the `offsets: bool` flag.
9494

9595
```php
96-
$parser = new TypeLang\Parser\Parser(
96+
$parser = new TypeLang\Parser\TypeParser(
9797
offsets: false,
9898
);
9999

@@ -111,7 +111,7 @@ Type offsets not allowed in "Example[Type]"
111111
To enable or disable callables (delegates), use the `callables: bool` flag.
112112

113113
```php
114-
$parser = new TypeLang\Parser\Parser(
114+
$parser = new TypeLang\Parser\TypeParser(
115115
callables: false,
116116
);
117117

@@ -128,7 +128,7 @@ Callable types not allowed in "fn()"
128128
To enable or disable shape fields, use the `shapes: bool` flag.
129129

130130
```php
131-
$parser = new TypeLang\Parser\Parser(
131+
$parser = new TypeLang\Parser\TypeParser(
132132
shapes: false,
133133
);
134134

@@ -150,7 +150,7 @@ Shape fields not allowed in "array{\n foo: T,\n ...\n}"
150150
To enable or disable union types, use the `union: bool` flag.
151151

152152
```php
153-
$parser = new TypeLang\Parser\Parser(
153+
$parser = new TypeLang\Parser\TypeParser(
154154
union: false,
155155
);
156156

@@ -167,7 +167,7 @@ Union types not allowed in "T|U"
167167
To enable or disable union types, use the `intersection: bool` flag.
168168

169169
```php
170-
$parser = new TypeLang\Parser\Parser(
170+
$parser = new TypeLang\Parser\TypeParser(
171171
intersection: false,
172172
);
173173

@@ -184,7 +184,7 @@ Intersection types not allowed in "T&U"
184184
To enable or disable conditional types (expressions), use the `conditional: bool` flag.
185185

186186
```php
187-
$parser = new TypeLang\Parser\Parser(
187+
$parser = new TypeLang\Parser\TypeParser(
188188
conditional: false,
189189
);
190190

@@ -201,7 +201,7 @@ Conditional expressions not allowed in "T is U ? 23 : 42"
201201
To enable or disable attributes, use the `attributes: bool` flag.
202202

203203
```php
204-
$parser = new TypeLang\Parser\Parser(
204+
$parser = new TypeLang\Parser\TypeParser(
205205
attributes: false,
206206
);
207207

docs/Writerside/topics/parser/tolerant-mode.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Such a mode will be convenient to use, for example, for analyzing phpdoc
99
docblocks, separating types from their descriptions.
1010

1111
```php
12-
$parser = new TypeLang\Parser\Parser(
12+
$parser = new TypeLang\Parser\TypeParser(
1313
// enable "tolerant" mode
1414
tolerant: true,
1515
);
@@ -19,7 +19,7 @@ As an example, let's try to parse the contents of the "`@return`" docblock.
1919
Similar actions can be implemented for other annotations.
2020

2121
```php
22-
$parser = new TypeLang\Parser\Parser(
22+
$parser = new TypeLang\Parser\TypeParser(
2323
tolerant: true,
2424
);
2525

docs/Writerside/topics/printer.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ contains an `print()` method for displaying ASTs as formatted strings.
4040
<tab title="PrettyPrinter">
4141

4242
```php
43-
$parser = new TypeLang\Parser\Parser();
43+
$parser = new TypeLang\Parser\TypeParser();
4444
$printer = new TypeLang\Printer\PrettyPrinter();
4545

4646
$result = $parser->parse(<<<'PHP'
@@ -64,7 +64,7 @@ echo $printer->print($result);
6464
<tab title="NativeTypePrinter">
6565
6666
```php
67-
$parser = new TypeLang\Parser\Parser();
67+
$parser = new TypeLang\Parser\TypeParser();
6868
$printer = new TypeLang\Printer\NativeTypePrinter();
6969
7070
$result = $parser->parse(<<<'PHP'
@@ -89,7 +89,7 @@ echo $printer->print($result);
8989
<tab title="PrettyPrinter">
9090
9191
```php
92-
$parser = new TypeLang\Parser\Parser();
92+
$parser = new TypeLang\Parser\TypeParser();
9393
$printer = new TypeLang\Printer\PrettyPrinter();
9494
9595
$result = $parser->parse(<<<'PHP'
@@ -108,7 +108,7 @@ echo $printer->print($result);
108108
<tab title="NativeTypePrinter">
109109
110110
```php
111-
$parser = new TypeLang\Parser\Parser();
111+
$parser = new TypeLang\Parser\TypeParser();
112112
$printer = new TypeLang\Printer\NativeTypePrinter();
113113
114114
$result = $parser->parse(<<<'PHP'
@@ -132,7 +132,7 @@ echo $printer->print($result);
132132
<tab title="PrettyPrinter">
133133
134134
```php
135-
$parser = new TypeLang\Parser\Parser();
135+
$parser = new TypeLang\Parser\TypeParser();
136136
$printer = new TypeLang\Printer\PrettyPrinter();
137137
138138
$result = $parser->parse(<<<'PHP'
@@ -151,7 +151,7 @@ echo $printer->print($result);
151151
<tab title="NativeTypePrinter">
152152
153153
```php
154-
$parser = new TypeLang\Parser\Parser();
154+
$parser = new TypeLang\Parser\TypeParser();
155155
$printer = new TypeLang\Printer\NativeTypePrinter();
156156
157157
$result = $parser->parse(<<<'PHP'

libs/parser/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ composer require type-lang/parser
3636
## Quick Start
3737

3838
```php
39-
$parser = new \TypeLang\Parser\Parser();
39+
$parser = new \TypeLang\Parser\TypeParser();
4040

4141
$type = $parser->parse(<<<'PHP'
4242
array{
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use TypeLang\Node\Type\TypeNode;
1212
use TypeLang\Parser\Exception\ParserExceptionInterface;
1313

14-
final class InMemoryCachedParser implements ParserInterface
14+
final class InMemoryTypeParser implements TypeParserInterface
1515
{
1616
/**
1717
* @var array<non-empty-string, TypeNode>
@@ -24,7 +24,7 @@ final class InMemoryCachedParser implements ParserInterface
2424
private array $sequences = [];
2525

2626
public function __construct(
27-
private readonly ParserInterface $parser = new Parser(),
27+
private readonly TypeParserInterface $parser = new TypeParser(),
2828
private readonly SourceFactoryInterface $sources = new SourceFactory(),
2929
) {}
3030

libs/parser/src/Internal/ExecutionContext.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
use TypeLang\Node\Type\Literal\StringLiteralNode;
2323
use TypeLang\Node\Type\TypeNode;
2424
use TypeLang\Parser\ParsedResult;
25-
use TypeLang\Parser\ParserFeatures;
25+
use TypeLang\Parser\TypeParserFeatures;
2626

2727
/**
2828
* @phpstan-type GrammarConfigArrayType array{
@@ -71,7 +71,7 @@ public function __construct(
7171
/**
7272
* @api this property is accessible inside the grammar reducers
7373
*/
74-
protected ParserFeatures $features,
74+
protected TypeParserFeatures $features,
7575
/**
7676
* @api this property is accessible inside the grammar reducers
7777
*/

libs/parser/src/Traverser/MatcherVisitor.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88

99
class MatcherVisitor extends Visitor
1010
{
11-
private ?Node $found = null;
11+
public private(set) ?Node $found = null;
12+
13+
public bool $isFound {
14+
get => $this->found !== null;
15+
}
1216

1317
private bool $shouldContinue = false;
1418

@@ -21,16 +25,6 @@ public function __construct(
2125
private readonly ?\Closure $break = null,
2226
) {}
2327

24-
public function isFound(): bool
25-
{
26-
return $this->found !== null;
27-
}
28-
29-
public function getFoundNode(): ?Node
30-
{
31-
return $this->found;
32-
}
33-
3428
public function before(): void
3529
{
3630
$this->found = null;

libs/parser/src/Traverser/StreamDumperVisitor.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@
66

77
final class StreamDumperVisitor extends DumperVisitor
88
{
9+
public const string DEFAULT_OUTPUT_STREAM = 'php://stderr';
10+
911
/**
1012
* @var resource
1113
*/
1214
private readonly mixed $stream;
1315

1416
public function __construct(
1517
bool $simplifyNames = true,
16-
string $stream = 'php://stderr',
18+
string $stream = self::DEFAULT_OUTPUT_STREAM,
1719
) {
1820
parent::__construct($simplifyNames);
1921

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use TypeLang\Parser\Exception\SemanticException;
1818
use TypeLang\Parser\Internal\ExecutionContext;
1919

20-
final class Parser implements ParserInterface
20+
final class TypeParser implements TypeParserInterface
2121
{
2222
private ExecutionContext $strict {
2323
get => $this->strict ??= new ExecutionContext($this->features, false);
@@ -28,7 +28,7 @@ final class Parser implements ParserInterface
2828
}
2929

3030
public function __construct(
31-
public readonly ParserFeatures $features = new ParserFeatures(),
31+
public readonly TypeParserFeatures $features = new TypeParserFeatures(),
3232
private readonly SourceFactoryInterface $sources = new SourceFactory(),
3333
) {}
3434

0 commit comments

Comments
 (0)