WpvLessc

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.

Methods

findImport

findImport($url) 

Arguments

$url

fileExists

fileExists($name) 

Arguments

$name

compressList

compressList($items, $delim) 
static

Arguments

$items

$delim

preg_quote

preg_quote($what) 
static

Arguments

$what

tryImport

tryImport($importPath, $parentBlock, $out) 

Arguments

$importPath

$parentBlock

$out

compileImportedProps

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

Arguments

$props

$block

$out

$sourceParser

$importDir

Recursively compiles a block.

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

Arguments

$block

compileCSSBlock

compileCSSBlock($block) 

Arguments

$block

compileMedia

compileMedia($media) 

Arguments

$media

mediaParent

mediaParent($scope) 

Arguments

$scope

compileNestedBlock

compileNestedBlock($block, $selectors) 

Arguments

$block

$selectors

compileRoot

compileRoot($root) 

Arguments

$root

compileProps

compileProps($block, $out) 

Arguments

$block

$out

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

deduplicate($lines) 

Arguments

$lines

sortProps

sortProps($props, $split = false) 

Arguments

$props

$split

compileMediaQuery

compileMediaQuery($queries) 

Arguments

$queries

multiplyMedia

multiplyMedia($env, $childQueries = null) 

Arguments

$env

$childQueries

expandParentSelectors

expandParentSelectors(&$tag, $replace) 

Arguments

$tag

$replace

findClosestSelectors

findClosestSelectors() 

multiplySelectors

multiplySelectors($selectors) 

Arguments

$selectors

compileSelectors

compileSelectors($selectors) 

Arguments

$selectors

eq

eq($left, $right) 

Arguments

$left

$right

patternMatch

patternMatch($block, $orderedArgs, $keywordArgs) 

Arguments

$block

$orderedArgs

$keywordArgs

patternMatchAll

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

Arguments

$blocks

$orderedArgs

$keywordArgs

$skip

findBlocks

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

Arguments

$searchIn

$path

$orderedArgs

$keywordArgs

$seen

zipSetArgs

zipSetArgs($args, $orderedValues, $keywordValues) 

Arguments

$args

$orderedValues

$keywordValues

compileProp

compileProp($prop, $block, $out) 

Arguments

$prop

$block

$out

Compiles a primitive value into a CSS property value.

