PHP Class FOF30\Less\Parser\Parser

lessphp v0.3.9 http://leafo.net/lessphp LESS css compiler, adapted from http://lesscss.org Copyright 2012, Leaf Corcoran Licensed under MIT or GPLv3, see LICENSE Responsible for taking a string of LESS code and converting it into a syntax tree
Since: 2.0
Exibir arquivo Open project: akeeba/fof Class Usage Examples

Protected Properties

Property Type Description
$blockDirectives
$commentMulti
$commentMultiLeft
$commentMultiRight
$commentSingle
$inParens Consider: property1: 10 -5; // is two numbers, 10 and -5 property2: (10 -5); // should evaluate to 5
$lineDirectives
$literalCache Caches preg escaped literals
$nextBlockId Used to uniquely identify blocks
$operatorString Regex string to match any of the operators
$precedence
$supressDivisionProps These properties will supress division unless it's inside parenthases
$whitePattern

Public Methods

Method Description
__construct ( [type] $lessc, string $sourceName = null ) Constructor
parse ( string $buffer ) : [type] Parse text
propertyValue ( &$value, [type] $keyName = null ) : boolean Consume a list of values for a property
throwError ( string $msg = "parse error", [type] $count = null ) : void [throwError description]

Protected Methods

Method Description
append ( [type] $prop, [type] $pos = null ) : void Append a property to the current block
argumentDef ( &$args, &$isVararg, [type] $delim = ',' ) : boolean Consume an argument definition list surrounded by () each argument is a variable name with optional value or at the end a .
argumentValues ( &$args, [type] $delim = ',' ) : boolean Consume a list of property values delimited by ; and wrapped in ()
assign ( string $name = null ) : boolean Consume an assignment operator Can optionally take a name that will be set to the current property name
color ( &$out ) : boolean a # color
end ( ) : boolean Consume an end of statement delimiter
expHelper ( type $lhs, type $minP ) : string Recursively parse infix equation with $lhs at precedence $minP
expression ( &$out ) : boolean Attempt to consume an expression.
expressionList ( &$exps ) : boolean a list of expressions
fixTags ( [type] $tags ) : [type] [fixTags description]
func ( &$func ) : boolean A css function
genericList ( &$out, [type] $parseItem, string $delim = "", boolean $flatten = true ) : boolean [genericList description]
guard ( &$guard ) : boolean [guard description]
guardGroup ( &$guardGroup ) : boolean A bunch of guards that are and'd together
guards ( &$guards ) : boolean [guards description]
import ( &$out ) : boolean an import statement
interpolation ( &$out ) : boolean [interpolation description]
isDirective ( string $dirname, [type] $directives ) : boolean [isDirective description]
keyword ( &$word ) : boolean Consume a keyword
literal ( [type] $what, [type] $eatWhitespace = null ) : boolean [literal description]
match ( [type] $regex, &$out, [type] $eatWhitespace = null ) : boolean Try to match something on head of buffer
mediaExpression ( &$out ) : boolean [mediaExpression description]
mediaQuery ( &$out ) : [type] [mediaQuery description]
mediaQueryList ( &$out ) : boolean [mediaQueryList description]
mixinTags ( &$tags ) : boolean List of tags of specifying mixin path Optionally separated by > (lazy, accepts extra >)
openString ( [type] $end, &$out, [type] $nestingOpen = null, [type] $rejectStrs = null ) : boolean An unbounded string stopped by $end
parenValue ( &$out ) : boolean [parenValue description]
parseChunk ( ) : boolean Parse a single chunk off the head of the buffer and append it to the current parse environment.
peek ( [type] $regex, &$out = null, [type] $from = null ) : boolean Match something without consuming it
pop ( ) : [type] Pop something off the stack
pushBlock ( [type] $selectors = null, [type] $type = null ) : stdClass [pushBlock description]
pushSpecialBlock ( [type] $type ) : stdClass Push a block that doesn't multiply tags
removeComments ( [type] $text ) : [type] Remove comments from $text
seek ( [type] $where = null ) : boolean Seek to a spot in the buffer or return where we are on no argument
string ( &$out ) : boolean [string description]
tag ( &$tag, boolean $simple = false ) : boolean A single tag
tagBracket ( &$value ) : boolean A bracketed value (contained within in a tag definition)
tagExpression ( &$value ) : boolean [tagExpression description]
tags ( &$tags, [type] $simple = false, [type] $delim = ',' ) : boolean Consume a list of tags This accepts a hanging delimiter
to ( [type] $what, &$out, boolean $until = false, boolean $allowNewline = false ) : boolean Advance counter to next occurrence of $what $until - don't include $what in advance $allowNewline, if string, will be used as valid char set
unit ( &$unit ) : boolean [unit description]
value ( &$value ) : boolean a single value
variable ( &$name ) : boolean Consume a less variable
whitespace ( ) : boolean Watch some whitespace

