@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
@@ -2,231 +2,388 @@
2
2
  * Jexl
3
3
  * Copyright 2020 Tom Shawver
4
4
  */
5
- import * as handlers from "./handlers.js";
6
- import { states } from "./states.js";
5
+ import { JexlSyntaxError } from "../errors.js";
6
+ const logical = new Set(['&&', '||']);
7
+ const omittedAlternateBefore = new Set([
8
+ 'closeParen',
9
+ 'closeBracket',
10
+ 'closeCurl',
11
+ 'comma',
12
+ 'semicolon'
13
+ ]);
14
+ export { JexlSyntaxError } from "../errors.js";
7
15
  /**
8
- * The handler to run for a token type when the state it appears in doesn't
9
- * name one of its own. Token types absent here — the brackets, parens and
10
- * separators — carry no behavior beyond the state transition the state machine
11
- * gives them.
12
- */
13
- const tokenHandlers = {
14
- binaryOp: handlers.binaryOp,
15
- dot: handlers.dot,
16
- identifier: handlers.identifier,
17
- literal: handlers.literal,
18
- semicolon: handlers.semicolon,
19
- templateString: handlers.templateString,
20
- unaryOp: handlers.unaryOp
21
- };
22
- /**
23
- * The Parser is a state machine that converts tokens from the {@link Lexer}
24
- * into an Abstract Syntax Tree (AST), capable of being evaluated in any
25
- * context by {@link compileAst}. The Parser expects that all tokens
26
- * provided to it are legal and typed properly according to the grammar, but
27
- * accepts that the tokens may still be in an invalid order or in some other
28
- * unparsable configuration that requires it to throw an Error.
29
- * @param {{}} grammar The grammar object to use to parse Jexl strings
30
- * @param {string} [prefix] A string prefix to prepend to the expression string
31
- * for error messaging purposes. This is useful for when a new Parser is
32
- * instantiated to parse an subexpression, as the parent Parser's
33
- * expression string thus far can be passed for a more user-friendly
34
- * error message.
35
- * @param {{}} [stopMap] A mapping of token types to any truthy value. When the
36
- * token type is encountered, the parser will return the mapped value
37
- * instead of boolean false.
16
+ * Converts the tokens from the {@link Lexer} into an Abstract Syntax Tree, for
17
+ * {@link compileAst} to lower to closures. A Pratt parser: each level of the
18
+ * grammar is a method, from `_sequence` (loosest) down to `_primary`, and
19
+ * binary operators are climbed by the precedence the grammar gives them, so
20
+ * operators a host registers slot in without the parser knowing them.
38
21
  */
