import { GenLex, IParser, MixedParser, SingleParser, TupleParser, } from '../masala-parser.js' import { GenlexTracer, ParsingLog, Tracer } from './debugger.js' export interface TokenParser extends SingleParser> {} export type TokenCollection = { [key: string]: TokenParser } export interface Token { name: string value: T __token: true } export interface IGenLex { // TODO: make overload here /** * * @param parser parser of the token * @param name token name * @param priority the token with higher numeric priority is tried before others. * * Choice with grammar is made after token selection ! */ tokenize( keyword: string, name: string, priority?: number, ): TokenParser tokenize( parser: IParser, name: string, priority?: number, ): TokenParser use(grammar: SingleParser): SingleParser use(grammar: TupleParser): TupleParser use( grammar: MixedParser, ): MixedParser use(grammar: IParser): IParser tokens(): TokenCollection setSeparators(spacesCharacters: string): this /** * Select the parser used by genlex. It will be used as `separator.optrep().then(token).then(separator.optrep())`. * So the separator must not be optional or it will make an infinite loop. * The separation in your text can't be a strict one-time separation with Genlex. * @param parser */ setSeparatorsParser(parser: IParser): this /** * No separators accepted between tokens. * For example to parse: "@masala/function" and forbid "@masala/ function" * Whereas "2+2" is parsed like "2+ 2" */ noSeparator(): this /** * tokenize all items, given them the name of the token * Example: keywords(['AND', 'OR']) will create the tokens named 'AND' and 'OR' with C.string('AND'), C.string('OR) * @param tokens */ keywords(tokens: string[]): Array> get(tokenName: string): TokenParser } export interface ITracingGenLex extends IGenLex { tracer: GenlexTracer flush(): ParsingLog[] flushForAi(): ParsingLog[] }