INDENT_SPACE
INDENT_SPACE
Performs lexical analysis and provides a token generator.
Tokens are defined as single units of code (e.g. tag, class, id, attributeStart, attribute, attributeEnd)
These will run through the parser and be converted to an AST
The lexer works sequentially, lex()
will return a generator and
you can read that generator in any manner you like.
The generator will produce valid tokens until the end of the passed
input.
Usage example:
use Phug\Lexer;
$lexer = new Lexer();
foreach ($lexer->lex($pugInput) as $token)
var_dump($token);
$state : \Phug\Lexer\State
The state of the current lexing process.
$lastToken : \Phug\Lexer\TokenInterface
$previousToken : \Phug\Lexer\TokenInterface|null
hasModule(string|\Phug\Util\ModuleInterface $module) : boolean
string|\Phug\Util\ModuleInterface | $module |
getModule(string|\Phug\Util\ModuleInterface $module) : \Phug\Util\ModuleInterface
string|\Phug\Util\ModuleInterface | $module |
addModule(string|\Phug\Util\ModuleInterface $module) : $this
string|\Phug\Util\ModuleInterface | $module |
removeModule(string|\Phug\Util\ModuleInterface $module) : $this
string|\Phug\Util\ModuleInterface | $module |
getState() : \Phug\Lexer\State
Returns the state object of the current lexing process.
__construct(array|null $options = null)
Creates a new lexer instance.
The options should be an associative array
Valid options are:
lexer_state_class_name: The class of the lexer state to use level: The internal indentation level to start on indent_style: The indentation character (auto-detected) indentwidth: How often to repeat indentStyle (auto-detected) encoding: The encoding when working with mb*-functions (auto-detected) scanners: An array of scans that will be performed
Add a new scan to 'scans' to extend the lexer. Notice that the parser needs to be able to handle newly introduced tokens provided by scanners.
array|null | $options | the options passed to the lexer instance |
getPreviousToken() : \Phug\Lexer\TokenInterface|null
getScanners() : array<mixed,\Phug\Lexer\ScannerInterface>
Returns the current scanners registered for the lexing process.
prependScanner(string $name, \Phug\Lexer\ScannerInterface|string $scanner) : $this
Adds a new scanner class to use in the lexing process at the top of scanning order.
The scanner class needs to extend Phug\Lexer\ScannerInterface. It can be the class name itself or an instance of it.
string | $name | |
\Phug\Lexer\ScannerInterface|string | $scanner |
addScanner(string $name, \Phug\Lexer\ScannerInterface|string $scanner) : $this
Adds a new scanner class to use in the lexing process.
The scanner class needs to extend Phug\Lexer\ScannerInterface. It can be the class name itself or an instance of it.
string | $name | |
\Phug\Lexer\ScannerInterface|string | $scanner |
lex(string $input, null $path = null) : \Phug\iterable
Returns a generator that will lex the passed input sequentially.
If you don't move the generator, the lexer does nothing.
Only as soon as you iterate the generator or call next()
/current()
on it
the lexer will start its work and spit out tokens sequentially.
This approach requires less memory during the lexing process.
The returned tokens are required to be Phug\Lexer\TokenInterface
instances.
string | $input | the pug-string to lex into tokens. |
null | $path |
a generator that can be iterated sequentially
getLastToken() : \Phug\Lexer\TokenInterface
dumpAttributeToken(\Phug\Lexer\Token\AttributeToken $token)
\Phug\Lexer\Token\AttributeToken | $token |
dumpTextToken(\Phug\Lexer\Token\TextToken $token)
\Phug\Lexer\Token\TextToken | $token |
dumpExpressionToken(\Phug\Lexer\Token\ExpressionToken $token)
\Phug\Lexer\Token\ExpressionToken | $token |
getTokenSymbol(\Phug\Lexer\TokenInterface $token)
\Phug\Lexer\TokenInterface | $token |
dumpToken(\Phug\Lexer\TokenInterface $token)
\Phug\Lexer\TokenInterface | $token |
setLastToken(\Phug\Lexer\TokenInterface $lastToken)
\Phug\Lexer\TokenInterface | $lastToken |