rawsql-ts
Version:
[beta]High-performance SQL parser and AST analyzer written in TypeScript. Provides fast parsing and advanced transformation capabilities.
33 lines • 1.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.UsingClauseParser = void 0;
const Clause_1 = require("../models/Clause");
const Lexeme_1 = require("../models/Lexeme");
const SourceExpressionParser_1 = require("./SourceExpressionParser");
/**
* Parses the USING clause in DELETE statements.
*/
class UsingClauseParser {
static parseFromLexeme(lexemes, index) {
var _a;
if (lexemes[index].value !== "using") {
throw new Error(`Syntax error at position ${index}: Expected 'USING' but found '${lexemes[index].value}'.`);
}
let idx = index + 1;
const sources = [];
// Parse the first source expression referenced by USING.
const firstSource = SourceExpressionParser_1.SourceExpressionParser.parseFromLexeme(lexemes, idx);
sources.push(firstSource.value);
idx = firstSource.newIndex;
// Parse any additional sources separated by commas.
while (((_a = lexemes[idx]) === null || _a === void 0 ? void 0 : _a.type) === Lexeme_1.TokenType.Comma) {
idx++;
const nextSource = SourceExpressionParser_1.SourceExpressionParser.parseFromLexeme(lexemes, idx);
sources.push(nextSource.value);
idx = nextSource.newIndex;
}
return { value: new Clause_1.UsingClause(sources), newIndex: idx };
}
}
exports.UsingClauseParser = UsingClauseParser;
//# sourceMappingURL=UsingClauseParser.js.map