rawsql-ts
Version:
[beta]High-performance SQL parser and AST analyzer written in TypeScript. Provides fast parsing and advanced transformation capabilities.
21 lines • 994 B
JavaScript
import { TokenType } from "../models/Lexeme";
export class ParseError extends Error {
constructor(message, index, context) {
super(message);
this.index = index;
this.context = context;
this.name = "ParseError";
}
static fromUnparsedLexemes(lexemes, index, messagePrefix) {
const start = Math.max(0, index - 2);
const end = Math.min(lexemes.length, index + 3);
const context = lexemes.slice(start, end).map((lexeme, idx) => {
const marker = idx + start === index ? '>' : ' ';
const typeName = TokenType[lexeme.type] || lexeme.type; // Convert type to name if possible
return `${marker} ${idx + start}:${lexeme.value} [${typeName}]`;
}).join('\n');
const message = `${messagePrefix} Unparsed lexeme remains at index ${index}: ${lexemes[index].value}\nContext:\n${context}`;
return new ParseError(message, index, context);
}
}
//# sourceMappingURL=ParseError.js.map