Documentations › mmo.client › php › scs Lexer MMO\client\scs · 1 symbol · generated 30 Sep 2026
Turns a .scs source into a flat list of Token .
class MMO\client\scs\Lexer Namespace MMO\client\scsThe lexer is deliberately thin: it only makes the decisions that cannot be made later (where a string,
a comment or an interpolation ends), and keeps everything else -- including whether a token was preceded
by whitespace -- so the parser can re-render css values exactly as they were written.
Newlines are emitted as [`TokenType::Newline`](https://mmoframework.fr/documentation/mmo.client/php/scs/TokenType.md#tokentype-newline) tokens, with runs of blank lines collapsed into a single
one: a statement ends with a `;`, not with a newline, but the parser still reports an error on the line
it was written on, and a selector list may be wrapped. $tokens = (new Lexer('@let $spacing = 16px', 'theme.scs'))->tokenize();
Index OPERATORS multi-character operators, longest first WHITESPACE col filename length line pos source advance($count) error($message, $context, $line, $col, $text) getFilename() getSource() isDigit($c) isIdentChar($c) isIdentStart($c) isOperand($token) peek($offset) readBalanced($open, $close) Read until the matching closing character, honoring nesting, strings and comments. readIdent() readNumber($ws, $line, $col) readString($quote) skipComment() skipTo($stop) token($type, $text, $ws, $line, $col) tokenize() __construct($source, $filename, $line, $col)
Constants2 multi-character operators, longest first
const OPERATORS = ['==', '!=', '<=', '>=', '&&', '||', '::', '..'] const WHITESPACE = [' ', ' ', '
', ''] Properties6 protected int $col Type int protected string $filename Type string protected int $length Type int protected int $line Type int protected int $pos = 0 Type int protected string $source Type string Methods18 protected function advance(int $count = 1): void protected function error(string $message, array $context, int $line, int $col, string $text): MMO\client\exceptions\eSCS function getFilename(): string function getSource(): string protected function isDigit(string $c): bool protected function isIdentChar(string $c): bool protected function isIdentStart(string $c): bool protected function isOperand(?MMO\client\scs\Token $token): bool $token null | Token returns bool true when $token can end an expression, which means a following - is a binary operator rather than the start of an identifier
protected function peek(int $offset = 0): string Read until the matching closing character, honoring nesting, strings and comments.
protected function readBalanced(string $open, string $close): string The opening character must already have been consumed. protected function readIdent(): string protected function readNumber(bool $ws, int $line, int $col): MMO\client\scs\Token protected function readString(string $quote): string protected function skipTo(string $stop): void protected function token(
MMO\client\scs\TokenType $type,
string $text,
bool $ws,
int $line,
int $col
): MMO\client\scs\Token function tokenize(): array function __construct(string $source, string $filename = '<scs>', int $line = 1, int $col = 1) $source string the .scs source $filename = '<scs>' string used for error reporting only $line = 1 int the line the source starts at (interpolations are lexed as fragments) $col = 1 int the column the source starts at