PHP Class PhpCss\Parser

Afficher le fichier Open project: ThomasWeinert/PhpCss Class Usage Examples

Protected Properties

Свойство Type Description
$_tokens array(Scanner\Token) List of tokens from scanner

Méthodes publiques

Méthode Description
__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

Méthodes protégées

Méthode Description
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.

Private Methods

Méthode Description
handleMismatch ( array() $expectedTokens, integer $position ) : Exception Handle the case if none of the expected tokens could be found.

Method Details

__construct() public méthode

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

delegate() protected méthode

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
Résultat Ast

endOfTokens() protected méthode

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
Résultat boolean

ignore() protected méthode

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
Résultat boolean

lookahead() protected méthode

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
Résultat PhpCss\Scanner\Token | null

matchToken() protected méthode

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
Résultat boolean

parse() abstract public méthode

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
Résultat Ast

read() protected méthode

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
Résultat PhpCss\Scanner\Token

Property Details

$_tokens protected_oe property

List of tokens from scanner
protected array(Scanner\Token) $_tokens
Résultat array(Scanner\Token)