rawsql-ts
Version:
[beta]High-performance SQL parser and AST analyzer written in TypeScript. Provides fast parsing and advanced transformation capabilities.
37 lines (36 loc) • 1.62 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 or an identifier (e.g., `a.id`), the sign is treated as an operator.
* - If the previous lexeme is a closing parenthesis (e.g., `count(*)`), the sign is also 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 string literal
*/
private readSingleQuotedString;
}