{"version":3,"sources":["../../../src/parser/tokenizer/tokens.ts"],"sourcesContent":["import Decimal from '../../core/decimal/decimal';\r\nimport { Position } from '../../core/positions';\r\nimport PositionRange from \"../../core/positions\";\r\nimport IOError from '../../errors/io-error';\r\nimport TokenType from './token-types';\r\n\r\n/**\r\n * Represents the error value stored in ERROR tokens.\r\n * When the originalError is an IOError, errorCode will be available.\r\n */\r\nexport interface TokenErrorValue {\r\n  __error: true;\r\n  errorCode?: string;       // Error code from IOError (e.g., 'string-not-closed')\r\n  message: string;\r\n  originalError: Error;\r\n}\r\n\r\n/**\r\n * Type guard to check if an error is an IOError with an errorCode\r\n */\r\nexport function isIOError(error: Error): error is IOError {\r\n  return error instanceof IOError || 'errorCode' in error;\r\n}\r\n\r\n/**\r\n * Union type representing all possible token values.\r\n * This provides type safety for the parsed value of each token type.\r\n */\r\nexport type TokenValue =\r\n  | string                  // STRING, OPEN_STRING, RAW_STRING, symbols\r\n  | number                  // NUMBER (includes Infinity, NaN)\r\n  | bigint                  // BIGINT\r\n  | Decimal                 // DECIMAL\r\n  | boolean                 // BOOLEAN\r\n  | null                    // NULL\r\n  | Date                    // DATETIME, DATE, TIME\r\n  | Buffer                  // BINARY\r\n  | TokenErrorValue         // ERROR\r\n  | undefined;              // UNDEFINED\r\n\r\n/**\r\n * String literal type for token subtypes.\r\n */\r\nexport type TokenSubType =\r\n  | 'REGULAR_STRING'\r\n  | 'OPEN_STRING'\r\n  | 'RAW_STRING'\r\n  | 'BINARY_STRING'\r\n  | 'HEX'\r\n  | 'OCTAL'\r\n  | 'BINARY'\r\n  | typeof TokenType.DATETIME\r\n  | typeof TokenType.DATE\r\n  | typeof TokenType.TIME\r\n  | typeof TokenType.SECTION_SCHEMA\r\n  | typeof TokenType.SECTION_NAME\r\n  | undefined;\r\n\r\n/**\r\n* Represents a parsed token.\r\n*/\r\nclass Token implements PositionRange {\r\n  pos: number;\r\n  row: number;\r\n  col: number;\r\n  token: string;\r\n  value: TokenValue;\r\n  type: TokenType | string;\r\n  subType?: TokenSubType | string;\r\n\r\n  constructor() {\r\n    this.pos = -1;\r\n    this.row = -1;\r\n    this.col = -1;\r\n    this.token = '';\r\n    this.value = undefined;\r\n    this.type = '';\r\n    this.subType = '';\r\n  }\r\n\r\n  /**\r\n   * Create a token.\r\n   * @param pos - The starting position of the token in the input.\r\n   * @param row - The row number of the token's starting position.\r\n   * @param col - The column number of the token's starting position.\r\n   * @param token - The raw text of the token from the input.\r\n   * @param value - The parsed value of the token.\r\n   * @param type - A descriptive type name for the token.\r\n   * @param subType - Optional subtype for the token.\r\n   */\r\n  static init(pos: number, row: number, col: number, token: string, value: TokenValue, type: TokenType | string, subType?: TokenSubType | string): Token {\r\n    const t = new Token()\r\n    t.pos = pos;\r\n    t.row = row;\r\n    t.col = col;\r\n    t.token = token;\r\n    t.value = value;\r\n    t.type = type;\r\n\r\n    if (subType) {\r\n      t.subType = subType;\r\n    }\r\n\r\n    return t;\r\n  }\r\n\r\n  clone(): Token {\r\n    const t = new Token();\r\n    t.pos = this.pos;\r\n    t.row = this.row;\r\n    t.col = this.col;\r\n    t.token = this.token;\r\n    t.value = this.value;\r\n    t.type = this.type;\r\n    t.subType = this.subType;\r\n    return t;\r\n  }\r\n\r\n  getStartPos(): Position {\r\n    return { row: this.row, col: this.col, pos: this.pos };\r\n  }\r\n\r\n  /**\r\n   * Returns the ending position (row, col, pos) of the token.\r\n   * Useful for debugging and generating error messages.\r\n   */\r\n  getEndPos(): Position {\r\n    const text      = this.token.trimEnd();\r\n    const lines     = text.split('\\n');\r\n    const lastLine  = lines[lines.length - 1];\r\n\r\n    const row = this.row + lines.length - 1;\r\n    const col = lines.length > 1 ? lastLine.length : this.col + lastLine.length;\r\n    const pos = this.pos + text.length;\r\n\r\n    return { row, col, pos };\r\n  }\r\n}\r\n\r\n\r\nexport default Token;"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,sBAAoB;AAiBb,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