Home / Function/ next() — tailwindcss Function Reference

next() — tailwindcss Function Reference

Architecture documentation for the next() function in css_variable_machine.rs from the tailwindcss codebase.

Entity Profile

Dependency Diagram

graph TD
  d49cd571_864c_24d7_de5c_7536b447f88b["next()"]
  268529ba_4bf9_7a41_0273_72baf0f193f0["css_variable_machine.rs"]
  d49cd571_864c_24d7_de5c_7536b447f88b -->|defined in| 268529ba_4bf9_7a41_0273_72baf0f193f0
  style d49cd571_864c_24d7_de5c_7536b447f88b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

crates/oxide/src/extractor/css_variable_machine.rs lines 21–88

    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);
                            }
                        }
                    }
                }

                Class::Escape => match cursor.next.into() {
                    // An escaped whitespace character is not allowed
                    //
                    // In CSS it is allowed, but in the context of a class it's not because then we
                    // would have spaces in the class.
                    //
                    // E.g.: `bg-(--my-\ color)`
                    //                  ^
                    Class::Whitespace => return self.restart(),

                    // An escape at the end of the class is not allowed
                    Class::End => return self.restart(),

                    // An escaped character, skip the next character, resume after
                    //
                    // E.g.: `--my-\#variable`
                    //             ^           We are here
                    //               ^         Resume here
                    _ => cursor.advance_twice(),
                },

                // Character is not valid anymore
                _ => return self.restart(),
            }
        }

        MachineState::Idle
    }

Domain

Subdomains

Frequently Asked Questions

What does next() do?
next() is a function in the tailwindcss codebase, defined in crates/oxide/src/extractor/css_variable_machine.rs.
Where is next() defined?
next() is defined in crates/oxide/src/extractor/css_variable_machine.rs at line 21.

Analyze Your Own Codebase

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

Try Supermodel Free