Class FOFLessParser

Description

This class is taken verbatim from:

lessphp v0.3.8 http://leafo.net/lessphp

LESS css compiler, adapted from http://lesscss.org

Copyright 2012, Leaf Corcoran <leafot@gmail.com> 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

Located in /libraries/fof/less/parser/parser.php (line 26)


	
			
Variable Summary
 static mixed $commentMulti
 static mixed $commentMultiLeft
 static mixed $commentMultiRight
 static mixed $commentSingle
 static mixed $literalCache
 static mixed $nextBlockId
 static mixed $operatorString
 static mixed $precedence
 static mixed $supressDivisionProps
 static mixed $whitePattern
 mixed $inParens
Method Summary
 FOFLessParser __construct ([type] $lessc, [string $sourceName = null])
 void append ([type] $prop, [[type] $pos = null])
 boolean argumentDef ([type] &$args, [type] &$isVararg, [[type] $delim = ','])
 boolean argumentValues ([type] &$args, [[type] $delim = ','])
 boolean assign ([string $name = null])
 boolean color ([type] &$out)
 boolean end ()
 string expHelper (type $lhs, type $minP)
 boolean expression (string &$out)
 boolean expressionList ([type] &$exps)
 [type] fixTags ([type] $tags)
 boolean func ([type] &$func)
 boolean genericList ([type] &$out, [type] $parseItem, [string $delim = ""], [boolean $flatten = true])
 boolean guard ([type] &$guard)
 boolean guardGroup ([type] &$guardGroup)
 boolean guards ([type] &$guards)
 boolean import ([type] &$out)
 boolean interpolation ([type] &$out)
 boolean isDirective (string $dirname, [type] $directives)
 boolean keyword ([type] &$word)
 boolean literal ([type] $what, [[type] $eatWhitespace = null])
 boolean match ([type] $regex, [type] &$out, [[type] $eatWhitespace = null])
 boolean mediaExpression ([type] &$out)
 [type] mediaQuery ([type] &$out)
 boolean mediaQueryList ([type] &$out)
 boolean mixinTags ([type] &$tags)
 boolean openString ([type] $end, [type] &$out, [[type] $nestingOpen = null], [[type] $rejectStrs = null])
 boolean parenValue ([type] &$out)
 [type] parse (string $buffer)
 boolean parseChunk ()
 boolean peek ([type] $regex, [[type] &$out = null], [[type] $from = null])
 [type] pop ()
 boolean propertyValue ([type] &$value, [[type] $keyName = null])
 stdClass pushBlock ([[type] $selectors = null], [[type] $type = null])
 stdClass pushSpecialBlock ([type] $type)
 [type] removeComments ([type] $text)
 boolean seek ([[type] $where = null])
 boolean string ([type] &$out)
 boolean tag ([type] &$tag, [boolean $simple = false])
 boolean tagBracket ([type] &$value)
 boolean tagExpression ([type] &$value)
 boolean tags ([type] &$tags, [[type] $simple = false], [[type] $delim = ','])
 void throwError ([string $msg = "parse error"], [[type] $count = null])
 boolean to ([type] $what, [type] &$out, [boolean $until = false], [boolean $allowNewline = false])
 boolean unit ([type] &$unit)
 boolean value ([type] &$value)
 boolean variable ([type] &$name)
 boolean whitespace ()
Variables
static mixed $commentMulti (line 46)
  • access: protected
static mixed $commentMultiLeft = "/*" (line 50)
  • access: protected
static mixed $commentMultiRight = "*/" (line 52)
  • access: protected
static mixed $commentSingle = "//" (line 48)
  • access: protected
static mixed $literalCache = array() (line 76)
  • access: protected
static mixed $nextBlockId = 0 (line 29)
  • access: protected
static mixed $operatorString (line 55)
  • access: protected
static mixed $precedence = array(
'=<' => 0,
'>=' => 0,
'=' => 0,
'<' => 0,
'>' => 0,
'+' => 1,
'-' => 1,
'*' => 2,
'/' => 2,
'%' => 2,
)
(line 31)
  • access: protected
static mixed $supressDivisionProps = array('/border-radius$/i', '/^font$/i') (line 58)
  • access: protected
static mixed $whitePattern (line 44)
  • access: protected
mixed $blockDirectives = array("font-face", "keyframes", "page", "-moz-document") (line 60)
  • access: protected
mixed $inParens = false (line 73)

