What is @lezer/css?
@lezer/css is a parser for CSS written using the Lezer parser system. It provides a way to parse CSS code into a syntax tree, which can be useful for syntax highlighting, code analysis, and other tooling purposes.
What are @lezer/css's main functionalities?
Parsing CSS
This feature allows you to parse a CSS string into a syntax tree. The code sample demonstrates how to use the parser to convert a CSS string into a tree structure.
const {parser} = require('@lezer/css');
const input = 'body { color: red; }';
const tree = parser.parse(input);
console.log(tree.toString());
Syntax Tree Traversal
This feature allows you to traverse the syntax tree generated by the parser. The code sample shows how to use a TreeCursor to iterate over the nodes in the syntax tree.
const {parser} = require('@lezer/css');
const {TreeCursor} = require('@lezer/common');
const input = 'body { color: red; }';
const tree = parser.parse(input);
let cursor = tree.cursor();
do {
console.log(cursor.node.type.name);
} while (cursor.next());
Other packages similar to @lezer/css
postcss
PostCSS is a tool for transforming CSS with JavaScript plugins. It provides a way to parse CSS into an Abstract Syntax Tree (AST), which can then be manipulated and transformed. Compared to @lezer/css, PostCSS is more focused on transforming and processing CSS rather than just parsing it.
css-tree
CSSTree is a tool for working with CSS, including parsing, generating, and analyzing CSS code. It provides a detailed AST and various utilities for manipulating CSS. CSSTree offers more comprehensive features for CSS analysis and transformation compared to @lezer/css.
stylelint
Stylelint is a modern linter that helps you avoid errors and enforce conventions in your styles. While it also parses CSS, its primary focus is on linting and enforcing coding standards, which is different from the primary parsing focus of @lezer/css.
1.1.2 (2023-05-15)
Bug fixes
Make keyframe selector parsing more flexible to support timeline ranges.
Allow multiple comma-separated keyframe selectors per keyframe.