Home / File/ css_variable_machine.rs — tailwindcss Source File

css_variable_machine.rs — tailwindcss Source File

Architecture documentation for css_variable_machine.rs, a rust file in the tailwindcss codebase. 6 imports, 0 dependents.

File rust Oxide Extractor 6 imports 4 functions

Entity Profile

Dependency Diagram

graph LR
  4ca248f9_dfd5_e064_756a_26e6b692010c["css_variable_machine.rs"]
  3738bcff_79f7_1a66_4d92_6040bc27985d["super::CssVariableMachine"]
  4ca248f9_dfd5_e064_756a_26e6b692010c --> 3738bcff_79f7_1a66_4d92_6040bc27985d
  96a36755_a007_15e1_ec6c_526c02d24b9b["crate::cursor"]
  4ca248f9_dfd5_e064_756a_26e6b692010c --> 96a36755_a007_15e1_ec6c_526c02d24b9b
  05907c18_a40e_a5a9_c7c3_5faba98e1e87["crate::extractor::machine::"]
  4ca248f9_dfd5_e064_756a_26e6b692010c --> 05907c18_a40e_a5a9_c7c3_5faba98e1e87
  7a907858_c7d2_db19_0e89_e3d1d2242e48["classification_macros::ClassifyBytes"]
  4ca248f9_dfd5_e064_756a_26e6b692010c --> 7a907858_c7d2_db19_0e89_e3d1d2242e48
  4d153f79_f78b_b66c_1e8a_11a0eb99bd41["crate::extractor::machine::Machine"]
  4ca248f9_dfd5_e064_756a_26e6b692010c --> 4d153f79_f78b_b66c_1e8a_11a0eb99bd41
  433675ca_8d0e_feff_42a5_b3f666878cca["pretty_assertions::assert_eq"]
  4ca248f9_dfd5_e064_756a_26e6b692010c --> 433675ca_8d0e_feff_42a5_b3f666878cca
  style 4ca248f9_dfd5_e064_756a_26e6b692010c fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

use crate::cursor;
use crate::extractor::machine::{Machine, MachineState};
use classification_macros::ClassifyBytes;

/// Extract CSS variables from an input.
///
/// E.g.:
///
/// ```text
/// var(--my-variable)
///     ^^^^^^^^^^^^^
/// ```
#[derive(Debug, Default)]
pub struct CssVariableMachine;

impl Machine for CssVariableMachine {
    #[inline(always)]
    fn reset(&mut self) {}

    #[inline]
    fn next(&mut self, cursor: &mut cursor::Cursor<'_>) -> MachineState {
        // CSS Variables must start with `--`
        if Class::Dash != cursor.curr.into() || Class::Dash != cursor.next.into() {
            return MachineState::Idle;
        }

        let start_pos = cursor.pos;
        let len = cursor.input.len();

        cursor.advance_twice();

        while cursor.pos < len {
            match cursor.curr.into() {
                // https://drafts.csswg.org/css-syntax-3/#ident-token-diagram
                //
                Class::AllowedCharacter | Class::Dash => {
                    match cursor.next.into() {
                        // Valid character followed by a valid character or an escape character
                        //
                        // E.g.: `--my-variable`
                        //                ^^
                        // E.g.: `--my-\#variable`
                        //            ^^
                        Class::AllowedCharacter | Class::Dash | Class::Escape => cursor.advance(),

                        // Valid character followed by anything else means the variable is done
                        //
                        // E.g.: `'--my-variable'`
                        //                      ^
                        _ => {
                            // There must be at least 1 character after the `--`
                            if cursor.pos - start_pos < 2 {
                                return self.restart();
                            } else {
                                return self.done(start_pos, cursor);
                            }
                        }
                    }
                }

// ... (155 more lines)

Domain

Subdomains

Dependencies

  • classification_macros::ClassifyBytes
  • crate::cursor
  • crate::extractor::machine::
  • crate::extractor::machine::Machine
  • pretty_assertions::assert_eq
  • super::CssVariableMachine

Frequently Asked Questions

What does css_variable_machine.rs do?
css_variable_machine.rs is a source file in the tailwindcss codebase, written in rust. It belongs to the Oxide domain, Extractor subdomain.
What functions are defined in css_variable_machine.rs?
css_variable_machine.rs defines 4 function(s): next, reset, test_css_variable_machine_extraction, test_css_variable_machine_performance.
What does css_variable_machine.rs depend on?
css_variable_machine.rs imports 6 module(s): classification_macros::ClassifyBytes, crate::cursor, crate::extractor::machine::, crate::extractor::machine::Machine, pretty_assertions::assert_eq, super::CssVariableMachine.
Where is css_variable_machine.rs in the architecture?
css_variable_machine.rs is located at crates/oxide/src/extractor/css_variable_machine.rs (domain: Oxide, subdomain: Extractor, directory: crates/oxide/src/extractor).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free