if we are in parens we can be more liberal with whitespace around operators because it must evaluate to a single value and thus is less ambiguous.

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

  • access: protected
mixed $lineDirectives = array("charset") (line 62)
  • access: protected
Methods
Constructor __construct (line 84)

Constructor

  • access: public
FOFLessParser __construct ([type] $lessc, [string $sourceName = null])
  • [type] $lessc: [description]
  • string $sourceName: [description]
append (line 2115)

Append a property to the current block

  • access: protected
void append ([type] $prop, [[type] $pos = null])
  • [type] $prop: [description]
  • [type] $pos: [description]
argumentDef (line 1226)

Consume an argument definition list surrounded by () each argument is a variable name with optional value or at the end a ... or a variable named followed by ...

  • access: protected
boolean argumentDef ([type] &$args, [type] &$isVararg, [[type] $delim = ','])
  • [type] &$args: [description]
  • [type] &$isVararg: [description]
  • [type] $delim: [description]
argumentValues (line 1170)

Consume a list of property values delimited by ; and wrapped in ()

  • access: protected
boolean argumentValues ([type] &$args, [[type] $delim = ','])
  • [type] &$args: [description]
  • [type] $delim: [description]
assign (line 1639)

Consume an assignment operator Can optionally take a name that will be set to the current property name

  • access: protected
boolean assign ([string $name = null])
  • string $name: [description]
color (line 1143)

a # color

  • access: protected
boolean color ([type] &$out)
  • [type] &$out: [description]
end (line 1673)

Consume an end of statement delimiter

  • access: protected
boolean end ()
expHelper (line 512)

Recursively parse infix equation with $lhs at precedence $minP

  • access: protected
string expHelper (type $lhs, type $minP)
  • type $lhs: [description]
  • type $minP: [description]
expression (line 475)

Attempt to consume an expression.

boolean expression (string &$out)
  • string &$out: [description]
expressionList (line 447)

a list of expressions

  • access: protected
boolean expressionList ([type] &$exps)
  • [type] &$exps: [description]
fixTags (line 426)

[fixTags description]

  • return: [description]
  • access: protected
[type] fixTags ([type] $tags)
  • [type] $tags: [description]
func (line 1536)

A css function

  • access: protected
boolean func ([type] &$func)
  • [type] &$func: [description]
genericList (line 1846)

[genericList description]

  • access: protected
boolean genericList ([type] &$out, [type] $parseItem, [string $delim = ""], [boolean $flatten = true])
  • [type] &$out: [description]
  • [type] $parseItem: [description]
  • string $delim: [description]
  • boolean $flatten: [description]
guard (line 1771)

[guard description]

  • access: protected
boolean guard ([type] &$guard)
  • [type] &$guard: [description]
guardGroup (line 1738)

A bunch of guards that are and'd together

  • todo: rename to guardGroup
  • access: protected
boolean guardGroup ([type] &$guardGroup)
  • [type] &$guardGroup: [description]
guards (line 1695)

[guards description]

  • access: protected
boolean guards ([type] &$guards)
  • [type] &$guards: [description]
import (line 753)

an import statement

  • access: protected
boolean import ([type] &$out)
  • [type] &$out: [description]
interpolation (line 1080)

[interpolation description]

  • access: protected
boolean interpolation ([type] &$out)
  • [type] &$out: [description]
isDirective (line 410)

[isDirective description]

  • access: protected
boolean isDirective (string $dirname, [type] $directives)
  • string $dirname: [description]
  • [type] $directives: [description]
keyword (line 1656)

Consume a keyword

  • access: protected
boolean keyword ([type] &$word)
  • [type] &$word: [description]
literal (line 1803)

[literal description]

  • access: protected
boolean literal ([type] $what, [[type] $eatWhitespace = null])
  • [type] $what: [description]
  • [type] $eatWhitespace: [description]
match (line 1931)

Try to match something on head of buffer

  • access: protected
boolean match ([type] $regex, [type] &$out, [[type] $eatWhitespace = null])
  • [type] $regex: [description]
  • [type] &$out: [description]
  • [type] $eatWhitespace: [description]
mediaExpression (line 864)

[mediaExpression description]

  • access: protected
boolean mediaExpression ([type] &$out)
  • [type] &$out: [description]
mediaQuery (line 802)

[mediaQuery description]

  • return: [description]
  • access: protected
[type] mediaQuery ([type] &$out)
  • [type] &$out: [description]
