Skip to main content

Crate treesitter_types_css

Crate treesitter_types_css 

Source
Expand description

Strongly-typed AST types for CSS, auto-generated from tree-sitter-css’s node-types.json.

This crate is generated by treesitter-types and is automatically kept up to date when a new version of the grammar crate is released.

These types have been tested by parsing the Bootstrap source code.

See the Tree-sitter project for more information about the underlying parser framework.

§Example

use treesitter_types_css::*;

// A small CSS stylesheet.
let src = b"\
body {
    color: red;
    font-size: 16px;
}
";

// Parse the source with tree-sitter and convert into typed AST.
let mut parser = tree_sitter::Parser::new();
parser.set_language(&tree_sitter_css::LANGUAGE.into()).unwrap();
let tree = parser.parse(src, None).unwrap();
let stylesheet = Stylesheet::from_node(tree.root_node(), src).unwrap();

// The stylesheet has one top-level child: a rule set for `body`.
assert_eq!(stylesheet.children.len(), 1);

let StylesheetChildren::RuleSet(rule_set) = &stylesheet.children[0] else {
    panic!("expected a rule set");
};
// The rule set contains the selector and declarations.
assert!(!rule_set.children.is_empty());
assert_eq!(rule_set.span.start.row, 0);

Re-exports§

pub use tree_sitter_css;
pub use treesitter_types::tree_sitter;

Structs§

AdjacentSiblingSelector
Arguments
AtKeyword
AtRule
AttributeName
AttributeSelector
BinaryExpression
BinaryQuery
Block
CallExpression
CharsetStatement
ChildSelector
ClassName
ClassSelector
ColorValue
Comment
Declaration
DescendantSelector
EscapeSequence
FeatureName
FeatureQuery
FloatValue
From
FunctionName
GridValue
IdName
IdSelector
Identifier
ImportStatement
Important
ImportantValue
IntegerValue
JsComment
KeyframeBlock
KeyframeBlockList
KeyframesName
KeyframesStatement
KeywordQuery
MediaStatement
NamespaceName
NamespaceSelector
NamespaceStatement
NestingSelector
ParenthesizedQuery
ParenthesizedValue
PlainValue
PostcssStatement
PropertyName
PseudoClassSelector
PseudoElementSelector
RuleSet
ScopeStatement
SelectorQuery
Selectors
SiblingSelector
Span
StringContent
StringValue
Stylesheet
SupportsStatement
TagName
To
UnaryQuery
Unit
UniversalSelector

Enums§

AdjacentSiblingSelectorChildren
AnyNode
ArgumentsChildren
AtRuleChildren
AttributeNameChildren
AttributeSelectorChildren
BinaryExpressionChildren
BinaryQueryChildren
BlockChildren
CallExpressionChildren
CharsetStatementChildren
ChildSelectorChildren
ClassNameChildren
ClassSelectorChildren
DeclarationChildren
DescendantSelectorChildren
FeatureQueryChildren
GridValueChildren
IdSelectorChildren
ImportStatementChildren
KeyframeBlockChildren
KeyframesStatementChildren
MediaStatementChildren
NamespaceSelectorChildren
NamespaceStatementChildren
ParenthesizedQueryChildren
ParenthesizedValueChildren
ParseError
PostcssStatementChildren
PseudoClassSelectorChildren
PseudoElementSelectorChildren
RuleSetChildren
ScopeStatementChildren
SelectorQueryChildren
SelectorsChildren
SiblingSelectorChildren
StringValueChildren
StylesheetChildren
SupportsStatementChildren
UnaryQueryChildren

Traits§

FromNode
Every generated struct and enum implements this.
LeafNode
Implemented by every generated leaf type (identifiers, literals, etc.)
Spanned
Implemented by every generated type that has a source location.