/* Array with different values*/ import type { IParser, Option, Response } from '../masala-parser.d.ts' import type { Tuple, NEUTRAL, MixedTuple } from './tuple.d.ts' import type { VoidParser } from './void-parser.js' // A SingleParser is really a IParser that don't have weird Neutral or Void value export interface SingleParser extends IParser { then(dropped: VoidParser): TupleParser then(empty: EmptyTupleParser): TupleParser then(sameTuple: TupleParser): TupleParser then(otherTuple: TupleParser): MixedParser then(mixed: MixedParser): MixedParser then(same: SingleParser): TupleParser then(other: SingleParser): MixedParser then(p: IParser): TupleParser then(p: IParser): MixedParser thenEos(): TupleParser //or(other: SingleParser): SingleParser or(other: SingleParser): SingleParser or(other: IParser): IParser /*or(other: TupleParser): TupleParser; or(other: TupleParser): TupleParser | TupleParser; or>(other: P): SingleParser | P; */ rep(): TupleParser opt(): SingleParser> optrep(): TupleParser val(text: string): T } export interface TupleParser extends IParser> { first(): SingleParser // will be undefined last(): SingleParser single(): SingleParser // alias of first() then(dropped: VoidParser): TupleParser then(empty: EmptyTupleParser): TupleParser then(sameTuple: TupleParser): TupleParser then(otherTuple: TupleParser): MixedParser then(mixed: MixedParser): MixedParser then(other: SingleParser): TupleParser then(other: SingleParser): MixedParser then(p: IParser): TupleParser then(p: IParser): MixedParser thenEos(): this /** * Maps the content of the tuple value into an array. * However, it's usually better to work directly on the Tuple, not the TupleParser */ array(): SingleParser /** * Join the content of the tuple into a string, using the separator ('' by default) * @param separator */ join(separator?: string): SingleParser tupleMap(f: (x: T) => Y): TupleParser /** * single() is an alias of first(), expressing that the * parser had only a single value. */ single(): SingleParser rep(): TupleParser /* last(): SingleParser; first(): SingleParser; optrep(): TupleParser; */ val(text: string): Tuple map>( f: (value: TUPLE, response: Response) => Y, ): SingleParser rep(): TupleParser opt(): IParser>> optrep(): TupleParser or(other: TupleParser): TupleParser or(other: IParser): IParser val(text: string): Tuple } export interface EmptyTupleParser extends TupleParser { first(): SingleParser // will be undefined last(): SingleParser then(other: SingleParser): TupleParser then(dropped: VoidParser): EmptyTupleParser then(empty: EmptyTupleParser): EmptyTupleParser /* then(other: TupleParser): TupleParser; then(other: MixedParser): MixedParser; then(other: SingleParser): SingleParser; */ or(other: EmptyTupleParser): EmptyTupleParser or(other: IParser): IParser val(text: string): Tuple } export interface MixedParser extends TupleParser { first(): SingleParser last(): SingleParser then(dropped: VoidParser): MixedParser then(empty: EmptyTupleParser): MixedParser then(other: TupleParser): MixedParser then(other: MixedParser): MixedParser then(other: SingleParser): MixedParser val(text: string): MixedTuple tupleMap(f: (x: FIRST | LAST) => Y): TupleParser or(other: MixedParser): MixedParser or(other: IParser): IParser map>( f: (value: TUPLE, response: Response) => Y, ): SingleParser map>( f: (value: TUPLE, response: Response) => Y, ): SingleParser }