Method Details

__construct() public method

Constructor
public __construct ( [type] $lessc, string $sourceName = null )
$lessc [type]
$sourceName string [description]

append() protected method

Append a property to the current block
protected append ( [type] $prop, [type] $pos = null ) : void
$prop [type]
$pos [type]
return void

argumentDef() protected method

.. or a variable named followed by ...
protected argumentDef ( &$args, &$isVararg, [type] $delim = ',' ) : boolean
$delim [type]
return boolean

argumentValues() protected method

Consume a list of property values delimited by ; and wrapped in ()
protected argumentValues ( &$args, [type] $delim = ',' ) : boolean
$delim [type]
return boolean

assign() protected method

Consume an assignment operator Can optionally take a name that will be set to the current property name
protected assign ( string $name = null ) : boolean
$name string [description]
return boolean

color() protected method

a # color
protected color ( &$out ) : boolean
return boolean

end() protected method

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

expHelper() protected method

Recursively parse infix equation with $lhs at precedence $minP
protected expHelper ( type $lhs, type $minP ) : string
$lhs type [description]
$minP type [description]
return string

expression() protected method

Attempt to consume an expression.
protected expression ( &$out ) : boolean
return boolean

expressionList() protected method

a list of expressions
protected expressionList ( &$exps ) : boolean
return boolean

fixTags() protected method

[fixTags description]
protected fixTags ( [type] $tags ) : [type]
$tags [type]
return [type]

func() protected method

A css function
protected func ( &$func ) : boolean
return boolean

genericList() protected method

[genericList description]
protected genericList ( &$out, [type] $parseItem, string $delim = "", boolean $flatten = true ) : boolean
$parseItem [type]
$delim string [description]
$flatten boolean [description]
return boolean

guard() protected method

[guard description]
protected guard ( &$guard ) : boolean
return boolean

guardGroup() protected method

A bunch of guards that are and'd together
protected guardGroup ( &$guardGroup ) : boolean
return boolean

guards() protected method

[guards description]
protected guards ( &$guards ) : boolean
return boolean

import() protected method

an import statement
protected import ( &$out ) : boolean
return boolean

interpolation() protected method

[interpolation description]
protected interpolation ( &$out ) : boolean
return boolean

isDirective() protected method

[isDirective description]
protected isDirective ( string $dirname, [type] $directives ) : boolean
$dirname string [description]
$directives [type]
return boolean

keyword() protected method

Consume a keyword
protected keyword ( &$word ) : boolean
return boolean

literal() protected method

[literal description]
protected literal ( [type] $what, [type] $eatWhitespace = null ) : boolean
$what [type]
$eatWhitespace [type]
return boolean

match() protected method

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

mediaExpression() protected method

[mediaExpression description]
protected mediaExpression ( &$out ) : boolean
return boolean

mediaQuery() protected method

[mediaQuery description]
protected mediaQuery ( &$out ) : [type]
return [type]

mediaQueryList() protected method

[mediaQueryList description]
protected mediaQueryList ( &$out ) : boolean
return boolean

mixinTags() protected method

List of tags of specifying mixin path Optionally separated by > (lazy, accepts extra >)
protected mixinTags ( &$tags ) : boolean
return boolean

