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

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

$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
throws
SyntaxError

When the passed expression is invalid

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() : Node
Return values
Node

parseArrayExpression()

public parseArrayExpression() : ArrayNode
Return values
ArrayNode

parseExpression()

public parseExpression([int $precedence = 0 ]) : Node
Parameters
$precedence : int = 0
Return values
Node

parseHashExpression()

public parseHashExpression() : ArrayNode
Return values
ArrayNode

parsePostfixExpression()

public parsePostfixExpression(Node $node) : GetAttrNode|Node
Parameters
$node : Node
Return values
GetAttrNode|Node

parsePrimaryExpression()

public parsePrimaryExpression() : Node
Return values
Node

parseConditionalExpression()

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

        
On this page

Search results