Skip to main content

Module token_kinds

Module token_kinds 

Source
Expand description

Token kinds, ported from include/hermes/Parser/TokenKinds.def.

Every variant appears in the EXACT order of TokenKinds.def so that ord(kind) == kind as u16 and the range-marker predicates stay plain integer comparisons — identical to the C++ lexer.

Enums§

TokenKind
JavaScript token kinds.

Constants§

NUM_JS_TOKENS
Number of token kinds = ord(_last_token) + 1.

Functions§

binop_precedence
\return the binary-operator precedence of kind, or None if not a binary op.
match_reserved_word
Recognise a reserved word by its bytes (mirrors matchReservedWord in JSLexer.cpp). Returns TokenKind::identifier if bytes is not a reserved word. Pure: no strict-mode filtering (that lives in lexer-core’s scanReservedWord).
ord
\return the integer ordinal of kind (matches C++ ord).
token_kind_str
\return the human-readable name of kind (matches C++ tokenKindStr).
token_kind_str_by_ord
\return the human-readable name for the token kind with the given ordinal. Used by the lexer to pre-intern reserved words by ordinal without needing to reconstruct a TokenKind value (which would require an unsafe transmute).
variant_name
\return the .def variant name of kind (e.g. l_brace, eof), matching the C++ tokenVariantName switch used by js-lexer-dump.