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 : TokenStream
- $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() : Node
- Parses arguments.
- parseArrayExpression() : ArrayNode
- parseExpression() : Node
- parseHashExpression() : ArrayNode
- parsePostfixExpression() : GetAttrNode|Node
- parsePrimaryExpression() : Node
- getPrimary() : Node
- parseConditionalExpression() : Node
- 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
TokenStream
$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() : Node
Return values
NodeparseArrayExpression()
public
parseArrayExpression() : ArrayNode
Return values
ArrayNodeparseExpression()
public
parseExpression([int $precedence = 0 ]) : Node
Parameters
- $precedence : int = 0
Return values
NodeparseHashExpression()
public
parseHashExpression() : ArrayNode
Return values
ArrayNodeparsePostfixExpression()
public
parsePostfixExpression(Node $node) : GetAttrNode|Node
Parameters
- $node : Node
Return values
GetAttrNode|NodeparsePrimaryExpression()
public
parsePrimaryExpression() : Node
Return values
NodegetPrimary()
protected
getPrimary() : Node
Return values
NodeparseConditionalExpression()
protected
parseConditionalExpression(Node $expr) : Node
Parameters
- $expr : Node
Return values
NodedoParse()
private
doParse(TokenStream $stream[, array<string|int, mixed>|null $names = [] ]) : Node
Parameters
- $stream : TokenStream
- $names : array<string|int, mixed>|null = []