class Lessc (View source)

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.

Properties

static $VERSION
static $TRUE
static $FALSE
protected $libFunctions
protected $registeredVars
protected $preserveComments
$vPrefix
$mPrefix
$parentSelector
$importDisabled
$importDir
$scope
$formatter
$formatterName
$parser
$_parseFile
$env
$count
protected $numberPrecision
protected $allParsedFiles
protected $sourceParser
protected $sourceLoc
static protected $nextImportId
static protected $cssColors

Methods

findImport($url)

No description

bool
fileExists(string $name)

fileExists

static 
compressList($items, $delim)

No description

static 
preg_quote($what)

No description

tryImport($importPath, $parentBlock, $out)

No description

compileImportedProps($props, $block, $out, $sourceParser, $importDir)

No description

compileBlock($block)

Recursively compiles a block.

compileCSSBlock($block)

No description

compileMedia($media)

No description

mediaParent($scope)

No description

compileNestedBlock($block, $selectors)

No description

compileRoot($root)

No description

compileProps($block, $out)

No description

deduplicate($lines)

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)

No description

compileMediaQuery($queries)

No description

multiplyMedia($env, $childQueries = null)

No description

expandParentSelectors($tag, $replace)

No description

findClosestSelectors()

No description

multiplySelectors($selectors)

No description

compileSelectors($selectors)

No description

eq($left, $right)

No description

patternMatch($block, $orderedArgs, $keywordArgs)

No description

patternMatchAll($blocks, $orderedArgs, $keywordArgs, $skip = array())

No description

findBlocks($searchIn, $path, $orderedArgs, $keywordArgs, $seen = array())

No description

zipSetArgs($args, $orderedValues, $keywordValues)

No description

compileProp($prop, $block, $out)

No description

compileValue($value)

Compiles a primitive value into a CSS property value.

lib_pow($args)

No description

lib_pi()

No description

lib_mod($args)

No description

lib_tan($num)

No description

lib_sin($num)

No description

lib_cos($num)

No description

lib_atan($num)

No description

lib_asin($num)

No description

lib_acos($num)

No description

lib_sqrt($num)

No description

lib_extract($value)

No description

lib_isnumber($value)

No description

lib_isstring($value)

No description

lib_iscolor($value)

No description

lib_iskeyword($value)

No description

lib_ispixel($value)

No description

lib_ispercentage($value)

No description

lib_isem($value)

No description

lib_isrem($value)

No description

lib_rgbahex($color)

No description

lib_argb($color)

No description

string
lib_data_uri(array $value)

Given an url, decide whether to output a regular link or the base64-encoded contents of the file

lib_e($arg)

No description

lib__sprintf($args)

No description

lib_floor($arg)

No description

lib_ceil($arg)

No description

lib_round($arg)

No description

lib_unit($arg)

No description

colorArgs($args)

Helper function to get arguments for color manipulation functions.

lib_darken($args)

No description

lib_lighten($args)

No description

lib_saturate($args)

No description

lib_desaturate($args)

No description

lib_spin($args)

No description

lib_fadeout($args)

No description

lib_fadein($args)

No description

lib_hue($color)

No description

lib_saturation($color)

No description

lib_lightness($color)

No description

lib_alpha($value)

No description

lib_fade($args)

No description

lib_percentage($arg)

No description

array
lib_tint($args)

Mix color with white in variable proportion.

array
lib_shade($args)

Mix color with black in variable proportion.

array
lib_mix(array $args)

lib_mix mixes two colors by weight mix(@color1, @color2, [@weight: 50%]); http://sass-lang.com/docs/yardoc/Sass/Script/Functions.html#mix-instance_method

array
lib_contrast(array $args)

lib_contrast

lib_luma($color)

No description

assertColor($value, $error = "expected color value")

No description

assertNumber($value, $error = "expecting number")

No description

assertArgs($value, $expectedArgs, $name = "")

No description

