\lessc

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 intstance 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.

Summary

Methods
Properties
Constants
compressList()
preg_quote()
lib_red()
lib_green()
lib_blue()
__construct()
compile()
compileFile()
checkedCompile()
cachedCompile()
parse()
setFormatter()
setPreserveComments()
registerFunction()
unregisterFunction()
setVariables()
unsetVariable()
setImportDir()
addImportDir()
allParsedFiles()
ccompile()
cexecute()
$VERSION
$vPrefix
$mPrefix
$parentSelector
$importDisabled
$importDir
$defaultValue
No constants found
findImport()
fileExists()
tryImport()
compileImportedProps()
compileBlock()
compileCSSBlock()
compileMedia()
mediaParent()
compileNestedBlock()
compileRoot()
compileProps()
sortProps()
compileMediaQuery()
multiplyMedia()
expandParentSelectors()
findClosestSelectors()
multiplySelectors()
compileSelectors()
eq()
patternMatch()
patternMatchAll()
findBlocks()
zipSetArgs()
compileProp()
compileValue()
lib_pow()
lib_pi()
lib_mod()
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_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()
assertColor()
assertNumber()
assertArgs()
toHSL()
toRGB_helper()
toRGB()
clamp()
funcToColor()
reduce()
coerceColor()
coerceString()
flattenList()
toBool()
evaluate()
stringConcatenate()
fixColor()
op_number_color()
op_color_number()
op_color_color()
op_number_number()
makeOutputBlock()
pushEnv()
popEnv()
set()
get()
injectVariables()
makeParser()
newFormatter()
addParsedFile()
throwError()
$TRUE
$FALSE
$libFunctions
$registeredVars
$preserveComments
$numberPrecision
$allParsedFiles
$sourceParser
$sourceLoc
$nextImportId
$cssColors
N/A
No private methods found
No private properties found
N/A

Properties

$VERSION

$VERSION

$vPrefix

$vPrefix

$mPrefix

$mPrefix

$parentSelector

$parentSelector

$importDisabled

$importDisabled

$importDir

$importDir

$defaultValue

$defaultValue

$TRUE

$TRUE

$FALSE

$FALSE

$libFunctions

$libFunctions

$registeredVars

$registeredVars

$preserveComments

$preserveComments

$numberPrecision

$numberPrecision

$allParsedFiles

$allParsedFiles

$sourceParser

$sourceParser

$sourceLoc

$sourceLoc

$nextImportId

$nextImportId

$cssColors

$cssColors

Methods

compressList()

compressList( $items,  $delim)

Parameters

$items
$delim

preg_quote()

preg_quote( $what)

Parameters

$what

lib_red()

lib_red( $color)

Parameters

$color

lib_green()

lib_green( $color)

Parameters

$color

lib_blue()

lib_blue( $color)

Parameters

$color

__construct()

__construct( $fname)

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

Parameters

$fname

compile()

compile( $string,  $name)

Parameters

$string
$name

compileFile()

compileFile( $fname,  $outFname)

Parameters

$fname
$outFname

checkedCompile()

checkedCompile( $in,  $out)

Parameters

$in
$out

cachedCompile()

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

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?

Returns

array —

lessphp cache structure

parse()

parse( $str,  $initialVariables)

Parameters

$str
$initialVariables

setFormatter()

setFormatter( $name)

Parameters

$name

setPreserveComments()

setPreserveComments( $preserve)

Parameters

$preserve

registerFunction()

registerFunction( $name,  $func)

Parameters

$name
$func

unregisterFunction()

unregisterFunction( $name)

Parameters

$name

setVariables()

setVariables( $variables)

Parameters

$variables

unsetVariable()

unsetVariable( $name)

Parameters

$name

setImportDir()

setImportDir( $dirs)

Parameters

$dirs

addImportDir()

addImportDir( $dir)

Parameters

$dir

allParsedFiles()

allParsedFiles()

ccompile()

ccompile( $in,  $out,  $less)

Parameters

$in
$out
$less

cexecute()

cexecute( $in,  $force,  $less)

Parameters

$in
$force
$less

findImport()

findImport( $url)

Parameters

$url

fileExists()

fileExists( $name)

Parameters

$name

tryImport()

tryImport( $importPath,  $parentBlock,  $out)

Parameters

$importPath
$parentBlock
$out

compileImportedProps()

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

Parameters

$props
$block
$out
$sourceParser
$importDir

compileBlock()

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

compileCSSBlock()

compileCSSBlock( $block)

Parameters

$block

compileMedia()

compileMedia( $media)

Parameters

$media

mediaParent()

mediaParent( $scope)

Parameters

$scope

compileNestedBlock()

compileNestedBlock( $block,  $selectors)

Parameters

$block
$selectors

compileRoot()

compileRoot( $root)

Parameters

$root

compileProps()

compileProps( $block,  $out)

Parameters

$block
$out

sortProps()

sortProps( $props,  $split)

Parameters

$props
$split

compileMediaQuery()

compileMediaQuery( $queries)

Parameters

$queries

multiplyMedia()

multiplyMedia( $env,  $childQueries)

Parameters

$env
$childQueries

expandParentSelectors()

expandParentSelectors( $tag,  $replace)

Parameters

$tag
$replace

findClosestSelectors()

findClosestSelectors()

multiplySelectors()

multiplySelectors( $selectors)

Parameters

$selectors

compileSelectors()

compileSelectors( $selectors)

Parameters

$selectors

eq()

eq( $left,  $right)

Parameters

$left
$right

patternMatch()

patternMatch( $block,  $orderedArgs,  $keywordArgs)

