import { FunctionExpression, AttributeExpression, LiteralExpression, Expression, DataType, LiteralExpressionType } from '../state/index.js'; import { FormattingResult } from './astFormatting.js'; export interface State { data: string; id: number; } export interface OkResult { state: State; value: A; } export interface ErrorResult { error: string; pertinenceLevel?: PertinenceLevel; } export declare const enum PertinenceLevel { Low = 1, Medium = 2, High = 3 } export type Result = OkResult | ErrorResult; export type Parser = (state: State) => Result; export type ArrayParser = (accu: Array) => Parser>; export declare const eosError: ErrorResult; export declare const expectedPredicateError: ErrorResult; /** * Determine if the given expression is of Func type. */ export declare function isFunc(expression: Expression | ErrorResult): expression is FunctionExpression; /** * Check whether the given value is the type of a precedence operation. */ export declare function isPrecedenceOperationType(target: string): boolean; /** * Return the last raised error. */ export declare function getLastError(): ErrorResult; /** * Set the last raised error. */ export declare function setLastError(newError: ErrorResult): ErrorResult; /** * Return a new state for the given string. */ export declare function newState(data: string): State; /** * Return the next state of a string from a given state. */ export declare function nextState(state: State): State; /** * Return a new AST node of type scalar. */ export declare function newScalar(type: LiteralExpressionType, value: string | number | boolean, originalType?: DataType): LiteralExpression; /** * Generate a AST node of type function call. */ export declare function newFunctionASTNode(value: string, paramList: Array, isAggregate?: boolean, returnType?: DataType): FunctionExpression; /** * Generate a new AST node of type attribute. */ export declare function newAttributeExpression(attributeName: string, from: string): AttributeExpression; /** * Generate an ErrorResult and save it as the last generated/encountered error. * The "B" at the end of the function name stands for "Backup". */ export declare function newErrorResult(errMsg: string, pertinenceLevel?: PertinenceLevel): ErrorResult; /** * A type guard for typescript compiler. * Allow not to type every time things like: * if ((>myVar).error) { * return (>myVar).error; * } * return (>myVar).state; */ export declare function isOkResult(variable: Result): variable is OkResult; /** * Make sure the given value is of type ErrorResult */ export declare function isErrorResult(variable: FormattingResult): variable is ErrorResult; /** * Check whether the given char exists in a given string. * If a string was given as target, instead of a char, compare only its * first char. */ export declare function isCharInString(targetChar: string, refString: string): boolean; /** * Check whether a value exists in a given array. */ export declare function isValueInArray(searchedValue: unknown, ref: Array): boolean; /** * Take and run a first parser, then return a new parser * that will be called when the first parser will be done with its job. * Prevent from checking what a parser returns each time we want to do * something with its returned state. * */ export declare function bind_(parser: Parser, error?: ErrorResult): any; /** * Loop over a collection of parsers and execute them until one is * successfully exeecuted. * If none of the parsers returns a positive result, return the last error * instead. * * parser1() => ErrorResult * -> parser2() => ErrorResult * -> ... * -> parser5() => OkResult */ export declare function or(parserList: Array>): Parser; /** * Run a parser, then return the OkResult or an error, depending on whether * its value matches the given result or not. * * @param shouldNotMatch: When omitted, expect the reference to * be found in the parsing result. Else, expect it not to be found. */ export declare function match(parser: Parser, reference: Array, shouldNotMatch?: boolean): Parser; /** * Run a parser and return the OkResult if its value does not match the * given result. */ export declare function notMatch(parser: Parser, reference: Array): Parser; /** * A parser builder. * Take a value and return a new parser of the type of the given value */ export declare function return_(value: A): Parser; /** * This is a generic parser builder. * It takes a parser of type A, and return a new parser of type A[] * * Emulate the '*' character of a regex, which means "0, 1, * or several". * * It basically keeps calling a parser of a given type/token until it reaches a * character that is not of the same type, or until it reaches the end of the * string. * * regex signature: * */ export declare function star(parser: Parser): ArrayParser; /** * A parser builder in the way that it takes a parser of type A and returns a * parser of array of A. * * It expects to find one or several juxtaposed occurences of a given caracter, * from the given state of the parsed data. * * regex signature: + */ export declare function plus(parser: Parser): ArrayParser; /** * Expect to find 0 or 1 occurence of the given word. * Here "word" is the searched char or string. */ export declare function option(parser: Parser): Parser; /** * Check whether the expression parser reached the end of the input string. */ export declare function isEoS(state: State): boolean; /** * A generic low level parser which epxects to find only one char at a time. * Return an error or a result depending on a given predicate. */ export declare function expectChar(state: State, predicate: boolean, errorMessage?: string): Result;