Skip to main content

Module lex

Module lex 

Source
Expand description

The lexer: the single cssToken matcher the plugin installs on the engine, and the scanners it reads spans with.

CSS is context-sensitive — the same characters can begin a selector, a property or a value — so the matcher owns the hard tokenisation and the grammar only assembles typed nodes from what it emits. Which token comes out depends on the rule that is active when the character is read: the engine reads a token only when the alternate being tried needs one, under the rule trying it, and passes that rule to the matcher.

See ts/src/css.ts for the canonical commentary; the three ports are kept in step, and this module follows buildCssTokenMatcher there line for line.

Structs§

Error
A parse failure.

Enums§

Tin
A token kind.

Functions§

es_is_whitespace
Whether c is whitespace as ECMAScript defines it, which is NOT what char::is_whitespace answers.
es_trim
Trim as JavaScript’s String.prototype.trim does. See es_is_whitespace for why this is not str::trim.
split_selectors
Split a selector-group prelude on its top-level commas (commas inside strings, () or [] are part of a single selector), stripping comments and trimming each selector. An empty prelude yields an empty list.
strip_comments
Remove /* ... */ comments from a selector or value run, leaving quoted strings (which may contain /*) untouched.
vendor_prefix
^(-[a-z]+-): a vendor prefix on an at-keyword, e.g. -webkit-keyframes.