Parameters

$block
$orderedArgs
$keywordArgs

patternMatchAll()

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

Parameters

$blocks
$orderedArgs
$keywordArgs
$skip

findBlocks()

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

Parameters

$searchIn
$path
$orderedArgs
$keywordArgs
$seen

zipSetArgs()

zipSetArgs( $args,  $orderedValues,  $keywordValues)

Parameters

$args
$orderedValues
$keywordValues

compileProp()

compileProp( $prop,  $block,  $out)

Parameters

$prop
$block
$out

compileValue()

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

lib_pow()

lib_pow( $args)

Parameters

$args

lib_pi()

lib_pi()

lib_mod()

lib_mod( $args)

Parameters

$args

lib_tan()

lib_tan( $num)

Parameters

$num

lib_sin()

lib_sin( $num)

Parameters

$num

lib_cos()

lib_cos( $num)

Parameters

$num

lib_atan()

lib_atan( $num)

Parameters

$num

lib_asin()

lib_asin( $num)

Parameters

$num

lib_acos()

lib_acos( $num)

Parameters

$num

lib_sqrt()

lib_sqrt( $num)

Parameters

$num

lib_extract()

lib_extract( $value)

Parameters

$value

lib_isnumber()

lib_isnumber( $value)

Parameters

$value

lib_isstring()

lib_isstring( $value)

Parameters

$value

lib_iscolor()

lib_iscolor( $value)

Parameters

$value

lib_iskeyword()

lib_iskeyword( $value)

Parameters

$value

lib_ispixel()

lib_ispixel( $value)

Parameters

$value

lib_ispercentage()

lib_ispercentage( $value)

Parameters

$value

lib_isem()

lib_isem( $value)

Parameters

$value

lib_isrem()

lib_isrem( $value)

Parameters

$value

lib_rgbahex()

lib_rgbahex( $color)

Parameters

$color

lib_argb()

lib_argb( $color)

Parameters

$color

lib_e()

lib_e( $arg)

Parameters

$arg

lib__sprintf()

lib__sprintf( $args)

Parameters

$args

lib_floor()

lib_floor( $arg)

Parameters

$arg

lib_ceil()

lib_ceil( $arg)

Parameters

$arg

lib_round()

lib_round( $arg)

Parameters

$arg

lib_unit()

lib_unit( $arg)

Parameters

$arg

colorArgs()

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

lib_darken()

lib_darken( $args)

Parameters

$args

lib_lighten()

lib_lighten( $args)

Parameters

$args

lib_saturate()

lib_saturate( $args)

Parameters

$args

lib_desaturate()

lib_desaturate( $args)

Parameters

$args

lib_spin()

lib_spin( $args)

Parameters

$args

lib_fadeout()

lib_fadeout( $args)

Parameters

$args

lib_fadein()

lib_fadein( $args)

Parameters

$args

lib_hue()

lib_hue( $color)

Parameters

$color

lib_saturation()

lib_saturation( $color)

Parameters

$color

lib_lightness()

lib_lightness( $color)

Parameters

$color

lib_alpha()

lib_alpha( $value)

Parameters

$value

lib_fade()

lib_fade( $args)

Parameters

$args

lib_percentage()

lib_percentage( $arg)

Parameters

$arg

lib_mix()

lib_mix( $args)

Parameters

$args

lib_contrast()

lib_contrast( $args)

Parameters

$args

assertColor()

assertColor( $value,  $error)

Parameters

$value
$error

assertNumber()

assertNumber( $value,  $error)

Parameters

$value
$error

assertArgs()

assertArgs( $value,  $expectedArgs,  $name)

Parameters

$value
$expectedArgs
$name

toHSL()

toHSL( $color)

Parameters

$color

toRGB_helper()

toRGB_helper( $comp,  $temp1,  $temp2)

Parameters

$comp
$temp1
$temp2

toRGB()

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

clamp()

clamp( $v,  $max,  $min)

Parameters

$v
$max
$min

funcToColor()

funcToColor( $func)

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

Parameters

$func

reduce()

reduce( $value,  $forExpression)

Parameters

$value
$forExpression

coerceColor()

coerceColor( $value)

Parameters

$value

coerceString()

coerceString( $value)

Parameters

$value

flattenList()

flattenList( $value)

Parameters

$value

toBool()

toBool( $a)

Parameters

$a

evaluate()

evaluate( $exp)

Parameters

$exp

stringConcatenate()

stringConcatenate( $left,  $right)

Parameters

$left
$right

fixColor()

fixColor( $c)

Parameters

$c

op_number_color()

op_number_color( $op,  $lft,  $rgt)

Parameters

$op
$lft
$rgt

op_color_number()

op_color_number( $op,  $lft,  $rgt)

Parameters

$op
$lft
$rgt

op_color_color()

op_color_color( $op,  $left,  $right)

Parameters

$op
$left
$right

op_number_number()

op_number_number( $op,  $left,  $right)

Parameters

$op
$left
$right

makeOutputBlock()

makeOutputBlock( $type,  $selectors)

Parameters

$type
$selectors

pushEnv()

pushEnv( $block)

Parameters

$block

popEnv()

popEnv()

set()

set( $name,  $value)

Parameters

$name
$value

get()

get( $name,  $default)

Parameters

$name
$default

injectVariables()

injectVariables( $args)

Parameters

$args

makeParser()

makeParser( $name)

Parameters

$name

newFormatter()

newFormatter()

addParsedFile()

addParsedFile( $file)

Parameters

$file

throwError()

throwError( $msg)

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

Parameters

$msg