Documentation

Parser
in package

Parsers a token stream.

This parser implements a "Precedence climbing" algorithm.

Tags
see
http://www.engr.mun.ca/~theo/Misc/exp_parsing.htm
see
http://en.wikipedia.org/wiki/Operator-precedence_parser
author

Fabien Potencier fabien@symfony.com

Table of Contents

OPERATOR_LEFT  = 1
OPERATOR_RIGHT  = 2
$binaryOperators  : mixed
$functions  : mixed
$lint  : mixed
$names  : mixed
$stream  : mixed
$unaryOperators  : mixed
__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 mixed $binaryOperators

$functions

private mixed $functions

$unaryOperators

private mixed $unaryOperators

Methods

__construct()

public __construct(array<string|int, mixed> $functions) : mixed
Parameters
$functions : array<string|int, mixed>
Return values
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
throws
SyntaxError

When the passed expression is invalid

Return values
void

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
throws
SyntaxError
Return values
Node

parseArguments()

Parses arguments.

public parseArguments() : mixed
Return values
mixed

parseArrayExpression()

public parseArrayExpression() : mixed
Return values
mixed

parseExpression()

public parseExpression(int $precedence) : mixed
Parameters
$precedence : int
Return values
mixed

parseHashExpression()

public parseHashExpression() : mixed
Return values
mixed

parsePostfixExpression()

public parsePostfixExpression(Node $node) : mixed
Parameters
$node : Node
Return values
mixed

parsePrimaryExpression()

public parsePrimaryExpression() : mixed
Return values
mixed

getPrimary()

protected getPrimary() : mixed
Return values
mixed

parseConditionalExpression()

protected parseConditionalExpression(Node $expr) : mixed
Parameters
$expr : Node
Return values
mixed

Search results