PHP Class Leafo\ScssPhp\Parser

Author: Leaf Corcoran ([email protected])
Afficher le fichier Open project: leafo/scssphp Class Usage Examples

Protected Properties

Свойство Type Description
$commentPattern
$operatorPattern
$precedence array
$whitePattern

Méthodes publiques

Méthode Description
__construct ( string $sourceName, integer $sourceIndex, string $encoding = 'utf-8' ) Constructor
getSourceName ( ) : string Get source file name
parse ( string $buffer ) : Leafo\ScssPhp\Block Parser buffer
parseSelector ( string $buffer, string &$out ) : boolean Parse a selector or selector list
parseValue ( string $buffer, string &$out ) : boolean Parse a value or value list
throwParseError ( string $msg = 'parse error' ) Throw parser error

Méthodes protégées

Méthode Description
append ( array $statement, integer $pos = null ) Append statement to current block
appendComment ( array $comment ) Append comment to current block
argValue ( array &$out ) : boolean Parse argument value
argValues ( array &$out ) : boolean Parse argument values
argumentDef ( array &$out ) : boolean Parse mixin/function definition argument list
argumentList ( array &$out ) : boolean Parse function call argument list
color ( array &$out ) : boolean Parse color
end ( ) : boolean Consume an end of statement delimiter
expHelper ( array $lhs, integer $minP ) : array Parse left-hand side of subexpression
expression ( array &$out ) : boolean Parse expression
flattenList ( array $value ) : array Turn list of length 1 into value type
func ( &$func ) : boolean Parse function call
genericList ( array &$out, callable $parseItem, string $delim = '', boolean $flatten = true ) : boolean Parse generic list
interpolation ( array &$out, boolean $lookWhite = true ) : boolean Parser interpolation
keyword ( string &$word, boolean $eatWhitespace = null ) : boolean Parse a keyword
last ( ) : array | null Returns last child was appended
literal ( string $what, boolean $eatWhitespace = null ) : boolean Match literal string
map ( array &$out ) : boolean Parse map
match ( string $regex, array &$out, boolean $eatWhitespace = null ) : boolean Try to match something on head of buffer
matchString ( array &$m, string $delim ) : boolean Match string looking for either ending delim, escape, or string interpolation
mediaExpression ( array &$out ) : boolean Parse media expression
mediaQuery ( array &$out ) : boolean Parse media query
mediaQueryList ( array &$out ) : boolean Parse media query list
mixedKeyword ( array &$out ) : boolean Parse keyword or interpolation
openString ( string $end, array &$out, string $nestingOpen = null ) : boolean Parse an unbounded string stopped by $end
parenValue ( array &$out ) : boolean Parse parenthesized value
parseChunk ( ) : boolean Parse a single chunk off the head of the buffer and append it to the current parse environment.
peek ( string $regex, array &$out, integer $from = null ) : integer Peek input stream
placeholder ( string &$placeholder ) : boolean Parse a placeholder
popBlock ( ) : Leafo\ScssPhp\Block Pop scope and return last block
progid ( array &$out ) : boolean Parse "progid:"
propertyName ( array &$out ) : boolean Parse property name (as an array of parts or a string)
pushBlock ( array $selectors, integer $pos ) : Leafo\ScssPhp\Block Push block onto parse tree
pushSpecialBlock ( string $type, integer $pos ) : Leafo\ScssPhp\Block Push special (named) block onto parse tree
seek ( integer $where = null ) : integer Seek to position in input stream (or return current position in input stream)
selector ( array &$out ) : boolean Parse whitespace separated selector list
selectorSingle ( array &$out ) : boolean Parse the parts that make up a selector
selectors ( array &$out ) : boolean Parse comma separated selector list
show ( )
spaceList ( array &$out ) : boolean Parse space separated value list
string ( array &$out ) : boolean Parse string
stripAssignmentFlags ( array &$value ) : array Strip assignment flag from the list
stripOptionalFlag ( array &$selectors ) : string Strip optional flag from selector list
to ( $what, &$out, $until = false, $allowNewline = false )
unit ( &$unit ) : boolean Parse number with unit
url ( array &$out ) : boolean Parse a url
value ( array &$out ) : boolean Parse value
valueList ( string &$out ) : boolean Parse comma separated value list
variable ( array &$out ) : boolean Parse a variable
whitespace ( ) : boolean Match some whitespace

Private Methods

Méthode Description
extractLineNumbers ( string $buffer ) Extract line numbers from buffer
getSourcePosition ( integer $pos ) : integer Get source line number and column (given character position in the buffer)
pregQuote ( string $what ) : string Quote regular expression
restoreEncoding ( ) Restore internal encoding
saveEncoding ( ) Save internal encoding

Method Details

