Index

Lexer

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

class

Lexer

Lexer.php:19

Turns a .scs source into a flat list of Token.

class MMO\client\scs\Lexer
Namespace
MMO\client\scs
The 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();

Constants2

OPERATORS

multi-character operators, longest first

const OPERATORS = ['==', '!=', '<=', '>=', '&&', '||', '::', '..']

WHITESPACE

const WHITESPACE = [' ', ' ', ' ', ' ']

Properties6

col

protected int $col
Type
int

filename

protected string $filename
Type
string

length

protected int $length
Type
int

line

protected int $line
Type
int

pos

protected int $pos = 0
Type
int

source

protected string $source
Type
string

Methods18

advance($count)

Lexer.php:168
protected function advance(int $count = 1): void
$count = 1int
returnsvoid

error($message, $context, $line, $col, $text)

Lexer.php:280
protected function error(string $message, array $context, int $line, int $col, string $text): MMO\client\exceptions\eSCS
$messagestring
$contextarray
$lineint
$colint
$textstring
returnseSCS

isOperand($token)

Lexer.php:192
protected function isOperand(?MMO\client\scs\Token $token): bool
$tokennull | Token
returnsbooltrue when $token can end an expression, which means a following - is a binary operator rather than the start of an identifier

readBalanced($open, $close)

Lexer.php:245

Read until the matching closing character, honoring nesting, strings and comments.

protected function readBalanced(string $open, string $close): stringThe opening character must already have been consumed.
$openstring
$closestring
returnsstringthe inner text

readNumber($ws, $line, $col)

Lexer.php:209
protected function readNumber(bool $ws, int $line, int $col): MMO\client\scs\Token
$wsbool
$lineint
$colint
returnsToken

token($type, $text, $ws, $line, $col)

Lexer.php:160
protected function token( MMO\client\scs\TokenType $type, string $text, bool $ws, int $line, int $col ): MMO\client\scs\Token
$typeTokenType
$textstring
$wsbool
$lineint
$colint
returnsToken

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

Lexer.php:37
function __construct(string $source, string $filename = '<scs>', int $line = 1, int $col = 1)
$sourcestringthe .scs source
$filename = '<scs>'stringused for error reporting only
$line = 1intthe line the source starts at (interpolations are lexed as fragments)
$col = 1intthe column the source starts at