oak-cmd 0.0.11

High-performance incremental Windows Command (CMD) parser for the oak ecosystem with flexible configuration, supporting shell scripting and automation workflows.
Documentation
use oak_core::UniversalTokenRole;

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(u16)]
/// Represents all possible token kinds in the Windows Command (CMD) scripting language.
pub enum CmdTokenType {
    /// Whitespace characters
    Whitespace,
    /// Newline characters
    Newline,
    /// Comments (starting with REM or ::)
    Comment,
    /// String literals
    StringLiteral,
    /// Variable references (e.g., %VAR%)
    Variable,
    /// Numeric literals
    NumberLiteral,
    /// Identifiers
    Identifier,
    /// CMD keywords (IF, FOR, SET, etc.)
    Keyword,
    /// Operators (==, EQU, NEQ, etc.)
    Operator,
    /// Delimiters
    Delimiter,
    /// Command names
    Command,
    /// Labels (starting with :)
    Label,
    /// Plain text content
    Text,
    /// Error token
    Error,
    /// End of file marker
    Eof,
}

impl oak_core::TokenType for CmdTokenType {
    const END_OF_STREAM: Self = Self::Eof;
    type Role = UniversalTokenRole;

    fn is_ignored(&self) -> bool {
        matches!(self, Self::Whitespace | Self::Newline | Self::Comment)
    }

    fn is_comment(&self) -> bool {
        matches!(self, Self::Comment)
    }

    fn is_whitespace(&self) -> bool {
        matches!(self, Self::Whitespace | Self::Newline)
    }

    fn role(&self) -> Self::Role {
        match self {
            Self::Whitespace | Self::Newline => UniversalTokenRole::Whitespace,
            Self::Comment => UniversalTokenRole::Comment,
            Self::Keyword => UniversalTokenRole::Keyword,
            Self::Identifier | Self::Variable | Self::Command | Self::Label => UniversalTokenRole::Name,
            Self::StringLiteral | Self::NumberLiteral => UniversalTokenRole::Literal,
            Self::Operator => UniversalTokenRole::Operator,
            Self::Delimiter => UniversalTokenRole::Punctuation,
            Self::Eof => UniversalTokenRole::Eof,
            Self::Error => UniversalTokenRole::Error,
            _ => UniversalTokenRole::None,
        }
    }
}