Parser class

A relatively straight-forward predictive parser. There is no tokenization/lexing stage, the input is parsed in one sweep.

To make the parser fast enough to run in the browser, several optimization had to be made:

  • Matching and slicing on a huge input is often cause of slowdowns. The solution is to chunkify the input into smaller strings. The chunks are stored in the chunks var, j holds the current chunk index, and currentPos holds the index of the current chunk in relation to input. This gives us an almost 4x speed-up.

  • In many cases, we don't need to match individual tokens; for example, if a value doesn't hold any variables, operations or dynamic references, the parser can effectively 'skip' it, treating it as a literal. An example would be '1px solid #000' - which evaluates to itself, we don't need to know what the individual components are. The drawback, of course is that you don't get the benefits of syntax-checking on the CSS. This gives us a 50% speed-up in the parser, and a smaller speed-up in the code-gen.

Token matching is done with the $ function, which either takes a terminal string or regexp, or a non-terminal function to call. It also takes care of moving all the indices forwards.

Constructors

Parser(LessOptions options)
Normal Parser constructor, with less options
Parser.fromImporter(Contexts context, ImportManager imports, FileInfo fileInfo)
Parser constructor used in @import process

Properties

Text to insert as header
read / write
context Contexts
Environment variables
read / write
fileInfo FileInfo
Data about the file being parsed
read / write
globalVars ↔ String
Less variables to define at the file start
read / write
imports ↔ ImportManager
Data to process @import directives
read / write
modifyVars ↔ String
Less variables to define at the end of file
read / write
parsers Parsers
To reference other Parsers functions
read / write
preText ↔ String
Banner and glovalVars mix
read / write
hashCode → int
The hash code for this object.
read-only, inherited
runtimeType → Type
A representation of the runtime type of the object.
read-only, inherited

Methods

parse(String str) → Future<Ruleset>
Parse an input string into an abstract syntax tree. [...]
serializeVars(List<VariableDefinition> vars) → String
Transform the vars list to a string format to be included in the less file. Such as: [...]
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
inherited
toString() → String
Returns a string representation of this object.
inherited

Operators

operator ==(dynamic other) → bool
The equality operator.
inherited