\PhugParser

Takes tokens from the Lexer and creates an AST out of it.

This class takes generated tokens from the Lexer sequentially and produces an Abstract Syntax Tree (AST) out of it

The AST is an object-tree containing Phug\Parser\Node instances with parent/child relations

This AST is passed to the compiler to generate PHTML out of it

Usage example:

use Phug\Parser;

$parser = new Parser();
var_dump($parser->parse($pugInput));

Summary

Methods
Properties
Constants
hasModule()
getModule()
getModules()
getStaticModules()
addModule()
addModules()
removeModule()
getModuleBaseClassName()
__construct()
getLexer()
setTokenHandler()
parse()
dump()
No public properties found
No constants found
getNodeName()
dumpNode()
No protected properties found
N/A
No private methods found
$modules
$lexer
$state
$tokenHandlers
N/A

Properties

$modules

$modules : \Phug\Util\Partial\array<ModuleInterface>

Type

\Phug\Util\Partial\array

$lexer

$lexer : \Phug\Lexer

The lexer used in this parser instance.

Type

\Phug\Lexer

$tokenHandlers

$tokenHandlers : array<mixed,callable>

Type

array<mixed,callable>

Methods

hasModule()

hasModule(string|\Phug\Util\ModuleInterface  $module) : boolean

Parameters

string|\Phug\Util\ModuleInterface $module

Returns

boolean

getModules()

getModules() : \Phug\Util\Partial\array<ModuleInterface>

Returns

\Phug\Util\Partial\array

getStaticModules()

getStaticModules() : \Phug\Util\Partial\array<string>

Returns

\Phug\Util\Partial\array

addModule()

addModule(string|\Phug\Util\ModuleInterface  $module) : $this

Parameters

string|\Phug\Util\ModuleInterface $module

Returns

$this

addModules()

addModules(\Phug\Util\Partial\array<string|\Phug\Util\Partial\ModuleInterface>  $modules) : $this

Parameters

\Phug\Util\Partial\array $modules

Returns

$this

removeModule()

removeModule(string|\Phug\Util\ModuleInterface  $module) : $this

Parameters

string|\Phug\Util\ModuleInterface $module

Returns

$this

getModuleBaseClassName()

getModuleBaseClassName() 

__construct()

__construct(array|null  $options = null) 

Creates a new parser instance.

The parser will run the provided input through the lexer and generate an AST out of it.

The AST will be an object-tree consisting of Phug\Parser\Node instances

You can take the AST and either compile it with the Compiler or handle it yourself

Parameters

array|null $options

the options array

Throws

\Phug\ParserException

getLexer()

getLexer() : \Phug\Lexer

Returns the currently used Lexer instance.

Returns

\Phug\Lexer

setTokenHandler()

setTokenHandler(  $className,   $handler) 

Parameters

$className
$handler

parse()

parse(string  $input, string  $path = null) : \Phug\Parser\NodeInterface

Parses the provided input-string to an AST.

The Abstract Syntax Tree (AST) will be an object-tree consisting of \Phug\Parser\Node instances.

You can either let the compiler compile it or compile it yourself

The root-node will always be of type 'document', from there on it can contain several kinds of nodes

Parameters

string $input

the input jade string that is to be parsed

string $path

optional path of file the input comes from

Returns

\Phug\Parser\NodeInterface

the root-node of the parsed AST

dump()

dump(string  $input) : string

Dump a representation of the parser rendering.

Parameters

string $input

the input jade string that is to be parsed

Returns

string —

representation of parser rendering