Skip to content

Commit 8a0f2b0

Browse files
refactor(glob-matcher)!: Migrated to new Cursor and class reorganization (#313)
2 parents 30860dd + 3a2a3fa commit 8a0f2b0

97 files changed

Lines changed: 692 additions & 585 deletions

File tree

Some content is hidden

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

packages/glob-matcher/README.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -148,16 +148,16 @@ The `(string) $glob->regex` is:
148148
The `$glob->node` is:
149149

150150
```plain
151-
LastDragon_ru\GlobMatcher\Glob\Ast\GlobNode {
151+
LastDragon_ru\GlobMatcher\Glob\Ast\Nodes\GlobNode {
152152
+children: [
153-
LastDragon_ru\GlobMatcher\Glob\Ast\SegmentNode {},
154-
LastDragon_ru\GlobMatcher\Glob\Ast\GlobstarNode {
153+
LastDragon_ru\GlobMatcher\Glob\Ast\Nodes\SegmentNode {},
154+
LastDragon_ru\GlobMatcher\Glob\Ast\Nodes\GlobstarNode {
155155
+count: 2
156156
},
157-
LastDragon_ru\GlobMatcher\Glob\Ast\NameNode {
157+
LastDragon_ru\GlobMatcher\Glob\Ast\Nodes\NameNode {
158158
+children: [
159-
LastDragon_ru\GlobMatcher\Glob\Ast\QuestionNode {},
160-
LastDragon_ru\GlobMatcher\Glob\Ast\StringNode {
159+
LastDragon_ru\GlobMatcher\Glob\Ast\Nodes\QuestionNode {},
160+
LastDragon_ru\GlobMatcher\Glob\Ast\Nodes\StringNode {
161161
+string: ".txt"
162162
},
163163
]
@@ -258,36 +258,36 @@ The `iterator_to_array($expander)` is:
258258
The `$expander->node` is:
259259

260260
```plain
261-
LastDragon_ru\GlobMatcher\BraceExpander\Ast\BraceExpansionNode {
261+
LastDragon_ru\GlobMatcher\BraceExpander\Ast\Nodes\BraceExpansionNode {
262262
+children: [
263-
LastDragon_ru\GlobMatcher\BraceExpander\Ast\SequenceNode {
263+
LastDragon_ru\GlobMatcher\BraceExpander\Ast\Nodes\SequenceNode {
264264
+children: [
265-
LastDragon_ru\GlobMatcher\BraceExpander\Ast\BraceExpansionNode {
265+
LastDragon_ru\GlobMatcher\BraceExpander\Ast\Nodes\BraceExpansionNode {
266266
+children: [
267-
LastDragon_ru\GlobMatcher\BraceExpander\Ast\StringNode {
267+
LastDragon_ru\GlobMatcher\BraceExpander\Ast\Nodes\StringNode {
268268
+string: "a"
269269
},
270270
]
271271
},
272-
LastDragon_ru\GlobMatcher\BraceExpander\Ast\BraceExpansionNode {
272+
LastDragon_ru\GlobMatcher\BraceExpander\Ast\Nodes\BraceExpansionNode {
273273
+children: [
274-
LastDragon_ru\GlobMatcher\BraceExpander\Ast\IntegerSequenceNode {
274+
LastDragon_ru\GlobMatcher\BraceExpander\Ast\Nodes\IntegerSequenceNode {
275275
+start: "0"
276276
+end: "10"
277277
+increment: 2
278278
},
279279
]
280280
},
281-
LastDragon_ru\GlobMatcher\BraceExpander\Ast\BraceExpansionNode {
281+
LastDragon_ru\GlobMatcher\BraceExpander\Ast\Nodes\BraceExpansionNode {
282282
+children: [
283-
LastDragon_ru\GlobMatcher\BraceExpander\Ast\StringNode {
283+
LastDragon_ru\GlobMatcher\BraceExpander\Ast\Nodes\StringNode {
284284
+string: "c"
285285
},
286286
]
287287
},
288288
]
289289
},
290-
LastDragon_ru\GlobMatcher\BraceExpander\Ast\StringNode {
290+
LastDragon_ru\GlobMatcher\BraceExpander\Ast\Nodes\StringNode {
291291
+string: ".txt"
292292
},
293293
]

packages/glob-matcher/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"php": "^8.4|^8.5",
2121
"ext-filter": "*",
2222
"ext-mbstring": "*",
23-
"lastdragon-ru/text-parser": "self.version"
23+
"lastdragon-ru/text-parser": "self.version",
24+
"symfony/polyfill-php85": "^1.33.0"
2425
},
2526
"require-dev": {
2627
"lastdragon-ru/phpunit-extensions": "self.version",

packages/glob-matcher/src/BraceExpander/Ast/BraceExpansionNode.php

Lines changed: 0 additions & 33 deletions
This file was deleted.

packages/glob-matcher/src/BraceExpander/Ast/BraceExpansionNodeChild.php

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace LastDragon_ru\GlobMatcher\BraceExpander\Ast;
4+
5+
use LastDragon_ru\TextParser\Cursor\Axes\ArrayAxis;
6+
use LastDragon_ru\TextParser\Cursor\Axis;
7+
use LastDragon_ru\TextParser\Cursor\Cursor as NodeCursor;
8+
use LastDragon_ru\TextParser\Cursor\Offsettable;
9+
10+
/**
11+
* @template TNode of Node
12+
*
13+
* @extends NodeCursor<TNode, Node>
14+
*/
15+
class Cursor extends NodeCursor {
16+
/**
17+
* @var Axis<covariant self<covariant TNode>>&Offsettable<covariant self<covariant TNode>>
18+
*/
19+
public Axis&Offsettable $children {
20+
get => new ArrayAxis(
21+
fn ($node, $offset) => new static($node, $this, $offset),
22+
$this->node instanceof NodeParent ? $this->node->children : [],
23+
);
24+
}
25+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace LastDragon_ru\GlobMatcher\BraceExpander\Ast\Factories;
4+
5+
use LastDragon_ru\GlobMatcher\BraceExpander\Ast\Node;
6+
use LastDragon_ru\GlobMatcher\BraceExpander\Ast\Nodes\BraceExpansionNode;
7+
use LastDragon_ru\GlobMatcher\BraceExpander\Ast\Nodes\BraceExpansionNodeChild;
8+
use LastDragon_ru\TextParser\Ast\NodeFactory;
9+
use Override;
10+
11+
/**
12+
* @extends NodeFactory<BraceExpansionNode, Node&BraceExpansionNodeChild>
13+
*/
14+
class BraceExpansionNodeFactory extends NodeFactory {
15+
#[Override]
16+
protected function onCreate(array $children): ?object {
17+
return new BraceExpansionNode($children);
18+
}
19+
20+
#[Override]
21+
protected function onPush(array $children, ?object $node): bool {
22+
return true;
23+
}
24+
}

packages/glob-matcher/src/BraceExpander/Parser/Factories/BraceExpansionNodeFactoryTest.php renamed to packages/glob-matcher/src/BraceExpander/Ast/Factories/BraceExpansionNodeFactoryTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php declare(strict_types = 1);
22

3-
namespace LastDragon_ru\GlobMatcher\BraceExpander\Parser\Factories;
3+
namespace LastDragon_ru\GlobMatcher\BraceExpander\Ast\Factories;
44

5-
use LastDragon_ru\GlobMatcher\BraceExpander\Ast\BraceExpansionNode;
6-
use LastDragon_ru\GlobMatcher\BraceExpander\Ast\StringNode;
5+
use LastDragon_ru\GlobMatcher\BraceExpander\Ast\Nodes\BraceExpansionNode;
6+
use LastDragon_ru\GlobMatcher\BraceExpander\Ast\Nodes\StringNode;
77
use LastDragon_ru\GlobMatcher\Package\TestCase;
88
use PHPUnit\Framework\Attributes\CoversClass;
99

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace LastDragon_ru\GlobMatcher\BraceExpander\Ast\Factories;
4+
5+
use LastDragon_ru\GlobMatcher\BraceExpander\Ast\Node;
6+
use LastDragon_ru\GlobMatcher\BraceExpander\Ast\Nodes\SequenceNode;
7+
use LastDragon_ru\GlobMatcher\BraceExpander\Ast\Nodes\SequenceNodeChild;
8+
use LastDragon_ru\TextParser\Ast\NodeFactory;
9+
use Override;
10+
11+
use function count;
12+
13+
/**
14+
* @extends NodeFactory<SequenceNode, Node&SequenceNodeChild>
15+
*/
16+
class SequenceNodeFactory extends NodeFactory {
17+
#[Override]
18+
protected function onCreate(array $children): ?object {
19+
return count($children) > 1 ? new SequenceNode($children) : null;
20+
}
21+
22+
#[Override]
23+
protected function onPush(array $children, ?object $node): bool {
24+
return true;
25+
}
26+
}

packages/glob-matcher/src/BraceExpander/Parser/Factories/SequenceNodeFactoryTest.php renamed to packages/glob-matcher/src/BraceExpander/Ast/Factories/SequenceNodeFactoryTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php declare(strict_types = 1);
22

3-
namespace LastDragon_ru\GlobMatcher\BraceExpander\Parser\Factories;
3+
namespace LastDragon_ru\GlobMatcher\BraceExpander\Ast\Factories;
44

5-
use LastDragon_ru\GlobMatcher\BraceExpander\Ast\BraceExpansionNode;
6-
use LastDragon_ru\GlobMatcher\BraceExpander\Ast\SequenceNode;
7-
use LastDragon_ru\GlobMatcher\BraceExpander\Ast\StringNode;
5+
use LastDragon_ru\GlobMatcher\BraceExpander\Ast\Nodes\BraceExpansionNode;
6+
use LastDragon_ru\GlobMatcher\BraceExpander\Ast\Nodes\SequenceNode;
7+
use LastDragon_ru\GlobMatcher\BraceExpander\Ast\Nodes\StringNode;
88
use LastDragon_ru\GlobMatcher\Package\TestCase;
99
use PHPUnit\Framework\Attributes\CoversClass;
1010

packages/glob-matcher/src/BraceExpander/Ast/IncrementalSequenceNode.php

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)