@witchcraft/expressit 0.2.2 → 0.3.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.
- package/README.md +1 -2
- package/dist/Lexer.d.ts +99 -94
- package/dist/Lexer.d.ts.map +1 -1
- package/dist/Lexer.js +221 -574
- package/dist/Parser.d.ts +26 -26
- package/dist/Parser.d.ts.map +1 -1
- package/dist/Parser.js +106 -116
- package/dist/ast/builders/array.js +7 -8
- package/dist/ast/builders/condition.d.ts +1 -1
- package/dist/ast/builders/condition.d.ts.map +1 -1
- package/dist/ast/builders/condition.js +2 -1
- package/dist/ast/builders/delim.d.ts +2 -2
- package/dist/ast/builders/delim.d.ts.map +1 -1
- package/dist/ast/builders/error.d.ts +2 -2
- package/dist/ast/builders/error.d.ts.map +1 -1
- package/dist/ast/builders/expression.d.ts +2 -2
- package/dist/ast/builders/expression.d.ts.map +1 -1
- package/dist/ast/builders/expression.js +4 -8
- package/dist/ast/builders/group.d.ts +1 -1
- package/dist/ast/builders/group.d.ts.map +1 -1
- package/dist/ast/builders/group.js +8 -11
- package/dist/ast/builders/pos.d.ts +2 -2
- package/dist/ast/builders/pos.d.ts.map +1 -1
- package/dist/ast/builders/token.d.ts +2 -2
- package/dist/ast/builders/token.d.ts.map +1 -1
- package/dist/ast/builders/token.js +1 -1
- package/dist/ast/builders/type.d.ts +2 -2
- package/dist/ast/builders/type.d.ts.map +1 -1
- package/dist/ast/builders/variable.d.ts +3 -3
- package/dist/ast/builders/variable.d.ts.map +1 -1
- package/dist/ast/builders/variable.js +5 -6
- package/dist/ast/createConditionNode.d.ts +1 -1
- package/dist/ast/createConditionNode.d.ts.map +1 -1
- package/dist/ast/createConditionNode.js +1 -2
- package/dist/ast/createGroupNode.d.ts +1 -1
- package/dist/ast/createGroupNode.d.ts.map +1 -1
- package/dist/ast/createToken.d.ts +2 -2
- package/dist/ast/createToken.d.ts.map +1 -1
- package/dist/ast/createToken.js +2 -2
- package/dist/ast/error.d.ts +2 -2
- package/dist/ast/error.d.ts.map +1 -1
- package/dist/ast/error.js +1 -0
- package/dist/ast/handlers.d.ts +23 -23
- package/dist/ast/handlers.d.ts.map +1 -1
- package/dist/ast/handlers.js +23 -26
- package/dist/examples/ParserWithSqlSupport.d.ts +5 -5
- package/dist/examples/ParserWithSqlSupport.d.ts.map +1 -1
- package/dist/examples/ParserWithSqlSupport.js +22 -28
- package/dist/examples/ShortcutContextParser.js +2 -5
- package/dist/index.js +2 -2
- package/dist/internal/ExpressitError.d.ts +2 -2
- package/dist/internal/ExpressitError.d.ts.map +1 -1
- package/dist/internal/ExpressitError.js +7 -10
- package/dist/internal/checkParserOpts.js +21 -22
- package/dist/internal/escapeVariableOrPrefix.js +1 -1
- package/dist/internal/parseParserOptions.js +3 -4
- package/dist/package.json.js +2 -60
- package/dist/types/ast.d.ts +60 -58
- package/dist/types/ast.d.ts.map +1 -1
- package/dist/types/ast.js +26 -27
- package/dist/types/autocomplete.d.ts +23 -21
- package/dist/types/autocomplete.d.ts.map +1 -1
- package/dist/types/autocomplete.js +24 -21
- package/dist/types/errors.d.ts +12 -10
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/errors.js +8 -7
- package/dist/types/index.js +2 -2
- package/dist/types/parser.d.ts +3 -3
- package/dist/types/parser.d.ts.map +1 -1
- package/dist/utils/extractTokens.js +4 -5
- package/dist/utils/generateParentsMap.js +7 -8
- package/dist/utils/getCursorInfo.js +5 -3
- package/dist/utils/getOppositeDelimiter.d.ts +2 -2
- package/dist/utils/getOppositeDelimiter.d.ts.map +1 -1
- package/dist/utils/getOppositeDelimiter.js +1 -1
- package/dist/utils/getSurroundingErrors.js +2 -3
- package/dist/utils/isBracket.js +1 -1
- package/dist/utils/isDelimiter.d.ts +2 -2
- package/dist/utils/isDelimiter.d.ts.map +1 -1
- package/dist/utils/isDelimiter.js +1 -1
- package/dist/utils/isNode.js +1 -1
- package/dist/utils/isParen.d.ts +2 -2
- package/dist/utils/isParen.d.ts.map +1 -1
- package/dist/utils/isParen.js +1 -1
- package/dist/utils/isQuote.d.ts +2 -2
- package/dist/utils/isQuote.d.ts.map +1 -1
- package/dist/utils/isQuote.js +1 -1
- package/dist/utils/isToken.js +1 -1
- package/dist/utils/prettyAst.js +10 -11
- package/package.json +19 -20
- package/src/Lexer.ts +100 -90
- package/src/Parser.ts +68 -68
- package/src/ast/builders/condition.ts +3 -3
- package/src/ast/builders/delim.ts +4 -4
- package/src/ast/builders/error.ts +3 -3
- package/src/ast/builders/expression.ts +4 -8
- package/src/ast/builders/group.ts +2 -4
- package/src/ast/builders/pos.ts +3 -3
- package/src/ast/builders/token.ts +3 -3
- package/src/ast/builders/type.ts +2 -2
- package/src/ast/builders/variable.ts +5 -5
- package/src/ast/createConditionNode.ts +2 -2
- package/src/ast/createGroupNode.ts +4 -4
- package/src/ast/createToken.ts +6 -6
- package/src/ast/error.ts +2 -2
- package/src/ast/handlers.ts +20 -20
- package/src/examples/ParserWithSqlSupport.ts +12 -6
- package/src/internal/ExpressitError.ts +6 -6
- package/src/internal/checkParserOpts.ts +13 -13
- package/src/internal/escapeVariableOrPrefix.ts +1 -1
- package/src/types/ast.ts +101 -96
- package/src/types/autocomplete.ts +26 -22
- package/src/types/errors.ts +18 -13
- package/src/types/parser.ts +3 -3
- package/src/utils/extractTokens.ts +1 -1
- package/src/utils/getCursorInfo.ts +2 -2
- package/src/utils/getOppositeDelimiter.ts +3 -3
- package/src/utils/getSurroundingErrors.ts +4 -4
- package/src/utils/isDelimiter.ts +3 -3
- package/src/utils/isParen.ts +2 -2
- package/src/utils/isQuote.ts +2 -2
- package/src/utils/prettyAst.ts +3 -3
package/dist/Parser.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { isWhitespace } from "@alanscodelog/utils/isWhitespace.js";
|
|
8
|
-
import { setReadOnly } from "@alanscodelog/utils/setReadOnly.js";
|
|
9
|
-
import { unreachable } from "@alanscodelog/utils/unreachable.js";
|
|
1
|
+
import { get } from "@alanscodelog/utils/get";
|
|
2
|
+
import { insert } from "@alanscodelog/utils/insert";
|
|
3
|
+
import { isArray } from "@alanscodelog/utils/isArray";
|
|
4
|
+
import { isWhitespace } from "@alanscodelog/utils/isWhitespace";
|
|
5
|
+
import { setReadOnly } from "@alanscodelog/utils/setReadOnly";
|
|
6
|
+
import { unreachable } from "@alanscodelog/utils/unreachable";
|
|
10
7
|
import { pos } from "./ast/builders/pos.js";
|
|
11
8
|
import { createCondition } from "./ast/createNormalizedCondition.js";
|
|
12
9
|
import { createExpression } from "./ast/createNormalizedExpression.js";
|
|
@@ -22,6 +19,7 @@ import { unescape } from "./internal/unescape.js";
|
|
|
22
19
|
import { Lexer, $C, $T } from "./Lexer.js";
|
|
23
20
|
import { TOKEN_TYPE, AST_TYPE } from "./types/ast.js";
|
|
24
21
|
import { SUGGESTION_TYPE } from "./types/autocomplete.js";
|
|
22
|
+
import "./types/errors.js";
|
|
25
23
|
import { extractTokens } from "./utils/extractTokens.js";
|
|
26
24
|
import { generateParentsMap } from "./utils/generateParentsMap.js";
|
|
27
25
|
import { getCursorInfo } from "./utils/getCursorInfo.js";
|
|
@@ -47,7 +45,7 @@ const defaultNodeDirs = {
|
|
|
47
45
|
const createDefaultRequires = (partial = {}) => ({
|
|
48
46
|
whitespace: {
|
|
49
47
|
...defaultNodeDirs,
|
|
50
|
-
...partial.whitespace
|
|
48
|
+
...partial.whitespace ?? {}
|
|
51
49
|
},
|
|
52
50
|
group: partial.group ?? false,
|
|
53
51
|
prefix: partial.prefix ?? false
|
|
@@ -58,34 +56,8 @@ const tokenRequiresWhitespace = (valid, whitespace, wordOps) => {
|
|
|
58
56
|
};
|
|
59
57
|
const tokenVariable = [TOKEN_TYPE.BACKTICK, TOKEN_TYPE.DOUBLEQUOTE, TOKEN_TYPE.SINGLEQUOTE, TOKEN_TYPE.VALUE, TOKEN_TYPE.REGEX];
|
|
60
58
|
class Parser {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
__publicField(this, "evaluationOptionsChecked", false);
|
|
64
|
-
__publicField(this, "validationOptionsChecked", false);
|
|
65
|
-
__publicField(this, "options");
|
|
66
|
-
__publicField(this, "lexer");
|
|
67
|
-
__publicField(this, "$");
|
|
68
|
-
__publicField(this, "$categories");
|
|
69
|
-
__publicField(this, "info");
|
|
70
|
-
__publicField(this, "state", {
|
|
71
|
-
rawInput: "",
|
|
72
|
-
lexedTokens: [],
|
|
73
|
-
index: 0,
|
|
74
|
-
shift: 0
|
|
75
|
-
});
|
|
76
|
-
__publicField(this, "subParserOne");
|
|
77
|
-
__publicField(this, "subParserTwo");
|
|
78
|
-
const opts = parseParserOptions(options ?? {});
|
|
79
|
-
checkParserOpts(opts);
|
|
80
|
-
this.options = opts;
|
|
81
|
-
this.lexer = new Lexer(opts);
|
|
82
|
-
this.$ = this.lexer.$;
|
|
83
|
-
this.$categories = this.lexer.$categories;
|
|
84
|
-
this.info = {
|
|
85
|
-
expandedSepAlsoCustom: this.lexer.symbols.expandedSepAlsoCustom,
|
|
86
|
-
customOpAlsoNegation: this.lexer.symbols.customOpAlsoNegation
|
|
87
|
-
};
|
|
88
|
-
}
|
|
59
|
+
// needed for evaluate and validate so they are only checked on demand
|
|
60
|
+
evaluationOptionsChecked = false;
|
|
89
61
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
90
62
|
_checkEvaluationOptions() {
|
|
91
63
|
if (!this.evaluationOptionsChecked) {
|
|
@@ -93,6 +65,7 @@ class Parser {
|
|
|
93
65
|
this.evaluationOptionsChecked = true;
|
|
94
66
|
}
|
|
95
67
|
}
|
|
68
|
+
validationOptionsChecked = false;
|
|
96
69
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
97
70
|
_checkValidationOptions() {
|
|
98
71
|
if (!this.validationOptionsChecked) {
|
|
@@ -100,6 +73,29 @@ class Parser {
|
|
|
100
73
|
this.validationOptionsChecked = true;
|
|
101
74
|
}
|
|
102
75
|
}
|
|
76
|
+
options;
|
|
77
|
+
lexer;
|
|
78
|
+
$;
|
|
79
|
+
$categories;
|
|
80
|
+
info;
|
|
81
|
+
constructor(options) {
|
|
82
|
+
const opts = parseParserOptions(options ?? {});
|
|
83
|
+
checkParserOpts(opts);
|
|
84
|
+
this.options = opts;
|
|
85
|
+
this.lexer = new Lexer(opts);
|
|
86
|
+
this.$ = this.lexer.$;
|
|
87
|
+
this.$categories = this.lexer.$categories;
|
|
88
|
+
this.info = {
|
|
89
|
+
expandedSepAlsoCustom: this.lexer.symbols.expandedSepAlsoCustom,
|
|
90
|
+
customOpAlsoNegation: this.lexer.symbols.customOpAlsoNegation
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
state = {
|
|
94
|
+
rawInput: "",
|
|
95
|
+
lexedTokens: [],
|
|
96
|
+
index: 0,
|
|
97
|
+
shift: 0
|
|
98
|
+
};
|
|
103
99
|
/**
|
|
104
100
|
* This is exposed mainly for debugging purposes. Use parse directly instead.
|
|
105
101
|
*/
|
|
@@ -148,6 +144,8 @@ class Parser {
|
|
|
148
144
|
};
|
|
149
145
|
return res;
|
|
150
146
|
}
|
|
147
|
+
subParserOne;
|
|
148
|
+
subParserTwo;
|
|
151
149
|
createSubParserIfNotExists(opts, which = "One") {
|
|
152
150
|
if (this[`subParser${which}`] === void 0) {
|
|
153
151
|
this[`subParser${which}`] = new Parser(opts);
|
|
@@ -161,8 +159,7 @@ class Parser {
|
|
|
161
159
|
};
|
|
162
160
|
}
|
|
163
161
|
getCategoryTokens(type) {
|
|
164
|
-
|
|
165
|
-
return (_a = this.$categories[type]) == null ? void 0 : _a.entries;
|
|
162
|
+
return this.$categories[type]?.entries;
|
|
166
163
|
}
|
|
167
164
|
getTokenType(type) {
|
|
168
165
|
return this.$[type];
|
|
@@ -177,9 +174,9 @@ class Parser {
|
|
|
177
174
|
if (token2 === void 0) return false;
|
|
178
175
|
if (token2.type === type) return true;
|
|
179
176
|
const tokenType = this.getTokenType(token2.type);
|
|
180
|
-
if (
|
|
177
|
+
if (tokenType?.type === type) return true;
|
|
181
178
|
const category = this.$categories[type];
|
|
182
|
-
if (
|
|
179
|
+
if (category?.entries[token2.type] !== void 0) {
|
|
183
180
|
return true;
|
|
184
181
|
}
|
|
185
182
|
return false;
|
|
@@ -207,8 +204,7 @@ class Parser {
|
|
|
207
204
|
return this.peek(1) === void 0;
|
|
208
205
|
}
|
|
209
206
|
consumeAny() {
|
|
210
|
-
|
|
211
|
-
return this.consume((_a = this.peek(1)) == null ? void 0 : _a.type);
|
|
207
|
+
return this.consume(this.peek(1)?.type);
|
|
212
208
|
}
|
|
213
209
|
consume(type) {
|
|
214
210
|
if (type === void 0) {
|
|
@@ -220,21 +216,21 @@ class Parser {
|
|
|
220
216
|
}
|
|
221
217
|
if (this.$categories[type] !== void 0) {
|
|
222
218
|
const categoryToken = this.$categories[type];
|
|
223
|
-
const tokenType = categoryToken
|
|
219
|
+
const tokenType = categoryToken?.entries[nextToken.type];
|
|
224
220
|
if (categoryToken && tokenType) {
|
|
225
221
|
this.state.index++;
|
|
226
222
|
return this.transformCategoryToken(nextToken, categoryToken);
|
|
227
223
|
} else {
|
|
228
|
-
|
|
224
|
+
unreachable();
|
|
229
225
|
}
|
|
230
226
|
} else {
|
|
231
227
|
const tokenType = this.getTokenType(type);
|
|
232
228
|
if (tokenType !== void 0) {
|
|
233
|
-
if (
|
|
229
|
+
if (nextToken?.type === tokenType.type) {
|
|
234
230
|
this.state.index++;
|
|
235
231
|
return nextToken;
|
|
236
232
|
} else {
|
|
237
|
-
throw new Error(`Expected token type ${tokenType.type}, got ${nextToken
|
|
233
|
+
throw new Error(`Expected token type ${tokenType.type}, got ${nextToken?.type}`);
|
|
238
234
|
}
|
|
239
235
|
}
|
|
240
236
|
}
|
|
@@ -256,11 +252,10 @@ class Parser {
|
|
|
256
252
|
}
|
|
257
253
|
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
258
254
|
ruleBool(type) {
|
|
259
|
-
var _a;
|
|
260
255
|
const OP_TYPE = type === "AND" ? $C.OPERATOR_AND : $C.OPERATOR_OR;
|
|
261
256
|
const pairs = [];
|
|
262
257
|
let next = this.peek(1);
|
|
263
|
-
while (pairs.length < 1 ||
|
|
258
|
+
while (pairs.length < 1 || pairs[pairs.length - 1]?.[1] !== void 0) {
|
|
264
259
|
const exp = type === "AND" ? this.ruleCondition() : this.ruleBool("AND");
|
|
265
260
|
next = this.peek(1);
|
|
266
261
|
const canAttemptErrorRecovery = type === "AND" ? ["error", "and"].includes(this.options.onMissingBooleanOperator) : this.options.onMissingBooleanOperator === "or";
|
|
@@ -328,12 +323,11 @@ class Parser {
|
|
|
328
323
|
return res;
|
|
329
324
|
}
|
|
330
325
|
ruleCondition() {
|
|
331
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
332
326
|
const not = this.ruleNot();
|
|
333
327
|
const property = this.ruleConditionProperty();
|
|
334
|
-
const propVal =
|
|
335
|
-
const propOpVal =
|
|
336
|
-
const isExpanded = (
|
|
328
|
+
const propVal = property?.prop?.value === void 0 ? void 0 : !property.prop.value.valid ? "" : property.prop.value.value;
|
|
329
|
+
const propOpVal = property?.rest?.propertyOperator === void 0 ? void 0 : !property.rest.propertyOperator?.valid ? "" : property.rest.propertyOperator?.value;
|
|
330
|
+
const isExpanded = (property?.rest?.sepL ?? property?.rest?.sepR) !== void 0;
|
|
337
331
|
const convertRegexValues = typeof this.options.regexValues === "function" && !this.options.regexValues(propVal, propOpVal, isExpanded);
|
|
338
332
|
const convertArrayValues = typeof this.options.arrayValues === "function" && !this.options.arrayValues(propVal, propOpVal, isExpanded);
|
|
339
333
|
let value = this.ruleConditionValue(property, { convertRegexValues, convertArrayValues });
|
|
@@ -345,15 +339,15 @@ class Parser {
|
|
|
345
339
|
group$1 = value;
|
|
346
340
|
value = void 0;
|
|
347
341
|
}
|
|
348
|
-
if (convertRegexValues && isNode(value) && value.type === AST_TYPE.VARIABLE &&
|
|
342
|
+
if (convertRegexValues && isNode(value) && value.type === AST_TYPE.VARIABLE && value.quote?.left.type === TOKEN_TYPE.REGEX) {
|
|
349
343
|
value = variable(void 0, void 0, token.value(
|
|
350
|
-
(
|
|
344
|
+
(value.quote?.left?.value ?? "") + (value.value.value ?? "") + (value.quote?.right?.value ?? ""),
|
|
351
345
|
pos(value)
|
|
352
346
|
), void 0);
|
|
353
347
|
}
|
|
354
348
|
if (group$1) {
|
|
355
349
|
if (property) {
|
|
356
|
-
return condition(not, property
|
|
350
|
+
return condition(not, property?.prop, property?.rest, group(void 0, void 0, ...group$1));
|
|
357
351
|
}
|
|
358
352
|
if (value) {
|
|
359
353
|
return group(void 0, condition(not, void 0, void 0, value), ...group$1);
|
|
@@ -361,14 +355,14 @@ class Parser {
|
|
|
361
355
|
return group(not, value, ...group$1);
|
|
362
356
|
}
|
|
363
357
|
if ([not, property, value].every((_) => _ === void 0)) return void 0;
|
|
364
|
-
return condition(not, property
|
|
358
|
+
return condition(not, property?.prop, property?.rest, value);
|
|
365
359
|
}
|
|
366
360
|
ruleConditionValue(property, { convertRegexValues = false, convertArrayValues = false } = {}) {
|
|
367
361
|
const next = this.peek(1);
|
|
368
362
|
const next2 = this.peek(2);
|
|
369
363
|
const next3 = this.peek(3);
|
|
370
364
|
const next4 = this.peek(4);
|
|
371
|
-
if (this.options.prefixableGroups && property === void 0 &&
|
|
365
|
+
if (this.options.prefixableGroups && property === void 0 && next?.type !== $T.PAREN_L && (this.isType(next, $C.VALUE) && (this.isType(next2, $T.PAREN_L) || this.isType(next2, $C.QUOTE_ANY) && this.isType(next3, $T.PAREN_L)) || this.isType(next, $C.QUOTE_ANY) && (this.isType(next2, $T.PAREN_L) || this.isType(next2, $C.VALUE) && (this.isType(next3, $T.PAREN_L) || // "a(
|
|
372
366
|
this.isType(next3, $C.QUOTE_ANY) && this.isType(next4, $T.PAREN_L))))) {
|
|
373
367
|
const res = this.ruleVariable({ unprefixed: true });
|
|
374
368
|
if (res) return res;
|
|
@@ -396,7 +390,7 @@ class Parser {
|
|
|
396
390
|
if (onlyValues && !this.nextIsEof()) {
|
|
397
391
|
while (!this.nextIsEof() && (!this.isType(this.peek(1), $T.PAREN_R) || parenLeftCount !== 0)) {
|
|
398
392
|
const token2 = this.consumeAny();
|
|
399
|
-
start
|
|
393
|
+
start ??= extractPosition(token2, this.state.shift).start;
|
|
400
394
|
if (token2.type === $T.PAREN_L) {
|
|
401
395
|
parenLeftCount++;
|
|
402
396
|
}
|
|
@@ -406,7 +400,7 @@ class Parser {
|
|
|
406
400
|
}
|
|
407
401
|
}
|
|
408
402
|
if (start !== void 0) {
|
|
409
|
-
end
|
|
403
|
+
end ??= extractPosition(this.peek(0), this.state.shift).end;
|
|
410
404
|
}
|
|
411
405
|
const parenR = this.isType(this.peek(1), $T.PAREN_R) ? this.ruleParenR() : void 0;
|
|
412
406
|
if (start !== void 0) {
|
|
@@ -446,7 +440,7 @@ class Parser {
|
|
|
446
440
|
return array(bracketL, values, bracketR);
|
|
447
441
|
}
|
|
448
442
|
const start = bracketL.start;
|
|
449
|
-
const end = bracketR
|
|
443
|
+
const end = bracketR?.end;
|
|
450
444
|
const subInput = this.state.rawInput.slice(start, end);
|
|
451
445
|
this.createSubParserIfNotExists({
|
|
452
446
|
...this.options,
|
|
@@ -508,12 +502,12 @@ class Parser {
|
|
|
508
502
|
const next3 = this.peek(3);
|
|
509
503
|
if (next && (this.isExactType(next, $T.QUOTE_DOUBLE) || this.isExactType(next, $T.QUOTE_SINGLE) || this.isExactType(next, $T.QUOTE_BACKTICK))) {
|
|
510
504
|
const quoteType = next.type;
|
|
511
|
-
if (
|
|
505
|
+
if (next2?.type === quoteType) {
|
|
512
506
|
const quoteL = this.ruleQuote(quoteType);
|
|
513
507
|
const quoteR = this.ruleQuote(quoteType);
|
|
514
508
|
return variable(void 0, quoteL, void 0, quoteR);
|
|
515
509
|
}
|
|
516
|
-
if (
|
|
510
|
+
if (next3?.type === next.type) {
|
|
517
511
|
const quoteL = this.ruleQuote(quoteType);
|
|
518
512
|
const value = this.isType(next2, $T.VALUE_UNQUOTED) ? this.ruleValueUnquoted({}) : this.ruleValueNot(quoteType);
|
|
519
513
|
const quoteR = this.ruleQuote(quoteType);
|
|
@@ -594,8 +588,8 @@ class Parser {
|
|
|
594
588
|
}
|
|
595
589
|
ruleQuote(type) {
|
|
596
590
|
const quote = this.peek(1);
|
|
597
|
-
if (type !==
|
|
598
|
-
throw new Error(`Expected quote type ${type}, got ${quote
|
|
591
|
+
if (type !== quote?.type) {
|
|
592
|
+
throw new Error(`Expected quote type ${type}, got ${quote?.type}`);
|
|
599
593
|
}
|
|
600
594
|
switch (type) {
|
|
601
595
|
case $T.QUOTE_SINGLE:
|
|
@@ -635,7 +629,7 @@ class Parser {
|
|
|
635
629
|
}
|
|
636
630
|
ruleParenL() {
|
|
637
631
|
const next = this.peek(1);
|
|
638
|
-
const value =
|
|
632
|
+
const value = next?.type === $T.PAREN_L ? this.consume($T.PAREN_L) : this.createErrorToken($T.PAREN_L);
|
|
639
633
|
const loc = extractPosition(value, this.state.shift);
|
|
640
634
|
return this.state.shift === 0 || loc.start > 0 ? delimiter.parenL(value.isError ? void 0 : value.value, loc) : void 0;
|
|
641
635
|
}
|
|
@@ -645,7 +639,7 @@ class Parser {
|
|
|
645
639
|
}
|
|
646
640
|
ruleBracketL() {
|
|
647
641
|
const next = this.peek(1);
|
|
648
|
-
const value =
|
|
642
|
+
const value = next?.type === $T.BRACKET_L ? this.consume($T.BRACKET_L) : this.createErrorToken($T.BRACKET_L);
|
|
649
643
|
const loc = extractPosition(value, this.state.shift);
|
|
650
644
|
return this.state.shift === 0 || loc.start > 0 ? delimiter.bracketL(value.isError ? void 0 : value.value, loc) : void 0;
|
|
651
645
|
}
|
|
@@ -703,14 +697,13 @@ class Parser {
|
|
|
703
697
|
return [{ suggestion, value: "/" }];
|
|
704
698
|
case SUGGESTION_TYPE.REGEX_FLAGS:
|
|
705
699
|
return regexFlags.map((value) => ({ suggestion, value })).filter((completion) => {
|
|
706
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
707
700
|
const { suggestion: suggestion2, value } = completion;
|
|
708
701
|
if (suggestion2.type !== SUGGESTION_TYPE.REGEX_FLAGS) {
|
|
709
702
|
return true;
|
|
710
703
|
}
|
|
711
704
|
const token2 = suggestion2.cursorInfo;
|
|
712
|
-
const flags = token2.at &&
|
|
713
|
-
if (
|
|
705
|
+
const flags = token2.at && getParent(token2.at, parentMap)?.quote?.flags === suggestion2.cursorInfo.at ? token2.at : token2.next && getParent(token2.next, parentMap)?.quote?.flags === suggestion2.cursorInfo.next ? token2.next : token2.prev && getParent(token2.prev, parentMap)?.quote?.flags === suggestion2.cursorInfo.prev ? token2.prev : void 0;
|
|
706
|
+
if (flags?.value?.includes(value)) {
|
|
714
707
|
return false;
|
|
715
708
|
}
|
|
716
709
|
return true;
|
|
@@ -801,14 +794,13 @@ class Parser {
|
|
|
801
794
|
* ```
|
|
802
795
|
*/
|
|
803
796
|
autosuggest(input, ast, index) {
|
|
804
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
|
|
805
797
|
const parentMap = generateParentsMap(ast);
|
|
806
798
|
const opts = this.options;
|
|
807
799
|
const tokens = extractTokens(ast);
|
|
808
800
|
const token2 = getCursorInfo(input, tokens, index);
|
|
809
801
|
const wordOps = [...opts.keywords.and, ...opts.keywords.or, ...opts.keywords.not].filter((op) => !op.isSymbol);
|
|
810
|
-
const canSuggestOpAfterPrev = token2.valid.prev && tokenVariable.includes(
|
|
811
|
-
const canSuggestOpBeforeNext = token2.valid.next && tokenVariable.includes(
|
|
802
|
+
const canSuggestOpAfterPrev = token2.valid.prev && tokenVariable.includes(token2.valid.prev?.type) && (token2.whitespace.prev || token2.valid.prev.type === TOKEN_TYPE.PARENR) && !token2.at && token2.valid.next === void 0;
|
|
803
|
+
const canSuggestOpBeforeNext = token2.valid.next && tokenVariable.includes(token2.valid.next?.type) && token2.whitespace.next && // no parenL allowed since check since there will already be prefix suggestions
|
|
812
804
|
!token2.at && token2.valid.prev === void 0;
|
|
813
805
|
const requiresWhitespacePrev = tokenRequiresWhitespace(token2.valid.prev, token2.whitespace.prev, wordOps);
|
|
814
806
|
const requiresWhitespaceNext = tokenRequiresWhitespace(token2.valid.next, token2.whitespace.next, wordOps);
|
|
@@ -899,8 +891,8 @@ class Parser {
|
|
|
899
891
|
break;
|
|
900
892
|
case TOKEN_TYPE.VALUE: {
|
|
901
893
|
const errorParent = getParent(error, parentMap);
|
|
902
|
-
const prefixedValue =
|
|
903
|
-
const isRegexValue =
|
|
894
|
+
const prefixedValue = errorParent?.type === AST_TYPE.VARIABLE ? getParent(error, parentMap)?.prefix?.value : false;
|
|
895
|
+
const isRegexValue = errorParent?.type === AST_TYPE.VARIABLE && (errorParent.quote?.left.type === TOKEN_TYPE.REGEX || errorParent.quote?.right.type === TOKEN_TYPE.REGEX);
|
|
904
896
|
if (!isRegexValue) {
|
|
905
897
|
if (!prefixedValue && opts.prefixableGroups) {
|
|
906
898
|
suggestions.push({
|
|
@@ -971,16 +963,16 @@ class Parser {
|
|
|
971
963
|
const nextCondition = getParent(nextVar, parentMap);
|
|
972
964
|
const atVar = getParent(token2.at, parentMap);
|
|
973
965
|
const atCondition = getParent(atVar, parentMap);
|
|
974
|
-
const isVarPrev = !token2.whitespace.prev &&
|
|
975
|
-
const isVarNext = !token2.whitespace.next &&
|
|
976
|
-
const isVarAt =
|
|
977
|
-
const isPropertyPrev =
|
|
978
|
-
const isPropertyNext =
|
|
979
|
-
const isPropertyAt =
|
|
980
|
-
const isPropertyOperatorPrev =
|
|
981
|
-
const isPropertyOperatorNext =
|
|
982
|
-
const isPropertyOperatorAt =
|
|
983
|
-
const noArrayValuesTarget =
|
|
966
|
+
const isVarPrev = !token2.whitespace.prev && token2.valid.prev?.type !== TOKEN_TYPE.REGEX && prevVar?.type === AST_TYPE.VARIABLE && (prevCondition?.type === AST_TYPE.CONDITION && prevCondition.value === prevVar && (prevVar.quote?.right === token2.valid.prev || prevVar.value === token2.valid.prev) || prevCondition?.type === AST_TYPE.ARRAY);
|
|
967
|
+
const isVarNext = !token2.whitespace.next && token2.valid.next?.type !== TOKEN_TYPE.REGEX && nextVar?.type === AST_TYPE.VARIABLE && (nextCondition?.type === AST_TYPE.CONDITION && nextCondition.value === nextVar && (nextVar.quote?.left === token2.valid.next || nextVar.value === token2.valid.next) || nextCondition?.type === AST_TYPE.ARRAY);
|
|
968
|
+
const isVarAt = atVar?.type === AST_TYPE.VARIABLE && atCondition?.type === AST_TYPE.CONDITION || prevVar?.type === AST_TYPE.VARIABLE && token2.valid.prev === prevVar?.quote?.left || nextVar?.type === AST_TYPE.VARIABLE && token2.valid.next === nextVar?.quote?.right;
|
|
969
|
+
const isPropertyPrev = prevCondition?.type === AST_TYPE.CONDITION && prevVar !== void 0 && prevVar === prevCondition?.property;
|
|
970
|
+
const isPropertyNext = nextCondition?.type === AST_TYPE.CONDITION && nextVar !== void 0 && nextVar === nextCondition?.property;
|
|
971
|
+
const isPropertyAt = atCondition?.type === AST_TYPE.CONDITION && atVar !== void 0 && atVar === atCondition?.property;
|
|
972
|
+
const isPropertyOperatorPrev = prevVar?.type === AST_TYPE.CONDITION && token2.valid.prev === prevVar?.propertyOperator;
|
|
973
|
+
const isPropertyOperatorNext = nextVar?.type === AST_TYPE.CONDITION && token2.valid.next === nextVar?.propertyOperator;
|
|
974
|
+
const isPropertyOperatorAt = atVar?.type === AST_TYPE.CONDITION && token2.at === atVar?.propertyOperator;
|
|
975
|
+
const noArrayValuesTarget = token2.valid.prev?.type === TOKEN_TYPE.BRACKETL && (token2.valid.next === void 0 || token2.valid.next?.type === TOKEN_TYPE.BRACKETR);
|
|
984
976
|
const target = isVarPrev ? token2.valid.prev : !noArrayValuesTarget && !isPropertyPrev && !isPropertyOperatorPrev && isVarNext ? token2.valid.next : isVarAt ? token2.at : void 0;
|
|
985
977
|
const propertyTarget = isPropertyPrev ? token2.valid.prev : !noArrayValuesTarget && !isVarPrev && !isPropertyOperatorPrev && isPropertyNext ? token2.valid.next : isPropertyAt ? token2.at : void 0;
|
|
986
978
|
const propOpTarget = isPropertyOperatorPrev ? token2.valid.prev : !noArrayValuesTarget && !isVarPrev && !isPropertyPrev && isPropertyOperatorNext ? token2.valid.next : isPropertyOperatorAt ? token2.at : void 0;
|
|
@@ -992,15 +984,15 @@ class Parser {
|
|
|
992
984
|
const condition2 = parentParent;
|
|
993
985
|
const isValue = condition2.propertyOperator !== void 0 && condition2.value === parent;
|
|
994
986
|
const maybeGroup = getParent(parentParent, parentMap);
|
|
995
|
-
const isPrefix =
|
|
987
|
+
const isPrefix = maybeGroup?.type === AST_TYPE.GROUP && maybeGroup.prefix === condition2;
|
|
996
988
|
const varStart = getCursorInfo(input, ast, parent.start);
|
|
997
989
|
const varEnd = getCursorInfo(input, ast, parent.end);
|
|
998
990
|
const targetRequiresWhitespacePrev = tokenRequiresWhitespace(varStart.valid.prev, varStart.whitespace.prev, wordOps);
|
|
999
991
|
const targetRequiresWhitespaceNext = tokenRequiresWhitespace(varEnd.valid.next, varEnd.whitespace.next, wordOps);
|
|
1000
|
-
const prefixedValue = parent.type === AST_TYPE.VARIABLE ?
|
|
1001
|
-
const isSepPrev =
|
|
1002
|
-
const arrayValue =
|
|
1003
|
-
const isRegexFlag = target ===
|
|
992
|
+
const prefixedValue = parent.type === AST_TYPE.VARIABLE ? parent?.prefix?.value : false;
|
|
993
|
+
const isSepPrev = token2.prev?.type === TOKEN_TYPE.OP_EXPANDED_SEP;
|
|
994
|
+
const arrayValue = parentParent?.type === AST_TYPE.ARRAY;
|
|
995
|
+
const isRegexFlag = target === parent.quote?.flags;
|
|
1004
996
|
if (!isRegexFlag && !isSepPrev && !isValue && !arrayValue && !prefixedValue && opts.prefixableGroups) {
|
|
1005
997
|
suggestions.push({
|
|
1006
998
|
...baseSuggestion,
|
|
@@ -1057,9 +1049,9 @@ class Parser {
|
|
|
1057
1049
|
range: pos(propOpTarget)
|
|
1058
1050
|
});
|
|
1059
1051
|
}
|
|
1060
|
-
const canSuggestValue = token2.whitespace.next && (token2.whitespace.prev ||
|
|
1052
|
+
const canSuggestValue = token2.whitespace.next && (token2.whitespace.prev || token2.prev?.type === TOKEN_TYPE.BRACKETL || token2.prev?.type === TOKEN_TYPE.PARENL) || token2.whitespace.prev && (token2.whitespace.next || token2.next?.type === TOKEN_TYPE.BRACKETR || token2.next?.type === TOKEN_TYPE.PARENR);
|
|
1061
1053
|
if (canSuggestValue) {
|
|
1062
|
-
const inArrayNode = [nextCondition, prevCondition, nextVar, prevVar].find((_) =>
|
|
1054
|
+
const inArrayNode = [nextCondition, prevCondition, nextVar, prevVar].find((_) => _?.type === AST_TYPE.ARRAY) !== void 0;
|
|
1063
1055
|
const opsNotNeeded = ["and", "or"].includes(opts.onMissingBooleanOperator);
|
|
1064
1056
|
if (inArrayNode || opsNotNeeded) {
|
|
1065
1057
|
suggestions.push({
|
|
@@ -1085,8 +1077,8 @@ class Parser {
|
|
|
1085
1077
|
const tokenValidNextParent = getParent(token2.valid.next, parentMap);
|
|
1086
1078
|
const canSuggestRegexFlags = (
|
|
1087
1079
|
// has existing flags before/after
|
|
1088
|
-
token2.at && token2.at ===
|
|
1089
|
-
|
|
1080
|
+
token2.at && token2.at === tokenAtParent?.quote?.flags || token2.valid.prev && token2.valid.prev === tokenValidPrevParent?.quote?.flags || token2.valid.next && token2.valid.next === tokenValidNextParent?.quote?.flags || // no flags
|
|
1081
|
+
token2.valid.prev?.type === TOKEN_TYPE.REGEX && token2.valid.prev === tokenValidPrevParent.quote?.right
|
|
1090
1082
|
);
|
|
1091
1083
|
if (canSuggestRegexFlags) {
|
|
1092
1084
|
suggestions.push({
|
|
@@ -1263,7 +1255,6 @@ class Parser {
|
|
|
1263
1255
|
* Normalizes the ast by applying {@link GroupNode GroupNodes} and converting {@link ConditionNode ConditionNodes} to {@link NormalizedConditionNode NormalizedConditionNodes}.
|
|
1264
1256
|
*/
|
|
1265
1257
|
normalize(ast) {
|
|
1266
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
|
|
1267
1258
|
this._checkEvaluationOptions();
|
|
1268
1259
|
const opts = this.options;
|
|
1269
1260
|
if (!ast.valid) {
|
|
@@ -1275,8 +1266,8 @@ class Parser {
|
|
|
1275
1266
|
const self_ = this;
|
|
1276
1267
|
if (ast.type === AST_TYPE.CONDITION) {
|
|
1277
1268
|
if (!(ast.value.type === AST_TYPE.GROUP)) {
|
|
1278
|
-
const isValue = ast.value.type === AST_TYPE.ARRAY ||
|
|
1279
|
-
let name =
|
|
1269
|
+
const isValue = ast.value.type === AST_TYPE.ARRAY || ast.value?.quote?.left.type === TOKEN_TYPE.REGEX;
|
|
1270
|
+
let name = ast.property?.value?.value ? unescape(ast.property.value.value) : isValue ? void 0 : unescape(ast.value.value.value);
|
|
1280
1271
|
const isNested = operator2 !== void 0;
|
|
1281
1272
|
if (prefix !== void 0 && !isNested) {
|
|
1282
1273
|
name = name ? applyPrefix(prefix, name, opts.prefixApplier) : prefix;
|
|
@@ -1286,16 +1277,16 @@ class Parser {
|
|
|
1286
1277
|
value = name ?? true;
|
|
1287
1278
|
name = prefix;
|
|
1288
1279
|
} else {
|
|
1289
|
-
value = ast.value.type === AST_TYPE.ARRAY ? ast.value.values.map((val) => unescape(val.value.value)) :
|
|
1280
|
+
value = ast.value.type === AST_TYPE.ARRAY ? ast.value.values.map((val) => unescape(val.value.value)) : ast.value?.quote?.left.type === TOKEN_TYPE.REGEX ? ast.value.value?.value : ast.property && ast.value.type === AST_TYPE.VARIABLE ? unescape(ast.value.value.value) : true;
|
|
1290
1281
|
}
|
|
1291
1282
|
const propertyKeys = name ? opts.keyParser(name) : [];
|
|
1292
1283
|
const boolValue = applyBoolean(groupValue, ast.operator === void 0);
|
|
1293
1284
|
const valuePrefix = ast.value.type === AST_TYPE.VARIABLE && ast.value.prefix ? unescape(ast.value.prefix.value) : void 0;
|
|
1294
|
-
operator2
|
|
1295
|
-
const isRegex =
|
|
1296
|
-
const isQuoted =
|
|
1285
|
+
operator2 ??= ast.propertyOperator?.value;
|
|
1286
|
+
const isRegex = ast.value?.quote?.left.type === TOKEN_TYPE.REGEX;
|
|
1287
|
+
const isQuoted = ast.value?.quote !== void 0;
|
|
1297
1288
|
const isExpanded = ast.sep !== void 0;
|
|
1298
|
-
const regexFlags =
|
|
1289
|
+
const regexFlags = ast.value?.quote?.flags?.value;
|
|
1299
1290
|
const query = {
|
|
1300
1291
|
value,
|
|
1301
1292
|
operator: operator2,
|
|
@@ -1316,14 +1307,14 @@ class Parser {
|
|
|
1316
1307
|
name = applyPrefix(prefix, name, opts.prefixApplier);
|
|
1317
1308
|
}
|
|
1318
1309
|
const boolValue = applyBoolean(groupValue, ast.operator === void 0);
|
|
1319
|
-
const operator22 =
|
|
1310
|
+
const operator22 = ast.propertyOperator?.value;
|
|
1320
1311
|
return self_.normalize(ast.value, name, boolValue, operator22);
|
|
1321
1312
|
}
|
|
1322
1313
|
}
|
|
1323
1314
|
if (ast.type === AST_TYPE.GROUP) {
|
|
1324
|
-
const _prefix =
|
|
1315
|
+
const _prefix = ast.prefix?.type === AST_TYPE.CONDITION && ast.prefix?.value.type === AST_TYPE.VARIABLE ? unescape(ast.prefix.value.value.value) : void 0;
|
|
1325
1316
|
const isNotToken = _prefix === void 0;
|
|
1326
|
-
const _groupValue =
|
|
1317
|
+
const _groupValue = ast.prefix?.type === AST_TYPE.CONDITION ? ast.prefix.operator === void 0 : !(ast.prefix?.valid === true);
|
|
1327
1318
|
const applied = isNotToken ? prefix : applyPrefix(prefix, _prefix, opts.prefixApplier);
|
|
1328
1319
|
return self_.normalize(ast.expression, applied, applyBoolean(groupValue, _groupValue), operator2);
|
|
1329
1320
|
}
|
|
@@ -1342,7 +1333,6 @@ class Parser {
|
|
|
1342
1333
|
* The context does not need to be passed. If it's not passed, the function will not attempt to get the values (so it will not error) and the contextValue param of the valueValidator will be undefined.
|
|
1343
1334
|
*/
|
|
1344
1335
|
validate(ast, context) {
|
|
1345
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
1346
1336
|
const self = this;
|
|
1347
1337
|
self._checkValidationOptions();
|
|
1348
1338
|
const opts = self.options;
|
|
@@ -1357,7 +1347,7 @@ class Parser {
|
|
|
1357
1347
|
const self_ = this;
|
|
1358
1348
|
if (ast.type === AST_TYPE.CONDITION) {
|
|
1359
1349
|
if (!(ast.value.type === AST_TYPE.GROUP)) {
|
|
1360
|
-
const isValue = ast.value.type === AST_TYPE.ARRAY ||
|
|
1350
|
+
const isValue = ast.value.type === AST_TYPE.ARRAY || ast.value?.quote?.left.type === TOKEN_TYPE.REGEX;
|
|
1361
1351
|
const nameNode = ast.property ? ast.property : isValue ? void 0 : ast.value;
|
|
1362
1352
|
let name = nameNode ? unescape(nameNode.value.value) : void 0;
|
|
1363
1353
|
const isNested = operator2 !== void 0;
|
|
@@ -1372,17 +1362,17 @@ class Parser {
|
|
|
1372
1362
|
propertyNodes = [...prefixes];
|
|
1373
1363
|
} else {
|
|
1374
1364
|
propertyNodes = [...prefixes, ...nameNode ? [nameNode] : []];
|
|
1375
|
-
value = ast.value.type === AST_TYPE.ARRAY ? ast.value.values :
|
|
1365
|
+
value = ast.value.type === AST_TYPE.ARRAY ? ast.value.values : ast.value?.quote?.left.type === TOKEN_TYPE.REGEX ? ast.value : ast.property && ast.value.type === AST_TYPE.VARIABLE ? ast.value : true;
|
|
1376
1366
|
}
|
|
1377
1367
|
const propertyKeys = name ? opts.keyParser(name) : [];
|
|
1378
1368
|
const contextValue = context !== void 0 ? get(context, propertyKeys) : void 0;
|
|
1379
1369
|
const boolValue = applyBoolean(groupValue, ast.operator === void 0);
|
|
1380
1370
|
const valuePrefix = ast.value.type === AST_TYPE.VARIABLE && ast.value.prefix ? ast.value.prefix : void 0;
|
|
1381
|
-
operator2
|
|
1382
|
-
const isRegex =
|
|
1383
|
-
const isQuoted =
|
|
1371
|
+
operator2 ??= ast.propertyOperator;
|
|
1372
|
+
const isRegex = ast.value?.quote?.left.type === TOKEN_TYPE.REGEX;
|
|
1373
|
+
const isQuoted = ast.value?.quote !== void 0;
|
|
1384
1374
|
const isExpanded = ast.sep !== void 0;
|
|
1385
|
-
const regexFlags =
|
|
1375
|
+
const regexFlags = ast.value?.quote?.flags;
|
|
1386
1376
|
const query = {
|
|
1387
1377
|
value,
|
|
1388
1378
|
operator: operator2,
|
|
@@ -1415,10 +1405,10 @@ class Parser {
|
|
|
1415
1405
|
}
|
|
1416
1406
|
}
|
|
1417
1407
|
if (ast.type === AST_TYPE.GROUP) {
|
|
1418
|
-
const _prefix =
|
|
1408
|
+
const _prefix = ast.prefix?.type === AST_TYPE.CONDITION && ast.prefix.value.type === AST_TYPE.VARIABLE ? ast.prefix.value : void 0;
|
|
1419
1409
|
if (_prefix) prefixes.push(_prefix);
|
|
1420
|
-
const _groupValue =
|
|
1421
|
-
self_.validate(ast.expression, context, applyPrefix(prefix,
|
|
1410
|
+
const _groupValue = ast.prefix?.type === AST_TYPE.CONDITION ? ast.prefix.operator === void 0 : !(ast.prefix?.valid === true);
|
|
1411
|
+
self_.validate(ast.expression, context, applyPrefix(prefix, _prefix?.value.value ?? "", opts.prefixApplier), applyBoolean(groupValue, _groupValue), results, prefixes, operator2);
|
|
1422
1412
|
}
|
|
1423
1413
|
if (ast.type === AST_TYPE.EXPRESSION) {
|
|
1424
1414
|
self_.validate(ast.left, context, prefix, groupValue, results, [...prefixes], operator2);
|
|
@@ -2,17 +2,16 @@ import { token } from "./token.js";
|
|
|
2
2
|
import { TOKEN_TYPE } from "../../types/ast.js";
|
|
3
3
|
import { createArrayNode } from "../createArrayNode.js";
|
|
4
4
|
function array(values, bracket = { right: true, left: true }, parenLeftPos, parenRightPos) {
|
|
5
|
-
var _a, _b, _c, _d, _e, _f;
|
|
6
5
|
const node = {
|
|
7
6
|
values
|
|
8
7
|
};
|
|
9
8
|
node.bracket = {};
|
|
10
|
-
const start =
|
|
11
|
-
const end =
|
|
12
|
-
parenLeftPos
|
|
13
|
-
parenRightPos
|
|
9
|
+
const start = values[0]?.start ?? parenLeftPos?.end;
|
|
10
|
+
const end = values[values.length - 1]?.end ?? parenRightPos?.start ?? parenLeftPos?.end;
|
|
11
|
+
parenLeftPos ??= start !== void 0 ? { start: start - 1, end: start } : void 0;
|
|
12
|
+
parenRightPos ??= end !== void 0 ? { start: end, end: end + 1 } : void 0;
|
|
14
13
|
node.bracket.left = token(TOKEN_TYPE.BRACKETL, "[", parenLeftPos);
|
|
15
|
-
if (bracket
|
|
14
|
+
if (bracket?.right) {
|
|
16
15
|
node.bracket.right = token(TOKEN_TYPE.BRACKETR, "]", parenRightPos);
|
|
17
16
|
} else {
|
|
18
17
|
if (parenRightPos) {
|
|
@@ -20,8 +19,8 @@ function array(values, bracket = { right: true, left: true }, parenLeftPos, pare
|
|
|
20
19
|
}
|
|
21
20
|
node.bracket.right = token(TOKEN_TYPE.BRACKETR, void 0, parenRightPos);
|
|
22
21
|
}
|
|
23
|
-
node.start =
|
|
24
|
-
node.end =
|
|
22
|
+
node.start = node.bracket.left?.start ?? start ?? node.bracket?.right.start;
|
|
23
|
+
node.end = node.bracket?.right?.end ?? end ?? node.bracket.left.end;
|
|
25
24
|
return createArrayNode(node);
|
|
26
25
|
}
|
|
27
26
|
export {
|
|
@@ -10,5 +10,5 @@ import { type AnyToken, type ArrayNode, type ConditionNode, type ErrorToken, typ
|
|
|
10
10
|
* @param propertyOperator Set the operator for a property condition. A property must have been passed. The property operator must be a valid token. There is no case where it would not be. If using an operator that is the same as a separator, if used as an operator, should be set as an operator.
|
|
11
11
|
* @param sep Pass separator tokens for expanded property conditions.
|
|
12
12
|
*/
|
|
13
|
-
export declare function condition(value: VariableNode | GroupNode | ArrayNode | ErrorToken, not?: true | ValidToken<TOKEN_TYPE.NOT>, property?: VariableNode | ErrorToken, propertyOperator?: AnyToken<TOKEN_TYPE.OP_CUSTOM | TOKEN_TYPE.VALUE>, { right, left }?: Partial<Record<"right" | "left", ValidToken<TOKEN_TYPE.OP_EXPANDED_SEP>>>): ConditionNode;
|
|
13
|
+
export declare function condition(value: VariableNode | GroupNode | ArrayNode | ErrorToken, not?: true | ValidToken<typeof TOKEN_TYPE.NOT>, property?: VariableNode | ErrorToken, propertyOperator?: AnyToken<typeof TOKEN_TYPE.OP_CUSTOM | typeof TOKEN_TYPE.VALUE>, { right, left }?: Partial<Record<"right" | "left", ValidToken<typeof TOKEN_TYPE.OP_EXPANDED_SEP>>>): ConditionNode;
|
|
14
14
|
//# sourceMappingURL=condition.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"condition.d.ts","sourceRoot":"","sources":["../../../src/ast/builders/condition.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,SAAS,EAAE,KAAK,aAAa,EAAE,KAAK,UAAU,EAAmB,KAAK,SAAS,EAAiB,KAAK,UAAU,EAAE,KAAK,UAAU,EAAE,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAG5M;;;;;;;;;;GAUG;AAEH,wBAAgB,SAAS,CACxB,KAAK,EACH,YAAY,GACZ,SAAS,GACT,SAAS,GACT,UAAU,EACZ,GAAG,GAAE,IAAI,GAAG,UAAU,CAAC,UAAU,CAAC,GAAG,CAAQ,
|
|
1
|
+
{"version":3,"file":"condition.d.ts","sourceRoot":"","sources":["../../../src/ast/builders/condition.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,SAAS,EAAE,KAAK,aAAa,EAAE,KAAK,UAAU,EAAmB,KAAK,SAAS,EAAiB,KAAK,UAAU,EAAE,KAAK,UAAU,EAAE,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAG5M;;;;;;;;;;GAUG;AAEH,wBAAgB,SAAS,CACxB,KAAK,EACH,YAAY,GACZ,SAAS,GACT,SAAS,GACT,UAAU,EACZ,GAAG,GAAE,IAAI,GAAG,UAAU,CAAC,OAAO,UAAU,CAAC,GAAG,CAAQ,EACpD,QAAQ,CAAC,EAAE,YAAY,GAAG,UAAU,EACpC,gBAAgB,CAAC,EAAE,QAAQ,CAAC,OAAO,UAAU,CAAC,SAAS,GAAG,OAAO,UAAU,CAAC,KAAK,CAAC,EAClF,EAAE,KAAK,EAAE,IAAI,EAAE,GAAE,OAAO,CAAC,MAAM,CAAC,OAAO,GAAG,MAAM,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,eAAe,CAAC,CAAC,CAAO,GACrG,aAAa,CAsBf"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { pos } from "./pos.js";
|
|
2
|
+
import "../../types/ast.js";
|
|
2
3
|
import { createConditionNode } from "../createConditionNode.js";
|
|
3
4
|
function condition(value, not = true, property, propertyOperator, { right, left } = {}) {
|
|
4
5
|
const position = pos(value);
|
|
5
6
|
const notStart = not === true ? void 0 : not.start;
|
|
6
|
-
position.start = notStart ??
|
|
7
|
+
position.start = notStart ?? property?.start ?? propertyOperator?.start ?? position.start;
|
|
7
8
|
const node = {
|
|
8
9
|
property,
|
|
9
10
|
value,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type ExtractToken } from "../../types/ast.js";
|
|
2
2
|
/**
|
|
3
3
|
* Faster way, more intuitive way to generate the options for matching delimiters (e.g. quotes and parens) for functions like {@link variable} and {@link group} .
|
|
4
4
|
*/
|
|
5
|
-
export declare function delim<TLeft extends boolean | string, TRight extends boolean | string, TType extends TLeft extends string ?
|
|
5
|
+
export declare function delim<TLeft extends boolean | string, TRight extends boolean | string, TType extends TLeft extends string ? ExtractToken<TLeft> : TRight extends string ? ExtractToken<TRight> : undefined>(left?: TLeft, right?: TRight): {
|
|
6
6
|
left: TLeft extends string ? true : TLeft;
|
|
7
7
|
right: TRight extends string ? true : TRight;
|
|
8
8
|
} & TType extends undefined ? Record<string, never> : {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delim.d.ts","sourceRoot":"","sources":["../../../src/ast/builders/delim.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"delim.d.ts","sourceRoot":"","sources":["../../../src/ast/builders/delim.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,YAAY,EAAc,MAAM,oBAAoB,CAAA;AAElE;;GAEG;AAEH,wBAAgB,KAAK,CACpB,KAAK,SAAS,OAAO,GAAG,MAAM,EAC9B,MAAM,SAAS,OAAO,GAAG,MAAM,EAC/B,KAAK,SAAS,KAAK,SAAS,MAAM,GAC/B,YAAY,CAAC,KAAK,CAAC,GACnB,MAAM,SAAS,MAAM,GACrB,YAAY,CAAC,MAAM,CAAC,GACpB,SAAS,EAEZ,IAAI,GAAE,KAAsB,EAC5B,KAAK,GAAE,MAAwB,GAE/B;IACC,IAAI,EAAE,KAAK,SAAS,MAAM,GAAG,IAAI,GAAG,KAAK,CAAA;IACzC,KAAK,EAAE,MAAM,SAAS,MAAM,GAAG,IAAI,GAAG,MAAM,CAAA;CAC5C,GAAG,KAAK,SAAS,SAAS,GAAG,MAAM,CAAC,MAAM,EAAC,KAAK,CAAC,GAAG;IAAE,IAAI,EAAE,KAAK,CAAA;CAAE,CAepE"}
|