All checks were successful
Build, Push and Deploy / build-and-push (push) Successful in 3m3s
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 16s
Build, Push and Deploy / deploy-staging (push) Successful in 32s
Build, Push and Deploy / deploy-production (push) Has been skipped
Build, Push and Deploy / cleanup (push) Successful in 1s
43 lines
1.0 KiB
PHP
43 lines
1.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Sabberworm\CSS;
|
|
|
|
use Sabberworm\CSS\CSSList\Document;
|
|
use Sabberworm\CSS\Parsing\ParserState;
|
|
use Sabberworm\CSS\Parsing\SourceException;
|
|
|
|
/**
|
|
* This class parses CSS from text into a data structure.
|
|
*/
|
|
class Parser
|
|
{
|
|
/**
|
|
* @var ParserState
|
|
*/
|
|
private $parserState;
|
|
|
|
/**
|
|
* @param string $text the complete CSS as text (i.e., usually the contents of a CSS file)
|
|
* @param int<1, max> $lineNumber the line number (starting from 1, not from 0)
|
|
*/
|
|
public function __construct(string $text, ?Settings $parserSettings = null, int $lineNumber = 1)
|
|
{
|
|
if ($parserSettings === null) {
|
|
$parserSettings = Settings::create();
|
|
}
|
|
$this->parserState = new ParserState($text, $parserSettings, $lineNumber);
|
|
}
|
|
|
|
/**
|
|
* Parses the CSS provided to the constructor and creates a `Document` from it.
|
|
*
|
|
* @throws SourceException
|
|
*/
|
|
public function parse(): Document
|
|
{
|
|
return Document::parse($this->parserState);
|
|
}
|
|
}
|