lexer_css.ts

Hand-written CSS lexer.

Emits: comment, atrule (a container wrapping rule + prelude), rule, selector, string, property, important, function, url (a container), keyword (and/not/only/or inside at-rule preludes), and punctuation.

Structure is decided by a brace-context lookahead: from each item, the first top-level {, ;, or } (skipping strings, comments, (), and []) says whether the item is a qualified rule (its prelude is a selector) or a declaration (property : value). Because that decision is purely local, the flat main loop nests to any depth, so native CSS nesting works for free.

Values (declaration right-hand sides and at-rule preludes) are tokenized sparsely: only strings, url(), functions, !important, and property-before-colon are tokenized; numbers, colors, units, and bare identifiers stay plain text.

Resilience: unterminated strings extend to end of line; unterminated comments and blocks extend to end of window.

view source

Declarations
#

lexer_css
#

lexer_css.ts view source

SyntaxLang import {lexer_css} from '@fuzdev/fuz_code/lexer_css.js';

The CSS language registration for the lexer engine.

Depends on
#

Imported by
#