UNPKG

rawsql-ts

Version:

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

37 lines 2.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DeleteClauseParser = void 0; const Clause_1 = require("../models/Clause"); const SourceExpressionParser_1 = require("./SourceExpressionParser"); const LexemeCommentUtils_1 = require("./utils/LexemeCommentUtils"); /** * Parses the target section of a DELETE statement ("DELETE FROM ..."). */ class DeleteClauseParser { static parseFromLexeme(lexemes, index) { var _a, _b, _c, _d, _e; if (index >= lexemes.length) { throw new Error(`[DeleteClauseParser] Unexpected end of input at position ${index}: expected 'DELETE FROM'.`); } const deleteToken = lexemes[index]; const tokenValue = (_a = deleteToken === null || deleteToken === void 0 ? void 0 : deleteToken.value) === null || _a === void 0 ? void 0 : _a.toLowerCase(); if (tokenValue !== "delete from") { const position = (_d = (_c = (_b = lexemes[index]) === null || _b === void 0 ? void 0 : _b.position) === null || _c === void 0 ? void 0 : _c.startPosition) !== null && _d !== void 0 ? _d : index; throw new Error(`[DeleteClauseParser] Syntax error at position ${position}: expected 'DELETE FROM' but found '${(_e = lexemes[index]) === null || _e === void 0 ? void 0 : _e.value}'.`); } const deleteTokenComments = (0, LexemeCommentUtils_1.extractLexemeComments)(deleteToken); // Skip past the DELETE FROM keyword token so we can parse the target source. const targetResult = SourceExpressionParser_1.SourceExpressionParser.parseFromLexeme(lexemes, index + 1); const deleteClause = new Clause_1.DeleteClause(targetResult.value); // Attach positioned comments captured from the DELETE keyword to the clause. if (deleteTokenComments.before.length > 0) { deleteClause.addPositionedComments("before", deleteTokenComments.before); } if (deleteTokenComments.after.length > 0) { deleteClause.addPositionedComments("after", deleteTokenComments.after); } return { value: deleteClause, newIndex: targetResult.newIndex }; } } exports.DeleteClauseParser = DeleteClauseParser; //# sourceMappingURL=DeleteClauseParser.js.map