[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/vendor/marcusschwarz/lesserphp/ -> lessc.inc.php (summary)

lessphp v0.6.0 http://leafo.net/lessphp LESS CSS compiler, adapted from http://lesscss.org

File Size: 4021 lines (103 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 5 classes

lessc:: (130 methods):
  findImport()
  fileExists()
  compressList()
  preg_quote()
  tryImport()
  compileImportedProps()
  compileBlock()
  compileCSSBlock()
  compileMedia()
  mediaParent()
  compileNestedBlock()
  compileRoot()
  compileProps()
  deduplicate()
  sortProps()
  compileMediaQuery()
  multiplyMedia()
  expandParentSelectors()
  findClosestSelectors()
  multiplySelectors()
  compileSelectors()
  eq()
  patternMatch()
  patternMatchAll()
  findBlocks()
  zipSetArgs()
  compileProp()
  compileValue()
  lib_pow()
  lib_pi()
  lib_mod()
  lib_convert()
  lib_abs()
  lib_min()
  lib_max()
  lib_tan()
  lib_sin()
  lib_cos()
  lib_atan()
  lib_asin()
  lib_acos()
  lib_sqrt()
  lib_extract()
  lib_isnumber()
  lib_isstring()
  lib_iscolor()
  lib_iskeyword()
  lib_ispixel()
  lib_ispercentage()
  lib_isem()
  lib_isrem()
  lib_rgbahex()
  lib_argb()
  lib_data_uri()
  lib_e()
  lib__sprintf()
  lib_floor()
  lib_ceil()
  lib_round()
  lib_unit()
  colorArgs()
  lib_darken()
  lib_lighten()
  lib_saturate()
  lib_desaturate()
  lib_spin()
  lib_fadeout()
  lib_fadein()
  lib_hue()
  lib_saturation()
  lib_lightness()
  lib_alpha()
  lib_fade()
  lib_percentage()
  lib_mix()
  lib_contrast()
  lib_luma()
  assertColor()
  assertNumber()
  assertArgs()
  assertMinArgs()
  toHSL()
  toRGB_helper()
  toRGB()
  clamp()
  funcToColor()
  reduce()
  coerceColor()
  coerceString()
  flattenList()
  toBool()
  evaluate()
  stringConcatenate()
  convert()
  fixColor()
  op_number_color()
  op_color_number()
  op_color_color()
  lib_red()
  lib_green()
  lib_blue()
  op_number_number()
  makeOutputBlock()
  pushEnv()
  popEnv()
  set()
  get()
  injectVariables()
  __construct()
  compile()
  compileFile()
  checkedCachedCompile()
  checkedCompile()
  cachedCompile()
  parse()
  makeParser()
  setFormatter()
  newFormatter()
  setPreserveComments()
  registerFunction()
  unregisterFunction()
  setVariables()
  unsetVariable()
  setImportDir()
  addImportDir()
  allParsedFiles()
  addParsedFile()
  throwError()
  ccompile()
  cexecute()

lessc_parser:: (46 methods):
  __construct()
  parse()
  parseChunk()
  isDirective()
  fixTags()
  expressionList()
  expression()
  expHelper()
  propertyValue()
  parenValue()
  value()
  import()
  mediaQueryList()
  mediaQuery()
  mediaExpression()
  openString()
  stringValue()
  interpolation()
  unit()
  color()
  argumentDef()
  tags()
  mixinTags()
  tagBracket()
  tag()
  func()
  variable()
  assign()
  keyword()
  end()
  guards()
  guardGroup()
  guard()
  literal()
  genericList()
  to()
  match()
  whitespace()
  peek()
  seek()
  throwError()
  pushBlock()
  pushSpecialBlock()
  append()
  pop()
  removeComments()

lessc_formatter_classic:: (5 methods):
  __construct()
  indentStr()
  property()
  isEmpty()
  block()

lessc_formatter_compressed:: (1 method):
  indentStr()

lessc_formatter_lessjs:: (0 methods):


Class: lessc  - X-Ref

The LESS compiler and parser.

Converting LESS to CSS is a three stage process. The incoming file is parsed
by `lessc_parser` into a syntax tree, then it is compiled into another tree
representing the CSS structure by `lessc`. The CSS tree is fed into a
formatter, like `lessc_formatter` which then outputs CSS as a string.

During the first compile, all values are *reduced*, which means that their
types are brought to the lowest form before being dump as strings. This
handles math equations, variable dereferences, and the like.

The `parse` function of `lessc` is the entry point.

In summary:

The `lessc` class creates an instance of the parser, feeds it LESS code,
then transforms the resulting tree to a CSS tree. This class also holds the
evaluation context, such as all available mixins and variables at any given
time.

The `lessc_parser` class is only concerned with parsing its input.

The `lessc_formatter` takes a CSS tree, and dumps it to a formatted string,
handling things like indentation.
findImport($url)   X-Ref
No description

fileExists($name)   X-Ref
No description

compressList($items, $delim)   X-Ref
No description

preg_quote($what)   X-Ref
No description

tryImport($importPath, $parentBlock, $out)   X-Ref
No description

compileImportedProps($props, $block, $out, $sourceParser, $importDir)   X-Ref
No description

compileBlock($block)   X-Ref
Recursively compiles a block.

A block is analogous to a CSS block in most cases. A single LESS document
is encapsulated in a block when parsed, but it does not have parent tags
so all of it's children appear on the root level when compiled.

Blocks are made up of props and children.

Props are property instructions, array tuples which describe an action
to be taken, eg. write a property, set a variable, mixin a block.

The children of a block are just all the blocks that are defined within.
This is used to look up mixins when performing a mixin.

Compiling the block involves pushing a fresh environment on the stack,
and iterating through the props, compiling each one.

See lessc::compileProp()


compileCSSBlock($block)   X-Ref
No description

compileMedia($media)   X-Ref
No description

mediaParent($scope)   X-Ref
No description

compileNestedBlock($block, $selectors)   X-Ref
No description

compileRoot($root)   X-Ref
No description

compileProps($block, $out)   X-Ref
No description

deduplicate($lines)   X-Ref
Deduplicate lines in a block. Comments are not deduplicated. If a
duplicate rule is detected, the comments immediately preceding each
occurence are consolidated.


sortProps($props, $split = false)   X-Ref
No description

compileMediaQuery($queries)   X-Ref
No description

multiplyMedia($env, $childQueries = null)   X-Ref
No description

expandParentSelectors(&$tag, $replace)   X-Ref
No description

findClosestSelectors()   X-Ref
No description

multiplySelectors($selectors)   X-Ref
No description

compileSelectors($selectors)   X-Ref
No description

eq($left, $right)   X-Ref
No description

patternMatch($block, $orderedArgs, $keywordArgs)   X-Ref
No description

patternMatchAll($blocks, $orderedArgs, $keywordArgs, $skip=array()   X-Ref
No description

findBlocks($searchIn, $path, $orderedArgs, $keywordArgs, $seen=array()   X-Ref
No description

zipSetArgs($args, $orderedValues, $keywordValues)   X-Ref
No description

compileProp($prop, $block, $out)   X-Ref
No description

compileValue($value)   X-Ref
Compiles a primitive value into a CSS property value.

Values in lessphp are typed by being wrapped in arrays, their format is
typically:

array(type, contents [, additional_contents]*)

The input is expected to be reduced. This function will not work on
things like expressions and variables.

lib_pow($args)   X-Ref
No description

lib_pi()   X-Ref
No description

lib_mod($args)   X-Ref
No description

lib_convert($args)   X-Ref
No description

lib_abs($num)   X-Ref
No description

lib_min($args)   X-Ref
No description

lib_max($args)   X-Ref
No description

lib_tan($num)   X-Ref
No description

lib_sin($num)   X-Ref
No description

lib_cos($num)   X-Ref
No description

lib_atan($num)   X-Ref
No description

lib_asin($num)   X-Ref
No description

lib_acos($num)   X-Ref
No description

lib_sqrt($num)   X-Ref
No description

lib_extract($value)   X-Ref
No description

lib_isnumber($value)   X-Ref
No description

lib_isstring($value)   X-Ref
No description

lib_iscolor($value)   X-Ref
No description

lib_iskeyword($value)   X-Ref
No description

lib_ispixel($value)   X-Ref
No description

lib_ispercentage($value)   X-Ref
No description

lib_isem($value)   X-Ref
No description

lib_isrem($value)   X-Ref
No description

lib_rgbahex($color)   X-Ref
No description

lib_argb($color)   X-Ref
No description

lib_data_uri($value)   X-Ref
Given an url, decide whether to output a regular link or the base64-encoded contents of the file

param: array  $value either an argument list (two strings) or a single string
return: string        formatted url(), either as a link or base64-encoded

lib_e($arg)   X-Ref
No description

lib__sprintf($args)   X-Ref
No description

lib_floor($arg)   X-Ref
No description

lib_ceil($arg)   X-Ref
No description

lib_round($arg)   X-Ref
No description

lib_unit($arg)   X-Ref
No description

colorArgs($args)   X-Ref
Helper function to get arguments for color manipulation functions.
takes a list that contains a color like thing and a percentage


lib_darken($args)   X-Ref
No description

lib_lighten($args)   X-Ref
No description

lib_saturate($args)   X-Ref
No description

lib_desaturate($args)   X-Ref
No description

lib_spin($args)   X-Ref
No description

lib_fadeout($args)   X-Ref
No description

lib_fadein($args)   X-Ref
No description

lib_hue($color)   X-Ref
No description

lib_saturation($color)   X-Ref
No description

lib_lightness($color)   X-Ref
No description

lib_alpha($value)   X-Ref
No description

lib_fade($args)   X-Ref
No description

lib_percentage($arg)   X-Ref
No description

lib_mix($args)   X-Ref
No description

lib_contrast($args)   X-Ref
No description

lib_luma($color)   X-Ref
No description

assertColor($value, $error = "expected color value")   X-Ref
No description

assertNumber($value, $error = "expecting number")   X-Ref
No description

assertArgs($value, $expectedArgs, $name="")   X-Ref
No description

assertMinArgs($value, $expectedMinArgs, $name="")   X-Ref
No description

toHSL($color)   X-Ref
No description

toRGB_helper($comp, $temp1, $temp2)   X-Ref
No description

toRGB($color)   X-Ref
Converts a hsl array into a color value in rgb.
Expects H to be in range of 0 to 360, S and L in 0 to 100


clamp($v, $max = 1, $min = 0)   X-Ref
No description

funcToColor($func)   X-Ref
Convert the rgb, rgba, hsl color literals of function type
as returned by the parser into values of color type.


reduce($value, $forExpression = false)   X-Ref
No description

coerceColor($value)   X-Ref
No description

coerceString($value)   X-Ref
No description

flattenList($value)   X-Ref
No description

toBool($a)   X-Ref
No description

evaluate($exp)   X-Ref
No description

stringConcatenate($left, $right)   X-Ref
No description

convert( $number, $to )   X-Ref
No description

fixColor($c)   X-Ref
No description

op_number_color($op, $lft, $rgt)   X-Ref
No description

op_color_number($op, $lft, $rgt)   X-Ref
No description

op_color_color($op, $left, $right)   X-Ref
No description

lib_red($color)   X-Ref
No description

lib_green($color)   X-Ref
No description

lib_blue($color)   X-Ref
No description

op_number_number($op, $left, $right)   X-Ref
No description

makeOutputBlock($type, $selectors = null)   X-Ref
No description

pushEnv($block = null)   X-Ref
No description

popEnv()   X-Ref
No description

set($name, $value)   X-Ref
No description

get($name)   X-Ref
No description

injectVariables($args)   X-Ref
No description

__construct($fname = null)   X-Ref
Initialize any static state, can initialize parser for a file
$opts isn't used yet


compile($string, $name = null)   X-Ref
No description

compileFile($fname, $outFname = null)   X-Ref
No description

checkedCachedCompile($in, $out, $force = false)   X-Ref
Based on explicit input/output files does a full change check on cache before compiling.

param: string $in
param: string $out
param: boolean $force
return: string Compiled CSS results

checkedCompile($in, $out)   X-Ref
No description

cachedCompile($in, $force = false)   X-Ref
Execute lessphp on a .less file or a lessphp cache structure

The lessphp cache structure contains information about a specific
less file having been parsed. It can be used as a hint for future
calls to determine whether or not a rebuild is required.

The cache structure contains two important keys that may be used
externally:

compiled: The final compiled CSS
updated: The time (in seconds) the CSS was last compiled

The cache structure is a plain-ol' PHP associative array and can
be serialized and unserialized without a hitch.

param: mixed $in Input
param: bool $force Force rebuild?
return: array lessphp cache structure

parse($str = null, $initialVariables = null)   X-Ref
No description

makeParser($name)   X-Ref
No description

setFormatter($name)   X-Ref
No description

newFormatter()   X-Ref
No description

setPreserveComments($preserve)   X-Ref
No description

registerFunction($name, $func)   X-Ref
No description

unregisterFunction($name)   X-Ref
No description

setVariables($variables)   X-Ref
No description

unsetVariable($name)   X-Ref
No description

setImportDir($dirs)   X-Ref
No description

addImportDir($dir)   X-Ref
No description

allParsedFiles()   X-Ref
No description

addParsedFile($file)   X-Ref
No description

throwError($msg = null)   X-Ref
Uses the current value of $this->count to show line and line number


ccompile($in, $out, $less = null)   X-Ref
No description

cexecute($in, $force = false, $less = null)   X-Ref
No description

Class: lessc_parser  - X-Ref

__construct($lessc, $sourceName = null)   X-Ref
No description

parse($buffer)   X-Ref
No description

parseChunk()   X-Ref
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.

isDirective($dirname, $directives)   X-Ref
No description

fixTags($tags)   X-Ref
No description

expressionList(&$exps)   X-Ref
No description

expression(&$out)   X-Ref
Attempt to consume an expression.

link: http://en.wikipedia.org/wiki/Operator-precedence_parser#Pseudo-code

expHelper($lhs, $minP)   X-Ref
recursively parse infix equation with $lhs at precedence $minP


propertyValue(&$value, $keyName = null)   X-Ref
No description

parenValue(&$out)   X-Ref
No description

value(&$value)   X-Ref
No description

import(&$out)   X-Ref
No description

mediaQueryList(&$out)   X-Ref
No description

mediaQuery(&$out)   X-Ref
No description

mediaExpression(&$out)   X-Ref
No description

openString($end, &$out, $nestingOpen=null, $rejectStrs = null)   X-Ref
No description

stringValue(&$out)   X-Ref
No description

interpolation(&$out)   X-Ref
No description

unit(&$unit)   X-Ref
No description

color(&$out)   X-Ref
No description

argumentDef(&$args, &$isVararg)   X-Ref
No description

tags(&$tags, $simple = false, $delim = ',')   X-Ref
No description

mixinTags(&$tags)   X-Ref
No description

tagBracket(&$parts, &$hasExpression)   X-Ref
No description

tag(&$tag, $simple = false)   X-Ref
No description

func(&$func)   X-Ref
No description

variable(&$name)   X-Ref
No description

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


keyword(&$word)   X-Ref
No description

end()   X-Ref
No description

guards(&$guards)   X-Ref
No description

guardGroup(&$guardGroup)   X-Ref
No description

guard(&$guard)   X-Ref
No description

literal($what, $eatWhitespace = null)   X-Ref
No description

genericList(&$out, $parseItem, $delim="", $flatten=true)   X-Ref
No description

to($what, &$out, $until = false, $allowNewline = false)   X-Ref
No description

match($regex, &$out, $eatWhitespace = null)   X-Ref
No description

whitespace()   X-Ref
No description

peek($regex, &$out = null, $from=null)   X-Ref
No description

seek($where = null)   X-Ref
No description

throwError($msg = "parse error", $count = null)   X-Ref
No description

pushBlock($selectors=null, $type=null)   X-Ref
No description

pushSpecialBlock($type)   X-Ref
No description

append($prop, $pos = null)   X-Ref
No description

pop()   X-Ref
No description

removeComments($text)   X-Ref
No description

Class: lessc_formatter_classic  - X-Ref

__construct()   X-Ref
No description

indentStr($n = 0)   X-Ref
No description

property($name, $value)   X-Ref
No description

isEmpty($block)   X-Ref
No description

block($block)   X-Ref
No description

Class: lessc_formatter_compressed  - X-Ref

indentStr($n = 0)   X-Ref
No description

Class: lessc_formatter_lessjs  - X-Ref