WooCommerce Code Reference

Lexer
in package

A lexer is a stateful stream generator, it returns the next token in the Source when advanced.

Assuming the source is valid, the final returned token will be EOF, after which the lexer will repeatedly return the same EOF token whenever called.

Algorithm is O(N) both on memory and time.

Tags
phpstan-import-type

ParserOptions from Parser

see
LexerTest

Table of Contents

TOKEN_AMP  = 38
TOKEN_AT  = 64
TOKEN_BANG  = 33
TOKEN_BRACE_L  = 123
TOKEN_BRACE_R  = 125
TOKEN_BRACKET_L  = 91
TOKEN_BRACKET_R  = 93
TOKEN_COLON  = 58
TOKEN_DOLLAR  = 36
TOKEN_DOT  = 46
TOKEN_EQUALS  = 61
TOKEN_PAREN_L  = 40
TOKEN_PAREN_R  = 41
TOKEN_PIPE  = 124
$lastToken  : Token
The previously focused non-ignored token.
$line  : int
The (1-indexed) line containing the current token.
$lineStart  : int
The character offset at which the current line begins.
$options  : array<string|int, mixed>
$source  : Source
$token  : Token
The currently focused non-ignored token.
$byteStreamPosition  : int
Current cursor position for ASCII representation of the source.
$position  : int
Current cursor position for UTF8 encoding of the source.
__construct()  : mixed
advance()  : Token
lookahead()  : Token
assertValidBlockStringCharacterCode()  : void
assertValidStringCharacterCode()  : void
moveStringCursor()  : self
Moves internal string cursor position.
positionAfterWhitespace()  : void
Reads from body starting at startPosition until it finds a non-whitespace or commented character, then places cursor to the position of that character.
readBlockString()  : Token
Reads a block string token from the source file.
readChar()  : array{: string, : int|null, : int}
Reads next UTF8Character from the byte stream, starting from $byteStreamPosition.
readChars()  : array{: string, : int}
Reads next $numberOfChars UTF8 characters from the byte stream.
readComment()  : Token
Reads a comment token from the source file.
readDigits()  : string
Returns string with all digits + changes current string cursor position to point to the first char after digits.
readName()  : Token
Reads an alphanumeric + underscore name from the source.
readNumber()  : Token
Reads a number token from the source file, either a float or an int depending on whether a decimal point appears.
readString()  : Token
readToken()  : Token
unexpectedCharacterMessage()  : string

Constants

Properties

Methods

__construct()

public __construct(Source $source[, array<string|int, mixed> $options = [] ]) : mixed
Parameters
$source : Source
$options : array<string|int, mixed> = []
Tags
phpstan-param

ParserOptions $options

Return values
mixed

assertValidBlockStringCharacterCode()

private assertValidBlockStringCharacterCode(int $code, int $position) : void
Parameters
$code : int
$position : int
Tags
throws
JsonException
throws
SyntaxError
Return values
void

assertValidStringCharacterCode()

private assertValidStringCharacterCode(int $code, int $position) : void
Parameters
$code : int
$position : int
Tags
throws
JsonException
throws
SyntaxError
Return values
void

moveStringCursor()

Moves internal string cursor position.

private moveStringCursor(int $positionOffset, int $byteStreamOffset) : self
Parameters
$positionOffset : int
$byteStreamOffset : int
Return values
self

positionAfterWhitespace()

Reads from body starting at startPosition until it finds a non-whitespace or commented character, then places cursor to the position of that character.

private positionAfterWhitespace() : void
Return values
void

readChar()

Reads next UTF8Character from the byte stream, starting from $byteStreamPosition.

private readChar([bool $advance = false ][, int|null $byteStreamPosition = null ]) : array{: string, : int|null, : int}
Parameters
$advance : bool = false
$byteStreamPosition : int|null = null
Return values
array{: string, : int|null, : int}

readChars()

Reads next $numberOfChars UTF8 characters from the byte stream.

private readChars(int $charCount) : array{: string, : int}
Parameters
$charCount : int
Return values
array{: string, : int}

readDigits()

Returns string with all digits + changes current string cursor position to point to the first char after digits.

private readDigits() : string
Tags
throws
JsonException
throws
SyntaxError
Return values
string

readNumber()

Reads a number token from the source file, either a float or an int depending on whether a decimal point appears.

private readNumber(int $line, int $col, Token $prev) : Token

Int: -?(0|[1-9][0-9]) Float: -?(0|[1-9][0-9])(.[0-9]+)?((E|e)(+|-)?[0-9]+)?

Parameters
$line : int
$col : int
$prev : Token
Tags
throws
JsonException
throws
SyntaxError
Return values
Token

unexpectedCharacterMessage()

private unexpectedCharacterMessage(int|null $code) : string
Parameters
$code : int|null
Tags
throws
JsonException
Return values
string