Skip to main content

CssParser

Struct CssParser 

Source
pub struct CssParser { /* private fields */ }
Expand description

Parser for CSS files.

Implementations§

Source§

impl CssParser

Source

pub fn new() -> Self

Create a new CSS parser.

Source

pub fn parse(&mut self, css_content: &str) -> Result<WebUIFragmentRecords>

Parse CSS content and return fragments.

Source

pub fn process_css( &mut self, css_content: &str, fragments: &mut WebUIFragmentRecords, ) -> Result<()>

Process CSS content and merge it into fragments.

Source

pub fn parse_inline_css(&mut self, style_content: &str) -> Result<String>

Parse inline CSS from style tags in HTML.

Source

pub fn extract_tokens(&mut self, css_content: &str) -> Result<HashSet<String>>

Extract CSS custom property token names used via var() in the given CSS.

Returns a set of variable names (without the -- prefix) that are referenced through var(--name) calls. Variables that are only defined (e.g., --bar: 12px) in the same CSS are excluded.

Handles nested fallbacks: var(--a, var(--b, var(--c))) yields {"a", "b", "c"} because each nested var() is a separate call_expression in the tree-sitter CSS AST.

Source

pub fn extract_definitions( &mut self, css_content: &str, ) -> Result<HashSet<String>>

Extract CSS custom property definitions from the given CSS.

Returns a set of variable names (without -- prefix) that are defined via --name: value declarations. This is used to exclude application-level token definitions (e.g., from <style> in the entry HTML) from the hoisted token set.

Source

pub fn extract_tokens_and_definitions( &mut self, css_content: &str, ) -> Result<(HashSet<String>, HashSet<String>)>

Extract both token usages and definitions in a single parse.

Returns (tokens, definitions) where:

  • tokens: var() usages with locally-defined properties already excluded
  • definitions: all custom property definitions (for global filtering)

Prefer this over calling extract_tokens + extract_definitions separately on the same CSS content to avoid redundant tree-sitter parses.

Trait Implementations§

Source§

impl Debug for CssParser

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CssParser

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.