rawsql-ts
Version:
[beta]High-performance SQL parser and AST analyzer written in TypeScript. Provides fast parsing and advanced transformation capabilities.
52 lines (51 loc) • 1.96 kB
TypeScript
import { BaseTokenReader } from './BaseTokenReader';
import { Lexeme } from '../models/Lexeme';
import { KeywordParser } from '../parsers/KeywordParser';
export declare const literalKeywordParser: KeywordParser;
export declare class LiteralTokenReader extends BaseTokenReader {
/**
* Try to read a literal token
*/
tryRead(previous: Lexeme | null): Lexeme | null;
private tryReadKeyword;
/**
* Determines if the current context treats '+' or '-' as a numeric sign or an operator.
* This method is used to differentiate between operators and numeric signs (e.g., '+' or '-').
*
* For example:
* - In `1-1`, the '-' is treated as an operator, so the expression is split into `1`, `-`, and `1`.
* - In `-1`, the '-' is treated as a sign, making `-1` a single, indivisible literal.
*
* The logic for determining whether '+' or '-' is a sign or an operator is as follows:
* - If there is no previous lexeme, it is considered the start of the input, so the sign is valid.
* - If the previous lexeme is a literal, identifier, parameter, or closing parenthesis, the sign is treated as an operator.
*
* @param previous The previous lexeme in the input stream.
* @returns "sign" if the context allows for a numeric sign, otherwise "operator".
*/
private determineSignOrOperator;
/**
* Read a numeric value
*/
private readDigit;
/**
* Read a MONEY value (allows commas as thousand separators)
*/
private readMoneyDigit;
/**
* Read a string literal
*/
private readSingleQuotedString;
/**
* Check if the current position starts a PostgreSQL dollar-quoted string
*/
private isDollarQuotedString;
/**
* Read a PostgreSQL dollar-quoted string
*/
private readDollarQuotedString;
/**
* Check if character is alphanumeric (letter or digit)
*/
private isAlphanumeric;
}