toHSL($color)

No description

toRGB_helper($comp, $temp1, $temp2)

No description

toRGB($color)

Converts a hsl array into a color value in rgb.

clamp($v, $max = 1, $min = 0)

No description

funcToColor($func)

Convert the rgb, rgba, hsl color literals of function type as returned by the parser into values of color type.

reduce($value, $forExpression = false)

No description

coerceColor($value)

No description

coerceString($value)

No description

flattenList($value)

No description

toBool($a)

No description

evaluate($exp)

No description

stringConcatenate($left, $right)

No description

fixColor($c)

No description

op_number_color($op, $lft, $rgt)

No description

op_color_number($op, $lft, $rgt)

No description

op_color_color($op, $left, $right)

No description

lib_red($color)

No description

lib_green($color)

No description

lib_blue($color)

No description

op_number_number($op, $left, $right)

No description

makeOutputBlock($type, $selectors = null)

No description

pushEnv($block = null)

No description

popEnv()

No description

set($name, $value)

No description

get($name)

No description

injectVariables($args)

No description

__construct($fname = null)

Initialize any static state, can initialize parser for a file $opts isn't used yet

compile($string, $name = null)

No description

compileFile($fname, $outFname = null)

No description

checkedCompile($in, $out)

No description

array|null
cachedCompile(mixed $in, bool $force = false)

Execute lessphp on a .less file or a lessphp cache structure

parse($str = null, $initialVariables = null)

No description

makeParser($name)

No description

setFormatter($name)

No description

newFormatter()

No description

setPreserveComments($preserve)

No description

registerFunction($name, $func)

No description

unregisterFunction($name)

No description

setVariables($variables)

No description

unsetVariable($name)

No description

setImportDir($dirs)

No description

addImportDir($dir)

No description

allParsedFiles()

No description

addParsedFile($file)

No description

throwError($msg = null)

Uses the current value of $this->count to show line and line number

static 
ccompile($in, $out, $less = null)

No description

static 
cexecute($in, $force = false, $less = null)

No description

Details

protected findImport($url)

No description

Parameters

$url

protected bool fileExists(string $name)

fileExists

Parameters

string $name Filename

Return Value

bool

static compressList($items, $delim)

No description

Parameters

$items
$delim

static preg_quote($what)

No description

Parameters

$what

protected tryImport($importPath, $parentBlock, $out)

No description

Parameters

$importPath
$parentBlock
$out

protected compileImportedProps($props, $block, $out, $sourceParser, $importDir)

No description

Parameters

$props
$block
$out
$sourceParser
$importDir

protected compileBlock($block)

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

Parameters

$block

protected compileCSSBlock($block)

No description

Parameters

$block

protected compileMedia($media)

No description

Parameters

$media

protected mediaParent($scope)

No description

Parameters

$scope

protected compileNestedBlock($block, $selectors)

No description

Parameters

$block
$selectors

protected compileRoot($root)

No description

Parameters

$root

protected compileProps($block, $out)

No description

Parameters

$block
$out

protected deduplicate($lines)

Deduplicate lines in a block. Comments are not deduplicated. If a duplicate rule is detected, the comments immediately preceding each occurence are consolidated.

Parameters

$lines

protected sortProps($props, $split = false)

No description

Parameters

$props
$split

protected compileMediaQuery($queries)

No description

Parameters

$queries

protected multiplyMedia($env, $childQueries = null)

No description

Parameters

$env
$childQueries

protected expandParentSelectors($tag, $replace)

No description

Parameters

$tag
$replace

protected findClosestSelectors()

No description

protected multiplySelectors($selectors)

No description

Parameters

$selectors

protected compileSelectors($selectors)

No description

Parameters

$selectors

protected eq($left, $right)

No description

Parameters

$left
$right

protected patternMatch($block, $orderedArgs, $keywordArgs)

No description

Parameters

$block
$orderedArgs
$keywordArgs