mediaQueryList (line 783)

[mediaQueryList description]

  • access: protected
boolean mediaQueryList ([type] &$out)
  • [type] &$out: [description]
mixinTags (line 1337)

List of tags of specifying mixin path Optionally separated by > (lazy, accepts extra >)

  • access: protected
boolean mixinTags ([type] &$tags)
  • [type] &$tags: [description]
openString (line 902)

An unbounded string stopped by $end

  • access: protected
boolean openString ([type] $end, [type] &$out, [[type] $nestingOpen = null], [[type] $rejectStrs = null])
  • [type] $end: [description]
  • [type] &$out: [description]
  • [type] $nestingOpen: [description]
  • [type] $rejectStrs: [description]
parenValue (line 623)

[parenValue description]

  • access: protected
boolean parenValue ([type] &$out)
  • [type] &$out: [description]
parse (line 116)

Parse text

  • return: [description]
  • access: public
[type] parse (string $buffer)
  • string $buffer: [description]
parseChunk (line 193)

Parse a single chunk off the head of the buffer and append it to the current parse environment.

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.

  • access: protected
boolean parseChunk ()
peek (line 1997)

Match something without consuming it

  • access: protected
boolean peek ([type] $regex, [[type] &$out = null], [[type] $from = null])
  • [type] $regex: [description]
  • [type] &$out: [description]
  • [type] $from: [description]
pop (line 2130)

Pop something off the stack

  • return: [description]
  • access: protected
[type] pop ()
propertyValue (line 574)

Consume a list of values for a property

  • access: public
boolean propertyValue ([type] &$value, [[type] $keyName = null])
  • [type] &$value: [description]
  • [type] $keyName: [description]
pushBlock (line 2075)

[pushBlock description]

  • access: protected
stdClass pushBlock ([[type] $selectors = null], [[type] $type = null])
  • [type] $selectors: [description]
  • [type] $type: [description]
pushSpecialBlock (line 2102)

Push a block that doesn't multiply tags

  • access: protected
stdClass pushSpecialBlock ([type] $type)
  • [type] $type: [description]
removeComments (line 2147)

Remove comments from $text

  • return: [description]
  • access: protected
[type] removeComments ([type] $text)
  • [type] $text: [description]
seek (line 2017)

Seek to a spot in the buffer or return where we are on no argument

  • access: protected
boolean seek ([[type] $where = null])
  • [type] $where: [description]
string (line 996)

[string description]

  • access: protected
boolean string ([type] &$out)
  • [type] &$out: [description]
tag (line 1425)

A single tag

  • access: protected
boolean tag ([type] &$tag, [boolean $simple = false])
  • [type] &$tag: [description]
  • boolean $simple: [description]
tagBracket (line 1363)

A bracketed value (contained within in a tag definition)

  • access: protected
boolean tagBracket ([type] &$value)
  • [type] &$value: [description]
tagExpression (line 1401)

[tagExpression description]

  • access: protected
boolean tagExpression ([type] &$value)
  • [type] &$value: [description]
tags (line 1307)

Consume a list of tags This accepts a hanging delimiter

  • access: protected
boolean tags ([type] &$tags, [[type] $simple = false], [[type] $delim = ','])
  • [type] &$tags: [description]
  • [type] $simple: [description]
  • [type] $delim: [description]
throwError (line 2041)

[throwError description]

  • access: public
void throwError ([string $msg = "parse error"], [[type] $count = null])
  • string $msg: [description]
  • [type] $count: [description]
to (line 1895)

Advance counter to next occurrence of $what $until - don't include $what in advance $allowNewline, if string, will be used as valid char set

  • access: protected
boolean to ([type] $what, [type] &$out, [boolean $until = false], [boolean $allowNewline = false])
  • [type] $what: [description]
  • [type] &$out: [description]
  • boolean $until: [description]
  • boolean $allowNewline: [description]
unit (line 1113)

[unit description]

  • access: protected
boolean unit ([type] &$unit)
  • [type] &$unit: [description]
value (line 658)

a single value

  • access: protected
boolean value ([type] &$value)
  • [type] &$value: [description]
variable (line 1607)

Consume a less variable

  • access: protected
boolean variable ([type] &$name)
  • [type] &$name: [description]
whitespace (line 1960)

Watch some whitespace

  • access: protected
boolean whitespace ()

Documentation generated on Tue, 19 Nov 2013 15:10:17 +0100 by phpDocumentor 1.4.3