Index

Printer

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

class

Printer

Printer.php:27

Prints an ast (Parser) back as Simple CSS source.

class MMO\client\scs\Printer
Namespace
MMO\client\scs
This is the reverse of the parser, and the only part of the package that writes `.scs` rather than css. It exists because a stylesheet is sometimes *generated* from another one rather than compiled: the theme configurator ([`ThemeConfigurator`](https://mmoframework.fr/documentation/mmo.client/php/ThemeConfigurator.md#themeconfigurator)) parses the token sources, replaces the values a user changed, and prints the whole thing back -- which is how a generated theme keeps the derivations of the file it came from (`bg: $palette.n50` stays an expression) instead of freezing every token into a literal. What it does *not* keep is comments: the lexer drops them, so a printed file is the code, not the source. ```php $ast = (new Parser(file_get_contents('tokens.scs'), 'tokens.scs'))->parse(); echo (new Printer())->print($ast); ```

Index

indent
atRule($node, $depth)
block($head, $body, $depth)
call($node)
condition($node, $depth)@if ... { } @else { }.
expression($node)
forPrelude($node)$i in 1..6 or $key:$value in $collection
map($node)
params($params, $always)
print($node)
statement($node, $depth)
statements($statements, $depth)
string($node)
terms($node)The terms of a value list, joined the way Evaluator::render reads them back.
theme($node, $depth)@theme [scope] { group { name: value; } } -- the dotted paths are folded back into the groups they were written as, in the order the file declared them.
useCall($node)
value($node)
__construct($indent)

Properties1

indent

protected string $indent
Type
string

Methods17

block($head, $body, $depth)

Printer.php:155
protected function block(string $head, array $body, int $depth): string
$headstringthe text before the brace
$bodyarray
$depthint
returnsstring

condition($node, $depth)

Printer.php:133

@if ... { } @else { }.

protected function condition(MMO\client\scs\nodes\IfNode $node, int $depth): stringAn `@elseif` is parsed as an `@if` alone in the else branch of another one, and it is printed back that way -- `@else { @if ... }` rather than `@elseif ...`. The two are the same statement to the compiler, so a printed file behaves identically; it is simply one level deeper than the source was written.
$nodeIfNode
$depthint
returnsstring

expression($node)

Printer.php:48
function expression(MMO\client\scs\nodes\Node $node): string
$nodeNodean expression node
returnsstringthe expression as it would be written in a source
(new Printer())->expression($themeNode->entries['color.bg']); // '$palette.n50'

forPrelude($node)

Printer.php:160

$i in 1..6 or $key:$value in $collection

protected function forPrelude(MMO\client\scs\nodes\ForNode $node): string
$nodeForNode
returnsstring

params($params, $always)

Printer.php:172
protected function params(array $params, bool $always = false): string
$paramsarray[['name' => string, 'default' => ?Node], ...]
$always = falsebooltrue to print () even with no parameter (an @fn is always a call)
returnsstring

print($node)

Printer.php:37
function print( MMO\client\scs\nodes\StylesheetNode|MMO\client\scs\nodes\Node|array $node ): string
$nodeStylesheetNode | Node | arraywhat to print: a stylesheet, a statement list, or one statement
returnsstringthe source, newline terminated when it is a statement

statement($node, $depth)

Printer.php:67
protected function statement(MMO\client\scs\nodes\Node $node, int $depth): string
$nodeNode
$depthint
returnsstring

statements($statements, $depth)

Printer.php:61
protected function statements(array $statements, int $depth): string
$statementsarray
$depthint
returnsstring

theme($node, $depth)

Printer.php:101

@theme [scope] { group { name: value; } } -- the dotted paths are folded back into the groups they were written as, in the order the file declared them.

protected function theme(MMO\client\scs\nodes\ThemeNode $node, int $depth): string
$nodeThemeNode
$depthint
returnsstring

__construct($indent)

Printer.php:31
function __construct(string $indent = ' ')
$indent = ' 'stringone level of indentation