expressionish 0.1.1 → 0.1.2
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 +313 -55
- package/dist/expressionish.mjs +3 -1424
- package/dist/expressionish.mjs.map +3 -3
- package/package.json +1 -1
package/dist/expressionish.d.ts
CHANGED
|
@@ -1,28 +1,41 @@
|
|
|
1
1
|
declare module "parse/base-token" {
|
|
2
2
|
import { type EvaluateOptions } from "types";
|
|
3
|
+
/** Represents the base options for all Token instances */
|
|
3
4
|
export interface BaseTokenOptions {
|
|
4
5
|
position: number;
|
|
5
6
|
type?: string;
|
|
6
7
|
value?: unknown;
|
|
7
8
|
}
|
|
9
|
+
/** Represents the base return value for all Token instance .toJSON() functions */
|
|
8
10
|
export interface BaseTokenJSON {
|
|
9
11
|
position: number;
|
|
10
12
|
type: string;
|
|
11
13
|
value?: unknown;
|
|
12
14
|
}
|
|
15
|
+
/** The most basic token; should not be used externally */
|
|
13
16
|
export default class BaseToken {
|
|
17
|
+
/** Position in the expression where the token occurs */
|
|
14
18
|
position: number;
|
|
19
|
+
/** Token type */
|
|
15
20
|
type: string;
|
|
21
|
+
/** Token value */
|
|
16
22
|
value?: unknown;
|
|
17
23
|
constructor(options: BaseTokenOptions);
|
|
24
|
+
/** Converts the token to a JSON.stringify()-able object */
|
|
18
25
|
toJSON(): BaseTokenJSON;
|
|
26
|
+
/** Evaluates the token */
|
|
19
27
|
evaluate(options: EvaluateOptions): Promise<unknown>;
|
|
20
28
|
}
|
|
21
29
|
}
|
|
22
30
|
declare module "types" {
|
|
23
31
|
import type BaseToken from "parse/base-token";
|
|
24
|
-
/**
|
|
25
|
-
export
|
|
32
|
+
/** Represents a small portion of an expression's text that may or may not have significance to the parser */
|
|
33
|
+
export interface GenericToken {
|
|
34
|
+
/** The position of the generic token within the expression text */
|
|
35
|
+
position: number;
|
|
36
|
+
/** The character(s) comprising the token */
|
|
37
|
+
value: string;
|
|
38
|
+
}
|
|
26
39
|
/** Data to be passed to variables when they are to be evaluated */
|
|
27
40
|
export type EvaluateData = Record<string | number | symbol, unknown>;
|
|
28
41
|
/** Function to call to validate a variable's arguments
|
|
@@ -39,38 +52,126 @@ declare module "types" {
|
|
|
39
52
|
data: EvaluateData,
|
|
40
53
|
/** variable or lookup name */
|
|
41
54
|
variable: Variable) => undefined | Promise<never>;
|
|
42
|
-
|
|
43
|
-
export
|
|
55
|
+
/** Called to evaluate the variable */
|
|
56
|
+
export type VariableEvaluateFnc = (data: EvaluateData, ...args: unknown[]) => undefined | unknown | Promise<undefined | unknown>;
|
|
57
|
+
/** Represents a variable definition */
|
|
58
|
+
export interface Variable {
|
|
59
|
+
/** Min arguments required by the variable */
|
|
44
60
|
minArgumentsCount?: number;
|
|
61
|
+
/** Max arguments required by the variable */
|
|
45
62
|
maxArgumentsCount?: number;
|
|
46
|
-
argsCheck
|
|
63
|
+
/** During evaluation of the expression, called prior to `argsCheck()` and `evaluate()` */
|
|
47
64
|
preeval?: PreEval;
|
|
48
|
-
evaluate
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
65
|
+
/** During evaluation of the expression, called to validate arguments prior to calling `evaluate()` */
|
|
66
|
+
argsCheck?: ArgsCheck;
|
|
67
|
+
/** Function to call to handle evaluation of the variable */
|
|
68
|
+
evaluate: VariableEvaluateFnc;
|
|
69
|
+
}
|
|
70
|
+
/** Represents a list of variables */
|
|
71
|
+
export interface VariableMap extends Map<string, Variable> {
|
|
72
|
+
/** Checks if the given variable name is used as a key within the map */
|
|
73
|
+
has(
|
|
74
|
+
/** Variable name to check */
|
|
75
|
+
name: string): boolean;
|
|
76
|
+
/** Retrieves the variable definition associated with the specified name */
|
|
77
|
+
get(
|
|
78
|
+
/** Name of variable to retrieve */
|
|
79
|
+
name: string): Variable;
|
|
80
|
+
/** Stores a variable definition */
|
|
81
|
+
set(
|
|
82
|
+
/** Name to associate with the variable */
|
|
83
|
+
name: string,
|
|
84
|
+
/** Variable definition */
|
|
85
|
+
definition: Variable): this;
|
|
86
|
+
}
|
|
87
|
+
/** Handler to lookup `name`
|
|
88
|
+
* @returns A variable declaration or undefined
|
|
59
89
|
*/
|
|
60
90
|
export type LookupFnc = (data: EvaluateData,
|
|
61
91
|
/** The variable name to look up */
|
|
62
92
|
name: string) => undefined | Variable | Promise<undefined | Variable>;
|
|
63
|
-
/** Represents a Map of Lookup handlers
|
|
64
|
-
|
|
65
|
-
|
|
93
|
+
/** Represents a Map of Lookup handlers */
|
|
94
|
+
export interface LookupMap extends Map<string, LookupFnc> {
|
|
95
|
+
has(
|
|
96
|
+
/** Variable prefix to check */
|
|
97
|
+
prefix: string): boolean;
|
|
98
|
+
get(
|
|
99
|
+
/** Variable prefix to retrieve associated lookup handler */
|
|
100
|
+
prefix: string): undefined | LookupFnc;
|
|
101
|
+
/** Stores the lookup */
|
|
102
|
+
set(
|
|
103
|
+
/** Variable prefix to associated with the lookup handler */
|
|
104
|
+
prefix: string,
|
|
105
|
+
/** Handler function to perform the lookup */
|
|
106
|
+
handler: LookupFnc): this;
|
|
107
|
+
}
|
|
108
|
+
/** Performs a logic-operation on the given inputs
|
|
109
|
+
* @returns The result of the operation
|
|
66
110
|
*/
|
|
67
|
-
export type LookupMap = Map<string, LookupFnc>;
|
|
68
111
|
export type LogicOperatorFnc = (data: EvaluateData, ...args: unknown[]) => boolean | Promise<boolean>;
|
|
69
|
-
|
|
70
|
-
export
|
|
112
|
+
/** Logic Operator Definition */
|
|
113
|
+
export interface LogicOperator {
|
|
114
|
+
/** Min arguments required by the variable */
|
|
115
|
+
minArgumentsCount?: number;
|
|
116
|
+
/** Max arguments required by the variable */
|
|
117
|
+
maxArgumentsCount?: number;
|
|
118
|
+
/** During evaluation of the expression, called prior to `argsCheck()` and `evaluate()` */
|
|
119
|
+
preeval?: PreEval;
|
|
120
|
+
/** During evaluation of the expression, called to validate arguments prior to calling `evaluate()` */
|
|
121
|
+
argsCheck?: ArgsCheck;
|
|
122
|
+
/** Function to call to handle evaluation of the variable */
|
|
123
|
+
evaluate: LogicOperatorFnc;
|
|
124
|
+
}
|
|
125
|
+
/** Represents a list of logic operators */
|
|
126
|
+
export interface LogicOperatorMap extends Map<string, LogicOperator> {
|
|
127
|
+
/** Check if the operator is used as a key within the map */
|
|
128
|
+
has(
|
|
129
|
+
/** Operator to check */
|
|
130
|
+
operator: string): boolean;
|
|
131
|
+
/** Returns the logic operator definition associated with the specified operator */
|
|
132
|
+
get(
|
|
133
|
+
/** Operator of which to retrieve the definition */
|
|
134
|
+
operator: string): undefined | LogicOperator;
|
|
135
|
+
/** Stores the given operator definition */
|
|
136
|
+
set(
|
|
137
|
+
/** Operator to associate with the definition */
|
|
138
|
+
operator: string,
|
|
139
|
+
/** Operator definition */
|
|
140
|
+
definition: LogicOperator): this;
|
|
141
|
+
}
|
|
142
|
+
/** Performs a comparison-operation on the given inputs
|
|
143
|
+
* @returns The result of the operation
|
|
144
|
+
*/
|
|
71
145
|
export type ComparisonOperatorFnc = (data: EvaluateData, v1: unknown, v2?: unknown) => boolean | Promise<boolean>;
|
|
72
|
-
|
|
73
|
-
export
|
|
146
|
+
/** Comparison Operator Definition */
|
|
147
|
+
export interface ComparisonOperator {
|
|
148
|
+
right?: 'never' | 'optional' | 'required';
|
|
149
|
+
/** During evaluation of the comparison operator called prior to `argsCheck()` and `evaluate()` */
|
|
150
|
+
preeval?: PreEval;
|
|
151
|
+
/** During evaluation of the comparison operator called to validate arguments prior to calling `evaluate()` */
|
|
152
|
+
argsCheck?: ArgsCheck;
|
|
153
|
+
/** Function to call to handle evaluation of the variable */
|
|
154
|
+
evaluate: ComparisonOperatorFnc;
|
|
155
|
+
}
|
|
156
|
+
/** Represents a list of comparison operators */
|
|
157
|
+
export interface ComparisonOperatorMap extends Map<string, ComparisonOperator> {
|
|
158
|
+
/** Check if the operator is used as a key within the map */
|
|
159
|
+
has(
|
|
160
|
+
/** Operator to check */
|
|
161
|
+
operator: string): boolean;
|
|
162
|
+
/** Returns the comparison operator definition associated with the specified operator */
|
|
163
|
+
get(
|
|
164
|
+
/** Operator of which to retrieve the definition */
|
|
165
|
+
operator: string): undefined | ComparisonOperator;
|
|
166
|
+
/** Stores the given operator definition */
|
|
167
|
+
set(
|
|
168
|
+
/** Operator to associate with the definition */
|
|
169
|
+
operator: string,
|
|
170
|
+
/** Operator definition */
|
|
171
|
+
definition: ComparisonOperator): this;
|
|
172
|
+
}
|
|
173
|
+
/** Result of a `tokenize()` attempt */
|
|
174
|
+
export type TokenizeResult<T = BaseToken> = [success: false] | [success: true, updatedCursor: number, result: T];
|
|
74
175
|
/** Options when Tokenizing an expression */
|
|
75
176
|
export interface TokenizeOptions {
|
|
76
177
|
/** The expression to tokenize */
|
|
@@ -93,13 +194,6 @@ declare module "types" {
|
|
|
93
194
|
/** Data to be passed into variable and/or lookup evaluators */
|
|
94
195
|
data?: EvaluateData;
|
|
95
196
|
}
|
|
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
197
|
}
|
|
104
198
|
declare module "tojson-types" {
|
|
105
199
|
/** Base that all other Token JSON inherit from */
|
|
@@ -160,8 +254,11 @@ declare module "tojson-types" {
|
|
|
160
254
|
/** Value to return when the condition is falsy */
|
|
161
255
|
whenFalse?: GroupedTokensJSON;
|
|
162
256
|
}
|
|
257
|
+
/** Represents a Variable Token */
|
|
163
258
|
export interface VariableTokenJSON extends BaseTokenJSON {
|
|
259
|
+
/** Variable name */
|
|
164
260
|
value: string;
|
|
261
|
+
/** Arguments to pass to the variable's `evaluate()` function */
|
|
165
262
|
arguments?: ArgumentsTokenJSON;
|
|
166
263
|
}
|
|
167
264
|
export type GroupedTokensJSON = LookupTokenJSON | IfTokenJSON | VariableTokenJSON | TextTokenJSON | SequenceTokenJSON;
|
|
@@ -170,19 +267,26 @@ declare module "tojson-types" {
|
|
|
170
267
|
declare module "parse/text/token" {
|
|
171
268
|
import BaseToken from "parse/base-token";
|
|
172
269
|
import type { TextTokenJSON } from "tojson-types";
|
|
270
|
+
/** Represents the options for a new TextToken instance */
|
|
173
271
|
export interface TextTokenOptions {
|
|
272
|
+
/** Position of the variable within the expression */
|
|
174
273
|
position: number;
|
|
274
|
+
/** The text of the token */
|
|
175
275
|
value: string;
|
|
176
276
|
}
|
|
277
|
+
/** Represents literal text */
|
|
177
278
|
export default class TextToken extends BaseToken {
|
|
279
|
+
/** The text of the token */
|
|
178
280
|
value: string;
|
|
179
281
|
constructor(options: TextTokenOptions);
|
|
282
|
+
/** Converts the token to a JSON.stringify()-able object */
|
|
180
283
|
toJSON(): TextTokenJSON;
|
|
181
284
|
}
|
|
182
285
|
}
|
|
183
286
|
declare module "parse/logic/operators" {
|
|
184
|
-
import type {
|
|
185
|
-
|
|
287
|
+
import type { LogicOperatorMap } from "types";
|
|
288
|
+
/** Built-in Logic Operators Map */
|
|
289
|
+
const _default: LogicOperatorMap;
|
|
186
290
|
export default _default;
|
|
187
291
|
}
|
|
188
292
|
declare module "parse/logic/token" {
|
|
@@ -190,16 +294,25 @@ declare module "parse/logic/token" {
|
|
|
190
294
|
import type { LogicTokenJSON } from "tojson-types";
|
|
191
295
|
import type ArgumentsToken from "parse/arguments/token";
|
|
192
296
|
import BaseToken from "parse/base-token";
|
|
297
|
+
/** Represents the options for a new LogicToken instance */
|
|
193
298
|
export interface LogicTokenOptions {
|
|
299
|
+
/** Position of the logic conditional within the expression */
|
|
194
300
|
position: number;
|
|
301
|
+
/** The operator used */
|
|
195
302
|
value: string;
|
|
303
|
+
/** Arguments to be passed to the operator's `evaluate()` function */
|
|
196
304
|
arguments: ArgumentsToken;
|
|
197
305
|
}
|
|
306
|
+
/** Represents a logical-conditional token */
|
|
198
307
|
export default class LogicToken extends BaseToken {
|
|
308
|
+
/** The operator used */
|
|
199
309
|
value: string;
|
|
310
|
+
/** Arguments to be passed to the operator's `evaluate()` function */
|
|
200
311
|
arguments: ArgumentsToken;
|
|
201
312
|
constructor(options: LogicTokenOptions);
|
|
313
|
+
/** Converts the token to a JSON.stringify()-able object */
|
|
202
314
|
toJSON(): LogicTokenJSON;
|
|
315
|
+
/** Evaluates the token */
|
|
203
316
|
evaluate(options: EvaluateOptions): Promise<unknown>;
|
|
204
317
|
}
|
|
205
318
|
}
|
|
@@ -208,16 +321,25 @@ declare module "parse/variable/token" {
|
|
|
208
321
|
import type { VariableTokenJSON } from "tojson-types";
|
|
209
322
|
import type ArgumentsToken from "parse/arguments/token";
|
|
210
323
|
import BaseToken from "parse/base-token";
|
|
324
|
+
/** Represents the options for a new VariableToken instance */
|
|
211
325
|
export interface VariableTokenOptions {
|
|
326
|
+
/** Position of the variable within the expression */
|
|
212
327
|
position: number;
|
|
328
|
+
/** The variable's name */
|
|
213
329
|
value: string;
|
|
330
|
+
/** Arguments to evaluate & pass to the variable's evaluate function */
|
|
214
331
|
arguments?: ArgumentsToken;
|
|
215
332
|
}
|
|
333
|
+
/** Represents a Variable token */
|
|
216
334
|
export default class VariableToken extends BaseToken {
|
|
335
|
+
/** The variable name */
|
|
217
336
|
value: string;
|
|
337
|
+
/** Arguments to evaluate & pass to the variable's evaluate function */
|
|
218
338
|
arguments?: ArgumentsToken;
|
|
219
339
|
constructor(options: VariableTokenOptions);
|
|
340
|
+
/** Converts the token to a JSON.stringify()-able object */
|
|
220
341
|
toJSON(): VariableTokenJSON;
|
|
342
|
+
/** Evaluates the token */
|
|
221
343
|
evaluate(options: EvaluateOptions): Promise<unknown>;
|
|
222
344
|
}
|
|
223
345
|
}
|
|
@@ -229,16 +351,24 @@ declare module "parse/sequence-token" {
|
|
|
229
351
|
import type { default as IfToken } from "parse/if/token";
|
|
230
352
|
import type { default as VariableToken } from "parse/variable/token";
|
|
231
353
|
import BaseToken from "parse/base-token";
|
|
354
|
+
/** Options used to create a new SequenceToken instance */
|
|
232
355
|
export interface SequenceTokenOptions {
|
|
356
|
+
/** Position in the expression where the sequence started */
|
|
233
357
|
position: number;
|
|
234
|
-
value?: LookupToken | IfToken | VariableToken | TextToken | SequenceToken;
|
|
235
358
|
}
|
|
359
|
+
/** Represents a sequence of tokens from the expression */
|
|
236
360
|
export default class SequenceToken extends BaseToken {
|
|
237
361
|
value: Array<LookupToken | IfToken | VariableToken | TextToken | SequenceToken>;
|
|
238
362
|
constructor(options: SequenceTokenOptions);
|
|
239
|
-
|
|
363
|
+
/** Adds a token to the end of sequence */
|
|
364
|
+
add(
|
|
365
|
+
/** Token instance to add to the sequence */
|
|
366
|
+
token: LookupToken | IfToken | VariableToken | TextToken | SequenceToken): void;
|
|
367
|
+
/** If the sequence contains a singular token it returns that token otherwise returns `this` */
|
|
240
368
|
get unwrap(): SequenceToken | TextToken | LookupToken | IfToken | VariableToken;
|
|
369
|
+
/** Converts the sequence to a JSON.stringify()-able object */
|
|
241
370
|
toJSON(): SequenceTokenJSON | LookupTokenJSON | IfTokenJSON | VariableTokenJSON | TextTokenJSON;
|
|
371
|
+
/** Evaluates the sequence */
|
|
242
372
|
evaluate(options: EvaluateOptions): Promise<unknown>;
|
|
243
373
|
}
|
|
244
374
|
}
|
|
@@ -253,14 +383,21 @@ declare module "parse/arguments/token" {
|
|
|
253
383
|
import type VariableToken from "parse/variable/token";
|
|
254
384
|
import BaseToken from "parse/base-token";
|
|
255
385
|
import SequenceToken from "parse/sequence-token";
|
|
386
|
+
/** Represents the options for a new ArgumentsToken instance */
|
|
256
387
|
export interface ArgumentsTokenOptions {
|
|
388
|
+
/** Position of the arguments-bloc within the expression */
|
|
257
389
|
position: number;
|
|
390
|
+
/** Tokens contained in the arguments-bloc */
|
|
258
391
|
value?: Array<LookupToken | IfToken | VariableToken | TextToken | SequenceToken | LogicToken | ComparisonToken>;
|
|
259
392
|
}
|
|
393
|
+
/** Represents a list of arguments */
|
|
260
394
|
export default class ArgumentsToken extends BaseToken {
|
|
395
|
+
/** Tokens contained in the arguments-bloc */
|
|
261
396
|
value: Array<LookupToken | IfToken | VariableToken | TextToken | SequenceToken | LogicToken | ComparisonToken>;
|
|
262
397
|
constructor(options: ArgumentsTokenOptions);
|
|
398
|
+
/** Converts the token to a JSON.stringify()-able object */
|
|
263
399
|
toJSON(): ArgumentsTokenJSON;
|
|
400
|
+
/** Evaluates the token */
|
|
264
401
|
evaluate(options: EvaluateOptions): Promise<unknown[]>;
|
|
265
402
|
}
|
|
266
403
|
}
|
|
@@ -325,25 +462,34 @@ declare module "parse/lookup/token" {
|
|
|
325
462
|
import type { LookupTokenJSON } from "tojson-types";
|
|
326
463
|
import BaseToken from "parse/base-token";
|
|
327
464
|
import ArgumentsToken from "parse/arguments/token";
|
|
465
|
+
/** Represents the options for a new LookupToken instance */
|
|
328
466
|
export interface LookupTokenOptions {
|
|
467
|
+
/** Position in the expression the token occurs */
|
|
329
468
|
position: number;
|
|
469
|
+
/** The lookup's prefix */
|
|
330
470
|
prefix: string;
|
|
471
|
+
/** The name following the prefix */
|
|
331
472
|
value: string;
|
|
473
|
+
/** Arguments to pass to the lookup result's `evaluate()` function */
|
|
332
474
|
arguments?: ArgumentsToken;
|
|
333
475
|
}
|
|
334
476
|
export default class LookupToken extends BaseToken {
|
|
477
|
+
/** Lookup's prefix */
|
|
335
478
|
prefix: string;
|
|
479
|
+
/** The name - following the prefix - to be looked up */
|
|
336
480
|
value: string;
|
|
481
|
+
/** Arguments to pass to the lookup result's `evaluate()` function */
|
|
337
482
|
arguments?: ArgumentsToken;
|
|
338
483
|
constructor(options: LookupTokenOptions);
|
|
484
|
+
/** Converts the token to a JSON.stringify()-able object */
|
|
339
485
|
toJSON(): LookupTokenJSON;
|
|
340
486
|
evaluate(options: EvaluateOptions): Promise<unknown>;
|
|
341
487
|
}
|
|
342
488
|
}
|
|
343
489
|
declare module "parse/comparison/operators" {
|
|
344
|
-
import type {
|
|
345
|
-
/** Comparison
|
|
346
|
-
const _default_1:
|
|
490
|
+
import type { ComparisonOperatorMap } from "types";
|
|
491
|
+
/** Built-in Comparison Operators Map */
|
|
492
|
+
const _default_1: ComparisonOperatorMap;
|
|
347
493
|
export default _default_1;
|
|
348
494
|
}
|
|
349
495
|
declare module "parse/comparison/token" {
|
|
@@ -356,18 +502,29 @@ declare module "parse/comparison/token" {
|
|
|
356
502
|
import type { default as SequenceToken } from "parse/sequence-token";
|
|
357
503
|
type operand = LookupToken | IfToken | VariableToken | TextToken | SequenceToken;
|
|
358
504
|
import BaseToken from "parse/base-token";
|
|
505
|
+
/** Represents the options for a new ComparisonToken instance */
|
|
359
506
|
export interface ComparisonTokenOptions {
|
|
507
|
+
/** Position of the comparison within the expression */
|
|
360
508
|
position: number;
|
|
509
|
+
/** Comparison operator used */
|
|
361
510
|
value: string;
|
|
511
|
+
/** Left side of comparison */
|
|
362
512
|
left: operand;
|
|
513
|
+
/** Right side of comparison */
|
|
363
514
|
right?: operand;
|
|
364
515
|
}
|
|
516
|
+
/** Represents a Comparison Token */
|
|
365
517
|
export default class ComparisonToken extends BaseToken {
|
|
518
|
+
/** Comparison operator used */
|
|
366
519
|
value: string;
|
|
520
|
+
/** Left side of comparison */
|
|
367
521
|
left: operand;
|
|
522
|
+
/** Right side of comparison */
|
|
368
523
|
right?: operand;
|
|
369
524
|
constructor(options: ComparisonTokenOptions);
|
|
525
|
+
/** Converts the token to a JSON.stringify()-able object */
|
|
370
526
|
toJSON(): ComparisonTokenJSON;
|
|
527
|
+
/** Evaluates the token */
|
|
371
528
|
evaluate(options: EvaluateOptions): Promise<unknown>;
|
|
372
529
|
}
|
|
373
530
|
}
|
|
@@ -383,18 +540,29 @@ declare module "parse/if/token" {
|
|
|
383
540
|
type ConditionToken = ComparisonToken | LogicToken;
|
|
384
541
|
type OperandToken = LookupToken | IfToken | VariableToken | TextToken | SequenceToken;
|
|
385
542
|
import BaseToken from "parse/base-token";
|
|
543
|
+
/** Represents the options for a new IfToken instance */
|
|
386
544
|
export interface IfTokenOptions {
|
|
545
|
+
/** Position of the if-bloc within the expression*/
|
|
387
546
|
position: number;
|
|
547
|
+
/** The condition of the if-bloc */
|
|
388
548
|
value: ConditionToken;
|
|
549
|
+
/** Token to evaluate if the condition is truthy */
|
|
389
550
|
whenTrue: OperandToken;
|
|
551
|
+
/** Token to evaluate if the condition is not truthy */
|
|
390
552
|
whenFalse?: OperandToken;
|
|
391
553
|
}
|
|
554
|
+
/** Represents an if token */
|
|
392
555
|
export default class IfToken extends BaseToken {
|
|
556
|
+
/** The condition of the if-bloc */
|
|
393
557
|
value: ConditionToken;
|
|
558
|
+
/** Token to evaluate if the condition is truthy */
|
|
394
559
|
whenTrue: OperandToken;
|
|
560
|
+
/** Token to evaluate if the condition is not truthy */
|
|
395
561
|
whenFalse?: OperandToken;
|
|
396
562
|
constructor(options: IfTokenOptions);
|
|
563
|
+
/** Converts the token to a JSON.stringify()-able object */
|
|
397
564
|
toJSON(): IfTokenJSON;
|
|
565
|
+
/** Evaluates the token */
|
|
398
566
|
evaluate(options: EvaluateOptions): Promise<unknown>;
|
|
399
567
|
}
|
|
400
568
|
}
|
|
@@ -420,62 +588,119 @@ declare module "parse/root/token" {
|
|
|
420
588
|
import type { RootTokenJSON } from "tojson-types";
|
|
421
589
|
import type { TokenizeOptions, PreEval, EvaluateData, LookupMap, VariableMap, LogicOperatorMap, ComparisonOperatorMap } from "types";
|
|
422
590
|
import SequenceToken from "parse/sequence-token";
|
|
591
|
+
/** Represents the options for a new RootToken instance */
|
|
423
592
|
export type RootTokenOptions = TokenizeOptions;
|
|
593
|
+
/** Represents the options passed to a RootToken instance's `evaluate()` function */
|
|
424
594
|
export interface RootEvaluateOptions {
|
|
595
|
+
/** When true, only validation will occur. Logic Operators, Comparison Operators, Variable & Lookups will not be evaluated */
|
|
425
596
|
onlyValidate?: boolean;
|
|
597
|
+
/** Called just prior to evaluating each variable and/or lookup */
|
|
426
598
|
preeval?: PreEval;
|
|
599
|
+
/** Data to pass to Logic Operators, Comparison Operators, Variables and Lookup results' `evaluate()` functions */
|
|
427
600
|
data?: EvaluateData;
|
|
428
601
|
}
|
|
602
|
+
/** Wrapper token representing the `tokenized()` expression */
|
|
429
603
|
export default class RootToken extends SequenceToken {
|
|
604
|
+
/** Map of externally defined Lookup Handlers */
|
|
430
605
|
lookups: LookupMap;
|
|
606
|
+
/** Map of externally defined Variables */
|
|
431
607
|
variables: VariableMap;
|
|
432
|
-
|
|
608
|
+
/** Map of externally defined Logic Operators */
|
|
433
609
|
logicOperators: LogicOperatorMap;
|
|
610
|
+
/** Map of exernally defined Comparison Operators */
|
|
434
611
|
comparisonOperators: ComparisonOperatorMap;
|
|
612
|
+
/** Expression that is/was tokenized */
|
|
613
|
+
expression: string;
|
|
435
614
|
constructor(options: RootTokenOptions);
|
|
615
|
+
/** Converts the token to a JSON.stringify()-able object */
|
|
436
616
|
toJSON(): RootTokenJSON;
|
|
617
|
+
/** Evaluates the token */
|
|
437
618
|
evaluate(options?: RootEvaluateOptions): Promise<unknown>;
|
|
438
619
|
}
|
|
439
620
|
}
|
|
440
621
|
declare module "parse/text/escape" {
|
|
441
622
|
import type { GenericToken, TokenizeResult } from "types";
|
|
442
|
-
|
|
623
|
+
/** Attempts to consume an escape-sequence from `tokens` starting at `cursor` */
|
|
624
|
+
const _default_2: (
|
|
625
|
+
/** List of generic tokens to be tokenized into Token instances */
|
|
626
|
+
tokens: GenericToken[],
|
|
627
|
+
/** Current position within the tokens list */
|
|
628
|
+
cursor: number,
|
|
629
|
+
/** Escapable character; defaults to "$[,]\\rnt and double backticks */
|
|
630
|
+
escapeChars?: string) => TokenizeResult<GenericToken>;
|
|
443
631
|
export default _default_2;
|
|
444
632
|
}
|
|
445
633
|
declare module "parse/text/quote" {
|
|
446
634
|
import type { GenericToken, TokenizeResult } from "types";
|
|
447
635
|
import TextToken from "parse/text/token";
|
|
448
|
-
|
|
636
|
+
/** Attempts to consume quoted text from `tokens` starting at `cursor` */
|
|
637
|
+
const _default_3: (
|
|
638
|
+
/** List of generic tokens to be tokenized into Token instances */
|
|
639
|
+
tokens: GenericToken[],
|
|
640
|
+
/** Current position within the tokens list */
|
|
641
|
+
cursor: number) => TokenizeResult<TextToken>;
|
|
449
642
|
export default _default_3;
|
|
450
643
|
}
|
|
451
644
|
declare module "parse/variable/tokenize" {
|
|
452
645
|
import type { GenericToken, TokenizeOptions, TokenizeResult } from "types";
|
|
453
646
|
import VariableToken from "parse/variable/token";
|
|
454
|
-
|
|
647
|
+
/** Attempts to consume a varaiable from `tokens` starting at `cursor` */
|
|
648
|
+
const _default_4: (
|
|
649
|
+
/** List of generic tokens to be tokenized into Token instances */
|
|
650
|
+
tokens: GenericToken[],
|
|
651
|
+
/** Current position within the tokens list */
|
|
652
|
+
cursor: number,
|
|
653
|
+
/** Options passed to the `tokenize()` call */
|
|
654
|
+
options: TokenizeOptions) => TokenizeResult<VariableToken>;
|
|
455
655
|
export default _default_4;
|
|
456
656
|
}
|
|
457
657
|
declare module "parse/whitespace/tokenize" {
|
|
458
658
|
import type { GenericToken, TokenizeResult } from "types";
|
|
459
|
-
/**
|
|
460
|
-
const _default_5: (
|
|
659
|
+
/** Attempts to consume sequential whitespace from `tokens` beginning at `cursor` */
|
|
660
|
+
const _default_5: (
|
|
661
|
+
/** List of generic tokens to be tokenized into Token instances */
|
|
662
|
+
tokens: GenericToken[],
|
|
663
|
+
/** Current position within the tokens list */
|
|
664
|
+
cursor: number) => TokenizeResult<string>;
|
|
461
665
|
export default _default_5;
|
|
462
666
|
}
|
|
463
667
|
declare module "parse/comparison/tokenize" {
|
|
464
668
|
import type { GenericToken, TokenizeOptions, TokenizeResult } from "types";
|
|
465
669
|
import ComparisonToken from "parse/comparison/token";
|
|
466
|
-
|
|
670
|
+
/** Attempts to consume a comparison from `tokens` starting at `cursor` */
|
|
671
|
+
const _default_6: (
|
|
672
|
+
/** List of generic tokens to be tokenized into Token instances */
|
|
673
|
+
tokens: GenericToken[],
|
|
674
|
+
/** Current position within the tokens list */
|
|
675
|
+
cursor: number,
|
|
676
|
+
/** Options passed to the initial `tokenize()` call */
|
|
677
|
+
options: TokenizeOptions) => TokenizeResult<ComparisonToken>;
|
|
467
678
|
export default _default_6;
|
|
468
679
|
}
|
|
469
680
|
declare module "parse/logic/tokenize" {
|
|
470
681
|
import type { GenericToken, TokenizeOptions, TokenizeResult } from "types";
|
|
471
682
|
import LogicToken from "parse/logic/token";
|
|
472
|
-
|
|
683
|
+
/** Attempts to consume a Logic Operator from `tokens` starting at `cursor` */
|
|
684
|
+
const tokenizeLogicOperator: (
|
|
685
|
+
/** List of generic tokens to be tokenized into Token instances */
|
|
686
|
+
tokens: GenericToken[],
|
|
687
|
+
/** Current position within the tokens list */
|
|
688
|
+
cursor: number,
|
|
689
|
+
/** Options passed to the `tokenize()` call */
|
|
690
|
+
options: TokenizeOptions) => TokenizeResult<LogicToken>;
|
|
473
691
|
export default tokenizeLogicOperator;
|
|
474
692
|
}
|
|
475
693
|
declare module "parse/if/tokenize" {
|
|
476
694
|
import type { GenericToken, TokenizeOptions, TokenizeResult } from "types";
|
|
477
695
|
import IfToken from "parse/if/token";
|
|
478
|
-
|
|
696
|
+
/** Attempts to consume an If Statement from `tokens` starting at `cursor` */
|
|
697
|
+
const _default_7: (
|
|
698
|
+
/** List of generic tokens to be tokenized into Token instances */
|
|
699
|
+
tokens: GenericToken[],
|
|
700
|
+
/** Current position within the tokens list */
|
|
701
|
+
cursor: number,
|
|
702
|
+
/** Options passed to the `tokenize()` call */
|
|
703
|
+
options: TokenizeOptions) => TokenizeResult<IfToken>;
|
|
479
704
|
export default _default_7;
|
|
480
705
|
}
|
|
481
706
|
declare module "parse/arguments/argument" {
|
|
@@ -485,19 +710,40 @@ declare module "parse/arguments/argument" {
|
|
|
485
710
|
import SequenceToken from "parse/sequence-token";
|
|
486
711
|
import TextToken from "parse/text/token";
|
|
487
712
|
import VariableToken from "parse/variable/token";
|
|
488
|
-
|
|
713
|
+
/** Attempts to tokenize a singular argument for a arguments-bloc from `tokens` starting at `cursor` */
|
|
714
|
+
const _default_8: (
|
|
715
|
+
/** List of generic tokens to be tokenized into Token instances */
|
|
716
|
+
tokens: GenericToken[],
|
|
717
|
+
/** Current position within the tokens list */
|
|
718
|
+
cursor: number,
|
|
719
|
+
/** Options passed to the initial `tokenize()` call */
|
|
720
|
+
options: TokenizeOptions) => TokenizeResult<LookupToken | IfToken | VariableToken | TextToken | SequenceToken>;
|
|
489
721
|
export default _default_8;
|
|
490
722
|
}
|
|
491
723
|
declare module "parse/arguments/tokenize" {
|
|
492
724
|
import type { GenericToken, TokenizeOptions, TokenizeResult } from "types";
|
|
493
725
|
import ArgumentsToken from "parse/arguments/token";
|
|
494
|
-
|
|
726
|
+
/** Attempts to consume an arguments-bloc from `tokens` starting at `cursor` */
|
|
727
|
+
const _default_9: (
|
|
728
|
+
/** List of generic tokens to be tokenized into Token instances */
|
|
729
|
+
tokens: GenericToken[],
|
|
730
|
+
/** Current position within the tokens list */
|
|
731
|
+
cursor: number,
|
|
732
|
+
/** Options passed to the initial `tokenize()` call */
|
|
733
|
+
options: TokenizeOptions) => TokenizeResult<ArgumentsToken>;
|
|
495
734
|
export default _default_9;
|
|
496
735
|
}
|
|
497
736
|
declare module "parse/lookup/tokenize" {
|
|
498
737
|
import type { GenericToken, TokenizeOptions, TokenizeResult } from "types";
|
|
499
738
|
import LookupToken from "parse/lookup/token";
|
|
500
|
-
|
|
739
|
+
/** Attempts to tokenize a Lookup from `tokens` starting at `cursor */
|
|
740
|
+
const _default_10: (
|
|
741
|
+
/** List of generic tokens to be tokenized into Token instances */
|
|
742
|
+
tokens: GenericToken[],
|
|
743
|
+
/** Current position within the tokens list */
|
|
744
|
+
cursor: number,
|
|
745
|
+
/** Options passed to the `tokenize()` call */
|
|
746
|
+
options: TokenizeOptions) => TokenizeResult<LookupToken>;
|
|
501
747
|
export default _default_10;
|
|
502
748
|
}
|
|
503
749
|
declare module "parse/text/block" {
|
|
@@ -507,24 +753,36 @@ declare module "parse/text/block" {
|
|
|
507
753
|
import type VariableToken from "parse/variable/token";
|
|
508
754
|
import SequenceToken from "parse/sequence-token";
|
|
509
755
|
import TextToken from "parse/text/token";
|
|
510
|
-
|
|
756
|
+
/** Attempts to consume a block-escape sequence from `tokens` starting at `cursor` */
|
|
757
|
+
const _default_11: (
|
|
758
|
+
/** List of generic tokens to be tokenized into Token instances */
|
|
759
|
+
tokens: GenericToken[],
|
|
760
|
+
/** Current position within the tokens list */
|
|
761
|
+
cursor: number,
|
|
762
|
+
/** Options passed to initial tokenize() call */
|
|
763
|
+
options: TokenizeOptions) => TokenizeResult<LookupToken | IfToken | VariableToken | TextToken | SequenceToken>;
|
|
511
764
|
export default _default_11;
|
|
512
765
|
}
|
|
513
766
|
declare module "parse/root/tokenize" {
|
|
514
767
|
import type { TokenizeOptions } from "types";
|
|
515
768
|
import RootToken from "parse/root/token";
|
|
516
|
-
|
|
769
|
+
/** Attempts to tokenize the given expression into Token instances */
|
|
770
|
+
const _default_12: (
|
|
771
|
+
/** Options passed to initial tokenize() call */
|
|
772
|
+
options: TokenizeOptions) => RootToken;
|
|
517
773
|
export default _default_12;
|
|
518
774
|
}
|
|
519
775
|
declare module "expressionish" {
|
|
520
|
-
import { TokenizeOptions, EvaluateOptions } from "types";
|
|
776
|
+
import { TokenizeOptions, LookupMap, EvaluateOptions, LogicOperatorMap, ComparisonOperatorMap } from "types";
|
|
777
|
+
export { TokenizeOptions, LookupMap, EvaluateOptions, LogicOperatorMap, ComparisonOperatorMap };
|
|
778
|
+
import { default as RootToken, RootTokenOptions, RootEvaluateOptions } from "parse/root/token";
|
|
779
|
+
export { RootToken, RootTokenOptions, RootEvaluateOptions };
|
|
521
780
|
export { default as ArgumentsToken, ArgumentsTokenOptions } from "parse/arguments/token";
|
|
522
781
|
export { default as BaseToken, BaseTokenOptions } from "parse/base-token";
|
|
523
782
|
export { default as ComparisonToken, ComparisonTokenOptions } from "parse/comparison/token";
|
|
524
783
|
export { default as IfToken, IfTokenOptions } from "parse/if/token";
|
|
525
784
|
export { default as LogicToken, LogicTokenOptions } from "parse/logic/token";
|
|
526
785
|
export { default as LookupToken, LookupTokenOptions } from "parse/lookup/token";
|
|
527
|
-
export { default as RootToken, RootTokenOptions, RootEvaluateOptions } from "parse/root/token";
|
|
528
786
|
export { default as SequenceToken } from "parse/sequence-token";
|
|
529
787
|
export { default as TextToken, TextTokenOptions } from "parse/text/token";
|
|
530
788
|
export { default as VariableToken, VariableTokenOptions } from "parse/variable/token";
|
|
@@ -532,7 +790,7 @@ declare module "expressionish" {
|
|
|
532
790
|
/** Parses a string expression into a usable Expressionish-Token instance */
|
|
533
791
|
export const tokenize: (
|
|
534
792
|
/** Options to use during tokenization */
|
|
535
|
-
options: TokenizeOptions) =>
|
|
793
|
+
options: TokenizeOptions) => RootToken;
|
|
536
794
|
/** Parses then evaluates expression text */
|
|
537
795
|
export const evaluate: (
|
|
538
796
|
/** Options passed to the parser and evaluator */
|