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