__construct() public méthode

Constructor
public __construct ( string $sourceName, integer $sourceIndex, string $encoding = 'utf-8' )
$sourceName string
$sourceIndex integer
$encoding string

append() protected méthode

Append statement to current block
protected append ( array $statement, integer $pos = null )
$statement array
$pos integer

appendComment() protected méthode

Append comment to current block
protected appendComment ( array $comment )
$comment array

argValue() protected méthode

Parse argument value
protected argValue ( array &$out ) : boolean
$out array
Résultat boolean

argValues() protected méthode

Parse argument values
protected argValues ( array &$out ) : boolean
$out array
Résultat boolean

argumentDef() protected méthode

Parse mixin/function definition argument list
protected argumentDef ( array &$out ) : boolean
$out array
Résultat boolean

argumentList() protected méthode

Parse function call argument list
protected argumentList ( array &$out ) : boolean
$out array
Résultat boolean

color() protected méthode

Parse color
protected color ( array &$out ) : boolean
$out array
Résultat boolean

end() protected méthode

Consume an end of statement delimiter
protected end ( ) : boolean
Résultat boolean

expHelper() protected méthode

Parse left-hand side of subexpression
protected expHelper ( array $lhs, integer $minP ) : array
$lhs array
$minP integer
Résultat array

expression() protected méthode

Parse expression
protected expression ( array &$out ) : boolean
$out array
Résultat boolean

flattenList() protected méthode

Turn list of length 1 into value type
protected flattenList ( array $value ) : array
$value array
Résultat array

func() protected méthode

Parse function call
protected func ( &$func ) : boolean
Résultat boolean

genericList() protected méthode

Parse generic list
protected genericList ( array &$out, callable $parseItem, string $delim = '', boolean $flatten = true ) : boolean
$out array
$parseItem callable
$delim string
$flatten boolean
Résultat boolean

getSourceName() public méthode

Get source file name
public getSourceName ( ) : string
Résultat string

interpolation() protected méthode

Parser interpolation
protected interpolation ( array &$out, boolean $lookWhite = true ) : boolean
$out array
$lookWhite boolean save information about whitespace before and after
Résultat boolean

keyword() protected méthode

Parse a keyword
protected keyword ( string &$word, boolean $eatWhitespace = null ) : boolean
$word string
$eatWhitespace boolean
Résultat boolean

last() protected méthode

Returns last child was appended
protected last ( ) : array | null
Résultat array | null

literal() protected méthode

Match literal string
protected literal ( string $what, boolean $eatWhitespace = null ) : boolean
$what string
$eatWhitespace boolean
Résultat boolean

map() protected méthode

Parse map
protected map ( array &$out ) : boolean
$out array
Résultat boolean

match() protected méthode

Try to match something on head of buffer
protected match ( string $regex, array &$out, boolean $eatWhitespace = null ) : boolean
$regex string
$out array
$eatWhitespace boolean
Résultat boolean

matchString() protected méthode

