export declare type NEUTRAL = symbol import type { Response } from '../masala-parser.d.ts' /** * Represents the sequence of tokens found by the parser. * A Tuple accepts a `NEUTRAL` element */ export interface Tuple { /** * Wrapped array */ value: T[] isEmpty(): boolean /** * Number of elements in the wrapped array */ size(): number /** * Returns the first token. It's up to the coder to know * if there is only one token * * ```js * const parser = C.char('a') * .then(C.char('b')) * .drop() * .then(C.char('c') * .single(); // Parsing will return 'c' * ``` * See [[array]] */ single(): T /** * Returns all tokens in an array * ```js * const parser = C.char('a') * .then(C.char('b')) * .then(C.char('c') * .array(); // Parsing will return ['a','b','c'] * ``` * See [[single]] */ array(): T[] /** * Returns the last element of the Tuple */ last(): T /** * Returns the first element of the Tuple */ first(): T /** * Returns value at index * @param index */ at(index: number): T /** * Join elements as one string joined by optional separator (ie empty '' separator by default) * @param separator join separator */ join(separator?: string): string append(other: Tuple): Tuple append(other: EmptyTuple): Tuple append(other: Tuple): MixedTuple append(element: T): Tuple append(element: Y): MixedTuple /** * The tuple will not change with the NEUTRAL element. * It will concatenate the two tuples as one, or add * a single element if it's not a Tuple. * Therefore a Tuple can wrap multiple arrays. * @param neutral : neutral element * * See [[TupleParser]] */ append(neutral: NEUTRAL): this; map (f : (x:T)=>Y): Tuple; } export interface EmptyTuple extends Tuple { append(neutral: NEUTRAL): this append(other: EmptyTuple): EmptyTuple append(other: MixedTuple): MixedTuple append(other: Tuple): Tuple append(element: Y): Tuple } export interface MixedTuple extends Tuple { first(): FIRST; last(): LAST; append(other: EmptyTuple): this; append(other: MixedTuple): MixedTuple; append(other: Tuple): MixedTuple; append(element: Y): MixedTuple; append(neutral: NEUTRAL): this; map (f : (x:FIRST| LAST)=>Y): Tuple; }