PHP Класс PhpCss\Parser

Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$_tokens array(Scanner\Token) List of tokens from scanner

Открытые методы

Метод Описание
__construct ( array &$tokens ) Construct a parser object taking the token list to operate on as argument
parse ( ) : Ast Execute the parsing process on the provided token stream

Защищенные методы

Метод Описание
delegate ( string $parserClass ) : Ast Delegate the parsing process to a subparser
endOfTokens ( integer $position ) : boolean Validate if the of the token stream is reached. The position parameter may be provided to look forward.
ignore ( array | integer | string $expectedTokens ) : boolean Try to read any of the $expectedTokens from the token stream and remove them from it.
lookahead ( array | integer | string $expectedTokens, integer $position, boolean $allowEndOfTokens = FALSE ) : Token | null Try to match any of the $expectedTokens against the given token stream position and return the matching one.
matchToken ( integer $position, integer $type ) : boolean Match a token on the token stream against a token type.
read ( array | integer | string $expectedTokens ) : Token Try to read any of the $expectedTokens from the token list and return the matching one.

Приватные методы

Метод Описание
handleMismatch ( array() $expectedTokens, integer $position ) : Exception Handle the case if none of the expected tokens could be found.

Описание методов

__construct() публичный Метод

Construct a parser object taking the token list to operate on as argument
public __construct ( array &$tokens )
$tokens array

delegate() защищенный Метод

The result of the subparser is returned Only the name of the subparser is expected here, the method takes care of providing the current token stream as well as instantiating the subparser.
protected delegate ( string $parserClass ) : Ast
$parserClass string
Результат Ast

endOfTokens() защищенный Метод

Validate if the of the token stream is reached. The position parameter may be provided to look forward.
protected endOfTokens ( integer $position ) : boolean
$position integer
Результат boolean

ignore() защищенный Метод

This method tries to match the current token list against all of the provided tokens. Matching tokens are removed from the list until a non matching token is found or the token list ends. The $expectedTokens parameter may be an array of tokens or a scalar value, which is handled the same way an array with only one entry would be. The special Token Scanner\Token::ANY is not valid here. The method return TRUE if tokens were removed, otherwise FALSE.
protected ignore ( array | integer | string $expectedTokens ) : boolean
$expectedTokens array | integer | string
Результат boolean

lookahead() защищенный Метод

This method tries to match the current token stream at the provided lookahead position against all of the provided tokens. If a match is found it simply returned. The token stream remains unchanged. If no match can be found a PhpCssParserException will thrown indicating what has been expected and what was found. The $expectedTokens parameter may be an array of tokens or a scalar value, which is handled the same way an array with only one entry would be. The special Token Scanner\Token::ANY may be used to indicate everything is valid and may be matched. However if it is used no other token may be specified, which does not make any sense, anyway. The position parameter may be provided to enforce a match on an arbitrary token stream position. Therefore unlimited lookahead is provided.
protected lookahead ( array | integer | string $expectedTokens, integer $position, boolean $allowEndOfTokens = FALSE ) : Token | null
$expectedTokens array | integer | string
$position integer
$allowEndOfTokens boolean
Результат PhpCss\Scanner\Token | null

matchToken() защищенный Метод

Returns true if the token at the given position exists and the provided token type matches type of the token at this position, false otherwise.
protected matchToken ( integer $position, integer $type ) : boolean
$position integer
$type integer
Результат boolean

parse() абстрактный публичный Метод

This method is supposed to handle all the steps needed to parse the current subsegment of the token stream. It is supposed to return a valid PhpCssAst. If the parsing process can't be completed because of invalid input a PhpCssParserException needs to be thrown. The methods protected methods read and lookahead should be used to operate on the token stream. They will throw PhpCssParserExceptions automatically in case they do not succeed.
abstract public parse ( ) : Ast
Результат Ast

read() защищенный Метод

This method tries to match the current token list against all of the provided tokens. If a match is found it is removed from the token list and returned. If no match can be found a PhpCssParserException will thrown indicating what has been expected and what was found. The $expectedTokens parameter may be an array of tokens or a scalar value, which is handled the same way an array with only one entry would be. The special Token Scanner\Token::ANY may be used to indicate everything is valid and may be matched. However if it is used no other token may be specified, which does not make any sense, anyway.
protected read ( array | integer | string $expectedTokens ) : Token
$expectedTokens array | integer | string
Результат PhpCss\Scanner\Token

Описание свойств

$_tokens защищенное свойство

List of tokens from scanner
protected array(Scanner\Token) $_tokens
Результат array(Scanner\Token)