PHP Class PhpCss\Parser

Datei anzeigen Open project: ThomasWeinert/PhpCss Class Usage Examples

Protected Properties

Property Type Description
$_tokens array(Scanner\Token) List of tokens from scanner

Public Methods

Method 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

Protected Methods

Method 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

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

Method Details

__construct() public method

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

delegate() protected method

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
return Ast

endOfTokens() protected method

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
return boolean

ignore() protected method

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
return boolean

lookahead() protected method

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
return PhpCss\Scanner\Token | null

matchToken() protected method

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
return boolean

parse() abstract public method

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
return Ast

read() protected method

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
return PhpCss\Scanner\Token

Property Details

$_tokens protected_oe property

List of tokens from scanner
protected array(Scanner\Token) $_tokens
return array(Scanner\Token)