UNPKG

rawsql-ts

Version:

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

30 lines 1.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.UnaryExpressionParser = void 0; const Lexeme_1 = require("../models/Lexeme"); const ValueComponent_1 = require("../models/ValueComponent"); const ValueParser_1 = require("./ValueParser"); class UnaryExpressionParser { static parseFromLexeme(lexemes, index) { let idx = index; // Process unary operator if (idx < lexemes.length && (lexemes[idx].type & Lexeme_1.TokenType.Operator)) { const operator = lexemes[idx].value; idx++; // Treat the asterisk as an Identifier, not as a unary operator if (operator === '*') { const v = new ValueComponent_1.ColumnReference(null, '*'); return { value: v, newIndex: idx }; } // Get the right-hand side value of the unary operator const result = ValueParser_1.ValueParser.parseFromLexeme(lexemes, idx); idx = result.newIndex; // Create unary expression const value = new ValueComponent_1.UnaryExpression(operator, result.value); return { value, newIndex: idx }; } throw new Error(`Invalid unary expression at index ${index}: ${lexemes[index].value}`); } } exports.UnaryExpressionParser = UnaryExpressionParser; //# sourceMappingURL=UnaryExpressionParser.js.map