@jbrowse/jexl 4.0.1 → 5.0.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.
Files changed (110) hide show
  1. package/README.md +163 -20
  2. package/dist/Expression.d.ts +16 -0
  3. package/dist/Expression.js +28 -4
  4. package/dist/Expression.js.map +1 -1
  5. package/dist/Jexl.d.ts +20 -8
  6. package/dist/Jexl.js +34 -15
  7. package/dist/Jexl.js.map +1 -1
  8. package/dist/Lexer.d.ts +4 -3
  9. package/dist/Lexer.js +29 -21
  10. package/dist/Lexer.js.map +1 -1
  11. package/dist/analyze.d.ts +84 -0
  12. package/dist/analyze.js +259 -0
  13. package/dist/analyze.js.map +1 -0
  14. package/dist/check.d.ts +109 -0
  15. package/dist/check.js +1267 -0
  16. package/dist/check.js.map +1 -0
  17. package/dist/collections.d.ts +3 -0
  18. package/dist/collections.js +140 -0
  19. package/dist/collections.js.map +1 -0
  20. package/dist/conditions.d.ts +62 -0
  21. package/dist/conditions.js +207 -0
  22. package/dist/conditions.js.map +1 -0
  23. package/dist/errors.d.ts +5 -0
  24. package/dist/errors.js +18 -0
  25. package/dist/errors.js.map +1 -0
  26. package/dist/evaluator/compile.d.ts +10 -7
  27. package/dist/evaluator/compile.js +292 -99
  28. package/dist/evaluator/compile.js.map +1 -1
  29. package/dist/grammar.d.ts +22 -9
  30. package/dist/grammar.js +83 -55
  31. package/dist/grammar.js.map +1 -1
  32. package/dist/index.d.ts +9 -0
  33. package/dist/index.js +16 -1
  34. package/dist/index.js.map +1 -1
  35. package/dist/operators.d.ts +34 -0
  36. package/dist/operators.js +131 -0
  37. package/dist/operators.js.map +1 -0
  38. package/dist/parser/Parser.d.ts +48 -91
  39. package/dist/parser/Parser.js +347 -221
  40. package/dist/parser/Parser.js.map +1 -1
  41. package/dist/types.d.ts +11 -5
  42. package/esm/Expression.d.ts +16 -0
  43. package/esm/Expression.js +28 -4
  44. package/esm/Expression.js.map +1 -1
  45. package/esm/Jexl.d.ts +20 -8
  46. package/esm/Jexl.js +34 -15
  47. package/esm/Jexl.js.map +1 -1
  48. package/esm/Lexer.d.ts +4 -3
  49. package/esm/Lexer.js +29 -21
  50. package/esm/Lexer.js.map +1 -1
  51. package/esm/analyze.d.ts +84 -0
  52. package/esm/analyze.js +256 -0
  53. package/esm/analyze.js.map +1 -0
  54. package/esm/check.d.ts +109 -0
  55. package/esm/check.js +1260 -0
  56. package/esm/check.js.map +1 -0
  57. package/esm/collections.d.ts +3 -0
  58. package/esm/collections.js +137 -0
  59. package/esm/collections.js.map +1 -0
  60. package/esm/conditions.d.ts +62 -0
  61. package/esm/conditions.js +200 -0
  62. package/esm/conditions.js.map +1 -0
  63. package/esm/errors.d.ts +5 -0
  64. package/esm/errors.js +14 -0
  65. package/esm/errors.js.map +1 -0
  66. package/esm/evaluator/compile.d.ts +10 -7
  67. package/esm/evaluator/compile.js +292 -99
  68. package/esm/evaluator/compile.js.map +1 -1
  69. package/esm/grammar.d.ts +22 -9
  70. package/esm/grammar.js +79 -53
  71. package/esm/grammar.js.map +1 -1
  72. package/esm/index.d.ts +9 -0
  73. package/esm/index.js +4 -0
  74. package/esm/index.js.map +1 -1
  75. package/esm/operators.d.ts +34 -0
  76. package/esm/operators.js +123 -0
  77. package/esm/operators.js.map +1 -0
  78. package/esm/parser/Parser.d.ts +48 -91
  79. package/esm/parser/Parser.js +349 -192
  80. package/esm/parser/Parser.js.map +1 -1
  81. package/esm/types.d.ts +11 -5
  82. package/package.json +1 -1
  83. package/src/Expression.ts +34 -4
  84. package/src/Jexl.ts +52 -16
  85. package/src/Lexer.ts +32 -21
  86. package/src/analyze.ts +378 -0
  87. package/src/check.ts +1682 -0
  88. package/src/collections.ts +148 -0
  89. package/src/conditions.ts +262 -0
  90. package/src/errors.ts +15 -0
  91. package/src/evaluator/compile.ts +351 -102
  92. package/src/grammar.ts +137 -55
  93. package/src/index.ts +15 -0
  94. package/src/operators.ts +151 -0
  95. package/src/parser/Parser.ts +389 -199
  96. package/src/types.ts +13 -3
  97. package/dist/parser/handlers.d.ts +0 -115
  98. package/dist/parser/handlers.js +0 -352
  99. package/dist/parser/handlers.js.map +0 -1
  100. package/dist/parser/states.d.ts +0 -47
  101. package/dist/parser/states.js +0 -176
  102. package/dist/parser/states.js.map +0 -1
  103. package/esm/parser/handlers.d.ts +0 -115
  104. package/esm/parser/handlers.js +0 -328
  105. package/esm/parser/handlers.js.map +0 -1
  106. package/esm/parser/states.d.ts +0 -47
  107. package/esm/parser/states.js +0 -140
  108. package/esm/parser/states.js.map +0 -1
  109. package/src/parser/handlers.ts +0 -372
  110. package/src/parser/states.ts +0 -159
