Index

Parser

MMO\client\scs · 1 symbol · generated 30 Sep 2026

class

Parser

Parser.php:24

Turns the tokens of a .scs source into an ast (StylesheetNode).

class MMO\client\scs\Parser
Namespace
MMO\client\scs
The parser reads two kinds of value: - **expressions** (`@let`, `@if`, `@for`, function arguments, `${...}`) where `+ - * /` are arithmetic; - **css values** (declarations, selectors, at-rule preludes) where they are plain css text, and only `$variables`, `${interpolations}` and known functions are evaluated -- this is exactly the distinction the language makes with `${...}` (`the` spec, 5.3).
$ast = (new Parser('@let $spacing = 16px', 'theme.scs'))->parse();

Index

CSS_FUNCTIONScss functions whose arguments must never be evaluated as arithmetic (calc(100% - 20px))
PRECEDENCEoperator precedence, highest binds tighter
filename
index
source
tokens
accept($type, $text)
at($type, $text)
error($token, $message, $context)
expect($type, $text)
expectTerminator($node)Consume the ; that ends a statement, or say where it is missing.
getFilename()
getSource()
location($token)
needsTerminator($node)
next()
parse()
parseArguments($raw, $selector)Read the arguments of a call.
parseArray()[4, 8, 16]
parseAtRule()
parseBlock()Parse a { ... } block.
parseComponent()
parseConfig()
parseCssTerm($selector)Read one term of a css value: everything that is not scs is kept as written.
parseDefinition($class)`@style name($a, $b = default) { ...
parseExpression($precedence)Parse a full expression, where + - * / are arithmetic (PRECEDENCE).
parseFor()
parseIdentPrimary()
parseIdentTerm($selector)An identifier in a css value is a call (spacing(4), lib::step(3), php::round(1.2), calc(...)), a namespaced reference (context::density) or plain css text.
parseIf()
parseImport()
parseInterpolated()Parse the body of an interpolation: a single expression.
parseInterpolation()
parseLet()
parseName()Read a reference to a definition: center, or lib::center for one that belongs to another file.
parseNamespace($token)@namespace ui -- name the definitions of this file.
parseOrder()
parseParameters()
parseParenthesis()(a + b) or a map literal (sm: 8px, md: 16px).
parsePrimary()
parseRawArgument($selector)Read one argument of a css-only function (calc, clamp, ...): everything is kept verbatim but $variables and ${interpolations}, which are still resolved.
parseRawAtRule($token)A css at-rule the language does not interpret: @media, @keyframes, @font-face, @supports...
parseRuleOrDeclaration()Decide between a nested rule and a declaration by looking ahead for the token that ends the statement: a { means everything read so far was a selector.
parseScreen()
parseStatement()
parseStatements($inBlock)
parseString()Read a string token, keeping the ${...} / #{...} it may contain interpolable.
parseTheme()
parseThemeEntries($prefix)Read the group { key: value } body of a @theme, flattening it into dotted paths.
parseThemeValue()Read the value of a theme token.
parseUnary()
parseUse()
parseValue()Parse the whole source as a single value, for the evaluation api (Compiler::evaluate).
parseValueList($css, $stop, $selector)Read a css value, a selector or an @let value: a list of terms, up to the end of the statement.
parseVariableRef()
parseVariant()
peek($offset)
skipNewlines()Skip end of lines, which are only statement separators.
skipTerminators()Skip what separates two statements: ; and the newlines around it.
startsThemeEntry($offset)
__construct($source, $filename, $line, $col)

Constants2

CSS_FUNCTIONS

css functions whose arguments must never be evaluated as arithmetic (calc(100% - 20px))

const CSS_FUNCTIONS = […81 items]

PRECEDENCE

operator precedence, highest binds tighter

const PRECEDENCE = […15 items]

Properties4

filename

protected string $filename
Type
string

index

protected int $index = 0
Type
int

source

protected string $source
Type
string

tokens

protected array $tokens
Type
array

Methods55

error($token, $message, $context)

Parser.php:121
protected function error(MMO\client\scs\Token $token, string $message, array $context = []): MMO\client\exceptions\eSCS
$tokenToken
$messagestring
$context = []array
returnseSCS

expectTerminator($node)

Parser.php:180

Consume the ; that ends a statement, or say where it is missing.

protected function expectTerminator(MMO\client\scs\nodes\Node $node): void
$nodeNodethe statement it belongs to
returnsvoid
throwswhen the statement is not terminated

needsTerminator($node)

Parser.php:162
protected function needsTerminator(MMO\client\scs\nodes\Node $node): bool
$nodeNodethe statement that was just read
returnsbooltrue when it must be followed by a ; -- everything but a block

parse()

Parser.php:74
function parse(): MMO\client\scs\nodes\StylesheetNode
returnsStylesheetNodethe parsed source
throwson any syntax error, located on the offending token

parseArguments($raw, $selector)

Parser.php:699

Read the arguments of a call.

protected function parseArguments(bool $raw, bool $selector = false): array
$rawbooltrue to keep the arguments as css (only variables and interpolations are evaluated)
$selector = falsebooltrue inside a selector, where a nested name(...) is itself a functional pseudo-class: :not(:has(::slotted(*))) is three selectors deep and still css
returnsarray

parseArray()

Parser.php:962

[4, 8, 16]

protected function parseArray(): MMO\client\scs\nodes\Node
returnsNode

parseAtRule()

Parser.php:254
protected function parseAtRule(): MMO\client\scs\nodes\Node
returnsNode

parseBlock()

Parser.php:188

Parse a { ... } block.

protected function parseBlock(): array
returnsarray

parseCssTerm($selector)

Parser.php:631

Read one term of a css value: everything that is not scs is kept as written.

protected function parseCssTerm(bool $selector = false): MMO\client\scs\nodes\Node
$selector = falsebooltrue in a selector, a property name or an at-rule prelude, where a name(...) is a functional pseudo-class (:not(.a, .b)) rather than a function to evaluate
returnsNode

parseDefinition($class)

Parser.php:381

@style name($a, $b = default) { ... } / @fn name($a) { ... }

protected function parseDefinition(string $class): MMO\client\scs\nodes\Node
$classstring
returnsNode

parseExpression($precedence)

Parser.php:866

Parse a full expression, where + - * / are arithmetic (PRECEDENCE).

function parseExpression(int $precedence = 0): MMO\client\scs\nodes\Node
$precedence = 0intthe minimum precedence to keep consuming operators at
returnsNode

parseIdentPrimary()

Parser.php:921
protected function parseIdentPrimary(): MMO\client\scs\nodes\Node
returnsNode

parseIdentTerm($selector)

Parser.php:653

An identifier in a css value is a call (spacing(4), lib::step(3), php::round(1.2), calc(...)), a namespaced reference (context::density) or plain css text.

protected function parseIdentTerm(bool $selector = false): MMO\client\scs\nodes\Node
$selector = falsebool
returnsNode

parseInterpolated()

Parser.php:814

Parse the body of an interpolation: a single expression.

function parseInterpolated(): MMO\client\scs\nodes\Node
returnsNode

parseInterpolation()

Parser.php:790
protected function parseInterpolation(): MMO\client\scs\nodes\Node
returnsNode

parseName()

Parser.php:400

Read a reference to a definition: center, or lib::center for one that belongs to another file.

protected function parseName(): array
returnsarray?string, name: string}

parseNamespace($token)

Parser.php:415

@namespace ui -- name the definitions of this file.

protected function parseNamespace(MMO\client\scs\Token $token): MMO\client\scs\nodes\Node`@namespace` is also a (rarely used) css at-rule: `@namespace svg url(...)` is left to css, only a lone identifier is read as the language instruction.
$tokenToken
returnsNode

parseParameters()

Parser.php:425
protected function parseParameters(): array
returnsarray[['name' => string, 'default' => ?Node], ...]

parseParenthesis()

Parser.php:932

(a + b) or a map literal (sm: 8px, md: 16px).

protected function parseParenthesis(): MMO\client\scs\nodes\Node
returnsNode

parsePrimary()

Parser.php:901
protected function parsePrimary(): MMO\client\scs\nodes\Node
returnsNode

parseRawArgument($selector)

Parser.php:723

Read one argument of a css-only function (calc, clamp, ...): everything is kept verbatim but $variables and ${interpolations}, which are still resolved.

protected function parseRawArgument(bool $selector = false): MMO\client\scs\nodes\ValueListNode
$selector = falsebooltrue to keep reading the argument as a selector
returnsValueListNode

parseRawAtRule($token)

Parser.php:580

A css at-rule the language does not interpret: @media, @keyframes, @font-face, @supports...

protected function parseRawAtRule(MMO\client\scs\Token $token): MMO\client\scs\nodes\AtRuleNode
$tokenToken
returnsAtRuleNode

parseRuleOrDeclaration()

Parser.php:214

Decide between a nested rule and a declaration by looking ahead for the token that ends the statement: a { means everything read so far was a selector.

protected function parseRuleOrDeclaration(): MMO\client\scs\nodes\Node
returnsNode

parseStatement()

Parser.php:196
protected function parseStatement(): MMO\client\scs\nodes\Node
returnsNode

parseStatements($inBlock)

Parser.php:137
protected function parseStatements(bool $inBlock): array
$inBlockbooltrue to stop on the closing } of the enclosing block
returnsarray

parseString()

Parser.php:751

Read a string token, keeping the ${...} / #{...} it may contain interpolable.

protected function parseString(): MMO\client\scs\nodes\Node
returnsNodea LiteralNode for a plain string, a StringNode otherwise

parseThemeEntries($prefix)

Parser.php:305

Read the group { key: value } body of a @theme, flattening it into dotted paths.

protected function parseThemeEntries(string $prefix): array
$prefixstring
returnsarraydotted path => value node

parseThemeValue()

Parser.php:345

Read the value of a theme token.

protected function parseThemeValue(): MMO\client\scs\nodes\ValueListNodeSame as a css value, except that a top level comma ends the token when what follows it is another `key:` -- so both `sm: 8px, md: 16px` and `font: "Inter", sans-serif` mean what they look like.

parseUnary()

Parser.php:889
protected function parseUnary(): MMO\client\scs\nodes\Node
returnsNode

parseValueList($css, $stop, $selector)

Parser.php:596

Read a css value, a selector or an @let value: a list of terms, up to the end of the statement.

protected function parseValueList(bool $css, array $stop = [], bool $selector = false): MMO\client\scs\nodes\ValueListNode
$cssbooltrue for css context (+ - * / stay literal), false for an expression context
$stop = []arrayextra punctuation that ends the list (not consumed)
$selector = falsebool
returnsValueListNode

parseVariableRef()

Parser.php:824
protected function parseVariableRef(): MMO\client\scs\nodes\Node
returnsNode

peek($offset)

Parser.php:83
protected function peek(int $offset = 0): MMO\client\scs\Token
$offset = 0int
returnsToken

skipNewlines()

Parser.php:112

Skip end of lines, which are only statement separators.

protected function skipNewlines(): void
returnsvoid

skipTerminators()

Parser.php:117

Skip what separates two statements: ; and the newlines around it.

protected function skipTerminators(): void
returnsvoid

startsThemeEntry($offset)

Parser.php:366
protected function startsThemeEntry(int $offset): bool
$offsetint
returnsbooltrue when the tokens at $offset start a new theme entry (name:)

__construct($source, $filename, $line, $col)

Parser.php:61
function __construct(string $source, string $filename = '<scs>', int $line = 1, int $col = 1)
$sourcestring
$filename = '<scs>'string
$line = 1int
$col = 1int