$replaceFunction
$replaceFunction : callable
Represents the state of a currently running lexing process.
$reader : \Phug\Reader
Contains the current `Phug\Reader` instance used by the lexer.
$lexer : \Phug\Lexer
Contains the current `Phug\Lexer` instance linked to the state.
$scanners : array<mixed,\Phug\Lexer\ScannerInterface>
List of scanner instances.
__construct(\Phug\Lexer $lexer, string $input, array $options)
Creates a new instance of the state.
\Phug\Lexer | $lexer | linked lexer |
string | $input | pug string input |
array | $options | indent settings, errors info and reader class name |
getLastToken() : \Phug\Lexer\TokenInterface
getLexer() : \Phug\Lexer|null
Returns the current lexer instance linked.
getReader() : \Phug\Reader
Returns the current reader instance that is used for parsing the input.
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
array|string | $scanners | the scanners to run |
the generator yielding all tokens found
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.
$scanners | ||
boolean | $required |
createToken(string $className) : \Phug\Lexer\TokenInterface
Creates a new instance of a token.
The token automatically receives line/offset/level information through this method.
string | $className | the class name of the token |
the token
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.
$className | ||
$pattern | ||
null | $modifiers |
endToken(\Phug\Lexer\TokenInterface $token) : \Phug\Lexer\TokenInterface
\Phug\Lexer\TokenInterface | $token |
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
string | $message | A meaningful error message |
integer | $code | Error code |
\Throwable | $previous | Source error |
loadScanner(string $scanner) : \Phug\Lexer\ScannerInterface
Load a scan class name as a scanner instance (use cache if yet loaded in the state).
string | $scanner | scanner class name |
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.
\Phug\Lexer\array |
$scanners | list of scanner instances/class names. |