@aws-lambda-powertools/jmespath 2.3.0 → 2.5.0
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/lib/cjs/Expression.js +5 -18
- package/lib/cjs/Functions.js +4 -6
- package/lib/cjs/Lexer.js +275 -204
- package/lib/cjs/ParsedResult.js +2 -0
- package/lib/cjs/Parser.js +676 -433
- package/lib/cjs/TreeInterpreter.js +364 -233
- package/lib/cjs/errors.d.ts +0 -6
- package/lib/cjs/errors.d.ts.map +1 -1
- package/lib/cjs/errors.js +39 -0
- package/lib/esm/Expression.js +5 -18
- package/lib/esm/Functions.js +4 -6
- package/lib/esm/Lexer.js +274 -203
- package/lib/esm/ParsedResult.js +2 -0
- package/lib/esm/Parser.js +675 -432
- package/lib/esm/TreeInterpreter.js +363 -232
- package/lib/esm/errors.d.ts +0 -6
- package/lib/esm/errors.d.ts.map +1 -1
- package/lib/esm/errors.js +39 -0
- package/package.json +2 -2
package/lib/esm/Lexer.js
CHANGED
|
@@ -1,15 +1,3 @@
|
|
|
1
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
-
};
|
|
6
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
7
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
8
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
9
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
10
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
|
-
};
|
|
12
|
-
var _Lexer_instances, _Lexer_position, _Lexer_expression, _Lexer_chars, _Lexer_current, _Lexer_length, _Lexer_consumeComparatorSigns, _Lexer_consumeEqualSign, _Lexer_consumeIdentifier, _Lexer_consumeNegativeNumber, _Lexer_consumeNumber, _Lexer_consumeSquareBracket, _Lexer_initializeForExpression, _Lexer_next, _Lexer_consumeUntil, _Lexer_consumeLiteral, _Lexer_consumeQuotedIdentifier, _Lexer_consumeRawStringLiteral, _Lexer_matchOrElse;
|
|
13
1
|
import { SIMPLE_TOKENS, START_IDENTIFIER, VALID_IDENTIFIER, VALID_NUMBER, WHITESPACE, } from './constants.js';
|
|
14
2
|
import { EmptyExpressionError, LexerError } from './errors.js';
|
|
15
3
|
/**
|
|
@@ -18,37 +6,11 @@ import { EmptyExpressionError, LexerError } from './errors.js';
|
|
|
18
6
|
* This lexer tokenizes a JMESPath expression into a sequence of tokens.
|
|
19
7
|
*/
|
|
20
8
|
class Lexer {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
_Lexer_current.set(this, void 0);
|
|
27
|
-
_Lexer_length.set(this, void 0);
|
|
28
|
-
/**
|
|
29
|
-
* Consume a comparator sign.
|
|
30
|
-
*
|
|
31
|
-
* This method is called when the lexer encounters a comparator sign.
|
|
32
|
-
*
|
|
33
|
-
* @param current The current character
|
|
34
|
-
*/
|
|
35
|
-
_Lexer_consumeComparatorSigns.set(this, (current) => {
|
|
36
|
-
switch (current) {
|
|
37
|
-
case '<':
|
|
38
|
-
return __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_matchOrElse).call(this, '=', 'lte', 'lt');
|
|
39
|
-
case '>':
|
|
40
|
-
return __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_matchOrElse).call(this, '=', 'gte', 'gt');
|
|
41
|
-
case '!':
|
|
42
|
-
return __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_matchOrElse).call(this, '=', 'ne', 'not');
|
|
43
|
-
case '|':
|
|
44
|
-
return __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_matchOrElse).call(this, '|', 'or', 'pipe');
|
|
45
|
-
case '&':
|
|
46
|
-
return __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_matchOrElse).call(this, '&', 'and', 'expref');
|
|
47
|
-
default:
|
|
48
|
-
return __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_consumeEqualSign).call(this);
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
}
|
|
9
|
+
#position;
|
|
10
|
+
#expression;
|
|
11
|
+
#chars;
|
|
12
|
+
#current;
|
|
13
|
+
#length;
|
|
52
14
|
/**
|
|
53
15
|
* Tokenize a JMESPath expression.
|
|
54
16
|
*
|
|
@@ -57,38 +19,38 @@ class Lexer {
|
|
|
57
19
|
* @param expression The JMESPath expression to tokenize.
|
|
58
20
|
*/
|
|
59
21
|
*tokenize(expression) {
|
|
60
|
-
|
|
61
|
-
while (
|
|
62
|
-
if (SIMPLE_TOKENS.has(
|
|
22
|
+
this.#initializeForExpression(expression);
|
|
23
|
+
while (this.#current !== '' && this.#current !== undefined) {
|
|
24
|
+
if (SIMPLE_TOKENS.has(this.#current)) {
|
|
63
25
|
yield {
|
|
64
26
|
// We know that SIMPLE_TOKENS has this.#current as a key because
|
|
65
27
|
// we checked for that above.
|
|
66
28
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
67
|
-
type: SIMPLE_TOKENS.get(
|
|
68
|
-
value:
|
|
69
|
-
start:
|
|
70
|
-
end:
|
|
29
|
+
type: SIMPLE_TOKENS.get(this.#current),
|
|
30
|
+
value: this.#current,
|
|
31
|
+
start: this.#position,
|
|
32
|
+
end: this.#position + 1,
|
|
71
33
|
};
|
|
72
|
-
|
|
34
|
+
this.#next();
|
|
73
35
|
}
|
|
74
|
-
else if (START_IDENTIFIER.has(
|
|
75
|
-
yield
|
|
36
|
+
else if (START_IDENTIFIER.has(this.#current)) {
|
|
37
|
+
yield this.#consumeIdentifier();
|
|
76
38
|
}
|
|
77
|
-
else if (WHITESPACE.has(
|
|
78
|
-
|
|
39
|
+
else if (WHITESPACE.has(this.#current)) {
|
|
40
|
+
this.#next();
|
|
79
41
|
}
|
|
80
|
-
else if (
|
|
81
|
-
yield
|
|
42
|
+
else if (this.#current === '[') {
|
|
43
|
+
yield this.#consumeSquareBracket();
|
|
82
44
|
}
|
|
83
|
-
else if (
|
|
84
|
-
yield
|
|
45
|
+
else if (this.#current === `'`) {
|
|
46
|
+
yield this.#consumeRawStringLiteral();
|
|
85
47
|
}
|
|
86
|
-
else if (
|
|
87
|
-
yield
|
|
48
|
+
else if (this.#current === '`') {
|
|
49
|
+
yield this.#consumeLiteral();
|
|
88
50
|
}
|
|
89
|
-
else if (VALID_NUMBER.has(
|
|
90
|
-
const start =
|
|
91
|
-
const buff =
|
|
51
|
+
else if (VALID_NUMBER.has(this.#current)) {
|
|
52
|
+
const start = this.#position;
|
|
53
|
+
const buff = this.#consumeNumber();
|
|
92
54
|
yield {
|
|
93
55
|
type: 'number',
|
|
94
56
|
value: parseInt(buff),
|
|
@@ -96,173 +58,282 @@ class Lexer {
|
|
|
96
58
|
end: start + buff.length,
|
|
97
59
|
};
|
|
98
60
|
}
|
|
99
|
-
else if (
|
|
100
|
-
yield
|
|
61
|
+
else if (this.#current === '-') {
|
|
62
|
+
yield this.#consumeNegativeNumber();
|
|
101
63
|
}
|
|
102
|
-
else if (
|
|
103
|
-
yield
|
|
64
|
+
else if (this.#current === '"') {
|
|
65
|
+
yield this.#consumeQuotedIdentifier();
|
|
104
66
|
}
|
|
105
|
-
else if (['<', '>', '!', '=', '|', '&'].includes(
|
|
106
|
-
yield
|
|
67
|
+
else if (['<', '>', '!', '=', '|', '&'].includes(this.#current)) {
|
|
68
|
+
yield this.#consumeComparatorSigns(this.#current);
|
|
107
69
|
}
|
|
108
70
|
else {
|
|
109
|
-
throw new LexerError(
|
|
71
|
+
throw new LexerError(this.#position, this.#current);
|
|
110
72
|
}
|
|
111
73
|
}
|
|
112
|
-
yield { type: 'eof', value: '', start:
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
_Lexer_position = new WeakMap(), _Lexer_expression = new WeakMap(), _Lexer_chars = new WeakMap(), _Lexer_current = new WeakMap(), _Lexer_length = new WeakMap(), _Lexer_consumeComparatorSigns = new WeakMap(), _Lexer_instances = new WeakSet(), _Lexer_consumeEqualSign = function _Lexer_consumeEqualSign() {
|
|
116
|
-
if (__classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_next).call(this) === '=') {
|
|
117
|
-
__classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_next).call(this);
|
|
118
|
-
return {
|
|
119
|
-
type: 'eq',
|
|
120
|
-
value: '==',
|
|
121
|
-
start: __classPrivateFieldGet(this, _Lexer_position, "f") - 1,
|
|
122
|
-
end: __classPrivateFieldGet(this, _Lexer_position, "f"),
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
throw new LexerError(__classPrivateFieldGet(this, _Lexer_position, "f") - 1, '=');
|
|
127
|
-
}
|
|
128
|
-
}, _Lexer_consumeIdentifier = function _Lexer_consumeIdentifier() {
|
|
129
|
-
const start = __classPrivateFieldGet(this, _Lexer_position, "f");
|
|
130
|
-
let buff = __classPrivateFieldGet(this, _Lexer_current, "f");
|
|
131
|
-
while (VALID_IDENTIFIER.has(__classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_next).call(this))) {
|
|
132
|
-
buff += __classPrivateFieldGet(this, _Lexer_current, "f");
|
|
74
|
+
yield { type: 'eof', value: '', start: this.#length, end: this.#length };
|
|
133
75
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Consume a comparator sign.
|
|
78
|
+
*
|
|
79
|
+
* This method is called when the lexer encounters a comparator sign.
|
|
80
|
+
*
|
|
81
|
+
* @param current The current character
|
|
82
|
+
*/
|
|
83
|
+
#consumeComparatorSigns = (current) => {
|
|
84
|
+
switch (current) {
|
|
85
|
+
case '<':
|
|
86
|
+
return this.#matchOrElse('=', 'lte', 'lt');
|
|
87
|
+
case '>':
|
|
88
|
+
return this.#matchOrElse('=', 'gte', 'gt');
|
|
89
|
+
case '!':
|
|
90
|
+
return this.#matchOrElse('=', 'ne', 'not');
|
|
91
|
+
case '|':
|
|
92
|
+
return this.#matchOrElse('|', 'or', 'pipe');
|
|
93
|
+
case '&':
|
|
94
|
+
return this.#matchOrElse('&', 'and', 'expref');
|
|
95
|
+
default:
|
|
96
|
+
return this.#consumeEqualSign();
|
|
97
|
+
}
|
|
139
98
|
};
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
99
|
+
/**
|
|
100
|
+
* Consume an equal sign.
|
|
101
|
+
*
|
|
102
|
+
* This method is called when the lexer encounters an equal sign.
|
|
103
|
+
* It checks if the next character is also an equal sign and returns
|
|
104
|
+
* the corresponding token.
|
|
105
|
+
*/
|
|
106
|
+
#consumeEqualSign() {
|
|
107
|
+
if (this.#next() === '=') {
|
|
108
|
+
this.#next();
|
|
109
|
+
return {
|
|
110
|
+
type: 'eq',
|
|
111
|
+
value: '==',
|
|
112
|
+
start: this.#position - 1,
|
|
113
|
+
end: this.#position,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
throw new LexerError(this.#position - 1, '=');
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Consume an unquoted identifier.
|
|
122
|
+
*
|
|
123
|
+
* This method is called when the lexer encounters a character that is a valid
|
|
124
|
+
* identifier. It advances the lexer until it finds a character that is not a
|
|
125
|
+
* valid identifier and returns the corresponding token.
|
|
126
|
+
*/
|
|
127
|
+
#consumeIdentifier() {
|
|
128
|
+
const start = this.#position;
|
|
129
|
+
let buff = this.#current;
|
|
130
|
+
while (VALID_IDENTIFIER.has(this.#next())) {
|
|
131
|
+
buff += this.#current;
|
|
132
|
+
}
|
|
144
133
|
return {
|
|
145
|
-
type: '
|
|
146
|
-
value:
|
|
147
|
-
start
|
|
134
|
+
type: 'unquoted_identifier',
|
|
135
|
+
value: buff,
|
|
136
|
+
start,
|
|
148
137
|
end: start + buff.length,
|
|
149
138
|
};
|
|
150
139
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
140
|
+
/**
|
|
141
|
+
* Consume a negative number.
|
|
142
|
+
*
|
|
143
|
+
* This method is called when the lexer encounters a negative sign.
|
|
144
|
+
* It checks if the next character is a number and returns the corresponding token.
|
|
145
|
+
*/
|
|
146
|
+
#consumeNegativeNumber() {
|
|
147
|
+
const start = this.#position;
|
|
148
|
+
const buff = this.#consumeNumber();
|
|
149
|
+
if (buff.length > 1) {
|
|
150
|
+
return {
|
|
151
|
+
type: 'number',
|
|
152
|
+
value: parseInt(buff),
|
|
153
|
+
start: start,
|
|
154
|
+
end: start + buff.length,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
// If the negative sign is not followed by a number, it is an error.
|
|
159
|
+
throw new LexerError(start, 'Unknown token after "-"');
|
|
160
|
+
}
|
|
167
161
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
162
|
+
/**
|
|
163
|
+
* Consume a raw string that is a number.
|
|
164
|
+
*
|
|
165
|
+
* It takes the current position and advances
|
|
166
|
+
* the lexer until it finds a character that
|
|
167
|
+
* is not a number.
|
|
168
|
+
*/
|
|
169
|
+
#consumeNumber() {
|
|
170
|
+
let buff = this.#current;
|
|
171
|
+
while (VALID_NUMBER.has(this.#next())) {
|
|
172
|
+
buff += this.#current;
|
|
173
|
+
}
|
|
174
|
+
return buff;
|
|
171
175
|
}
|
|
172
|
-
|
|
173
|
-
|
|
176
|
+
/**
|
|
177
|
+
* Consume a square bracket.
|
|
178
|
+
*
|
|
179
|
+
* This method is called when the lexer encounters a square bracket.
|
|
180
|
+
* It checks if the next character is a question mark or a closing
|
|
181
|
+
* square bracket and returns the corresponding token.
|
|
182
|
+
*/
|
|
183
|
+
#consumeSquareBracket() {
|
|
184
|
+
const start = this.#position;
|
|
185
|
+
const nextChar = this.#next();
|
|
186
|
+
if (nextChar == ']') {
|
|
187
|
+
this.#next();
|
|
188
|
+
return { type: 'flatten', value: '[]', start: start, end: start + 2 };
|
|
189
|
+
}
|
|
190
|
+
else if (nextChar == '?') {
|
|
191
|
+
this.#next();
|
|
192
|
+
return { type: 'filter', value: '[?', start: start, end: start + 2 };
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
return { type: 'lbracket', value: '[', start: start, end: start + 1 };
|
|
196
|
+
}
|
|
174
197
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
198
|
+
/**
|
|
199
|
+
* Initializes the lexer for the given expression.
|
|
200
|
+
*
|
|
201
|
+
* We use a separate method for this instead of the constructor
|
|
202
|
+
* because we want to be able to reuse the same lexer instance
|
|
203
|
+
* and also because we want to be able to expose a public API
|
|
204
|
+
* for tokenizing expressions like `new Lexer().tokenize(expression)`.
|
|
205
|
+
*
|
|
206
|
+
* @param expression The JMESPath expression to tokenize.
|
|
207
|
+
*/
|
|
208
|
+
#initializeForExpression(expression) {
|
|
209
|
+
if (typeof expression !== 'string') {
|
|
210
|
+
throw new EmptyExpressionError();
|
|
211
|
+
}
|
|
212
|
+
this.#position = 0;
|
|
213
|
+
this.#expression = expression;
|
|
214
|
+
this.#chars = Array.from(expression);
|
|
215
|
+
this.#current = this.#chars[0];
|
|
216
|
+
this.#length = this.#expression.length;
|
|
178
217
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
218
|
+
/**
|
|
219
|
+
* Advance the lexer to the next character in the expression.
|
|
220
|
+
*/
|
|
221
|
+
#next() {
|
|
222
|
+
if (this.#position === this.#length - 1) {
|
|
223
|
+
this.#current = '';
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
this.#position += 1;
|
|
227
|
+
this.#current = this.#chars[this.#position];
|
|
228
|
+
}
|
|
229
|
+
return this.#current;
|
|
187
230
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
231
|
+
/**
|
|
232
|
+
* Consume until the given delimiter is reached allowing
|
|
233
|
+
* for escaping of the delimiter with a backslash (`\`).
|
|
234
|
+
*
|
|
235
|
+
* @param delimiter The delimiter to consume until.
|
|
236
|
+
*/
|
|
237
|
+
#consumeUntil(delimiter) {
|
|
238
|
+
const start = this.#position;
|
|
239
|
+
let buff = '';
|
|
240
|
+
this.#next();
|
|
241
|
+
while (this.#current !== delimiter) {
|
|
242
|
+
if (this.#current === '\\') {
|
|
243
|
+
buff += '\\';
|
|
244
|
+
this.#next();
|
|
245
|
+
}
|
|
246
|
+
if (this.#current === '') {
|
|
247
|
+
// We've reached the end of the expression (EOF) before
|
|
248
|
+
// we found the delimiter. This is an error.
|
|
249
|
+
throw new LexerError(start, this.#expression.substring(start));
|
|
250
|
+
}
|
|
251
|
+
buff += this.#current;
|
|
252
|
+
this.#next();
|
|
253
|
+
}
|
|
254
|
+
// Skip the closing delimiter
|
|
255
|
+
this.#next();
|
|
256
|
+
return buff;
|
|
191
257
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
258
|
+
/**
|
|
259
|
+
* Process a literal.
|
|
260
|
+
*
|
|
261
|
+
* A literal is a JSON string that is enclosed in backticks.
|
|
262
|
+
*/
|
|
263
|
+
#consumeLiteral() {
|
|
264
|
+
const start = this.#position;
|
|
265
|
+
const lexeme = this.#consumeUntil('`').replace('\\`', '`');
|
|
266
|
+
try {
|
|
267
|
+
const parsedJson = JSON.parse(lexeme);
|
|
268
|
+
return {
|
|
269
|
+
type: 'literal',
|
|
270
|
+
value: parsedJson,
|
|
271
|
+
start,
|
|
272
|
+
end: this.#position - start,
|
|
273
|
+
};
|
|
201
274
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
// we found the delimiter. This is an error.
|
|
205
|
-
throw new LexerError(start, __classPrivateFieldGet(this, _Lexer_expression, "f").substring(start));
|
|
275
|
+
catch (error) {
|
|
276
|
+
throw new LexerError(start, lexeme);
|
|
206
277
|
}
|
|
207
|
-
buff += __classPrivateFieldGet(this, _Lexer_current, "f");
|
|
208
|
-
__classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_next).call(this);
|
|
209
278
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
const
|
|
279
|
+
/**
|
|
280
|
+
* Process a quoted identifier.
|
|
281
|
+
*
|
|
282
|
+
* A quoted identifier is a string that is enclosed in double quotes.
|
|
283
|
+
*/
|
|
284
|
+
#consumeQuotedIdentifier() {
|
|
285
|
+
const start = this.#position;
|
|
286
|
+
const lexeme = '"' + this.#consumeUntil('"') + '"';
|
|
287
|
+
const tokenLen = this.#position - start;
|
|
218
288
|
return {
|
|
219
|
-
type: '
|
|
220
|
-
value:
|
|
289
|
+
type: 'quoted_identifier',
|
|
290
|
+
value: JSON.parse(lexeme),
|
|
221
291
|
start,
|
|
222
|
-
end:
|
|
292
|
+
end: tokenLen,
|
|
223
293
|
};
|
|
224
294
|
}
|
|
225
|
-
|
|
226
|
-
|
|
295
|
+
/**
|
|
296
|
+
* Process a raw string literal.
|
|
297
|
+
*
|
|
298
|
+
* A raw string literal is a string that is enclosed in single quotes.
|
|
299
|
+
*/
|
|
300
|
+
#consumeRawStringLiteral() {
|
|
301
|
+
const start = this.#position;
|
|
302
|
+
const lexeme = this.#consumeUntil(`'`).replace(`\\'`, `'`);
|
|
303
|
+
const tokenLen = this.#position - start;
|
|
304
|
+
return {
|
|
305
|
+
type: 'literal',
|
|
306
|
+
value: lexeme,
|
|
307
|
+
start,
|
|
308
|
+
end: tokenLen,
|
|
309
|
+
};
|
|
227
310
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
}, _Lexer_matchOrElse = function _Lexer_matchOrElse(expected, matchType, elseType) {
|
|
249
|
-
const start = __classPrivateFieldGet(this, _Lexer_position, "f");
|
|
250
|
-
const current = __classPrivateFieldGet(this, _Lexer_current, "f");
|
|
251
|
-
const nextChar = __classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_next).call(this);
|
|
252
|
-
if (nextChar === expected) {
|
|
253
|
-
__classPrivateFieldGet(this, _Lexer_instances, "m", _Lexer_next).call(this);
|
|
311
|
+
/**
|
|
312
|
+
* Match the expected character and return the corresponding token type.
|
|
313
|
+
*
|
|
314
|
+
* @param expected The expected character
|
|
315
|
+
* @param matchType The token type to return if the expected character is found
|
|
316
|
+
* @param elseType The token type to return if the expected character is not found
|
|
317
|
+
*/
|
|
318
|
+
#matchOrElse(expected, matchType, elseType) {
|
|
319
|
+
const start = this.#position;
|
|
320
|
+
const current = this.#current;
|
|
321
|
+
const nextChar = this.#next();
|
|
322
|
+
if (nextChar === expected) {
|
|
323
|
+
this.#next();
|
|
324
|
+
return {
|
|
325
|
+
type: matchType,
|
|
326
|
+
value: current + nextChar,
|
|
327
|
+
start,
|
|
328
|
+
end: start + 2,
|
|
329
|
+
};
|
|
330
|
+
}
|
|
254
331
|
return {
|
|
255
|
-
type:
|
|
256
|
-
value: current
|
|
332
|
+
type: elseType,
|
|
333
|
+
value: current,
|
|
257
334
|
start,
|
|
258
|
-
end: start
|
|
335
|
+
end: start,
|
|
259
336
|
};
|
|
260
337
|
}
|
|
261
|
-
|
|
262
|
-
type: elseType,
|
|
263
|
-
value: current,
|
|
264
|
-
start,
|
|
265
|
-
end: start,
|
|
266
|
-
};
|
|
267
|
-
};
|
|
338
|
+
}
|
|
268
339
|
export { Lexer };
|
package/lib/esm/ParsedResult.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { TreeInterpreter } from './TreeInterpreter.js';
|
|
2
2
|
import { ArityError, JMESPathTypeError, UnknownFunctionError, VariadicArityError, } from './errors.js';
|
|
3
3
|
class ParsedResult {
|
|
4
|
+
expression;
|
|
5
|
+
parsed;
|
|
4
6
|
constructor(expression, parsed) {
|
|
5
7
|
this.expression = expression;
|
|
6
8
|
this.parsed = parsed;
|