Lexer
in package
CRUDUI expression lexer (expressions.md §1, JS Lexer parity).
Turns a condition string into a Token[] ending in EOF. WHITESPACE is consumed
but never emitted. The token order, multi-char operator precedence, multi-dot
handling, string escapes, and number rules mirror validator-ts Lexer exactly,
because the shared fixture's tokens array is byte-compared across 4 languages.
NO regex-split / no string-split evaluation anywhere (GRAMMAR §10): this is a single forward scan. PHP identifiers are ASCII (analysis note), so byte-wise scanning is exact.
Table of Contents
Properties
Methods
- __construct() : mixed
- Build a lexer over the given expression string.
- tokenize() : array<int, Token>
- Tokenize the whole input. WHITESPACE tokens are dropped; an EOF token is always appended last.
- advance() : string
- isAlpha() : bool
- isAlphaNumeric() : bool
- isAtEnd() : bool
- isDigit() : bool
- isWhitespace() : bool
- matchString() : bool
- matchWhitespace() : bool
- nextToken() : Token
- parseNumberLiteral() : int|float
- Parse a numeric literal to int or float. JS uses parseFloat (always float); for JSON byte-parity we keep an int when the source has no fractional/exponent part so the fixture's integer literals stay integers.
- peek() : string
- peekNext() : string
- readIdentifier() : Token
- readNumber() : Token
- readString() : Token
Properties
$input read-only
private
string
$input
$length read-only
private
int
$length
$position
private
int
$position
= 0
Methods
__construct()
Build a lexer over the given expression string.
public
__construct(string $input) : mixed
Parameters
- $input : string
tokenize()
Tokenize the whole input. WHITESPACE tokens are dropped; an EOF token is always appended last.
public
tokenize() : array<int, Token>
Return values
array<int, Token>advance()
private
advance() : string
Return values
stringisAlpha()
private
isAlpha(string $c) : bool
Parameters
- $c : string
Return values
boolisAlphaNumeric()
private
isAlphaNumeric(string $c) : bool
Parameters
- $c : string
Return values
boolisAtEnd()
private
isAtEnd() : bool
Return values
boolisDigit()
private
isDigit(string $c) : bool
Parameters
- $c : string
Return values
boolisWhitespace()
private
isWhitespace(string $c) : bool
Parameters
- $c : string
Return values
boolmatchString()
private
matchString(string $str) : bool
Parameters
- $str : string
Return values
boolmatchWhitespace()
private
matchWhitespace() : bool
Return values
boolnextToken()
private
nextToken() : Token
Return values
TokenparseNumberLiteral()
Parse a numeric literal to int or float. JS uses parseFloat (always float); for JSON byte-parity we keep an int when the source has no fractional/exponent part so the fixture's integer literals stay integers.
private
static parseNumberLiteral(string $value) : int|float
Parameters
- $value : string
Return values
int|floatpeek()
private
peek() : string
Return values
stringpeekNext()
private
peekNext() : string
Return values
stringreadIdentifier()
private
readIdentifier() : Token
Return values
TokenreadNumber()
private
readNumber() : Token
Return values
TokenreadString()
private
readString() : Token