UNPKG

rawsql-ts

Version:

High-performance SQL parser and AST analyzer written in TypeScript. Provides fast parsing and advanced transformation capabilities.

74 lines 1.98 kB
/** * Manages and coordinates multiple token readers */ export class TokenReaderManager { constructor(input, position = 0) { this.input = input; this.position = position; this.readers = []; } /** * Register a token reader * @param reader The reader to register * @returns This manager instance for chaining */ register(reader) { this.readers.push(reader); return this; } /** * Register multiple token readers * @param readers The readers to register * @returns This manager instance for chaining */ registerAll(readers) { for (let i = 0; i < readers.length; i++) { this.readers.push(readers[i]); } return this; } /** * Try to read a token using all registered readers * @param position The position to read from * @param previous The previous token, if any * @returns The lexeme if a reader could read it, null otherwise */ tryRead(position, previous) { this.position = position; const readers = this.readers; // Index-based iteration avoids iterator allocations in the hottest parse loop. for (let i = 0; i < readers.length; i++) { const reader = readers[i]; reader.setPosition(position); const lexeme = reader.tryRead(previous); if (lexeme) { this.position = reader.getPosition(); return lexeme; } } return null; } /** * Get the maximum position among all readers */ getMaxPosition() { return this.position; } /** * Get the input string */ getInput() { return this.input; } /** * Get cache statistics */ getCacheStats() { return { hits: 0, misses: 0, ratio: 0 }; } } //# sourceMappingURL=TokenReaderManager.js.map