protected patternMatchAll($blocks, $orderedArgs, $keywordArgs, $skip = array())

No description

Parameters

$blocks
$orderedArgs
$keywordArgs
$skip

protected findBlocks($searchIn, $path, $orderedArgs, $keywordArgs, $seen = array())

No description

Parameters

$searchIn
$path
$orderedArgs
$keywordArgs
$seen

protected zipSetArgs($args, $orderedValues, $keywordValues)

No description

Parameters

$args
$orderedValues
$keywordValues

protected compileProp($prop, $block, $out)

No description

Parameters

$prop
$block
$out

compileValue($value)

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.

Parameters

$value

protected lib_pow($args)

No description

Parameters

$args

protected lib_pi()

No description

protected lib_mod($args)

No description

Parameters

$args

protected lib_tan($num)

No description

Parameters

$num

protected lib_sin($num)

No description

Parameters

$num

protected lib_cos($num)

No description

Parameters

$num

protected lib_atan($num)

No description

Parameters

$num

protected lib_asin($num)

No description

Parameters

$num

protected lib_acos($num)

No description

Parameters

$num

protected lib_sqrt($num)

No description

Parameters

$num

protected lib_extract($value)

No description

Parameters

$value

protected lib_isnumber($value)

No description

Parameters

$value

protected lib_isstring($value)

No description

Parameters

$value

protected lib_iscolor($value)

No description

Parameters

$value

protected lib_iskeyword($value)

No description

Parameters

$value

protected lib_ispixel($value)

No description

Parameters

$value

protected lib_ispercentage($value)

No description

Parameters

$value

protected lib_isem($value)

No description

Parameters

$value

protected lib_isrem($value)

No description

Parameters

$value

protected lib_rgbahex($color)

No description

Parameters

$color

protected lib_argb($color)

No description

Parameters

$color

protected string lib_data_uri(array $value)

Given an url, decide whether to output a regular link or the base64-encoded contents of the file

Parameters

array $value

either an argument list (two strings) or a single string

Return Value

string

formatted url(), either as a link or base64-encoded

protected lib_e($arg)

No description

Parameters

$arg

protected lib__sprintf($args)

No description

Parameters

$args

protected lib_floor($arg)

No description

Parameters

$arg

protected lib_ceil($arg)

No description

Parameters

$arg

protected lib_round($arg)

No description

Parameters

$arg

protected lib_unit($arg)

No description

Parameters

$arg

colorArgs($args)

Helper function to get arguments for color manipulation functions.

takes a list that contains a color like thing and a percentage

Parameters

$args

protected lib_darken($args)

No description

Parameters

$args

protected lib_lighten($args)

No description

Parameters

$args

protected lib_saturate($args)

No description

Parameters

$args

protected lib_desaturate($args)

No description

Parameters

$args

protected lib_spin($args)

No description

Parameters

$args

protected lib_fadeout($args)

No description

Parameters

$args

protected lib_fadein($args)

No description

Parameters

$args

protected lib_hue($color)

No description

Parameters

$color

protected lib_saturation($color)

No description

Parameters

$color

protected lib_lightness($color)

No description

Parameters

$color

protected lib_alpha($value)

No description

Parameters

$value

protected lib_fade($args)

No description

Parameters

$args

protected lib_percentage($arg)

No description

Parameters

$arg

protected array lib_tint($args)

Mix color with white in variable proportion.