package/src/types.ts CHANGED
@@ -16,22 +16,25 @@ export type JexlValue =
16
16
  | undefined
17
17
  | JexlValue[]
18
18
  | { [key: string]: JexlValue }
19
+ | JexlFunction
20
+
21
+ /** What a lambda evaluates to, for a registered function to call. */
22
+ export type JexlFunction = (...args: JexlValue[]) => JexlValue
19
23
 
20
24
  export interface Token {
21
25
  type: string
22
- value: string | number | boolean | TemplatePart[]
26
+ value: string | number | boolean | null | TemplatePart[]
23
27
  raw: string
24
28
  }
25
29
 
26
30
  export interface AstNode {
27
31
  type: string
28
- _parent?: AstNode
29
32
  right?: AstNode
30
33
  }
31
34
 
32
35
  export interface Literal extends AstNode {
33
36
  type: 'Literal'
34
- value: string | number | boolean
37
+ value: string | number | boolean | null
35
38
  }
36
39
 
37
40
  export interface Identifier extends AstNode {
@@ -102,6 +105,12 @@ export interface AssignmentExpression extends AstNode {
102
105
  left: Identifier
103
106
  }
104
107
 
108
+ export interface Lambda extends AstNode {
109
+ type: 'Lambda'
110
+ params: string[]
111
+ body: AstNode
112
+ }
113
+
105
114
  export type AstNodeUnion =
106
115
  | Literal
107
116
  | Identifier
@@ -115,6 +124,7 @@ export type AstNodeUnion =
115
124
  | ConditionalExpression
116
125
  | SequenceExpression
117
126
  | AssignmentExpression
127
+ | Lambda
118
128
 
119
129
  export type NodeByType<T extends AstNodeUnion['type']> = Extract<
120
130
  AstNodeUnion,
@@ -1,115 +0,0 @@
1
- import Parser from './Parser.ts';
2
- import type { AstNode, Token } from '../types.ts';
3
- /**
4
- * Handles a subexpression that's used to define a transform argument's value.
5
- * @param {{type: <string>}} ast The subexpression tree
6
- */
7
- export declare function argVal(this: Parser, ast: AstNode | null): void;
8
- /**
9
- * Handles new array literals by adding them as a new node in the AST,
10
- * initialized with an empty array.
11
- */
12
- export declare function arrayStart(this: Parser): void;
13
- /**
14
- * Handles a subexpression representing an element of an array literal.
15
- * @param {{type: <string>}} ast The subexpression tree
16
- */
17
- export declare function arrayVal(this: Parser, ast: AstNode | null): void;
18
- /**
19
- * Handles tokens of type 'binaryOp', indicating an operation that has two
20
- * inputs: a left side and a right side.
21
- * @param {{type: <string>}} token A token object
22
- */
23
- export declare function binaryOp(this: Parser, token: Token): void;
24
- /**
25
- * Handles successive nodes in an identifier chain. More specifically, it
26
- * sets values that determine how the following identifier gets placed in the
27
- * AST.
28
- */
29
- export declare function dot(this: Parser): void;
30
- /**
31
- * Handles a subexpression used for filtering an array returned by an
32
- * identifier chain.
33
- * @param {{type: <string>}} ast The subexpression tree
34
- */
35
- export declare function filter(this: Parser, ast: AstNode | null): void;
36
- /**
37
- * Handles identifier tokens when used to indicate the name of a function to
38
- * be called.
39
- *
40
- * A call written against a value, `a.b(x)`, becomes `b(a, x)`: jexl functions
41
- * live in one global pool and have no receiver, so the value the name was read
42
- * from is passed as the first argument instead. Every function in the pool is
43
- * already written that way — `get(feature, key)`, `split(str, sep)` — which is
44
- * what makes the two spellings equivalent. Previously the receiver was simply
45
- * dropped, so `refName.split(' ')` quietly called `split(' ')`.
46
- */
47
- export declare function functionCall(this: Parser): void;
48
- /**
49
- * Handles identifier tokens by adding them as a new node in the AST.
50
- * @param {{type: <string>}} token A token object
51
- */
52
- export declare function identifier(this: Parser, token: Token): void;
53
- /**
54
- * Handles literal values, such as strings, booleans, and numerics, by adding
55
- * them as a new node in the AST.
56
- * @param {{type: <string>}} token A token object
57
- */
58
- export declare function literal(this: Parser, token: Token): void;
59
- /**
60
- * Handles template string tokens by parsing their interpolation expressions
61
- * and creating a TemplateLiteral AST node.
62
- * @param {{type: <string>}} token A token object
63
- */
64
- export declare function templateString(this: Parser, token: Token): void;
65
- /**
66
- * Queues a new object literal key to be written once a value is collected.
67
- * @param {{type: <string>}} token A token object
68
- */
69
- export declare function objKey(this: Parser, token: Token): void;
70
- /**
71
- * Handles new object literals by adding them as a new node in the AST,
72
- * initialized with an empty object.
73
- */
74
- export declare function objStart(this: Parser): void;
75
- /**
76
- * Handles an object value by adding its AST to the queued key on the object
77
- * literal node currently at the cursor.
78
- * @param {{type: <string>}} ast The subexpression tree
79
- */
80
- export declare function objVal(this: Parser, ast: AstNode | null): void;
81
- /**
82
- * Handles traditional subexpressions, delineated with the groupStart and
83
- * groupEnd elements.
84
- * @param {{type: <string>}} ast The subexpression tree
85
- */
86
- export declare function subExpression(this: Parser, ast: AstNode | null): void;
87
- /**
88
- * Handles a completed alternate subexpression of a ternary operator.
89
- * @param {{type: <string>}} ast The subexpression tree
90
- */
91
- export declare function ternaryEnd(this: Parser, ast: AstNode | null): void;
92
- /**
93
- * Handles a completed consequent subexpression of a ternary operator.
94
- * @param {{type: <string>}} ast The subexpression tree
95
- */
96
- export declare function ternaryMid(this: Parser, ast: AstNode | null): void;
97
- /**
98
- * Handles the start of a new ternary expression by encapsulating the tree so
99
- * far in a ConditionalExpression node, and using it as the test element.
100
- *
101
- * Every operator binds tighter than the conditional and so belongs in the test
102
- * — except `=`, which binds looser. `x = a ? b : c` therefore assigns the
103
- * conditional rather than testing the assignment, which had stored `a` in `x`.
104
- */
105
- export declare function ternaryStart(this: Parser): void;
106
- /**
107
- * Handles token of type 'unaryOp', indicating that the operation has only
108
- * one input: a right side.
109
- * @param {{type: <string>}} token A token object
110
- */
111
- export declare function unaryOp(this: Parser, token: Token): void;
112
- /**
113
- * Handles semicolon separator between expressions
114
- */
115
- export declare function semicolon(this: Parser): void;
@@ -1,352 +0,0 @@
1
- "use strict";
2
- /*
3
- * Jexl
4
- * Copyright 2020 Tom Shawver
5
- */
6
- var __importDefault = (this && this.__importDefault) || function (mod) {
7
- return (mod && mod.__esModule) ? mod : { "default": mod };
8
- };
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.argVal = argVal;
11
- exports.arrayStart = arrayStart;
12
- exports.arrayVal = arrayVal;
13
- exports.binaryOp = binaryOp;
14
- exports.dot = dot;
15
- exports.filter = filter;
16
- exports.functionCall = functionCall;
17
- exports.identifier = identifier;
18
- exports.literal = literal;
19
- exports.templateString = templateString;
20
- exports.objKey = objKey;
21
- exports.objStart = objStart;
22
- exports.objVal = objVal;
23
- exports.subExpression = subExpression;
24
- exports.ternaryEnd = ternaryEnd;
25
- exports.ternaryMid = ternaryMid;
26
- exports.ternaryStart = ternaryStart;
27
- exports.unaryOp = unaryOp;
28
- exports.semicolon = semicolon;
29
- const grammar_ts_1 = require("../grammar.js");
30
- // circular with Parser.ts, which is fine: the binding is only read from inside
31
- // a handler, long after both modules have finished evaluating
32
- const Parser_ts_1 = __importDefault(require("./Parser.js"));
33
- /**
34
- * Handles a subexpression that's used to define a transform argument's value.
35
- * @param {{type: <string>}} ast The subexpression tree
36
- */
37
- function argVal(ast) {
38
- if (ast) {
39
- ;
40
- this._cursor.args.push(ast);
41
- }
42
- }
43
- /**
44
- * Handles new array literals by adding them as a new node in the AST,
45
- * initialized with an empty array.
46
- */
47
- function arrayStart() {
48
- const node = {
49
- type: 'ArrayLiteral',
50
- value: []
51
- };
52
- this._placeAtCursor(node);
53
- }
54
- /**
55
- * Handles a subexpression representing an element of an array literal.
56
- * @param {{type: <string>}} ast The subexpression tree
57
- */
58
- function arrayVal(ast) {
59
- if (ast) {
60
- ;
61
- this._cursor.value.push(ast);
62
- }
63
- }
64
- /**
65
- * Handles tokens of type 'binaryOp', indicating an operation that has two
66
- * inputs: a left side and a right side.
67
- * @param {{type: <string>}} token A token object
68
- */
69
- function binaryOp(token) {
70
- if (token.value === '=') {
71
- // `from` marks a member access such as `a.b`; only a bare name can be
72
- // assigned to, since the compiled closure writes straight into the context
73
- if (this._cursor?.type !== 'Identifier' ||
74
- this._cursor.from) {
75
- throw new Error('Left side of assignment must be a variable name');
76
- }
77
- const node = {
78
- type: 'AssignmentExpression',
79
- operator: '=',
80
- left: this._cursor
81
- };
82
- this._cursor = this._cursor._parent;
83
- this._placeAtCursor(node);
84
- return;
85
- }
86
- const tokenValue = token.value;
87
- const precedence = (0, grammar_ts_1.precedenceOf)(this._grammar.elements[tokenValue]);
88
- let parent = this._cursor?._parent;
89
- while (parent) {
90
- const parentExpr = parent;
91
- if (!parentExpr.operator) {
92
- break;
93
- }
94
- // a prefix operator binds tighter than any binary one, so `-x ^ 2` groups
95
- // as `(-x) ^ 2` — the same way `-2 ^ 2` already does, since the Lexer folds
96
- // that sign into the literal. Looking `-` up in the grammar finds its
97
- // binary precedence instead, which is lower than `^`'s and gave `-(x ^ 2)`
98
- const parentPrecedence = parent.type === 'UnaryExpression'
99
- ? Infinity
100
- : (0, grammar_ts_1.precedenceOf)(this._grammar.elements[parentExpr.operator]);
101
- if (parentPrecedence < precedence) {
102
- break;
103
- }
104
- this._cursor = parent;
105
- parent = parent._parent;
106
- }
107
- const node = {
108
- type: 'BinaryExpression',
109
- operator: tokenValue,
110
- left: this._cursor
111
- };
112
- this._setParent(this._cursor, node);
113
- this._cursor = parent;
114
- this._placeAtCursor(node);
115
- }
116
- /**
117
- * Handles successive nodes in an identifier chain. More specifically, it
118
- * sets values that determine how the following identifier gets placed in the
119
- * AST.
120
- */
121
- function dot() {
122
- const cursor = this._cursor;
123
- // a dot continues an identifier chain. With nothing to continue — no cursor,
124
- // or an operator still waiting on its right-hand side — it would instead open
125
- // a relative path, the leading dot of `list[.price > 5]`. This fork removed
126
- // array filtering expressions, which are the only construct that gives a
127
- // relative path a root to resolve against, so it is rejected here rather than
128
- // parsed into a tree that can only fail once it is evaluated.
129
- if (!cursor ||
130
- cursor.type === 'UnaryExpression' ||
131
- (cursor.type === 'BinaryExpression' && !cursor.right)) {
132
- throw new Error(`Relative paths are not supported: ${this._exprStr}`);
133
- }
134
- this._nextIdentEncapsulate = true;
135
- }
136
- /**
137
- * Handles a subexpression used for filtering an array returned by an
138
- * identifier chain.
139
- * @param {{type: <string>}} ast The subexpression tree
140
- */
141
- function filter(ast) {
142
- const node = {
143
- type: 'FilterExpression',
144
- expr: ast,
145
- subject: this._cursor
146
- };
147
- this._placeBeforeCursor(node);
148
- }
149
- /**
150
- * Handles identifier tokens when used to indicate the name of a function to
151
- * be called.
152
- *
153
- * A call written against a value, `a.b(x)`, becomes `b(a, x)`: jexl functions
154
- * live in one global pool and have no receiver, so the value the name was read
155
- * from is passed as the first argument instead. Every function in the pool is
156
- * already written that way — `get(feature, key)`, `split(str, sep)` — which is
157
- * what makes the two spellings equivalent. Previously the receiver was simply
158
- * dropped, so `refName.split(' ')` quietly called `split(' ')`.
159
- */
160
- function functionCall() {
161
- const cursor = this._cursor;
162
- if (cursor?.type !== 'Identifier') {
163
- // reached by `a[expr]()`, whose subject is a filter rather than a name;
164
- // there is nothing to look up in the function pool
165
- throw new Error(`Functions must be called by name: ${this._exprStr}`);
166
- }
167
- const { from, value } = cursor;
168
- const node = {
169
- type: 'FunctionCall',
170
- name: value,
171
- args: from ? [from] : []
172
- };
173
- this._placeBeforeCursor(node);
174
- }
175
- /**
176
- * Handles identifier tokens by adding them as a new node in the AST.
177
- * @param {{type: <string>}} token A token object
178
- */
179
- function identifier(token) {
180
- const node = {
181
- type: 'Identifier',
182
- value: token.value
183
- };
184
- if (this._nextIdentEncapsulate) {
185
- node.from = this._cursor;
186
- this._placeBeforeCursor(node);
187
- this._nextIdentEncapsulate = false;
188
- }
189
- else {
190
- this._placeAtCursor(node);
191
- }
192
- }
193
- /**
194
- * Handles literal values, such as strings, booleans, and numerics, by adding
195
- * them as a new node in the AST.
196
- * @param {{type: <string>}} token A token object
197
- */
198
- function literal(token) {
199
- const node = {
200
- type: 'Literal',
201
- value: token.value
202
- };
203
- this._placeAtCursor(node);
204
- }
205
- /**
206
- * Handles template string tokens by parsing their interpolation expressions
207
- * and creating a TemplateLiteral AST node.
208
- * @param {{type: <string>}} token A token object
209
- */
210
- function templateString(token) {
211
- const parts = [];
212
- const tokenParts = Array.isArray(token.value) ? token.value : [];
213
- for (const part of tokenParts) {
214
- if (part.type === 'static') {
215
- parts.push({
216
- type: 'static',
217
- value: this._lexer._unescapeTemplateString(part.value)
218
- });
219
- }
220
- else {
221
- const subTokens = this._lexer.tokenize(part.value);
222
- const subParser = new Parser_ts_1.default(this._grammar, this._lexer);
223
- subParser.addTokens(subTokens);
224
- const subAst = subParser.complete();
225
- if (!subAst) {
226
- throw new Error('Empty interpolation in template string');
227
- }
228
- parts.push({
229
- type: 'expression',
230
- value: subAst
231
- });
232
- }
233
- }
234
- const node = {
235
- type: 'TemplateLiteral',
236
- parts
237
- };
238
- this._placeAtCursor(node);
239
- }
240
- /**
241
- * Queues a new object literal key to be written once a value is collected.
242
- * @param {{type: <string>}} token A token object
243
- */
244
- function objKey(token) {
245
- this._curObjKey = token.value;
246
- }
247
- /**
248
- * Handles new object literals by adding them as a new node in the AST,
249
- * initialized with an empty object.
250
- */
251
- function objStart() {
252
- const node = {
253
- type: 'ObjectLiteral',
254
- value: {}
255
- };
256
- this._placeAtCursor(node);
257
- }
258
- /**
259
- * Handles an object value by adding its AST to the queued key on the object
260
- * literal node currently at the cursor.
261
- * @param {{type: <string>}} ast The subexpression tree
262
- */
263
- function objVal(ast) {
264
- // defined rather than assigned so that the key "__proto__" becomes an
265
- // ordinary entry of the node's key map instead of re-pointing its prototype,
266
- // which dropped the entry before it could be compiled
267
- Object.defineProperty(this._cursor.value, this._curObjKey, {
268
- value: ast,
269
- writable: true,
270
- enumerable: true,
271
- configurable: true
272
- });
273
- }
274
- /**
275
- * Handles traditional subexpressions, delineated with the groupStart and
276
- * groupEnd elements.
277
- * @param {{type: <string>}} ast The subexpression tree
278
- */
279
- function subExpression(ast) {
280
- this._placeAtCursor(ast);
281
- }
282
- /**
283
- * Handles a completed alternate subexpression of a ternary operator.
284
- * @param {{type: <string>}} ast The subexpression tree
285
- */
286
- function ternaryEnd(ast) {
287
- ;
288
- this._cursor.alternate = ast ?? undefined;
289
- }
290
- /**
291
- * Handles a completed consequent subexpression of a ternary operator.
292
- * @param {{type: <string>}} ast The subexpression tree
293
- */
294
- function ternaryMid(ast) {
295
- ;
296
- this._cursor.consequent = ast ?? undefined;
297
- }
298
- /**
299
- * Handles the start of a new ternary expression by encapsulating the tree so
300
- * far in a ConditionalExpression node, and using it as the test element.
301
- *
302
- * Every operator binds tighter than the conditional and so belongs in the test
303
- * — except `=`, which binds looser. `x = a ? b : c` therefore assigns the
304
- * conditional rather than testing the assignment, which had stored `a` in `x`.
305
- */
306
- function ternaryStart() {
307
- let assignment;
308
- let test = this._tree;
309
- while (test.type === 'AssignmentExpression' && test.right) {
310
- assignment = test;
311
- test = test.right;
312
- }
313
- const node = {
314
- type: 'ConditionalExpression',
315
- test
316
- };
317
- if (assignment) {
318
- assignment.right = node;
319
- this._setParent(node, assignment);
320
- }
321
- else {
322
- this._tree = node;
323
- }
324
- this._cursor = node;
325
- }
326
- /**
327
- * Handles token of type 'unaryOp', indicating that the operation has only
328
- * one input: a right side.
329
- * @param {{type: <string>}} token A token object
330
- */
331
- function unaryOp(token) {
332
- const node = {
333
- type: 'UnaryExpression',
334
- operator: token.value
335
- };
336
- this._placeAtCursor(node);
337
- }
338
- /**
339
- * Handles semicolon separator between expressions
340
- */
341
- function semicolon() {
342
- if (!this._sequenceExpressions) {
343
- this._sequenceExpressions = [this._tree];
344
- }
345
- else {
346
- this._sequenceExpressions.push(this._tree);
347
- }
348
- this._tree = null;
349
- this._cursor = null;
350
- this._state = 'expectOperand';
351
- }
352
- //# sourceMappingURL=handlers.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"handlers.js","sourceRoot":"","sources":["../../src/parser/handlers.ts"],"names":[],"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IAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC/B,IAAI,CAAC,oBAAoB,GAAG,CAAC,IAAI,CAAC,KAAM,CAAC,CAAA;IAC3C,CAAC;SAAM,CAAC;QACN,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,KAAM,CAAC,CAAA;IAC7C,CAAC;IAED,IAAI,CAAC,KAAK,GAAG,IAAI,CAAA;IACjB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA;IACnB,IAAI,CAAC,MAAM,GAAG,eAAe,CAAA;AAC/B,CAAC"}
@@ -1,47 +0,0 @@
1
- import type { AstNode, Token } from '../types.ts';
2
- import type Parser from './Parser.ts';
3
- interface TokenTypeOptions {
4
- toState?: string;
5
- handler?: (this: Parser, token: Token) => void;
6
- }
7
- interface StateDefinition {
8
- tokenTypes?: Record<string, TokenTypeOptions>;
9
- subHandler?: (this: Parser, ast: AstNode | null) => void;
10
- endStates?: Record<string, string>;
11
- completable?: boolean;
12
- }
13
- type States = Record<string, StateDefinition>;
14
- /**
15
- * A mapping of all states in the finite state machine to a set of instructions
16
- * for handling or transitioning into other states. Each state can be handled
17
- * in one of two schemes: a tokenType map, or a subHandler.
18
- *
19
- * Standard expression elements are handled through the tokenType object. This
20
- * is an object map of all legal token types to encounter in this state (and
21
- * any unexpected token types will generate a thrown error) to an options
22
- * object that defines how they're handled. The available options are:
23
- *
24
- * {string} toState: The name of the state to which to transition
25
- * immediately after handling this token
26
- * {string} handler: The handler function to call when this token type is
27
- * encountered in this state. If omitted, the default handler
28
- * matching the token's "type" property will be called. If the handler
29
- * function does not exist, no call will be made and no error will be
30
- * generated. This is useful for tokens whose sole purpose is to
31
- * transition to other states.
32
- *
33
- * States that consume a subexpression should define a subHandler, the
34
- * function to be called with an expression tree argument when the
35
- * subexpression is complete. Completeness is determined through the
36
- * endStates object, which maps tokens on which an expression should end to the
37
- * state to which to transition once the subHandler function has been called.
38
- *
39
- * Additionally, any state in which it is legal to mark the AST as completed
40
- * should have a 'completable' property set to boolean true. Attempting to
41
- * call {@link Parser#complete} in any state without this property will result
42
- * in a thrown Error.
43
- *
44
- * @type {{}}
45
- */
46
- export declare const states: States;
47
- export {};