Parser
in package
Parsers a token stream.
This parser implements a "Precedence climbing" algorithm.
Tags
Table of Contents
Constants
- OPERATOR_LEFT = 1
- OPERATOR_RIGHT = 2
Properties
- $binaryOperators : array<string|int, mixed>
- $functions : array<string|int, mixed>
- $lint : bool
- $names : array<string|int, mixed>|null
- $stream : mixed
- $unaryOperators : array<string|int, mixed>
Methods
- __construct() : mixed
- lint() : void
- Validates the syntax of an expression.
- parse() : Node
- Converts a token stream to a node tree.
- parseArguments() : mixed
- Parses arguments.
- parseArrayExpression() : mixed
- parseExpression() : mixed
- parseHashExpression() : mixed
- parsePostfixExpression() : mixed
- parsePrimaryExpression() : mixed
- getPrimary() : mixed
- parseConditionalExpression() : mixed
- doParse() : Node
Constants
OPERATOR_LEFT
public
mixed
OPERATOR_LEFT
= 1
OPERATOR_RIGHT
public
mixed
OPERATOR_RIGHT
= 2
Properties
$binaryOperators
private
array<string|int, mixed>
$binaryOperators
$functions
private
array<string|int, mixed>
$functions
$lint
private
bool
$lint
= false
$names
private
array<string|int, mixed>|null
$names
$stream
private
mixed
$stream
$unaryOperators
private
array<string|int, mixed>
$unaryOperators
Methods
__construct()
public
__construct(array<string|int, mixed> $functions) : mixed
Parameters
- $functions : array<string|int, mixed>
lint()
Validates the syntax of an expression.
public
lint(TokenStream $stream[, array<string|int, mixed>|null $names = [] ]) : void
The syntax of the passed expression will be checked, but not parsed.
If you want to skip checking dynamic variable names, pass null
instead of the array.
Parameters
- $stream : TokenStream
- $names : array<string|int, mixed>|null = []
Tags
parse()
Converts a token stream to a node tree.
public
parse(TokenStream $stream[, array<string|int, mixed> $names = [] ]) : Node
The valid names is an array where the values are the names that the user can use in an expression.
If the variable name in the compiled PHP code must be different, define it as the key.
For instance, ['this' => 'container'] means that the variable 'container' can be used in the expression but the compiled code will use 'this'.
Parameters
- $stream : TokenStream
- $names : array<string|int, mixed> = []
Tags
Return values
NodeparseArguments()
Parses arguments.
public
parseArguments() : mixed
parseArrayExpression()
public
parseArrayExpression() : mixed
parseExpression()
public
parseExpression([int $precedence = 0 ]) : mixed
Parameters
- $precedence : int = 0
parseHashExpression()
public
parseHashExpression() : mixed
parsePostfixExpression()
public
parsePostfixExpression(Node $node) : mixed
Parameters
- $node : Node
parsePrimaryExpression()
public
parsePrimaryExpression() : mixed
getPrimary()
protected
getPrimary() : mixed
parseConditionalExpression()
protected
parseConditionalExpression(Node $expr) : mixed
Parameters
- $expr : Node
doParse()
private
doParse(TokenStream $stream[, array<string|int, mixed>|null $names = [] ]) : Node
Parameters
- $stream : TokenStream
- $names : array<string|int, mixed>|null = []