//! Keyword classification.
//!
//! Maps an identifier slice to a reserved-word [`TokenKind`], or returns
//! `None` if the slice is a plain identifier.  Contextual identifiers
//! (`of`, `as`, `from`, `async`, `get`, `set`, `target`, `meta`, `static`
//! outside class bodies) are lexed as [`TokenKind::Identifier`]; the
//! parser disambiguates them by syntactic position.

use crate::token::TokenKind;

/// Classify `bytes` as a reserved keyword, returning the keyword token kind
/// if it matches.  Returns `None` when `bytes` is a plain identifier.
#[must_use]
pub fn classify(bytes: &[u8]) -> Option<TokenKind> {
    match bytes {
        b"await" => Some(TokenKind::KwAwait),
        b"break" => Some(TokenKind::KwBreak),
        b"case" => Some(TokenKind::KwCase),
        b"catch" => Some(TokenKind::KwCatch),
        b"class" => Some(TokenKind::KwClass),
        b"const" => Some(TokenKind::KwConst),
        b"continue" => Some(TokenKind::KwContinue),
        b"debugger" => Some(TokenKind::KwDebugger),
        b"default" => Some(TokenKind::KwDefault),
        b"delete" => Some(TokenKind::KwDelete),
        b"do" => Some(TokenKind::KwDo),
        b"else" => Some(TokenKind::KwElse),
        b"enum" => Some(TokenKind::KwEnum),
        b"export" => Some(TokenKind::KwExport),
        b"extends" => Some(TokenKind::KwExtends),
        b"false" => Some(TokenKind::KwFalse),
        b"finally" => Some(TokenKind::KwFinally),
        b"for" => Some(TokenKind::KwFor),
        b"function" => Some(TokenKind::KwFunction),
        b"if" => Some(TokenKind::KwIf),
        b"implements" => Some(TokenKind::KwImplements),
        b"import" => Some(TokenKind::KwImport),
        b"in" => Some(TokenKind::KwIn),
        b"instanceof" => Some(TokenKind::KwInstanceof),
        b"interface" => Some(TokenKind::KwInterface),
        b"let" => Some(TokenKind::KwLet),
        b"new" => Some(TokenKind::KwNew),
        b"null" => Some(TokenKind::KwNull),
        b"package" => Some(TokenKind::KwPackage),
        b"private" => Some(TokenKind::KwPrivate),
        b"protected" => Some(TokenKind::KwProtected),
        b"public" => Some(TokenKind::KwPublic),
        b"return" => Some(TokenKind::KwReturn),
        b"static" => Some(TokenKind::KwStatic),
        b"super" => Some(TokenKind::KwSuper),
        b"switch" => Some(TokenKind::KwSwitch),
        b"this" => Some(TokenKind::KwThis),
        b"throw" => Some(TokenKind::KwThrow),
        b"true" => Some(TokenKind::KwTrue),
        b"try" => Some(TokenKind::KwTry),
        b"typeof" => Some(TokenKind::KwTypeof),
        b"var" => Some(TokenKind::KwVar),
        b"void" => Some(TokenKind::KwVoid),
        b"while" => Some(TokenKind::KwWhile),
        b"with" => Some(TokenKind::KwWith),
        b"yield" => Some(TokenKind::KwYield),
        _other => None,
    }
}
