rawsql-ts
Version:
[beta]High-performance SQL parser and AST analyzer written in TypeScript. Provides fast parsing and advanced transformation capabilities.
31 lines • 1.43 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.StringSpecifierTokenReader = void 0;
const Lexeme_1 = require("../models/Lexeme");
const BaseTokenReader_1 = require("./BaseTokenReader");
// Prefix sets for quick checks
const STRING_SPECIFIERS = new Set(['e\'', 'E\'', 'x\'', 'X\'', 'b\'', 'B\'']);
const UNICODE_STRING_SPECIFIERS = new Set(['u&\'', 'U&\'']);
class StringSpecifierTokenReader extends BaseTokenReader_1.BaseTokenReader {
/**
* Try to read an escaped literal like e'...', x'...', etc.
*/
tryRead(previous) {
const start = this.position;
// Check for prefixed literals: e', x', b'
if (this.canRead(1) && STRING_SPECIFIERS.has(this.input.slice(start, start + 2))) {
this.position += 1;
const result = this.createLexeme(Lexeme_1.TokenType.StringSpecifier, this.input.slice(start, this.position));
return result;
}
// Check for unicode literal: u&'
if (this.canRead(2) && UNICODE_STRING_SPECIFIERS.has(this.input.slice(start, start + 3))) {
this.position += 2;
const result = this.createLexeme(Lexeme_1.TokenType.StringSpecifier, this.input.slice(start, this.position));
return result;
}
return null;
}
}
exports.StringSpecifierTokenReader = StringSpecifierTokenReader;
//# sourceMappingURL=StringSpecifierTokenReader.js.map