PHP Class Leafo\ScssPhp\Parser

Author: Leaf Corcoran ([email protected])
Mostra file Open project: leafo/scssphp Class Usage Examples

Protected Properties

Property Type Description
$commentPattern
$operatorPattern
$precedence array
$whitePattern

Public Methods

Method 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

Protected Methods

Method 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

Method 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 method

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

append() protected method

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

appendComment() protected method

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

argValue() protected method

Parse argument value
protected argValue ( array &$out ) : boolean
$out array
return boolean

argValues() protected method

Parse argument values
protected argValues ( array &$out ) : boolean
$out array
return boolean

argumentDef() protected method

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

argumentList() protected method

Parse function call argument list
protected argumentList ( array &$out ) : boolean
$out array
return boolean

color() protected method

Parse color
protected color ( array &$out ) : boolean
$out array
return boolean

end() protected method

Consume an end of statement delimiter
protected end ( ) : boolean
return boolean

expHelper() protected method

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

expression() protected method

Parse expression
protected expression ( array &$out ) : boolean
$out array
return boolean

flattenList() protected method

Turn list of length 1 into value type
protected flattenList ( array $value ) : array
$value array
return array

func() protected method

Parse function call
protected func ( &$func ) : boolean
return boolean

genericList() protected method

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

getSourceName() public method

Get source file name
public getSourceName ( ) : string
return string

interpolation() protected method

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

keyword() protected method

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

last() protected method

Returns last child was appended
protected last ( ) : array | null
return array | null

literal() protected method

Match literal string
protected literal ( string $what, boolean $eatWhitespace = null ) : boolean
$what string
$eatWhitespace boolean
return boolean

map() protected method

Parse map
protected map ( array &$out ) : boolean
$out array
return boolean

match() protected method

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

matchString() protected method

{@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
return boolean True if match; false otherwise

mediaExpression() protected method

Parse media expression
protected mediaExpression ( array &$out ) : boolean
$out array
return boolean

mediaQuery() protected method

Parse media query
protected mediaQuery ( array &$out ) : boolean
$out array
return boolean

mediaQueryList() protected method

Parse media query list
protected mediaQueryList ( array &$out ) : boolean
$out array
return boolean

mixedKeyword() protected method

Parse keyword or interpolation
protected mixedKeyword ( array &$out ) : boolean
$out array
return boolean

openString() protected method

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

parenValue() protected method

Parse parenthesized value
protected parenValue ( array &$out ) : boolean
$out array
return boolean

parse() public method

Parser buffer
public parse ( string $buffer ) : Leafo\ScssPhp\Block
$buffer string
return Leafo\ScssPhp\Block

parseChunk() protected method

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

parseSelector() public method

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

parseValue() public method

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

peek() protected method

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

placeholder() protected method

Parse a placeholder
protected placeholder ( string &$placeholder ) : boolean
$placeholder string
return boolean

popBlock() protected method

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

progid() protected method

Parse "progid:"
protected progid ( array &$out ) : boolean
$out array
return boolean

propertyName() protected method

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

pushBlock() protected method

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

pushSpecialBlock() protected method

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

seek() protected method

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

selector() protected method

Parse whitespace separated selector list
protected selector ( array &$out ) : boolean
$out array
return boolean

selectorSingle() protected method

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

selectors() protected method

Parse comma separated selector list
protected selectors ( array &$out ) : boolean
$out array
return boolean

show() protected method

Deprecation:
protected show ( )

spaceList() protected method

Parse space separated value list
protected spaceList ( array &$out ) : boolean
$out array
return boolean

string() protected method

Parse string
protected string ( array &$out ) : boolean
$out array
return boolean

stripAssignmentFlags() protected method

Strip assignment flag from the list
protected stripAssignmentFlags ( array &$value ) : array
$value array
return array

stripOptionalFlag() protected method

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

throwParseError() public method

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

to() protected method

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 method

Parse number with unit
protected unit ( &$unit ) : boolean
return boolean

url() protected method

Parse a url
protected url ( array &$out ) : boolean
$out array
return boolean

value() protected method

Parse value
protected value ( array &$out ) : boolean
$out array
return boolean

valueList() protected method

Parse comma separated value list
protected valueList ( string &$out ) : boolean
$out string
return boolean

variable() protected method

Parse a variable
protected variable ( array &$out ) : boolean
$out array
return boolean

whitespace() protected method

Match some whitespace
protected whitespace ( ) : boolean
return 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
return array

$whitePattern protected_oe static_oe property

protected static $whitePattern