PHP Class lessc_parser, Beans

Exibir arquivo Open project: Getbeans/Beans 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
$operatorString regex string to match any of the operators
$precedence used to uniquely identify blocks
$supressDivisionProps these properties will supress division unless it's inside parenthases
$whitePattern

Public Methods

Method Description
__construct ( $lessc, $sourceName = null )
parse ( $buffer )
propertyValue ( &$value, $keyName = null ) consume a list of values for a property
throwError ( $msg = "parse error", $count = null ) * misc functions

Protected Methods

Method Description
append ( $prop, $pos = null ) append a property to the current block
argumentDef ( &$args, &$isVararg ) delimiter.
assign ( $name = null ) Consume an assignment operator Can optionally take a name that will be set to the current property name
color ( &$out ) a # color
end ( ) consume an end of statement delimiter
expHelper ( $lhs, $minP ) recursively parse infix equation with $lhs at precedence $minP
expression ( &$out ) Attempt to consume an expression.
expressionList ( &$exps ) a list of expressions
fixTags ( $tags )
func ( &$func ) a css function
genericList ( &$out, $parseItem, $delim = "", $flatten = true )
guard ( &$guard )
guardGroup ( &$guardGroup ) TODO rename to guardGroup
guards ( &$guards )
import ( &$out ) an import statement
interpolation ( &$out )
isDirective ( $dirname, $directives )
keyword ( &$word ) consume a keyword
literal ( $what, $eatWhitespace = null ) * raw parsing functions
match ( $regex, &$out, $eatWhitespace = null ) try to match something on head of buffer
mediaExpression ( &$out )
mediaQuery ( &$out )
mediaQueryList ( &$out )
mixinTags ( &$tags ) optionally separated by > (lazy, accepts extra >)
openString ( $end, &$out, $nestingOpen = null, $rejectStrs = null ) an unbounded string stopped by $end
parenValue ( &$out )
parseChunk ( ) Parse a single chunk off the head of the buffer and append it to the current parse environment.
peek ( $regex, &$out = null, $from = null ) match something without consuming it
pop ( ) pop something off the stack
pushBlock ( $selectors = null, $type = null )
pushSpecialBlock ( $type ) push a block that doesn't multiply tags
removeComments ( $text ) todo: make it work for all functions, not just url
seek ( $where = null ) seek to a spot in the buffer or return where we are on no argument
string ( &$out )
tag ( &$tag, $simple = false ) a space separated list of selectors
tagBracket ( &$parts, &$hasExpression ) a bracketed value (contained within in a tag definition)
tags ( &$tags, $simple = false, $delim = ',' ) this accepts a hanging delimiter
to ( $what, &$out, $until = false, $allowNewline = false ) $allowNewline, if string, will be used as valid char set
unit ( &$unit )
value ( &$value ) a single value
variable ( &$name ) consume a less variable
whitespace ( ) match some whitespace

Method Details

__construct() public method

public __construct ( $lessc, $sourceName = null )

append() protected method

append a property to the current block
protected append ( $prop, $pos = null )

argumentDef() protected method

delimiter.
protected argumentDef ( &$args, &$isVararg )

assign() protected method

Consume an assignment operator Can optionally take a name that will be set to the current property name
protected assign ( $name = null )

color() protected method

a # color
protected color ( &$out )

end() protected method

consume an end of statement delimiter
protected end ( )

expHelper() protected method

recursively parse infix equation with $lhs at precedence $minP
protected expHelper ( $lhs, $minP )

expression() protected method

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

expressionList() protected method

a list of expressions
protected expressionList ( &$exps )

fixTags() protected method

protected fixTags ( $tags )

func() protected method

a css function
protected func ( &$func )

genericList() protected method

protected genericList ( &$out, $parseItem, $delim = "", $flatten = true )

guard() protected method

protected guard ( &$guard )

guardGroup() protected method

TODO rename to guardGroup
protected guardGroup ( &$guardGroup )

guards() protected method

protected guards ( &$guards )

import() protected method

an import statement
protected import ( &$out )

interpolation() protected method

protected interpolation ( &$out )

isDirective() protected method

protected isDirective ( $dirname, $directives )

keyword() protected method

consume a keyword
protected keyword ( &$word )

literal() protected method

* raw parsing functions
protected literal ( $what, $eatWhitespace = null )

match() protected method

try to match something on head of buffer
protected match ( $regex, &$out, $eatWhitespace = null )

mediaExpression() protected method

protected mediaExpression ( &$out )

mediaQuery() protected method

protected mediaQuery ( &$out )

mediaQueryList() protected method

protected mediaQueryList ( &$out )

mixinTags() protected method

optionally separated by > (lazy, accepts extra >)
protected mixinTags ( &$tags )

openString() protected method

an unbounded string stopped by $end
protected openString ( $end, &$out, $nestingOpen = null, $rejectStrs = null )

parenValue() protected method

protected parenValue ( &$out )

parse() public method

public parse ( $buffer )

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 ( )

peek() protected method

match something without consuming it
protected peek ( $regex, &$out = null, $from = null )

pop() protected method

pop something off the stack
protected pop ( )

propertyValue() public method

consume a list of values for a property
public propertyValue ( &$value, $keyName = null )

pushBlock() protected method

protected pushBlock ( $selectors = null, $type = null )

pushSpecialBlock() protected method

push a block that doesn't multiply tags
protected pushSpecialBlock ( $type )

removeComments() protected method

todo: make it work for all functions, not just url
protected removeComments ( $text )

seek() protected method

seek to a spot in the buffer or return where we are on no argument
protected seek ( $where = null )

string() protected method

protected string ( &$out )

tag() protected method

a space separated list of selectors
protected tag ( &$tag, $simple = false )

tagBracket() protected method

a bracketed value (contained within in a tag definition)
protected tagBracket ( &$parts, &$hasExpression )

tags() protected method

this accepts a hanging delimiter
protected tags ( &$tags, $simple = false, $delim = ',' )

throwError() public method

* misc functions
public throwError ( $msg = "parse error", $count = null )

to() protected method

$allowNewline, if string, will be used as valid char set
protected to ( $what, &$out, $until = false, $allowNewline = false )

unit() protected method

protected unit ( &$unit )

value() protected method

a single value
protected value ( &$value )

variable() protected method

consume a less variable
protected variable ( &$name )

whitespace() protected method

match some whitespace
protected whitespace ( )

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

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

used to uniquely identify blocks
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