39
22
  class Parser {
40
23
  _grammar;
41
24
  _lexer;
42
- _state;
43
- _tree;
44
- _exprStr;
45
- _stopMap;
46
- _cursor;
47
- _subParser;
48
- _parentStop;
49
- _nextIdentEncapsulate;
50
- _curObjKey;
51
- _sequenceExpressions;
52
- constructor(grammar, lexer, prefix, stopMap) {
25
+ _tokens = [];
26
+ _pos = 0;
27
+ _offset;
28
+ _grouped;
29
+ _lambdaDepth = 0;
30
+ /**
31
+ * @param offset where the tokens start in the source, so that an error
32
+ * inside a template interpolation reports its place in the whole
33
+ */
34
+ constructor(grammar, lexer, offset = 0) {
53
35
  this._grammar = grammar;
54
36
  this._lexer = lexer;
55
- this._state = 'expectOperand';
56
- this._tree = null;
57
- this._exprStr = prefix || '';
58
- this._stopMap = stopMap || {};
37
+ this._offset = offset;
38
+ }
39
+ parse(source) {
40
+ const start = this._offset;
41
+ this._offset += source.length - source.trimStart().length;
42
+ try {
43
+ this.addTokens(this._lexer.tokenize(source));
44
+ }
45
+ catch (error) {
46
+ if (error instanceof JexlSyntaxError) {
47
+ error.offset += start;
48
+ }
49
+ throw error;
50
+ }
51
+ return this.complete();
52
+ }
53
+ addTokens(tokens) {
54
+ this._tokens = this._tokens.concat(tokens);
59
55
  }
60
56
  /**
61
- * Processes a new token into the AST and manages the transitions of the state
62
- * machine.
63
- * @param {{type: <string>}} token A token object, as provided by the
64
- * {@link Lexer#tokenize} function.
65
- * @throws {Error} if a token is added when the Parser has been marked as
66
- * complete by {@link #complete}, or if an unexpected token type is added.
67
- * @returns {boolean|*} the stopState value if this parser encountered a token
68
- * in the stopState mapb false if tokens can continue.
57
+ * @returns the expression tree, or null for an expression with no tokens
58
+ * @throws {JexlSyntaxError} if the tokens do not form exactly one expression
69
59
  */
70
- addToken(token) {
71
- if (this._state === 'complete') {
72
- throw new Error('Cannot add a new token to a completed Parser');
73
- }
74
- const state = states[this._state];
75
- const startExpr = this._exprStr;
76
- this._exprStr += token.raw;
77
- if (state.subHandler) {
78
- const subParser = this._subParser ?? this._startSubExpression(startExpr);
79
- const stopState = subParser.addToken(token);
80
- if (stopState) {
81
- this._endSubExpression();
82
- if (stopState === '_semicolon') {
83
- handlers.semicolon.call(this);
84
- }
85
- else if (this._parentStop) {
86
- return stopState;
87
- }
88
- else {
89
- this._state = stopState;
90
- }
60
+ complete() {
61
+ if (this._tokens.length === 0) {
62
+ return null;
63
+ }
64
+ const ast = this._sequence();
65
+ if (this._pos < this._tokens.length) {
66
+ throw this._unexpected(this._pos);
67
+ }
68
+ return ast;
69
+ }
70
+ _sequence() {
71
+ const first = this._assignment();
72
+ if (this._peek()?.type !== 'semicolon') {
73
+ return first;
74
+ }
75
+ const expressions = [first];
76
+ while (this._eat('semicolon')) {
77
+ const next = this._peek();
78
+ if (!next || next.type === 'closeParen') {
79
+ break;
91
80
  }
81
+ expressions.push(this._assignment());
82
+ }
83
+ return { type: 'SequenceExpression', expressions };
84
+ }
85
+ _assignment() {
86
+ if (this._atLambda()) {
87
+ return this._lambda();
88
+ }
89
+ const left = this._ternary();
90
+ const token = this._peek();
91
+ if (token?.type !== 'binaryOp' || token.value !== '=') {
92
+ return left;
92
93
  }
93
- else if (token.type === 'semicolon' && this._stopMap[token.type]) {
94
- return this._stopMap[token.type];
94
+ if (left.type !== 'Identifier' || left.from) {
95
+ throw this._error('Left side of assignment must be a variable name', this._pos);
95
96
  }
96
- else if (state.tokenTypes?.[token.type]) {
97
- const typeOpts = state.tokenTypes[token.type];
98
- // the state's own handler wins over the token type's default one, and a
99
- // token type with neither only drives the transition below
100
- const handleFunc = typeOpts.handler ?? tokenHandlers[token.type];
101
- handleFunc?.call(this, token);
102
- if (typeOpts.toState) {
103
- this._state = typeOpts.toState;
97
+ if (this._lambdaDepth > 0) {
98
+ throw this._error('Assignment is not supported in a lambda', this._pos);
99
+ }
100
+ this._pos++;
101
+ return {
102
+ type: 'AssignmentExpression',
103
+ operator: '=',
104
+ left,
105
+ right: this._assignment()
106
+ };
107
+ }
108
+ _atLambda() {
109
+ let i = this._pos;
110
+ if (this._tokens[i]?.type === 'identifier') {
111
+ return this._tokens[i + 1]?.type === 'arrow';
112
+ }
113
+ if (this._tokens[i]?.type !== 'openParen') {
114
+ return false;
115
+ }
116
+ i++;
117
+ while (this._tokens[i]?.type === 'identifier') {
118
+ i++;
119
+ if (this._tokens[i]?.type !== 'comma') {
120
+ break;
104
121
  }
122
+ i++;
105
123
  }
106
- else if (this._stopMap[token.type]) {
107
- return this._stopMap[token.type];
124
+ return (this._tokens[i]?.type === 'closeParen' &&
125
+ this._tokens[i + 1]?.type === 'arrow');
126
+ }
127
+ /** Parses the lambda {@link _atLambda} found, whose shape it has checked. */
128
+ _lambda() {
129
+ const params = [];
130
+ if (this._eat('openParen')) {
131
+ while (!this._eat('closeParen')) {
132
+ params.push(this._next().value);
133
+ this._eat('comma');
134
+ }
108
135
  }
109
136
  else {
110
- throw new Error(`Token ${token.raw} (${token.type}) unexpected in expression: ${this._exprStr}`);
137
+ params.push(this._next().value);
138
+ }
139
+ if (new Set(params).size < params.length) {
140
+ throw this._error('Duplicate lambda parameter name', this._pos);
111
141
  }
112
- return false;
142
+ this._pos++;
143
+ this._lambdaDepth++;
144
+ const body = this._assignment();
145
+ this._lambdaDepth--;
146
+ return { type: 'Lambda', params, body };
113
147
  }
114
- /**
115
- * Processes an array of tokens iteratively through the {@link #addToken}
116
- * function.
117
- * @param {Array<{type: <string>}>} tokens An array of tokens, as provided by
118
- * the {@link Lexer#tokenize} function.
119
- */
120
- addTokens(tokens) {
121
- for (const token of tokens) {
122
- this.addToken(token);
148
+ _ternary() {
149
+ const test = this._binary(-Infinity);
150
+ if (!this._eat('question')) {
151
+ return test;
123
152
  }
153
+ const node = { type: 'ConditionalExpression', test };
154
+ if (!this._eat('colon')) {
155
+ node.consequent = this._assignment();
156
+ this._expect('colon');
157
+ }
158
+ const next = this._peek();
159
+ if (next && !omittedAlternateBefore.has(next.type)) {
160
+ node.alternate = this._assignment();
161
+ }
162
+ return node;
124
163
  }
125
164
  /**
126
- * Marks this Parser instance as completed and retrieves the full AST.
127
- * @returns {{}|null} a full expression tree, ready for evaluation by the
128
- * {@link compileAst} function, or null if no tokens were passed to
129
- * the parser before complete was called
130
- * @throws {Error} if the parser is not in a state where it's legal to end
131
- * the expression, indicating that the expression is incomplete
165
+ * Parses operands joined by binary operators that bind tighter than `floor`.
166
+ * One exactly at `floor` binds only when it continues a right-associative
167
+ * chain, which is how `a ^ b ^ c` groups from the right.
132
168
  */
133
- complete() {
134
- // `_subParser` counts as unfinished business alongside `_cursor`: a group
135
- // that opened before anything was placed in the tree, as in "(1", leaves
136
- // the cursor null, and testing the cursor alone let the missing ")" pass
137
- // silently and evaluate as if it were closed.
138
- if ((this._cursor || this._subParser) &&
139
- !states[this._state].completable) {
140
- throw new Error(`Unexpected end of expression: ${this._exprStr}`);
141
- }
142
- if (this._subParser) {
143
- this._endSubExpression();
144
- }
145
- if (this._sequenceExpressions) {
146
- if (this._tree) {
147
- this._sequenceExpressions.push(this._tree);
148
- }
149
- const sequence = {
150
- type: 'SequenceExpression',
151
- expressions: this._sequenceExpressions
152
- };
153
- this._state = 'complete';
154
- return sequence;
155
- }
156
- this._state = 'complete';
157
- return this._cursor ? this._tree : null;
169
+ _binary(floor, rightAssociative = false) {
170
+ let left = this._unary();
171
+ for (;;) {
172
+ const token = this._peek();
173
+ if (token?.type !== 'binaryOp' || token.value === '=') {
174
+ return left;
175
+ }
176
+ const operator = token.value;
177
+ const op = this._grammar.elements[operator];
178
+ if (op.type !== 'binaryOp' ||
179
+ op.precedence < floor ||
180
+ (op.precedence === floor && !(rightAssociative && op.rightAssociative))) {
181
+ return left;
182
+ }
183
+ const at = this._pos++;
184
+ const right = this._binary(op.precedence, op.rightAssociative);
185
+ if (this._mixesNullish(operator, left, right)) {
186
+ throw this._error('Parenthesize ?? when mixing it with && or ||', at);
187
+ }
188
+ left = { type: 'BinaryExpression', operator, left, right };
189
+ }
158
190
  }
159
- /**
160
- * Ends a subexpression by completing the subParser and passing its result
161
- * to the subHandler configured in the current state.
162
- * @private
163
- */
164
- _endSubExpression() {
165
- states[this._state].subHandler.call(this, this._subParser.complete());
166
- this._subParser = undefined;
191
+ /** `a ?? b || c` has no grouping a reader can guess; JS refuses it too. */
192
+ _mixesNullish(operator, ...operands) {
193
+ return operands.some((operand) => operand.type === 'BinaryExpression' &&
194
+ !this._grouped?.has(operand) &&
195
+ (operator === '??'
196
+ ? logical.has(operand.operator)
197
+ : logical.has(operator) && operand.operator === '??'));
167
198
  }
168
- /**
169
- * Places a new tree node at the current position of the cursor (to the 'right'
170
- * property) and then advances the cursor to the new node. This function also
171
- * handles setting the parent of the new node.
172
- * @param {{type: <string>}} node A node to be added to the AST
173
- * @private
174
- */
175
- _placeAtCursor(node) {
176
- if (!this._cursor) {
177
- this._tree = node;
199
+ _unary() {
200
+ const token = this._peek();
201
+ if (token?.type !== 'unaryOp') {
202
+ return this._postfix(this._primary());
178
203
  }
179
- else {
180
- this._cursor.right = node;
181
- this._setParent(node, this._cursor);
204
+ this._pos++;
205
+ const operator = token.value;
206
+ const op = this._grammar.elements[operator];
207
+ return {
208
+ type: 'UnaryExpression',
209
+ operator,
210
+ right: this._binary(op?.type === 'unaryOp' ? op.precedence : Infinity)
211
+ };
212
+ }
213
+ _postfix(subject) {
214
+ let node = subject;
215
+ for (;;) {
216
+ switch (this._peek()?.type) {
217
+ case 'dot': {
218
+ this._pos++;
219
+ node = {
220
+ type: 'Identifier',
221
+ value: this._expect('identifier').value,
222
+ from: node
223
+ };
224
+ break;
225
+ }
226
+ case 'openBracket': {
227
+ this._pos++;
228
+ const expr = this._assignment();
229
+ this._expect('closeBracket');
230
+ node = { type: 'FilterExpression', expr, subject: node };
231
+ break;
232
+ }
233
+ case 'openParen': {
234
+ if (node.type !== 'Identifier' ||
235
+ this._tokens[this._pos - 1].type !== 'identifier') {
236
+ throw this._error('Functions must be called by name', this._pos);
237
+ }
238
+ this._pos++;
239
+ const { from, value } = node;
240
+ const args = this._list('closeParen');
241
+ node = {
242
+ type: 'FunctionCall',
243
+ name: value,
244
+ args: from ? [from, ...args] : args
245
+ };
246
+ break;
247
+ }
248
+ default: {
249
+ return node;
250
+ }
251
+ }
182
252
  }
183
- this._cursor = node;
184
253
  }
185
- /**
186
- * Places a tree node before the current position of the cursor, replacing
187
- * the node that the cursor currently points to. This should only be called in
188
- * cases where the cursor is known to exist, and the provided node already
189
- * contains a pointer to what's at the cursor currently.
190
- * @param {{type: <string>}} node A node to be added to the AST
191
- * @private
192
- */
193
- _placeBeforeCursor(node) {
194
- this._cursor = this._cursor?._parent;
195
- this._placeAtCursor(node);
254
+ _primary() {
255
+ const token = this._next();
256
+ switch (token.type) {
257
+ case 'literal': {
258
+ return {
259
+ type: 'Literal',
260
+ value: token.value
261
+ };
262
+ }
263
+ case 'identifier': {
264
+ return { type: 'Identifier', value: token.value };
265
+ }
266
+ case 'templateString': {
267
+ return this._template(token.value, this._pos - 1);
268
+ }
269
+ case 'openParen': {
270
+ const node = this._sequence();
271
+ this._expect('closeParen');
272
+ this._grouped ??= new WeakSet();
273
+ this._grouped.add(node);
274
+ return node;
275
+ }
276
+ case 'openBracket': {
277
+ return { type: 'ArrayLiteral', value: this._list('closeBracket') };
278
+ }
279
+ case 'openCurl': {
280
+ return this._object();
281
+ }
282
+ case 'dot': {
283
+ throw this._error('Relative paths are not supported', this._pos - 1);
284
+ }
285
+ default: {
286
+ throw this._unexpected(this._pos - 1);
287
+ }
288
+ }
196
289
  }
197
- /**
198
- * Sets the parent of a node by creating a non-enumerable _parent property
199
- * that points to the supplied parent argument.
200
- * @param {{type: <string>}} node A node of the AST on which to set a new
201
- * parent
202
- * @param {{type: <string>}} parent An existing node of the AST to serve as the
203
- * parent of the new node
204
- * @private
205
- */
206
- _setParent(node, parent) {
207
- Object.defineProperty(node, '_parent', {
208
- value: parent,
209
- writable: true
290
+ _list(close) {
291
+ const items = [];
292
+ while (!this._eat(close)) {
293
+ items.push(this._assignment());
294
+ if (!this._eat('comma')) {
295
+ this._expect(close);
296
+ break;
297
+ }
298
+ }
299
+ return items;
300
+ }
301
+ _object() {
302
+ const node = { type: 'ObjectLiteral', value: {} };
303
+ while (!this._eat('closeCurl')) {
304
+ const key = this._next();
305
+ if (key.type !== 'identifier' && key.type !== 'literal') {
306
+ throw this._unexpected(this._pos - 1);
307
+ }
308
+ this._expect('colon');
309
+ // defined rather than assigned, so that "__proto__" is an ordinary key
310
+ Object.defineProperty(node.value, String(key.value), {
311
+ value: this._assignment(),
312
+ writable: true,
313
+ enumerable: true,
314
+ configurable: true
315
+ });
316
+ if (!this._eat('comma')) {
317
+ this._expect('closeCurl');
318
+ break;
319
+ }
320
+ }
321
+ return node;
322
+ }
323
+ _template(tokenParts, index) {
324
+ let offset = this._offsetOf(index) + '`'.length;
325
+ const parts = tokenParts.map((part) => {
326
+ if (part.type === 'static') {
327
+ offset += part.value.length;
328
+ return {
329
+ type: 'static',
330
+ value: this._lexer._unescapeTemplateString(part.value)
331
+ };
332
+ }
333
+ const start = offset + '${'.length;
334
+ offset = start + part.value.length + '}'.length;
335
+ const sub = new Parser(this._grammar, this._lexer, start);
336
+ sub._lambdaDepth = this._lambdaDepth;
337
+ const value = sub.parse(part.value);
338
+ if (!value) {
339
+ throw new JexlSyntaxError('Empty interpolation in template string', start);
340
+ }
341
+ return { type: 'expression', value };
210
342
  });
343
+ return { type: 'TemplateLiteral', parts };
211
344
  }
212
- /**
213
- * Prepares the Parser to accept a subexpression by (re)instantiating the
214
- * subParser.
215
- * @param {string} [exprStr] The expression string to prefix to the new Parser
216
- * @returns {Parser} the new subParser, also stored on this instance
217
- * @private
218
- */
219
- _startSubExpression(exprStr) {
220
- let endStates = states[this._state].endStates;
221
- if (!endStates) {
222
- this._parentStop = true;
223
- endStates = this._stopMap;
345
+ _peek() {
346
+ return this._tokens[this._pos];
347
+ }
348
+ _next() {
349
+ const token = this._tokens[this._pos];
350
+ if (!token) {
351
+ throw this._error('Unexpected end of expression', this._pos);
352
+ }
353
+ this._pos++;
354
+ return token;
355
+ }
356
+ _eat(type) {
357
+ if (this._tokens[this._pos]?.type !== type) {
358
+ return false;
224
359
  }
225
- if (states[this._state].completable && !endStates.semicolon) {
226
- endStates = { ...endStates, semicolon: '_semicolon' };
360
+ this._pos++;
361
+ return true;
362
+ }
363
+ _expect(type) {
364
+ const token = this._next();
365
+ if (token.type !== type) {
366
+ throw this._unexpected(this._pos - 1);
367
+ }
368
+ return token;
369
+ }
370
+ _unexpected(index) {
371
+ const { raw, type } = this._tokens[index];
372
+ return this._error(`Token ${raw} (${type}) unexpected in expression`, index);
373
+ }
374
+ _error(message, index) {
375
+ const source = this._tokens
376
+ .slice(0, index + 1)
377
+ .map((token) => token.raw)
378
+ .join('');
379
+ return new JexlSyntaxError(`${message}: ${source}`, this._offsetOf(index));
380
+ }
381
+ _offsetOf(index) {
382
+ let offset = this._offset;
383
+ for (let i = 0; i < index; i++) {
384
+ offset += this._tokens[i].raw.length;
227
385
  }
228
- this._subParser = new Parser(this._grammar, this._lexer, exprStr, endStates);
229
- return this._subParser;
386
+ return offset;
230
387
  }
231
388
  }
232
389
  export default Parser;
@@ -1 +1 @@
1
- {"version":3,"file":"Parser.js","sourceRoot":"","sources":["../../src/parser/Parser.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AAC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