All files / src/tokenizer token-kind.ts

100% Statements 57/57
100% Branches 2/2
100% Functions 1/1
100% Lines 56/56

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97                                25x   25x 25x 25x 25x 25x 25x 25x 25x     25x     25x 25x 25x 25x 25x 25x 25x 25x   25x 25x     25x 25x 25x 25x 25x 25x     25x 25x 25x     25x     25x 25x 25x     25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x     25x 25x 25x 25x     25x     25x 25x   25x    
/**
 * TokenKind — simplified enum paralleling Spring TokenKind
 *
 * Each token type has one value in this enum.
 * Note: some semantics (e.g. isKeyword) are determined in the Token class directly.
 *
 * Every member carries an explicit ordinal. The enum is published, and TypeScript
 * compiles a numeric enum into a runtime object with a reverse map, so the ordinals
 * are part of the shipped ABI: a consumer that stores one, or reads `TokenKind[14]`,
 * observes them. A member declared without a value takes "one more than the previous
 * member", which silently renumbers every member after it — adding `DIV` among the
 * operators did exactly that, moving `MOD` from 14 to 15 and `EOF` from 53 to 54
 * between the published 1.2.2 and the 2.0.0 candidate. The values are therefore
 * written out, and `tests/unit/token-kind-stability.test.ts` pins the whole table so
 * that a future insertion cannot renumber the enum again.
 */
export enum TokenKind {
  // Literals
  LITERAL_INT = 0,
  LITERAL_LONG = 1,
  LITERAL_FLOAT = 2,
  LITERAL_DOUBLE = 3,
  LITERAL_HEX = 4,
  LITERAL_STRING = 5,
  LITERAL_BOOLEAN = 6,
  LITERAL_NULL = 7,
 
  // Identifiers
  IDENTIFIER = 8,
 
  // Operators
  PLUS = 9, // +
  MINUS = 10, // -
  STAR = 11, // *
  SLASH = 12, // /
  PERCENT = 13, // %
  DIV = 14, // div (textual form, listed in Spring's ALTERNATIVE_OPERATOR_NAMES)
  MOD = 15, // mod
  POWER = 16, // ^ or **
 
  INC = 17, // ++
  DEC = 18, // --
 
  // Comparison/Relational
  EQ = 19, // == or eq
  NE = 20, // != or ne
  LT = 21, // < or lt
  LE = 22, // <= or le
  GT = 23, // > or gt
  GE = 24, // >= or ge
 
  // Logical
  AND = 25, // && or and
  OR = 26, // || or or
  NOT = 27, // ! or not
 
  // Assignment
  ASSIGN = 28, // =
 
  // Special operators
  MATCHES = 29, // matches
  BETWEEN = 30, // between
  INSTANCEOF = 31, // instanceof
 
  // Delimiters
  LPAREN = 32, // (
  RPAREN = 33, // )
  LBRACKET = 34, // [
  RBRACKET = 35, // ]
  LBRACE = 36, // {
  RBRACE = 37, // }
  COMMA = 38, // ,
  COLON = 39, // :
  DOT = 40, // .
  SAFE_NAV = 41, // ?.
  QMARK = 42, // ?
  ELVIS = 43, // ?:
  HASH = 44, // #
  AT = 45, // @
  AMP_AT = 46, // &@
 
  // Projection/Selection
  PROJECTION = 47, // .![
  SELECTION = 48, // .?[
  SELECT_FIRST = 49, // .$[ or .^[
  SELECT_LAST = 50, // .*[
 
  // Type reference
  TYPE_START = 51, // T( (internal use)
 
  // Control
  NEW = 52, // new
  DOTDOT = 53, // .. (reserved)
 
  EOF = 54,
}