{@internal This is a workaround for preg_match's 250K string match limit.}}
protected matchString ( array &$m, string $delim ) : boolean
$m array Matches (passed by reference)
$delim string Delimeter
Résultat boolean True if match; false otherwise

mediaExpression() protected méthode

Parse media expression
protected mediaExpression ( array &$out ) : boolean
$out array
Résultat boolean

mediaQuery() protected méthode

Parse media query
protected mediaQuery ( array &$out ) : boolean
$out array
Résultat boolean

mediaQueryList() protected méthode

Parse media query list
protected mediaQueryList ( array &$out ) : boolean
$out array
Résultat boolean

mixedKeyword() protected méthode

Parse keyword or interpolation
protected mixedKeyword ( array &$out ) : boolean
$out array
Résultat boolean

openString() protected méthode

Parse an unbounded string stopped by $end
protected openString ( string $end, array &$out, string $nestingOpen = null ) : boolean
$end string
$out array
$nestingOpen string
Résultat boolean

parenValue() protected méthode

Parse parenthesized value
protected parenValue ( array &$out ) : boolean
$out array
Résultat boolean

parse() public méthode

Parser buffer
public parse ( string $buffer ) : Leafo\ScssPhp\Block
$buffer string
Résultat Leafo\ScssPhp\Block

parseChunk() protected méthode

Returns false when the buffer is empty, or when there is an error. This function is called repeatedly until the entire document is parsed. This parser is most similar to a recursive descent parser. Single functions represent discrete grammatical rules for the language, and they are able to capture the text that represents those rules. Consider the function Compiler::keyword(). (All parse functions are structured the same.) The function takes a single reference argument. When calling the function it will attempt to match a keyword on the head of the buffer. If it is successful, it will place the keyword in the referenced argument, advance the position in the buffer, and return true. If it fails then it won't advance the buffer and it will return false. All of these parse functions are powered by Compiler::match(), which behaves the same way, but takes a literal regular expression. Sometimes it is more convenient to use match instead of creating a new function. Because of the format of the functions, to parse an entire string of grammatical rules, you can chain them together using &&. But, if some of the rules in the chain succeed before one fails, then the buffer position will be left at an invalid state. In order to avoid this, Compiler::seek() is used to remember and set buffer positions. Before parsing a chain, use $s = $this->seek() to remember the current position into $s. Then if a chain fails, use $this->seek($s) to go back where we started.
protected parseChunk ( ) : boolean
Résultat boolean

parseSelector() public méthode

Parse a selector or selector list
public parseSelector ( string $buffer, string &$out ) : boolean
$buffer string
$out string
Résultat boolean

parseValue() public méthode

Parse a value or value list
public parseValue ( string $buffer, string &$out ) : boolean
$buffer string
$out string
Résultat boolean

peek() protected méthode

Peek input stream
protected peek ( string $regex, array &$out, integer $from = null ) : integer
$regex string
$out array
$from integer
Résultat integer

placeholder() protected méthode

Parse a placeholder
protected placeholder ( string &$placeholder ) : boolean
$placeholder string
Résultat boolean

popBlock() protected méthode

Pop scope and return last block
protected popBlock ( ) : Leafo\ScssPhp\Block
Résultat Leafo\ScssPhp\Block

progid() protected méthode

Parse "progid:"
protected progid ( array &$out ) : boolean
$out array
Résultat boolean

propertyName() protected méthode

Parse property name (as an array of parts or a string)
protected propertyName ( array &$out ) : boolean
$out array
Résultat boolean

pushBlock() protected méthode

Push block onto parse tree
protected pushBlock ( array $selectors, integer $pos ) : Leafo\ScssPhp\Block
$selectors array
$pos integer
Résultat Leafo\ScssPhp\Block

pushSpecialBlock() protected méthode

Push special (named) block onto parse tree
protected pushSpecialBlock ( string $type, integer $pos ) : Leafo\ScssPhp\Block
$type string
$pos integer
Résultat Leafo\ScssPhp\Block

seek() protected méthode

Seek to position in input stream (or return current position in input stream)
protected seek ( integer $where = null ) : integer
$where integer
Résultat integer

selector() protected méthode

Parse whitespace separated selector list
protected selector ( array &$out ) : boolean
$out array
Résultat boolean

selectorSingle() protected méthode

{@internal div[yes=no]#something.hello.world:nth-child(-2n+1)%placeholder}}
protected selectorSingle ( array &$out ) : boolean
$out array
Résultat boolean

selectors() protected méthode

Parse comma separated selector list
protected selectors ( array &$out ) : boolean
$out array
Résultat boolean

show() protected méthode

Deprecation:
protected show ( )

spaceList() protected méthode

Parse space separated value list
protected spaceList ( array &$out ) : boolean
$out array
Résultat boolean

string() protected méthode

Parse string
protected string ( array &$out ) : boolean
$out array
Résultat boolean

stripAssignmentFlags() protected méthode

Strip assignment flag from the list
protected stripAssignmentFlags ( array &$value ) : array
$value array
Résultat array

stripOptionalFlag() protected méthode

Strip optional flag from selector list
protected stripOptionalFlag ( array &$selectors ) : string
$selectors array
Résultat string

throwParseError() public méthode

Throw parser error
public throwParseError ( string $msg = 'parse error' )
$msg string

to() protected méthode

Deprecation: {@internal advance counter to next occurrence of $what $until - don't include $what in advance $allowNewline, if string, will be used as valid char set}}
protected to ( $what, &$out, $until = false, $allowNewline = false )

unit() protected méthode

Parse number with unit
protected unit ( &$unit ) : boolean
Résultat boolean

url() protected méthode

Parse a url
protected url ( array &$out ) : boolean
$out array
Résultat boolean

value() protected méthode

Parse value
protected value ( array &$out ) : boolean
$out array
Résultat boolean

valueList() protected méthode

Parse comma separated value list
protected valueList ( string &$out ) : boolean
$out string
Résultat boolean

variable() protected méthode

Parse a variable
protected variable ( array &$out ) : boolean
$out array
Résultat boolean

whitespace() protected méthode

Match some whitespace
protected whitespace ( ) : boolean
Résultat boolean

Property Details

$commentPattern protected_oe static_oe property

protected static $commentPattern

$operatorPattern protected_oe static_oe property

protected static $operatorPattern

$precedence protected_oe static_oe property

protected static array $precedence
Résultat array

$whitePattern protected_oe static_oe property

protected static $whitePattern