\PhugLexer

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);  Summary Methods Properties Constants hasModule() getModule() getModules() getStaticModules() addModule() addModules() removeModule() getModuleBaseClassName() hasState() getState() __construct() getPreviousToken() updateOptions() getScanners() prependScanner() addScanner() lex() getLastToken() dump() No public properties found INDENT_SPACE INDENT_TAB DEFAULT_TAB_WIDTH No protected methods found No protected properties found N/A getTokenName() dumpAttributeToken() dumpTextToken() dumpExpressionToken() getTokenSymbol() dumpToken() setLastToken() getRegExpOption() proceedTokenEvent() handleToken() handleTokens() filterScanner()$modules
$state$lastToken
$previousToken N/A Constants INDENT_SPACE INDENT_SPACE INDENT_TAB INDENT_TAB DEFAULT_TAB_WIDTH DEFAULT_TAB_WIDTH Properties $modules

$this getModuleBaseClassName() getModuleBaseClassName()  hasState() hasState() : boolean Returns true if a lexing process is active and a state exists, false if not. Returns boolean getState() getState() : \Phug\Lexer\State Returns the state object of the current lexing process. Returns \Phug\Lexer\State __construct() __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 Throws \Exception getPreviousToken() getPreviousToken() : \Phug\Lexer\TokenInterface|null Returns \Phug\Lexer\TokenInterface|null updateOptions() updateOptions()  Synchronize the lexer to the new options values. getScanners() getScanners() : array<mixed,\Phug\Lexer\ScannerInterface> Returns the current scanners registered for the lexing process. Returns array<mixed,\Phug\Lexer\ScannerInterface> prependScanner() 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.

Parameters

 string $name \Phug\Lexer\ScannerInterface|string$scanner

$this addScanner() 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.

Parameters

 string $name \Phug\Lexer\ScannerInterface|string$scanner

 $token handleTokens() handleTokens(\Phug\iterable$tokens) : \Phug\iterable

Parameters

 \$scanner