openString() protected method

An unbounded string stopped by $end
protected openString ( [type] $end, &$out, [type] $nestingOpen = null, [type] $rejectStrs = null ) : boolean
$end [type]
$nestingOpen [type]
$rejectStrs [type]
return boolean

parenValue() protected method

[parenValue description]
protected parenValue ( &$out ) : boolean
return boolean

parse() public method

Parse text
public parse ( string $buffer ) : [type]
$buffer string [description]
return [type]

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 lessc::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 lessc::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, lessc::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

peek() protected method

Match something without consuming it
protected peek ( [type] $regex, &$out = null, [type] $from = null ) : boolean
$regex [type]
$from [type]
return boolean

pop() protected method

Pop something off the stack
protected pop ( ) : [type]
return [type]

propertyValue() public method

Consume a list of values for a property
public propertyValue ( &$value, [type] $keyName = null ) : boolean
$keyName [type]
return boolean

pushBlock() protected method

[pushBlock description]
protected pushBlock ( [type] $selectors = null, [type] $type = null ) : stdClass
$selectors [type]
$type [type]
return stdClass

pushSpecialBlock() protected method

Push a block that doesn't multiply tags
protected pushSpecialBlock ( [type] $type ) : stdClass
$type [type]
return stdClass

removeComments() protected method

Remove comments from $text
protected removeComments ( [type] $text ) : [type]
$text [type]
return [type]

seek() protected method

Seek to a spot in the buffer or return where we are on no argument
protected seek ( [type] $where = null ) : boolean
$where [type]
return boolean

string() protected method

[string description]
protected string ( &$out ) : boolean
return boolean

tag() protected method

A single tag
protected tag ( &$tag, boolean $simple = false ) : boolean
$simple boolean [description]
return boolean

tagBracket() protected method

A bracketed value (contained within in a tag definition)
protected tagBracket ( &$value ) : boolean
return boolean

tagExpression() protected method

[tagExpression description]
protected tagExpression ( &$value ) : boolean
return boolean

tags() protected method

Consume a list of tags This accepts a hanging delimiter
protected tags ( &$tags, [type] $simple = false, [type] $delim = ',' ) : boolean
$simple [type]
$delim [type]
return boolean

throwError() public method

[throwError description]
public throwError ( string $msg = "parse error", [type] $count = null ) : void
$msg string [description]
$count [type]
return void

to() protected method

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 ( [type] $what, &$out, boolean $until = false, boolean $allowNewline = false ) : boolean
$what [type]
$until boolean [description]
$allowNewline boolean [description]
return boolean

unit() protected method

[unit description]
protected unit ( &$unit ) : boolean
return boolean

value() protected method

a single value
protected value ( &$value ) : boolean
return boolean

variable() protected method

Consume a less variable
protected variable ( &$name ) : boolean
return boolean

whitespace() protected method

Watch some whitespace
protected whitespace ( ) : boolean
return boolean

Property Details

$blockDirectives protected_oe property

protected $blockDirectives

$commentMulti protected_oe static_oe property

protected static $commentMulti

$commentMultiLeft protected_oe static_oe property

protected static $commentMultiLeft

$commentMultiRight protected_oe static_oe property

protected static $commentMultiRight

$commentSingle protected_oe static_oe property

protected static $commentSingle

$inParens protected_oe property

Consider: property1: 10 -5; // is two numbers, 10 and -5 property2: (10 -5); // should evaluate to 5
protected $inParens

$lineDirectives protected_oe property

protected $lineDirectives

$literalCache protected_oe static_oe property

Caches preg escaped literals
protected static $literalCache

$nextBlockId protected_oe static_oe property

Used to uniquely identify blocks
protected static $nextBlockId

$operatorString protected_oe static_oe property

Regex string to match any of the operators
protected static $operatorString

$precedence protected_oe static_oe property

protected static $precedence

$supressDivisionProps protected_oe static_oe property

These properties will supress division unless it's inside parenthases
protected static $supressDivisionProps

$whitePattern protected_oe static_oe property

protected static $whitePattern