expressionish 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/expressionish.d.ts +540 -0
- package/dist/expressionish.mjs +1429 -0
- package/dist/expressionish.mjs.map +7 -0
- package/package.json +4 -4
|
@@ -0,0 +1,540 @@
|
|
|
1
|
+
declare module "parse/base-token" {
|
|
2
|
+
import { type EvaluateOptions } from "types";
|
|
3
|
+
export interface BaseTokenOptions {
|
|
4
|
+
position: number;
|
|
5
|
+
type?: string;
|
|
6
|
+
value?: unknown;
|
|
7
|
+
}
|
|
8
|
+
export interface BaseTokenJSON {
|
|
9
|
+
position: number;
|
|
10
|
+
type: string;
|
|
11
|
+
value?: unknown;
|
|
12
|
+
}
|
|
13
|
+
export default class BaseToken {
|
|
14
|
+
position: number;
|
|
15
|
+
type: string;
|
|
16
|
+
value?: unknown;
|
|
17
|
+
constructor(options: BaseTokenOptions);
|
|
18
|
+
toJSON(): BaseTokenJSON;
|
|
19
|
+
evaluate(options: EvaluateOptions): Promise<unknown>;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
declare module "types" {
|
|
23
|
+
import type BaseToken from "parse/base-token";
|
|
24
|
+
/** Result of a `tokenize()` attempt */
|
|
25
|
+
export type TokenizeResult<T = BaseToken> = [success: false] | [success: true, updatedCursor: number, result: T];
|
|
26
|
+
/** Data to be passed to variables when they are to be evaluated */
|
|
27
|
+
export type EvaluateData = Record<string | number | symbol, unknown>;
|
|
28
|
+
/** Function to call to validate a variable's arguments
|
|
29
|
+
* @throws {import("./errors.ts").ExpressionArgumentsError} If an argument or the arguments list is invalid
|
|
30
|
+
*/
|
|
31
|
+
export type ArgsCheck = (
|
|
32
|
+
/** meta data passed to the evaluate() call */
|
|
33
|
+
data: EvaluateData,
|
|
34
|
+
/** Arguments passed to the variable */
|
|
35
|
+
...args: unknown[]) => undefined | Promise<never>;
|
|
36
|
+
/** Function to call just prior to evaluating a variable or looked up variable */
|
|
37
|
+
export type PreEval = (
|
|
38
|
+
/** Options passed to the `<root>.evaluate()` function */
|
|
39
|
+
data: EvaluateData,
|
|
40
|
+
/** variable or lookup name */
|
|
41
|
+
variable: Variable) => undefined | Promise<never>;
|
|
42
|
+
type GeneralEvaluateFnc = (data: EvaluateData, ...args: unknown[]) => Promise<unknown>;
|
|
43
|
+
export interface GeneralVariableDefinition<T = GeneralEvaluateFnc> {
|
|
44
|
+
minArgumentsCount?: number;
|
|
45
|
+
maxArgumentsCount?: number;
|
|
46
|
+
argsCheck?: ArgsCheck;
|
|
47
|
+
preeval?: PreEval;
|
|
48
|
+
evaluate: T;
|
|
49
|
+
}
|
|
50
|
+
/** Represents a variable definition */
|
|
51
|
+
export type Variable = GeneralVariableDefinition;
|
|
52
|
+
/** Represents a Map of variables where
|
|
53
|
+
* - the key is the variable's name
|
|
54
|
+
* - the value is the variable's definition
|
|
55
|
+
*/
|
|
56
|
+
export type VariableMap = Map<string, Variable>;
|
|
57
|
+
/** Represents a Lookup handler
|
|
58
|
+
* @returns {undefined | Variable} A variable declaration or undefined
|
|
59
|
+
*/
|
|
60
|
+
export type LookupFnc = (data: EvaluateData,
|
|
61
|
+
/** The variable name to look up */
|
|
62
|
+
name: string) => undefined | Variable | Promise<undefined | Variable>;
|
|
63
|
+
/** Represents a Map of Lookup handlers where
|
|
64
|
+
* * the key is the lookup variable-prefix
|
|
65
|
+
* * the value is the function to handle the lookup
|
|
66
|
+
*/
|
|
67
|
+
export type LookupMap = Map<string, LookupFnc>;
|
|
68
|
+
export type LogicOperatorFnc = (data: EvaluateData, ...args: unknown[]) => boolean | Promise<boolean>;
|
|
69
|
+
export type LogicOperatorDefinition = GeneralVariableDefinition<LogicOperatorFnc>;
|
|
70
|
+
export type LogicOperatorMap = Map<string, LogicOperatorDefinition>;
|
|
71
|
+
export type ComparisonOperatorFnc = (data: EvaluateData, v1: unknown, v2?: unknown) => boolean | Promise<boolean>;
|
|
72
|
+
export type ComparisonOperatorDefinition = GeneralVariableDefinition<ComparisonOperatorFnc>;
|
|
73
|
+
export type ComparisonOperatorMap = Map<string, ComparisonOperatorDefinition>;
|
|
74
|
+
/** Options when Tokenizing an expression */
|
|
75
|
+
export interface TokenizeOptions {
|
|
76
|
+
/** The expression to tokenize */
|
|
77
|
+
expression: string;
|
|
78
|
+
/** A map of Lookup handlers available to be accessed by the expression*/
|
|
79
|
+
lookups: LookupMap;
|
|
80
|
+
/** A map of variable handlers available to be accessed by the expression */
|
|
81
|
+
variables: VariableMap;
|
|
82
|
+
/** A map of additional condition logical operators */
|
|
83
|
+
logicalOperators?: LogicOperatorMap;
|
|
84
|
+
/** A map of additional condition comparison operators */
|
|
85
|
+
comparisonOperators?: ComparisonOperatorMap;
|
|
86
|
+
}
|
|
87
|
+
/** Options when evaluating a tokenized expression */
|
|
88
|
+
export interface EvaluateOptions extends TokenizeOptions {
|
|
89
|
+
/** When true the parser will only validate syntax, variable existence and lookup existence */
|
|
90
|
+
onlyValidate?: boolean;
|
|
91
|
+
/** Function to be called just prior to evaluating any variable or lookup */
|
|
92
|
+
preeval?: PreEval;
|
|
93
|
+
/** Data to be passed into variable and/or lookup evaluators */
|
|
94
|
+
data?: EvaluateData;
|
|
95
|
+
}
|
|
96
|
+
/** Represents a small portion of an expression's text that may or may not have significance to the parser */
|
|
97
|
+
export interface GenericToken {
|
|
98
|
+
/** The position of the generic token within the expression text */
|
|
99
|
+
position: number;
|
|
100
|
+
/** The character(s) comprising the token */
|
|
101
|
+
value: string;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
declare module "tojson-types" {
|
|
105
|
+
/** Base that all other Token JSON inherit from */
|
|
106
|
+
export interface BaseTokenJSON {
|
|
107
|
+
/** Token's position withing the expression text */
|
|
108
|
+
position: number;
|
|
109
|
+
/** Token Type */
|
|
110
|
+
type: string;
|
|
111
|
+
/** Value of the token */
|
|
112
|
+
value?: unknown;
|
|
113
|
+
}
|
|
114
|
+
/** Represents a Text Token */
|
|
115
|
+
export interface TextTokenJSON extends BaseTokenJSON {
|
|
116
|
+
/** The text of the token */
|
|
117
|
+
value: string;
|
|
118
|
+
}
|
|
119
|
+
/** Represets a Sequence Token */
|
|
120
|
+
export interface SequenceTokenJSON extends BaseTokenJSON {
|
|
121
|
+
/** The tokens making up the sequence */
|
|
122
|
+
value: Array<LookupTokenJSON | IfTokenJSON | VariableTokenJSON | TextTokenJSON | SequenceTokenJSON>;
|
|
123
|
+
}
|
|
124
|
+
/** Represents an Argument Token */
|
|
125
|
+
export interface ArgumentsTokenJSON<T = GroupedTokensJSON> extends BaseTokenJSON {
|
|
126
|
+
/** Arguments of the token */
|
|
127
|
+
value: Array<T>;
|
|
128
|
+
}
|
|
129
|
+
/** Represents a Lookup Token */
|
|
130
|
+
export interface LookupTokenJSON extends BaseTokenJSON {
|
|
131
|
+
/** The prefix of the variable */
|
|
132
|
+
prefix: string;
|
|
133
|
+
/** The variable to be looked up */
|
|
134
|
+
value: string;
|
|
135
|
+
/** Arguments to be passed to the looked up variable during evaluation */
|
|
136
|
+
arguments?: ArgumentsTokenJSON;
|
|
137
|
+
}
|
|
138
|
+
/** Represents a Comparison Token */
|
|
139
|
+
export interface ComparisonTokenJSON extends BaseTokenJSON {
|
|
140
|
+
/** The comparison operator */
|
|
141
|
+
value: string;
|
|
142
|
+
/** The left-hand side of the comparison */
|
|
143
|
+
left: GroupedTokensJSON;
|
|
144
|
+
/** The right-hand side of the comparison */
|
|
145
|
+
right?: GroupedTokensJSON;
|
|
146
|
+
}
|
|
147
|
+
/** Represents a Logic Token */
|
|
148
|
+
export interface LogicTokenJSON extends BaseTokenJSON {
|
|
149
|
+
/** The logic operator */
|
|
150
|
+
value: string;
|
|
151
|
+
/** Arguments to be passed to the logic operator's handler */
|
|
152
|
+
arguments: ArgumentsTokenJSON<LogicTokenJSON | ComparisonTokenJSON | GroupedTokensJSON>;
|
|
153
|
+
}
|
|
154
|
+
/** Represents an If Token */
|
|
155
|
+
export interface IfTokenJSON extends BaseTokenJSON {
|
|
156
|
+
/** The condition */
|
|
157
|
+
value: ComparisonTokenJSON | LogicTokenJSON;
|
|
158
|
+
/** Value to return when the condition is truthy */
|
|
159
|
+
whenTrue: GroupedTokensJSON;
|
|
160
|
+
/** Value to return when the condition is falsy */
|
|
161
|
+
whenFalse?: GroupedTokensJSON;
|
|
162
|
+
}
|
|
163
|
+
export interface VariableTokenJSON extends BaseTokenJSON {
|
|
164
|
+
value: string;
|
|
165
|
+
arguments?: ArgumentsTokenJSON;
|
|
166
|
+
}
|
|
167
|
+
export type GroupedTokensJSON = LookupTokenJSON | IfTokenJSON | VariableTokenJSON | TextTokenJSON | SequenceTokenJSON;
|
|
168
|
+
export type RootTokenJSON = SequenceTokenJSON | LookupTokenJSON | IfTokenJSON | VariableTokenJSON | TextTokenJSON;
|
|
169
|
+
}
|
|
170
|
+
declare module "parse/text/token" {
|
|
171
|
+
import BaseToken from "parse/base-token";
|
|
172
|
+
import type { TextTokenJSON } from "tojson-types";
|
|
173
|
+
export interface TextTokenOptions {
|
|
174
|
+
position: number;
|
|
175
|
+
value: string;
|
|
176
|
+
}
|
|
177
|
+
export default class TextToken extends BaseToken {
|
|
178
|
+
value: string;
|
|
179
|
+
constructor(options: TextTokenOptions);
|
|
180
|
+
toJSON(): TextTokenJSON;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
declare module "parse/logic/operators" {
|
|
184
|
+
import type { LogicOperatorDefinition } from "types";
|
|
185
|
+
const _default: Map<string, LogicOperatorDefinition>;
|
|
186
|
+
export default _default;
|
|
187
|
+
}
|
|
188
|
+
declare module "parse/logic/token" {
|
|
189
|
+
import type { EvaluateOptions } from "types";
|
|
190
|
+
import type { LogicTokenJSON } from "tojson-types";
|
|
191
|
+
import type ArgumentsToken from "parse/arguments/token";
|
|
192
|
+
import BaseToken from "parse/base-token";
|
|
193
|
+
export interface LogicTokenOptions {
|
|
194
|
+
position: number;
|
|
195
|
+
value: string;
|
|
196
|
+
arguments: ArgumentsToken;
|
|
197
|
+
}
|
|
198
|
+
export default class LogicToken extends BaseToken {
|
|
199
|
+
value: string;
|
|
200
|
+
arguments: ArgumentsToken;
|
|
201
|
+
constructor(options: LogicTokenOptions);
|
|
202
|
+
toJSON(): LogicTokenJSON;
|
|
203
|
+
evaluate(options: EvaluateOptions): Promise<unknown>;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
declare module "parse/variable/token" {
|
|
207
|
+
import type { EvaluateOptions } from "types";
|
|
208
|
+
import type { VariableTokenJSON } from "tojson-types";
|
|
209
|
+
import type ArgumentsToken from "parse/arguments/token";
|
|
210
|
+
import BaseToken from "parse/base-token";
|
|
211
|
+
export interface VariableTokenOptions {
|
|
212
|
+
position: number;
|
|
213
|
+
value: string;
|
|
214
|
+
arguments?: ArgumentsToken;
|
|
215
|
+
}
|
|
216
|
+
export default class VariableToken extends BaseToken {
|
|
217
|
+
value: string;
|
|
218
|
+
arguments?: ArgumentsToken;
|
|
219
|
+
constructor(options: VariableTokenOptions);
|
|
220
|
+
toJSON(): VariableTokenJSON;
|
|
221
|
+
evaluate(options: EvaluateOptions): Promise<unknown>;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
declare module "parse/sequence-token" {
|
|
225
|
+
import type { EvaluateOptions } from "types";
|
|
226
|
+
import type { LookupTokenJSON, IfTokenJSON, VariableTokenJSON, TextTokenJSON, SequenceTokenJSON } from "tojson-types";
|
|
227
|
+
import type { default as TextToken } from "parse/text/token";
|
|
228
|
+
import type { default as LookupToken } from "parse/lookup/token";
|
|
229
|
+
import type { default as IfToken } from "parse/if/token";
|
|
230
|
+
import type { default as VariableToken } from "parse/variable/token";
|
|
231
|
+
import BaseToken from "parse/base-token";
|
|
232
|
+
export interface SequenceTokenOptions {
|
|
233
|
+
position: number;
|
|
234
|
+
value?: LookupToken | IfToken | VariableToken | TextToken | SequenceToken;
|
|
235
|
+
}
|
|
236
|
+
export default class SequenceToken extends BaseToken {
|
|
237
|
+
value: Array<LookupToken | IfToken | VariableToken | TextToken | SequenceToken>;
|
|
238
|
+
constructor(options: SequenceTokenOptions);
|
|
239
|
+
add(token: LookupToken | IfToken | VariableToken | TextToken | SequenceToken): void;
|
|
240
|
+
get unwrap(): SequenceToken | TextToken | LookupToken | IfToken | VariableToken;
|
|
241
|
+
toJSON(): SequenceTokenJSON | LookupTokenJSON | IfTokenJSON | VariableTokenJSON | TextTokenJSON;
|
|
242
|
+
evaluate(options: EvaluateOptions): Promise<unknown>;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
declare module "parse/arguments/token" {
|
|
246
|
+
import type { EvaluateOptions } from "types";
|
|
247
|
+
import type { ArgumentsTokenJSON } from "tojson-types";
|
|
248
|
+
import type ComparisonToken from "parse/comparison/token";
|
|
249
|
+
import type IfToken from "parse/if/token";
|
|
250
|
+
import type LogicToken from "parse/logic/token";
|
|
251
|
+
import type LookupToken from "parse/lookup/token";
|
|
252
|
+
import type TextToken from "parse/text/token";
|
|
253
|
+
import type VariableToken from "parse/variable/token";
|
|
254
|
+
import BaseToken from "parse/base-token";
|
|
255
|
+
import SequenceToken from "parse/sequence-token";
|
|
256
|
+
export interface ArgumentsTokenOptions {
|
|
257
|
+
position: number;
|
|
258
|
+
value?: Array<LookupToken | IfToken | VariableToken | TextToken | SequenceToken | LogicToken | ComparisonToken>;
|
|
259
|
+
}
|
|
260
|
+
export default class ArgumentsToken extends BaseToken {
|
|
261
|
+
value: Array<LookupToken | IfToken | VariableToken | TextToken | SequenceToken | LogicToken | ComparisonToken>;
|
|
262
|
+
constructor(options: ArgumentsTokenOptions);
|
|
263
|
+
toJSON(): ArgumentsTokenJSON;
|
|
264
|
+
evaluate(options: EvaluateOptions): Promise<unknown[]>;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
declare module "errors" {
|
|
268
|
+
/** Represents a generic error when attempting to parse an expression */
|
|
269
|
+
export class ExpressionError extends Error {
|
|
270
|
+
/** When defined: where the error was encountered within the expression text */
|
|
271
|
+
position?: number;
|
|
272
|
+
constructor(
|
|
273
|
+
/** Message to associate with the error */
|
|
274
|
+
message: string,
|
|
275
|
+
/** Where the error was encountered within the expression text */
|
|
276
|
+
position?: number);
|
|
277
|
+
static get name(): string;
|
|
278
|
+
}
|
|
279
|
+
/** Represents an error related to the arguments list or a singular argument to be passed to a variable */
|
|
280
|
+
export class ExpressionArgumentsError extends ExpressionError {
|
|
281
|
+
/** The index of the argument in the arguments list */
|
|
282
|
+
index?: number;
|
|
283
|
+
/** The variable name the arguments list belongs to */
|
|
284
|
+
varname?: string;
|
|
285
|
+
constructor(
|
|
286
|
+
/** Message to associate with the error */
|
|
287
|
+
message: string,
|
|
288
|
+
/** Where the error was encountered within the expression text */
|
|
289
|
+
position?: number,
|
|
290
|
+
/** The index of the argument in the arguments list */
|
|
291
|
+
index?: number,
|
|
292
|
+
/** The variable name the arguments list belongs to */
|
|
293
|
+
varname?: string);
|
|
294
|
+
static get name(): string;
|
|
295
|
+
}
|
|
296
|
+
/** Represents an error related to parsing a variable */
|
|
297
|
+
export class ExpressionVariableError extends ExpressionError {
|
|
298
|
+
/** The associated variable name */
|
|
299
|
+
varname?: string;
|
|
300
|
+
constructor(
|
|
301
|
+
/** Message to associate with the error */
|
|
302
|
+
message: string,
|
|
303
|
+
/** Where the error was encountered within the expression text */
|
|
304
|
+
position?: number,
|
|
305
|
+
/** The variable name to associate with the error */
|
|
306
|
+
varname?: string);
|
|
307
|
+
static get name(): string;
|
|
308
|
+
}
|
|
309
|
+
/** Represents a syntax error within the given expression */
|
|
310
|
+
export class ExpressionSyntaxError extends ExpressionError {
|
|
311
|
+
/** The character associated with the error */
|
|
312
|
+
character?: string;
|
|
313
|
+
constructor(
|
|
314
|
+
/** Message to associate with the error */
|
|
315
|
+
message: string,
|
|
316
|
+
/** Where the error was encountered within the expression text */
|
|
317
|
+
position?: number,
|
|
318
|
+
/** The character associated with the error */
|
|
319
|
+
character?: string);
|
|
320
|
+
static get name(): string;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
declare module "parse/lookup/token" {
|
|
324
|
+
import type { EvaluateOptions } from "types";
|
|
325
|
+
import type { LookupTokenJSON } from "tojson-types";
|
|
326
|
+
import BaseToken from "parse/base-token";
|
|
327
|
+
import ArgumentsToken from "parse/arguments/token";
|
|
328
|
+
export interface LookupTokenOptions {
|
|
329
|
+
position: number;
|
|
330
|
+
prefix: string;
|
|
331
|
+
value: string;
|
|
332
|
+
arguments?: ArgumentsToken;
|
|
333
|
+
}
|
|
334
|
+
export default class LookupToken extends BaseToken {
|
|
335
|
+
prefix: string;
|
|
336
|
+
value: string;
|
|
337
|
+
arguments?: ArgumentsToken;
|
|
338
|
+
constructor(options: LookupTokenOptions);
|
|
339
|
+
toJSON(): LookupTokenJSON;
|
|
340
|
+
evaluate(options: EvaluateOptions): Promise<unknown>;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
declare module "parse/comparison/operators" {
|
|
344
|
+
import type { ComparisonOperatorDefinition } from "types";
|
|
345
|
+
/** Comparison Operator Map */
|
|
346
|
+
const _default_1: Map<string, ComparisonOperatorDefinition>;
|
|
347
|
+
export default _default_1;
|
|
348
|
+
}
|
|
349
|
+
declare module "parse/comparison/token" {
|
|
350
|
+
import type { EvaluateOptions } from "types";
|
|
351
|
+
import type { ComparisonTokenJSON } from "tojson-types";
|
|
352
|
+
import type { default as TextToken } from "parse/text/token";
|
|
353
|
+
import type { default as LookupToken } from "parse/lookup/token";
|
|
354
|
+
import type { default as IfToken } from "parse/if/token";
|
|
355
|
+
import type { default as VariableToken } from "parse/variable/token";
|
|
356
|
+
import type { default as SequenceToken } from "parse/sequence-token";
|
|
357
|
+
type operand = LookupToken | IfToken | VariableToken | TextToken | SequenceToken;
|
|
358
|
+
import BaseToken from "parse/base-token";
|
|
359
|
+
export interface ComparisonTokenOptions {
|
|
360
|
+
position: number;
|
|
361
|
+
value: string;
|
|
362
|
+
left: operand;
|
|
363
|
+
right?: operand;
|
|
364
|
+
}
|
|
365
|
+
export default class ComparisonToken extends BaseToken {
|
|
366
|
+
value: string;
|
|
367
|
+
left: operand;
|
|
368
|
+
right?: operand;
|
|
369
|
+
constructor(options: ComparisonTokenOptions);
|
|
370
|
+
toJSON(): ComparisonTokenJSON;
|
|
371
|
+
evaluate(options: EvaluateOptions): Promise<unknown>;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
declare module "parse/if/token" {
|
|
375
|
+
import type { EvaluateOptions } from "types";
|
|
376
|
+
import type { IfTokenJSON } from "tojson-types";
|
|
377
|
+
import type ComparisonToken from "parse/comparison/token";
|
|
378
|
+
import type LogicToken from "parse/logic/token";
|
|
379
|
+
import type LookupToken from "parse/lookup/token";
|
|
380
|
+
import type VariableToken from "parse/variable/token";
|
|
381
|
+
import type SequenceToken from "parse/sequence-token";
|
|
382
|
+
import type TextToken from "parse/text/token";
|
|
383
|
+
type ConditionToken = ComparisonToken | LogicToken;
|
|
384
|
+
type OperandToken = LookupToken | IfToken | VariableToken | TextToken | SequenceToken;
|
|
385
|
+
import BaseToken from "parse/base-token";
|
|
386
|
+
export interface IfTokenOptions {
|
|
387
|
+
position: number;
|
|
388
|
+
value: ConditionToken;
|
|
389
|
+
whenTrue: OperandToken;
|
|
390
|
+
whenFalse?: OperandToken;
|
|
391
|
+
}
|
|
392
|
+
export default class IfToken extends BaseToken {
|
|
393
|
+
value: ConditionToken;
|
|
394
|
+
whenTrue: OperandToken;
|
|
395
|
+
whenFalse?: OperandToken;
|
|
396
|
+
constructor(options: IfTokenOptions);
|
|
397
|
+
toJSON(): IfTokenJSON;
|
|
398
|
+
evaluate(options: EvaluateOptions): Promise<unknown>;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
declare module "misc/split" {
|
|
402
|
+
import { type GenericToken } from "types";
|
|
403
|
+
/** Splits the input into an array of unicode-aware characters
|
|
404
|
+
* @returns {string[]} An array containing the delimited characters where each entry is a character
|
|
405
|
+
*/
|
|
406
|
+
export const split: (
|
|
407
|
+
/** Input text to split into characters */
|
|
408
|
+
input: string) => string[];
|
|
409
|
+
/** Converts the input into a list of Generic tokens for further processing
|
|
410
|
+
* * Unicode multi-byte/character glyphs are treated as a singular entry
|
|
411
|
+
* * Each whitespace character is treated as a singular entry
|
|
412
|
+
* * `\` is treated as a singular entry, the following character is also treated as a singular entry regardless of what it is
|
|
413
|
+
* * \`\` is treated as a singular entry
|
|
414
|
+
* * All other ascii punctionation is treated as a singular entry
|
|
415
|
+
* * Non-unicode characters that are not whitespace or punctuation are grouped together and treated as a singular entry
|
|
416
|
+
*/
|
|
417
|
+
export const tokenize: (input: string) => GenericToken[];
|
|
418
|
+
}
|
|
419
|
+
declare module "parse/root/token" {
|
|
420
|
+
import type { RootTokenJSON } from "tojson-types";
|
|
421
|
+
import type { TokenizeOptions, PreEval, EvaluateData, LookupMap, VariableMap, LogicOperatorMap, ComparisonOperatorMap } from "types";
|
|
422
|
+
import SequenceToken from "parse/sequence-token";
|
|
423
|
+
export type RootTokenOptions = TokenizeOptions;
|
|
424
|
+
export interface RootEvaluateOptions {
|
|
425
|
+
onlyValidate?: boolean;
|
|
426
|
+
preeval?: PreEval;
|
|
427
|
+
data?: EvaluateData;
|
|
428
|
+
}
|
|
429
|
+
export default class RootToken extends SequenceToken {
|
|
430
|
+
lookups: LookupMap;
|
|
431
|
+
variables: VariableMap;
|
|
432
|
+
expression: string;
|
|
433
|
+
logicOperators: LogicOperatorMap;
|
|
434
|
+
comparisonOperators: ComparisonOperatorMap;
|
|
435
|
+
constructor(options: RootTokenOptions);
|
|
436
|
+
toJSON(): RootTokenJSON;
|
|
437
|
+
evaluate(options?: RootEvaluateOptions): Promise<unknown>;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
declare module "parse/text/escape" {
|
|
441
|
+
import type { GenericToken, TokenizeResult } from "types";
|
|
442
|
+
const _default_2: (tokens: GenericToken[], cursor: number, escapeChars?: string) => TokenizeResult<GenericToken>;
|
|
443
|
+
export default _default_2;
|
|
444
|
+
}
|
|
445
|
+
declare module "parse/text/quote" {
|
|
446
|
+
import type { GenericToken, TokenizeResult } from "types";
|
|
447
|
+
import TextToken from "parse/text/token";
|
|
448
|
+
const _default_3: (tokens: GenericToken[], cursor: number) => TokenizeResult<TextToken>;
|
|
449
|
+
export default _default_3;
|
|
450
|
+
}
|
|
451
|
+
declare module "parse/variable/tokenize" {
|
|
452
|
+
import type { GenericToken, TokenizeOptions, TokenizeResult } from "types";
|
|
453
|
+
import VariableToken from "parse/variable/token";
|
|
454
|
+
const _default_4: (tokens: GenericToken[], cursor: number, options: TokenizeOptions) => TokenizeResult<VariableToken>;
|
|
455
|
+
export default _default_4;
|
|
456
|
+
}
|
|
457
|
+
declare module "parse/whitespace/tokenize" {
|
|
458
|
+
import type { GenericToken, TokenizeResult } from "types";
|
|
459
|
+
/** Consumes sequential whitespace from `tokens` beginning at `cursor` */
|
|
460
|
+
const _default_5: (tokens: GenericToken[], cursor: number) => TokenizeResult<string>;
|
|
461
|
+
export default _default_5;
|
|
462
|
+
}
|
|
463
|
+
declare module "parse/comparison/tokenize" {
|
|
464
|
+
import type { GenericToken, TokenizeOptions, TokenizeResult } from "types";
|
|
465
|
+
import ComparisonToken from "parse/comparison/token";
|
|
466
|
+
const _default_6: (tokens: GenericToken[], cursor: number, options: TokenizeOptions) => TokenizeResult<ComparisonToken>;
|
|
467
|
+
export default _default_6;
|
|
468
|
+
}
|
|
469
|
+
declare module "parse/logic/tokenize" {
|
|
470
|
+
import type { GenericToken, TokenizeOptions, TokenizeResult } from "types";
|
|
471
|
+
import LogicToken from "parse/logic/token";
|
|
472
|
+
const tokenizeLogicOperator: (tokens: GenericToken[], cursor: number, options: TokenizeOptions) => TokenizeResult<LogicToken>;
|
|
473
|
+
export default tokenizeLogicOperator;
|
|
474
|
+
}
|
|
475
|
+
declare module "parse/if/tokenize" {
|
|
476
|
+
import type { GenericToken, TokenizeOptions, TokenizeResult } from "types";
|
|
477
|
+
import IfToken from "parse/if/token";
|
|
478
|
+
const _default_7: (tokens: GenericToken[], cursor: number, options: TokenizeOptions) => TokenizeResult<IfToken>;
|
|
479
|
+
export default _default_7;
|
|
480
|
+
}
|
|
481
|
+
declare module "parse/arguments/argument" {
|
|
482
|
+
import type { GenericToken, TokenizeOptions, TokenizeResult } from "types";
|
|
483
|
+
import IfToken from "parse/if/token";
|
|
484
|
+
import LookupToken from "parse/lookup/token";
|
|
485
|
+
import SequenceToken from "parse/sequence-token";
|
|
486
|
+
import TextToken from "parse/text/token";
|
|
487
|
+
import VariableToken from "parse/variable/token";
|
|
488
|
+
const _default_8: (tokens: GenericToken[], cursor: number, options: TokenizeOptions) => TokenizeResult<LookupToken | IfToken | VariableToken | TextToken | SequenceToken>;
|
|
489
|
+
export default _default_8;
|
|
490
|
+
}
|
|
491
|
+
declare module "parse/arguments/tokenize" {
|
|
492
|
+
import type { GenericToken, TokenizeOptions, TokenizeResult } from "types";
|
|
493
|
+
import ArgumentsToken from "parse/arguments/token";
|
|
494
|
+
const _default_9: (tokens: GenericToken[], cursor: number, options: TokenizeOptions) => TokenizeResult<ArgumentsToken>;
|
|
495
|
+
export default _default_9;
|
|
496
|
+
}
|
|
497
|
+
declare module "parse/lookup/tokenize" {
|
|
498
|
+
import type { GenericToken, TokenizeOptions, TokenizeResult } from "types";
|
|
499
|
+
import LookupToken from "parse/lookup/token";
|
|
500
|
+
const _default_10: (tokens: GenericToken[], cursor: number, options: TokenizeOptions) => TokenizeResult<LookupToken>;
|
|
501
|
+
export default _default_10;
|
|
502
|
+
}
|
|
503
|
+
declare module "parse/text/block" {
|
|
504
|
+
import type { GenericToken, TokenizeOptions, TokenizeResult } from "types";
|
|
505
|
+
import type IfToken from "parse/if/token";
|
|
506
|
+
import type LookupToken from "parse/lookup/token";
|
|
507
|
+
import type VariableToken from "parse/variable/token";
|
|
508
|
+
import SequenceToken from "parse/sequence-token";
|
|
509
|
+
import TextToken from "parse/text/token";
|
|
510
|
+
const _default_11: (tokens: GenericToken[], cursor: number, options: TokenizeOptions) => TokenizeResult<LookupToken | IfToken | VariableToken | TextToken | SequenceToken>;
|
|
511
|
+
export default _default_11;
|
|
512
|
+
}
|
|
513
|
+
declare module "parse/root/tokenize" {
|
|
514
|
+
import type { TokenizeOptions } from "types";
|
|
515
|
+
import RootToken from "parse/root/token";
|
|
516
|
+
const _default_12: (options: TokenizeOptions) => RootToken;
|
|
517
|
+
export default _default_12;
|
|
518
|
+
}
|
|
519
|
+
declare module "expressionish" {
|
|
520
|
+
import { TokenizeOptions, EvaluateOptions } from "types";
|
|
521
|
+
export { default as ArgumentsToken, ArgumentsTokenOptions } from "parse/arguments/token";
|
|
522
|
+
export { default as BaseToken, BaseTokenOptions } from "parse/base-token";
|
|
523
|
+
export { default as ComparisonToken, ComparisonTokenOptions } from "parse/comparison/token";
|
|
524
|
+
export { default as IfToken, IfTokenOptions } from "parse/if/token";
|
|
525
|
+
export { default as LogicToken, LogicTokenOptions } from "parse/logic/token";
|
|
526
|
+
export { default as LookupToken, LookupTokenOptions } from "parse/lookup/token";
|
|
527
|
+
export { default as RootToken, RootTokenOptions, RootEvaluateOptions } from "parse/root/token";
|
|
528
|
+
export { default as SequenceToken } from "parse/sequence-token";
|
|
529
|
+
export { default as TextToken, TextTokenOptions } from "parse/text/token";
|
|
530
|
+
export { default as VariableToken, VariableTokenOptions } from "parse/variable/token";
|
|
531
|
+
export { ExpressionError, ExpressionArgumentsError, ExpressionSyntaxError, ExpressionVariableError } from "errors";
|
|
532
|
+
/** Parses a string expression into a usable Expressionish-Token instance */
|
|
533
|
+
export const tokenize: (
|
|
534
|
+
/** Options to use during tokenization */
|
|
535
|
+
options: TokenizeOptions) => import("expressionish").RootToken;
|
|
536
|
+
/** Parses then evaluates expression text */
|
|
537
|
+
export const evaluate: (
|
|
538
|
+
/** Options passed to the parser and evaluator */
|
|
539
|
+
options: EvaluateOptions) => Promise<unknown>;
|
|
540
|
+
}
|