It is the same as calling mix(#ffffff, @color, @weight).

tint(@color, [@weight: 50%]);

http://lesscss.org/functions/#color-operations-tint

Parameters

$args

Return Value

array Color

protected array lib_shade($args)

Mix color with black in variable proportion.

It is the same as calling mix(#000000, @color, @weight)

shade(@color, [@weight: 50%]);

http://lesscss.org/functions/#color-operations-shade

Parameters

$args

Return Value

array Color

protected array lib_mix(array $args)

lib_mix mixes two colors by weight mix(@color1, @color2, [@weight: 50%]); http://sass-lang.com/docs/yardoc/Sass/Script/Functions.html#mix-instance_method

Parameters

array $args Args

Return Value

array

protected array lib_contrast(array $args)

lib_contrast

Parameters

array $args Args

Return Value

array

protected lib_luma($color)

No description

Parameters

$color

assertColor($value, $error = "expected color value")

No description

Parameters

$value
$error

assertNumber($value, $error = "expecting number")

No description

Parameters

$value
$error

assertArgs($value, $expectedArgs, $name = "")

No description

Parameters

$value
$expectedArgs
$name

protected toHSL($color)

No description

Parameters

$color

protected toRGB_helper($comp, $temp1, $temp2)

No description

Parameters

$comp
$temp1
$temp2

protected toRGB($color)

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

Parameters

$color

protected clamp($v, $max = 1, $min = 0)

No description

Parameters

$v
$max
$min

protected funcToColor($func)

Convert the rgb, rgba, hsl color literals of function type as returned by the parser into values of color type.

Parameters

$func

protected reduce($value, $forExpression = false)

No description

Parameters

$value
$forExpression

protected coerceColor($value)

No description

Parameters

$value

protected coerceString($value)

No description

Parameters

$value

protected flattenList($value)

No description

Parameters

$value

toBool($a)

No description

Parameters

$a

protected evaluate($exp)

No description

Parameters

$exp

protected stringConcatenate($left, $right)

No description

Parameters

$left
$right

protected fixColor($c)

No description

Parameters

$c

protected op_number_color($op, $lft, $rgt)

No description

Parameters

$op
$lft
$rgt

protected op_color_number($op, $lft, $rgt)

No description

Parameters

$op
$lft
$rgt

protected op_color_color($op, $left, $right)

No description

Parameters

$op
$left
$right

lib_red($color)

No description

Parameters

$color

lib_green($color)

No description

Parameters

$color

lib_blue($color)

No description

Parameters

$color

protected op_number_number($op, $left, $right)

No description

Parameters

$op
$left
$right

protected makeOutputBlock($type, $selectors = null)

No description

Parameters

$type
$selectors

protected pushEnv($block = null)

No description

Parameters

$block

protected popEnv()

No description

protected set($name, $value)

No description

Parameters

$name
$value

protected get($name)

No description

Parameters

$name

protected injectVariables($args)

No description

Parameters

$args

__construct($fname = null)

Initialize any static state, can initialize parser for a file $opts isn't used yet

Parameters

$fname

compile($string, $name = null)

No description

Parameters

$string
$name

compileFile($fname, $outFname = null)

No description

Parameters

$fname
$outFname

checkedCompile($in, $out)

No description

Parameters

$in
$out

array|null cachedCompile(mixed $in, bool $force = false)

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.

Parameters

mixed $in Input
bool $force

Force rebuild?

Return Value

array|null

lessphp cache structure

parse($str = null, $initialVariables = null)

No description

Parameters

$str
$initialVariables

protected makeParser($name)

No description

Parameters

$name

setFormatter($name)

No description

Parameters

$name

protected newFormatter()

No description

setPreserveComments($preserve)

No description

Parameters

$preserve

registerFunction($name, $func)

No description

Parameters

$name
$func

unregisterFunction($name)

No description

Parameters

$name

setVariables($variables)

No description

Parameters

$variables

unsetVariable($name)

No description

Parameters

$name

setImportDir($dirs)

No description

Parameters

$dirs

addImportDir($dir)

No description

Parameters

$dir

allParsedFiles()

No description

addParsedFile($file)

No description

Parameters

$file

throwError($msg = null)

Uses the current value of $this->count to show line and line number

Parameters

$msg

static ccompile($in, $out, $less = null)

No description

Parameters

$in
$out
$less

static cexecute($in, $force = false, $less = null)

No description

Parameters

$in
$force
$less