CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes48downloads
char.d.ts155 linesDownload Raw Back to lib
1/**
2 * This is an additional module specifically for string parsers.
3 *
4 * It contains parsers with token type bound to be `string`
5 * and expected to work with individual characters.
6 *
7 * It should work even if you have a custom way to split
8 * a string into symbols such as graphemes.
9 *
10 * Node:
11 * ```ts
12 * import * as pc from 'peberminta/char';
13 * ```
14 *
15 * Deno:
16 * ```ts
17 * import * as p from 'https://deno.land/x/peberminta@.../char.ts';
18 * ```
19 *
20 * @packageDocumentation
21 */
22import { Parser, Matcher, Data } from './core';
23/**
24 * Make a parser that looks for the exact match for a given character
25 * and returns a match with that character.
26 *
27 * Tokens expected to be individual characters/graphemes.
28 *
29 * @param char - A character to look for.
30 */
31export declare function char<TOptions>(char: string): Parser<string, TOptions, string>;
32/**
33 * Make a parser that matches and returns a character
34 * if it is present in a given character samples string/array.
35 *
36 * Tokens expected to be individual characters/graphemes.
37 *
38 * @param chars - An array (or a string) of all acceptable characters.
39 */
40export declare function oneOf<TOptions>(chars: string | string[]): Parser<string, TOptions, string>;
41export { oneOf as anyOf };
42/**
43 * Make a parser that matches and returns a character
44 * if it is absent in a given character samples string/array.
45 *
46 * Tokens expected to be individual characters/graphemes.
47 *
48 * @param chars - An array (or a string) of all characters that are not acceptable.
49 */
50export declare function noneOf<TOptions>(chars: string | string[]): Parser<string, TOptions, string>;
51/**
52 * Make a parser that matches input character against given regular expression.
53 *
54 * Use this to match characters belonging to a certain range
55 * or having a certain [unicode property](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Unicode_Property_Escapes).
56 *
57 * Use `satisfy` from core module instead if you need a predicate.
58 *
59 * Tokens expected to be individual characters/graphemes.
60 *
61 * @param regex - Tester regular expression.
62 */
63export declare function charTest<TOptions>(regex: RegExp): Parser<string, TOptions, string>;
64/**
65 * Make a parser that looks for the exact match for a given string,
66 * returns a match with that string and consumes an according number of tokens.
67 *
68 * Empty string matches without consuming input.
69 *
70 * Tokens expected to be individual characters/graphemes.
71 *
72 * @param str - A string to look for.
73 */
74export declare function str<TOptions>(str: string): Parser<string, TOptions, string>;
75/**
76 * Make a parser that concatenates characters/strings
77 * from all provided parsers into a single string.
78 *
79 * Nonmatch is returned if any of parsers didn't match.
80 *
81 * @param ps - Parsers sequence.
82 * Each parser can return a string or an array of strings.
83 */
84export declare function concat<TOptions>(...ps: Parser<string, TOptions, string | string[]>[]): Parser<string, TOptions, string>;
85/**
86 * Utility function to render a given parser position
87 * for error reporting and debug purposes.
88 *
89 * This is a version specific for char parsers.
90 *
91 * Note: it will fall back to core version (one token per line)
92 * in case any multicharacter tokens are present.
93 *
94 * @param data - Data object (tokens and options).
95 * @param i - Parser position in the tokens array.
96 * @param contextTokens - How many tokens (characters) around the current one to render.
97 * @returns A multiline string.
98 *
99 * @category Utility functions
100 */
101export declare function parserPosition(data: Data<string, unknown>, i: number, contextTokens?: number): string;
102/**
103 * Utility function that provides a bit cleaner interface for running a parser.
104 *
105 * This one throws an error in case parser didn't match
106 * OR the match is incomplete (some part of input string left unparsed).
107 *
108 * Input string is broken down to characters as `[...str]`
109 * unless you provide a pre-split array.
110 *
111 * @param parser - A parser to run.
112 * @param str - Input string or an array of graphemes.
113 * @param options - Parser options.
114 * @returns A matched value.
115 *
116 * @category Utility functions
117 */
118export declare function parse<TOptions, TValue>(parser: Parser<string, TOptions, TValue>, str: string | string[], options: TOptions): TValue;
119/**
120 * Utility function that provides a bit cleaner interface
121 * for running a parser over a string.
122 * Returns `undefined` in case parser did not match.
123 *
124 * Input string is broken down to characters as `[...str]`
125 * unless you provide a pre-split array.
126 *
127 * Note: this doesn't capture errors thrown during parsing.
128 * Nonmatch is considered a part or normal flow.
129 * Errors mean unrecoverable state and it's up to client code to decide
130 * where to throw errors and how to get back to safe state.
131 *
132 * @param parser - A parser to run.
133 * @param str - Input string or an array of graphemes.
134 * @param options - Parser options.
135 * @returns A matched value or `undefined` in case of nonmatch.
136 *
137 * @category Utility functions
138 */
139export declare function tryParse<TOptions, TValue>(parser: Parser<string, TOptions, TValue>, str: string | string[], options: TOptions): TValue | undefined;
140/**
141 * Utility function that provides a bit cleaner interface
142 * for running a {@link Matcher} over a string.
143 *
144 * Input string is broken down to characters as `[...str]`
145 * unless you provide a pre-split array.
146 *
147 * @param matcher - A matcher to run.
148 * @param str - Input string or an array of graphemes.
149 * @param options - Parser options.
150 * @returns A matched value.
151 *
152 * @category Utility functions
153 */
154export declare function match<TOptions, TValue>(matcher: Matcher<string, TOptions, TValue>, str: string | string[], options: TOptions): TValue;
155 
basant307/AI_Governance_Project · CoolFace