Properties

$replaceFunction

$replaceFunction : callable

Type

callable

$recursiveReplaceFunction

$recursiveReplaceFunction : callable

Type

callable

$nonDeepOptions

$nonDeepOptions : array<mixed,string>

Type

array<mixed,string>

$options

$options : \ArrayObject

Type

\ArrayObject

$optionNameHandlers

$optionNameHandlers : array

Type

array

$indentStyle

$indentStyle : string

Contains the currently detected indentation style.

Type

string

$indentWidth

$indentWidth : integer

Contains the currently detected indentation width.

Type

integer

$reader

$reader : \Phug\Reader

Contains the current `Phug\Reader` instance used by the lexer.

Type

\Phug\Reader

$lexer

$lexer : \Phug\Lexer

Contains the current `Phug\Lexer` instance linked to the state.

Type

\Phug\Lexer

$indentStack

$indentStack : array

Contains the stack of indent steps.

Type

array

Methods

getOptions()

getOptions() 

{@inheritdoc}

setOptions()

setOptions(  $options) 

{@inheritdoc}

Parameters

$options

setOptionsRecursive()

setOptionsRecursive(  $options) 

{@inheritdoc}

Parameters

$options

setOptionsDefaults()

setOptionsDefaults(  $options = null) 

{@inheritdoc}

Parameters

$options

hasOption()

hasOption(  $name) 

{@inheritdoc}

Parameters

$name

getOption()

getOption(  $name) 

{@inheritdoc}

Parameters

$name

setOption()

setOption(  $name,   $value) 

{@inheritdoc}

Parameters

$name
$value

unsetOption()

unsetOption(  $name) 

{@inheritdoc}

Parameters

$name

addOptionNameHandlers()

addOptionNameHandlers(callable  $handler) 

Parameters

callable $handler

resetOptions()

resetOptions() 

setLevel()

setLevel(integer  $level) : $this

Parameters

integer $level

Returns

$this

getIndentStyle()

getIndentStyle() : string

Returns the currently used indentation style.

Returns

string

setIndentStyle()

setIndentStyle(  $indentStyle) : $this

Sets the current indentation style to a new one.

The value needs to be one of the Lexer::INDENT_* constants, but you can also just pass either a single space or a single tab for the respective style.

Parameters

$indentStyle

Returns

$this

getIndentWidth()

getIndentWidth() : integer

Returns the currently used indentation width.

Returns

integer

setIndentWidth()

setIndentWidth(  $indentWidth) : $this

Sets the currently used indentation width.

The value of this specifies if e.g. 2 spaces make up one indentation level or 4.

Parameters

$indentWidth

Returns

$this

__construct()

__construct(\Phug\Lexer  $lexer, string  $input, array  $options) 

Creates a new instance of the state.

Parameters

\Phug\Lexer $lexer

linked lexer

string $input

pug string input

array $options

indent settings, errors info and reader class name

lastTokenIs()

lastTokenIs(  $classNames) : boolean

Parameters

$classNames

Returns

boolean

isAfterInterpolation()

isAfterInterpolation() : boolean

Return true if previous token was TagInterpolationEndToken or InterpolationEndToken.

Returns

boolean

getLexer()

getLexer() : \Phug\Lexer|null

Returns the current lexer instance linked.

Returns

\Phug\Lexer|null

getReader()

getReader() : \Phug\Reader

Returns the current reader instance that is used for parsing the input.

Returns

\Phug\Reader

getIndentLevel()

getIndentLevel() : integer

Returns the currently used indentation style.

Returns

integer

outdent()

outdent() : integer

Outdent and return the new level.

Returns

integer

nextOutdent()

nextOutdent() : integer

Return new outdent level if current above expected, or false if expected level reached.

Returns

integer

indent()

indent(null  $level = null) : integer

Indent and return the new level.

Parameters

null $level

Returns

integer

scan()

scan(array|string  $scanners) : \Phug\Lexer\iterable

Runs all passed scanners once on the input string.

The first scan that returns valid tokens will stop the scanning and yields these tokens. If you want to continuously scan on something, rather use the loopScan-method

Parameters

array|string $scanners

the scanners to run

Throws

\Phug\LexerException

Returns

\Phug\Lexer\iterable —

the generator yielding all tokens found

loopScan()

loopScan(  $scanners, boolean  $required = false) : \Phug\Lexer\iterable

Continuously scans with all scanners passed as the first argument.

If the second argument is true, it will throw an exception if none of the scanners produced any valid tokens. The reading also stops when the end of the input as been reached.

Parameters

$scanners
boolean $required

Throws

\Phug\LexerException

Returns

\Phug\Lexer\iterable

createCurrentSourceLocation()

createCurrentSourceLocation() 

createToken()

createToken(string  $className) : \Phug\Lexer\TokenInterface

Creates a new instance of a token.

The token automatically receives line/offset/level information through this method.

Parameters

string $className

the class name of the token

Returns

\Phug\Lexer\TokenInterface

the token

scanToken()

scanToken(  $className,   $pattern, null  $modifiers = null) : \Phug\Lexer\iterable

Quickly scans for a token by a single regular expression pattern.

If the pattern matches, this method will yield a new token. If not, it will yield nothing

All named capture groups are converted to set*()-methods, e.g. (?:<name>[a-z]+) will automatically call setName(<matchedValue>) on the token.

This method could be written without generators, but the way its designed is easier to use in scanners as you can simply return it's value without having to check for it to be null.

Parameters

$className
$pattern
null $modifiers

Returns

\Phug\Lexer\iterable

throwException()

throwException(string  $message, integer  $code, \Throwable  $previous = null) 

Throws a lexer-exception.

The current line and offset of the exception get automatically appended to the message

Parameters

string $message

A meaningful error message

integer $code

Error code

\Throwable $previous

Source error

Throws

\Phug\LexerException

handleOptionName()

handleOptionName(string  $name) : string

Parameters

string $name

Returns

string

filterTraversable()

filterTraversable(  $values) 

Parameters

$values

setOptionArrays()

setOptionArrays(array  $arrays, string  $functionName) : $this

Parameters

array $arrays
string $functionName

Returns

$this

mergeOptionValue()

mergeOptionValue(  $name,   $current,   $addedValue,   $functionName) 

Parameters

$name
$current
$addedValue
$functionName

setDefaultOption()

setDefaultOption(  $key,   $value) 

Parameters

$key
$value

withVariableReference()

withVariableReference(mixed  $variable,   $name, callable  $callback) : \Phug\Util\Partial\&$options

Parameters

mixed $variable
$name
callable $callback

Returns

\Phug\Util\Partial\&$options

withOptionReference()

withOptionReference(  $name, callable  $callback) : \Phug\Util\Partial\&$options

Parameters

$name
callable $callback

Returns

\Phug\Util\Partial\&$options

loadScanner()

loadScanner(string  $scanner) : \Phug\Lexer\ScannerInterface

Load a scan class name as a scanner instance (use cache if yet loaded in the state).

Parameters

string $scanner

scanner class name

Returns

\Phug\Lexer\ScannerInterface

filterScanners()

filterScanners(\Phug\Lexer\array<ScannerInterface|\Phug\Lexer\string>  $scanners) : array

Filters and validates the passed scanners.

This method makes sure that all scanners given are turned into their respective instances.

Parameters

\Phug\Lexer\array $scanners

list of scanner instances/class names.

Returns

array