rawsql-ts
Version:
[beta]High-performance SQL parser and AST analyzer written in TypeScript. Provides fast parsing and advanced transformation capabilities.
61 lines (60 loc) • 2.62 kB
TypeScript
import { Lexeme } from "../models/Lexeme";
import { ValueComponent, TypeValue } from "../models/ValueComponent";
export declare class FunctionExpressionParser {
/**
* Aggregate functions that support internal ORDER BY clause
*/
private static readonly AGGREGATE_FUNCTIONS_WITH_ORDER_BY;
/**
* Parse ARRAY expressions - handles both ARRAY[...] (literal) and ARRAY(...) (query) syntax
* @param lexemes Array of lexemes to parse
* @param index Current parsing index
* @returns Parsed array expression and new index
*/
private static parseArrayExpression;
static parseFromLexeme(lexemes: Lexeme[], index: number): {
value: ValueComponent;
newIndex: number;
};
static tryParseBinaryExpression(lexemes: Lexeme[], index: number, left: ValueComponent, allowAndOperator?: boolean, allowOrOperator?: boolean): {
value: ValueComponent;
newIndex: number;
} | null;
static parseBetweenExpression(lexemes: Lexeme[], index: number, value: ValueComponent, negated: boolean): {
value: ValueComponent;
newIndex: number;
};
/**
* Parse the upper bound of a BETWEEN expression with logical operator precedence
* This stops parsing when it encounters AND/OR operators at the same level
*/
private static parseBetweenUpperBound;
private static parseFunctionCall;
private static parseKeywordFunction;
static parseTypeValue(lexemes: Lexeme[], index: number): {
value: TypeValue;
newIndex: number;
};
/**
* Parse WITHIN GROUP (ORDER BY ...) clause
* @param lexemes Array of lexemes to parse
* @param index Current parsing index (should point to "WITHIN GROUP")
* @returns Parsed OrderByClause and new index
*/
private static parseWithinGroupClause;
/**
* Parse arguments for aggregate functions that support internal ORDER BY
* Handles patterns like: string_agg(expr, separator ORDER BY sort_expr)
* @param lexemes Array of lexemes to parse
* @param index Current parsing index (should point to opening parenthesis)
* @returns Parsed arguments, ORDER BY clause, closing parenthesis comments, and new index
*/
private static parseAggregateArguments;
/**
* Parse function arguments and capture closing parenthesis comments
* @param lexemes Array of lexemes to parse
* @param index Current parsing index (should point to opening parenthesis)
* @returns Parsed arguments, closing parenthesis comments, and new index
*/
private static parseArgumentWithComments;
}