compileValue($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.

Arguments

$value

lib_pow

lib_pow($args) 

Arguments

$args

lib_pi

lib_pi() 

lib_mod

lib_mod($args) 

Arguments

$args

lib_tan

lib_tan($num) 

Arguments

$num

lib_sin

lib_sin($num) 

Arguments

$num

lib_cos

lib_cos($num) 

Arguments

$num

lib_atan

lib_atan($num) 

Arguments

$num

lib_asin

lib_asin($num) 

Arguments

$num

lib_acos

lib_acos($num) 

Arguments

$num

lib_sqrt

lib_sqrt($num) 

Arguments

$num

lib_extract

lib_extract($value) 

Arguments

$value

lib_isnumber

lib_isnumber($value) 

Arguments

$value

lib_isstring

lib_isstring($value) 

Arguments

$value

lib_iscolor

lib_iscolor($value) 

Arguments

$value

lib_iskeyword

lib_iskeyword($value) 

Arguments

$value

lib_ispixel

lib_ispixel($value) 

Arguments

$value

lib_ispercentage

lib_ispercentage($value) 

Arguments

$value

lib_isem

lib_isem($value) 

Arguments

$value

lib_isrem

lib_isrem($value) 

Arguments

$value

lib_rgbahex

lib_rgbahex($color) 

Arguments

$color

lib_argb

lib_argb($color) 

Arguments

$color

lib_e

lib_e($arg) 

Arguments

$arg

lib__sprintf

lib__sprintf($args) 

Arguments

$args

lib_floor

lib_floor($arg) 

Arguments

$arg

lib_ceil

lib_ceil($arg) 

Arguments

$arg

lib_round

lib_round($arg) 

Arguments

$arg

lib_unit

lib_unit($arg) 

Arguments

$arg

Helper function to get arguments for color manipulation functions.

colorArgs($args) 

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

Arguments

$args

lib_darken

lib_darken($args) 

Arguments

$args

lib_lighten

lib_lighten($args) 

Arguments

$args

lib_saturate

lib_saturate($args) 

Arguments

$args

lib_desaturate

lib_desaturate($args) 

Arguments

$args

lib_spin

lib_spin($args) 

Arguments

$args

lib_fadeout

lib_fadeout($args) 

Arguments

$args

lib_fadein

lib_fadein($args) 

Arguments

$args

lib_hue

lib_hue($color) 

Arguments

$color

lib_saturation

lib_saturation($color) 

Arguments

$color

lib_lightness

lib_lightness($color) 

Arguments

$color

lib_alpha

lib_alpha($value) 

Arguments

$value

lib_fade

lib_fade($args) 

Arguments

$args

lib_percentage

lib_percentage($arg) 

Arguments

$arg

lib_mix

lib_mix($args) 

Arguments

$args

lib_contrast

lib_contrast($args) 

Arguments

$args

lib_luma

lib_luma($color) 

Arguments

$color

assertColor

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

Arguments

$value

$error

assertNumber

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

Arguments

$value

$error

assertArgs

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

Arguments

$value

$expectedArgs

$name

toHSL

toHSL($color) 

Arguments

$color

toRGB_helper

toRGB_helper($comp, $temp1, $temp2) 

Arguments

$comp

$temp1

$temp2

Converts a hsl array into a color value in rgb.

toRGB($color) 

Expects H to be in range of 0 to 360, S and L in 0 to 100

Arguments

$color

clamp

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

Arguments

$v

$max

$min

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

funcToColor($func) 

Arguments

$func

reduce

reduce($value, $forExpression = false) 

Arguments

$value

$forExpression

coerceColor

coerceColor($value) 

Arguments

$value

coerceString

coerceString($value) 

Arguments

$value

flattenList

flattenList($value) 

Arguments

$value

toBool

toBool($a) 

Arguments

$a

evaluate

evaluate($exp) 

Arguments

$exp

stringConcatenate

stringConcatenate($left, $right) 

Arguments

$left

$right

fixColor

fixColor($c) 

Arguments

$c

op_number_color

op_number_color($op, $lft, $rgt) 

Arguments

$op

$lft

$rgt

op_color_number

op_color_number($op, $lft, $rgt) 

Arguments

$op

$lft

$rgt

op_color_color

op_color_color($op, $left, $right) 

Arguments

$op

$left

$right

lib_red

lib_red($color) 

Arguments

$color

lib_green

lib_green($color) 

Arguments

$color

lib_blue

lib_blue($color) 

Arguments

$color

op_number_number

op_number_number($op, $left, $right) 

Arguments

$op

$left

$right

makeOutputBlock

makeOutputBlock($type, $selectors = null) 

Arguments

$type

$selectors

pushEnv

pushEnv($block = null) 

Arguments

$block

popEnv

popEnv() 

set

set($name, $value) 

Arguments

$name

$value

get

get($name) 

Arguments

$name

injectVariables

injectVariables($args) 

Arguments

$args

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

__construct($fname = null) 

Arguments

$fname

compile

compile($string, $name = null) 

Arguments

$string

$name

compileFile

compileFile($fname, $outFname = null) 

Arguments

$fname

$outFname

checkedCompile

checkedCompile($in, $out) 

Arguments

$in

$out

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

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

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.

Arguments

$in

mixed

Input

$force

bool

Force rebuild?

Response

array

lessphp cache structure

parse

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

Arguments

$str

$initialVariables

makeParser

makeParser($name) 

Arguments

$name

setFormatter

setFormatter($name) 

Arguments

$name

newFormatter

newFormatter() 

setPreserveComments

setPreserveComments($preserve) 

Arguments

$preserve

registerFunction

registerFunction($name, $func) 

Arguments

$name

$func

unregisterFunction

unregisterFunction($name) 

Arguments

$name

setVariables

setVariables($variables) 

Arguments

$variables

unsetVariable

unsetVariable($name) 

Arguments

$name

setImportDir

setImportDir($dirs) 

Arguments

$dirs

addImportDir

addImportDir($dir) 

Arguments

$dir

allParsedFiles

allParsedFiles() 

addParsedFile

addParsedFile($file) 

Arguments

$file

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

throwError($msg = null) 

Arguments

$msg

ccompile

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

Arguments

$in

$out

$less

cexecute

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

Arguments

$in

$force

$less

Properties

VERSION

VERSION : 
static

TRUE

TRUE : 
static

FALSE

FALSE : 
static

libFunctions

libFunctions : 

registeredVars

registeredVars : 

preserveComments

preserveComments : 

vPrefix

vPrefix : 

mPrefix

mPrefix : 

parentSelector

parentSelector : 

importDisabled

importDisabled : 

importDir

importDir : 

numberPrecision

numberPrecision : 

allParsedFiles

allParsedFiles : 

sourceParser

sourceParser : 

sourceLoc

sourceLoc : 

nextImportId

nextImportId : 
static

cssColors

cssColors : 
static