-
Notifications
You must be signed in to change notification settings - Fork 152
Expand file tree
/
Copy pathLineName.php
More file actions
65 lines (59 loc) · 1.83 KB
/
Copy pathLineName.php
File metadata and controls
65 lines (59 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
declare(strict_types=1);
namespace Sabberworm\CSS\Value;
use Sabberworm\CSS\OutputFormat;
use Sabberworm\CSS\Parsing\ParserState;
use Sabberworm\CSS\Parsing\UnexpectedEOFException;
use Sabberworm\CSS\Parsing\UnexpectedTokenException;
/**
* A name for a named CSS grid line.
*
* @see https://www.w3.org/TR/css-grid-1/#line-name
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Grid_layout/Named_grid_lines
*/
class LineName extends ValueList
{
/**
* @param array<string> $components
* @param int<1, max>|null $lineNumber
*/
public function __construct(array $components = [], ?int $lineNumber = null)
{
parent::__construct($components, ' ', $lineNumber);
}
/**
* @throws UnexpectedTokenException
* @throws UnexpectedEOFException
*
* @internal since V8.8.0
*/
public static function parse(ParserState $parserState): LineName
{
$parserState->consume('[');
$parserState->consumeWhiteSpace();
$names = [];
do {
if ($parserState->getSettings()->usesLenientParsing()) {
try {
$names[] = $parserState->parseIdentifier();
} catch (UnexpectedTokenException $e) {
if (!$parserState->comes(']')) {
throw $e;
}
}
} else {
$names[] = $parserState->parseIdentifier();
}
$parserState->consumeWhiteSpace();
} while (!$parserState->comes(']'));
$parserState->consume(']');
return new LineName($names, $parserState->currentLine());
}
/**
* @return non-empty-string
*/
public function render(OutputFormat $outputFormat): string
{
return '[' . parent::render(OutputFormat::createCompact()) . ']';
}
}