Skip to content

Commit 9dd05ed

Browse files
authored
[TASK] Extract method Selector::parseComponents (#1493)
This will allow the conversion of a selector string into an array of `Selector\Component` objects to also be used by the `setSelector()` method. Part of #1325.
1 parent 6f398f8 commit 9dd05ed

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

src/Property/Selector.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Sabberworm\CSS\Parsing\ParserState;
1010
use Sabberworm\CSS\Parsing\UnexpectedTokenException;
1111
use Sabberworm\CSS\Property\Selector\Combinator;
12+
use Sabberworm\CSS\Property\Selector\Component;
1213
use Sabberworm\CSS\Property\Selector\CompoundSelector;
1314
use Sabberworm\CSS\Property\Selector\SpecificityCalculator;
1415
use Sabberworm\CSS\Renderable;
@@ -76,11 +77,11 @@ final public function __construct(string $selector)
7677
/**
7778
* @param list<Comment> $comments
7879
*
79-
* @throws UnexpectedTokenException
80+
* @return list<Component>
8081
*
81-
* @internal
82+
* @throws UnexpectedTokenException
8283
*/
83-
public static function parse(ParserState $parserState, array &$comments = []): self
84+
private static function parseComponents(ParserState $parserState, array &$comments = []): array
8485
{
8586
// Whitespace is a descendent combinator, not allowed around a compound selector.
8687
// (It is allowed within, e.g. as part of a string or within a function like `:not()`.)
@@ -109,6 +110,20 @@ public static function parse(ParserState $parserState, array &$comments = []): s
109110
}
110111
}
111112

113+
return $selectorParts;
114+
}
115+
116+
/**
117+
* @param list<Comment> $comments
118+
*
119+
* @throws UnexpectedTokenException
120+
*
121+
* @internal
122+
*/
123+
public static function parse(ParserState $parserState, array &$comments = []): self
124+
{
125+
$selectorParts = self::parseComponents($parserState, $comments);
126+
112127
// Check that the selector has been fully parsed:
113128
if (!\in_array($parserState->peek(), ['{', '}', ',', ''], true)) {
114129
throw new UnexpectedTokenException(

0 commit comments

Comments
 (0)