@jbrowse/jexl 3.2.0 → 4.0.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/dist/Expression.js +1 -2
- package/dist/Expression.js.map +1 -1
- package/dist/Jexl.d.ts +8 -8
- package/dist/Jexl.js +7 -1
- package/dist/Jexl.js.map +1 -1
- package/dist/Lexer.d.ts +10 -8
- package/dist/Lexer.js +46 -35
- package/dist/Lexer.js.map +1 -1
- package/dist/evaluator/compile.d.ts +6 -4
- package/dist/evaluator/compile.js +42 -52
- package/dist/evaluator/compile.js.map +1 -1
- package/dist/grammar.d.ts +19 -2
- package/dist/grammar.js +1 -1
- package/dist/grammar.js.map +1 -1
- package/dist/parser/Parser.d.ts +2 -9
- package/dist/parser/Parser.js +2 -12
- package/dist/parser/Parser.js.map +1 -1
- package/dist/parser/handlers.d.ts +6 -3
- package/dist/parser/handlers.js +45 -28
- package/dist/parser/handlers.js.map +1 -1
- package/dist/parser/states.js +3 -5
- package/dist/parser/states.js.map +1 -1
- package/dist/types.d.ts +0 -3
- package/esm/Expression.js +1 -2
- package/esm/Expression.js.map +1 -1
- package/esm/Jexl.d.ts +8 -8
- package/esm/Jexl.js +7 -1
- package/esm/Jexl.js.map +1 -1
- package/esm/Lexer.d.ts +10 -8
- package/esm/Lexer.js +46 -35
- package/esm/Lexer.js.map +1 -1
- package/esm/evaluator/compile.d.ts +6 -4
- package/esm/evaluator/compile.js +42 -52
- package/esm/evaluator/compile.js.map +1 -1
- package/esm/grammar.d.ts +19 -2
- package/esm/grammar.js +1 -1
- package/esm/grammar.js.map +1 -1
- package/esm/parser/Parser.d.ts +2 -9
- package/esm/parser/Parser.js +2 -12
- package/esm/parser/Parser.js.map +1 -1
- package/esm/parser/handlers.d.ts +6 -3
- package/esm/parser/handlers.js +45 -28
- package/esm/parser/handlers.js.map +1 -1
- package/esm/parser/states.js +3 -5
- package/esm/parser/states.js.map +1 -1
- package/esm/types.d.ts +0 -3
- package/package.json +2 -1
- package/src/Expression.ts +1 -2
- package/src/Jexl.ts +20 -11
- package/src/Lexer.ts +47 -36
- package/src/evaluator/compile.ts +53 -68
- package/src/grammar.ts +23 -3
- package/src/parser/Parser.ts +2 -13
- package/src/parser/handlers.ts +48 -31
- package/src/parser/states.ts +3 -5
- package/src/types.ts +0 -3
- package/dist/evaluator/Evaluator.d.ts +0 -37
- package/dist/evaluator/Evaluator.js +0 -49
- package/dist/evaluator/Evaluator.js.map +0 -1
- package/esm/evaluator/Evaluator.d.ts +0 -37
- package/esm/evaluator/Evaluator.js +0 -47
- package/esm/evaluator/Evaluator.js.map +0 -1
- package/src/evaluator/Evaluator.ts +0 -58
package/esm/Lexer.js
CHANGED
|
@@ -2,12 +2,25 @@
|
|
|
2
2
|
* Jexl
|
|
3
3
|
* Copyright 2020 Tom Shawver
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
// what an identifier and a number look like, written once: the split regex
|
|
6
|
+
// below carves elements out of the expression with these, and _createToken
|
|
7
|
+
// then re-tests the elements it produced. Two spellings of either would
|
|
8
|
+
// disagree on some input, and each disagreement is an "Invalid expression
|
|
9
|
+
// token" for something the splitter was happy to produce.
|
|
10
|
+
const identChars = String.raw `a-zA-Zа-яА-Я_\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF$`;
|
|
11
|
+
const identPattern = `[${identChars}][${identChars}0-9]*`;
|
|
12
|
+
// unsigned: whether a leading '-' negates is decided separately, in getTokens
|
|
13
|
+
const numberPattern = String.raw `(?:(?:[0-9]*\.[0-9]+)|[0-9]+)`;
|
|
14
|
+
const numericRegex = new RegExp(`^-?${numberPattern}$`);
|
|
15
|
+
const identRegex = new RegExp(`^${identPattern}$`);
|
|
7
16
|
const escEscRegex = /\\\\/g;
|
|
8
17
|
// a string literal opens with one of exactly two quote characters, so the two
|
|
9
18
|
// unescaping regexes can just be named rather than built and cached per quote
|
|
10
19
|
const escQuoteRegex = { "'": /\\'/g, '"': /\\"/g };
|
|
20
|
+
// the escapes a template string's static text recognizes. One pass, so the
|
|
21
|
+
// backslash an escaped backslash yields can't be re-read as the start of the
|
|
22
|
+
// escape that follows it
|
|
23
|
+
const templateEscRegex = /\\([`$\\])/g;
|
|
11
24
|
const whitespaceRegex = /^\s*$/;
|
|
12
25
|
const preOpRegexElems = [
|
|
13
26
|
// Template strings
|
|
@@ -21,12 +34,7 @@ const preOpRegexElems = [
|
|
|
21
34
|
String.raw `\btrue\b`,
|
|
22
35
|
String.raw `\bfalse\b`
|
|
23
36
|
];
|
|
24
|
-
const postOpRegexElems = [
|
|
25
|
-
// Identifiers
|
|
26
|
-
'[a-zA-Zа-яА-Я_\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF\\$][a-zA-Z0-9а-яА-Я_\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF\\$]*',
|
|
27
|
-
// Numerics (without negative symbol)
|
|
28
|
-
String.raw `(?:(?:[0-9]*\.[0-9]+)|[0-9]+)`
|
|
29
|
-
];
|
|
37
|
+
const postOpRegexElems = [identPattern, numberPattern];
|
|
30
38
|
const unaryMinusToken = () => ({
|
|
31
39
|
type: 'unaryOp',
|
|
32
40
|
value: '-',
|
|
@@ -43,14 +51,16 @@ const minusNegatesAfter = new Set([
|
|
|
43
51
|
'semicolon'
|
|
44
52
|
]);
|
|
45
53
|
/**
|
|
46
|
-
* Lexer
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
+
* Lexer handles the lexical parsing of a Jexl string. Its responsibility is to
|
|
55
|
+
* identify the "parts of speech" of a Jexl expression, and tokenize and label
|
|
56
|
+
* each, but to do only the most minimal syntax checking; the only errors the
|
|
57
|
+
* Lexer should be concerned with are if it's unable to identify the utility of
|
|
58
|
+
* any of its tokens. Errors stemming from these tokens not being in a sensible
|
|
59
|
+
* configuration should be left for the Parser to handle.
|
|
60
|
+
*
|
|
61
|
+
* An instance is bound to one grammar and memoizes the regex that splits an
|
|
62
|
+
* expression into elements, which is expensive to build; {@link #_clearCache}
|
|
63
|
+
* discards it when the grammar's elements change.
|
|
54
64
|
*/
|
|
55
65
|
class Lexer {
|
|
56
66
|
_grammar;
|
|
@@ -88,10 +98,14 @@ class Lexer {
|
|
|
88
98
|
*/
|
|
89
99
|
getTokens(elements) {
|
|
90
100
|
const tokens = [];
|
|
91
|
-
|
|
101
|
+
// a prefix minus, held back until the element it applies to is known. It
|
|
102
|
+
// carries its own raw so that whitespace arriving before that element ("-
|
|
103
|
+
// 1") accumulates on the minus rather than on the token before it, which
|
|
104
|
+
// is what lets the parser's error messages quote the expression verbatim.
|
|
105
|
+
let pendingMinus;
|
|
92
106
|
for (const element of elements) {
|
|
93
107
|
if (this._isWhitespace(element)) {
|
|
94
|
-
const last = tokens.at(-1);
|
|
108
|
+
const last = pendingMinus ?? tokens.at(-1);
|
|
95
109
|
if (last) {
|
|
96
110
|
last.raw += element;
|
|
97
111
|
}
|
|
@@ -99,30 +113,32 @@ class Lexer {
|
|
|
99
113
|
else if (element === '-' && this._isNegative(tokens)) {
|
|
100
114
|
// a second prefix minus in a row ("- -x"): emit the pending one as a
|
|
101
115
|
// unary operator so this one can negate whatever comes next
|
|
102
|
-
if (
|
|
103
|
-
tokens.push(
|
|
116
|
+
if (pendingMinus) {
|
|
117
|
+
tokens.push(pendingMinus);
|
|
104
118
|
}
|
|
105
|
-
|
|
119
|
+
pendingMinus = unaryMinusToken();
|
|
106
120
|
}
|
|
107
|
-
else if (
|
|
108
|
-
negate = false;
|
|
121
|
+
else if (pendingMinus) {
|
|
109
122
|
if (numericRegex.exec(element)) {
|
|
110
123
|
// fold the sign into the number, so "-1" stays a single literal
|
|
111
|
-
|
|
124
|
+
const token = this._createToken('-' + element);
|
|
125
|
+
token.raw = pendingMinus.raw + element;
|
|
126
|
+
tokens.push(token);
|
|
112
127
|
}
|
|
113
128
|
else {
|
|
114
129
|
// anything else gets a standalone prefix operator, letting "-x",
|
|
115
130
|
// "-(a + b)" and "-foo.bar" negate a computed value
|
|
116
|
-
tokens.push(
|
|
131
|
+
tokens.push(pendingMinus, this._createToken(element));
|
|
117
132
|
}
|
|
133
|
+
pendingMinus = undefined;
|
|
118
134
|
}
|
|
119
135
|
else {
|
|
120
136
|
tokens.push(this._createToken(element));
|
|
121
137
|
}
|
|
122
138
|
}
|
|
123
139
|
// Catch a - at the end of the string. Let the parser handle that issue.
|
|
124
|
-
if (
|
|
125
|
-
tokens.push(
|
|
140
|
+
if (pendingMinus) {
|
|
141
|
+
tokens.push(pendingMinus);
|
|
126
142
|
}
|
|
127
143
|
return tokens;
|
|
128
144
|
}
|
|
@@ -249,10 +265,8 @@ class Lexer {
|
|
|
249
265
|
* @private
|
|
250
266
|
*/
|
|
251
267
|
_isNegative(tokens) {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
}
|
|
255
|
-
return minusNegatesAfter.has(tokens[tokens.length - 1].type);
|
|
268
|
+
const last = tokens.at(-1);
|
|
269
|
+
return !last || minusNegatesAfter.has(last.type);
|
|
256
270
|
}
|
|
257
271
|
/**
|
|
258
272
|
* A utility function to determine if a string consists of only space
|
|
@@ -348,10 +362,7 @@ class Lexer {
|
|
|
348
362
|
return parts;
|
|
349
363
|
}
|
|
350
364
|
_unescapeTemplateString(str) {
|
|
351
|
-
return str
|
|
352
|
-
.replaceAll('\\`', '`')
|
|
353
|
-
.replaceAll(String.raw `\$`, '$')
|
|
354
|
-
.replaceAll('\\\\', '\\');
|
|
365
|
+
return str.replaceAll(templateEscRegex, '$1');
|
|
355
366
|
}
|
|
356
367
|
}
|
|
357
368
|
export default Lexer;
|
package/esm/Lexer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Lexer.js","sourceRoot":"","sources":["../src/Lexer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,MAAM,YAAY,GAAG,
|
|
1
|
+
{"version":3,"file":"Lexer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,CAAC,WAAW,EAAE,OAAO,CAAC;aACvC,CAAC,CAAA;QACJ,CAAC;QAED,OAAO,KAAK,CAAA;IACd,CAAC;IAED,uBAAuB,CAAC,GAAW;QACjC,OAAO,GAAG,CAAC,UAAU,CAAC,gBAAgB,EAAE,IAAI,CAAC,CAAA;IAC/C,CAAC;CACF;AAED,eAAe,KAAK,CAAA"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import type { Grammar } from '../grammar.ts';
|
|
2
2
|
import type { AstNode, JexlValue } from '../types.ts';
|
|
3
|
-
|
|
3
|
+
/** The variables an expression is evaluated against. */
|
|
4
|
+
export type Context = Record<string, JexlValue>;
|
|
4
5
|
/**
|
|
5
|
-
* An AST node lowered to a closure. Calling it with
|
|
6
|
-
*
|
|
6
|
+
* An AST node lowered to a closure. Calling it with a context produces the
|
|
7
|
+
* node's value. The grammar is captured when the closure is built, so it is not
|
|
8
|
+
* a parameter.
|
|
7
9
|
*/
|
|
8
|
-
export type CompiledNode = (
|
|
10
|
+
export type CompiledNode = (context: Context) => JexlValue;
|
|
9
11
|
/**
|
|
10
12
|
* Lowers an expression tree into a tree of closures, resolving each node's type
|
|
11
13
|
* and its operator's implementation once, at compile time, rather than
|
package/esm/evaluator/compile.js
CHANGED
|
@@ -63,21 +63,17 @@ export function compileAst(ast, grammar) {
|
|
|
63
63
|
case 'Identifier': {
|
|
64
64
|
const name = node.value;
|
|
65
65
|
if (!node.from) {
|
|
66
|
-
return
|
|
67
|
-
? (ev) => ev._relContext[name]
|
|
68
|
-
: (ev) => ev._context[name];
|
|
66
|
+
return (ctx) => ctx[name];
|
|
69
67
|
}
|
|
70
68
|
const from = compileAst(node.from, grammar);
|
|
71
|
-
return (
|
|
72
|
-
const
|
|
73
|
-
if (
|
|
69
|
+
return (ctx) => {
|
|
70
|
+
const subject = from(ctx);
|
|
71
|
+
if (subject == null) {
|
|
74
72
|
return undefined;
|
|
75
73
|
}
|
|
76
74
|
// an identifier chained off an array reads through its first element
|
|
77
|
-
const
|
|
78
|
-
return
|
|
79
|
-
? undefined
|
|
80
|
-
: ctx[name];
|
|
75
|
+
const target = Array.isArray(subject) ? subject[0] : subject;
|
|
76
|
+
return target == null ? undefined : target[name];
|
|
81
77
|
};
|
|
82
78
|
}
|
|
83
79
|
case 'BinaryExpression': {
|
|
@@ -93,17 +89,17 @@ export function compileAst(ast, grammar) {
|
|
|
93
89
|
if (evalOnDemand) {
|
|
94
90
|
// operands stay unevaluated behind an `eval` thunk, so operators such
|
|
95
91
|
// as && and || can short-circuit
|
|
96
|
-
return (
|
|
92
|
+
return (ctx) => evalOnDemand({ eval: () => left(ctx) }, { eval: () => right(ctx) });
|
|
97
93
|
}
|
|
98
94
|
const fn = op.eval;
|
|
99
95
|
if (!fn) {
|
|
100
|
-
return (
|
|
101
|
-
left(
|
|
102
|
-
right(
|
|
96
|
+
return (ctx) => {
|
|
97
|
+
left(ctx);
|
|
98
|
+
right(ctx);
|
|
103
99
|
return undefined;
|
|
104
100
|
};
|
|
105
101
|
}
|
|
106
|
-
return (
|
|
102
|
+
return (ctx) => fn(left(ctx), right(ctx));
|
|
107
103
|
}
|
|
108
104
|
case 'UnaryExpression': {
|
|
109
105
|
const right = compileAst(node.right, grammar);
|
|
@@ -115,12 +111,12 @@ export function compileAst(ast, grammar) {
|
|
|
115
111
|
: undefined;
|
|
116
112
|
if (!fn) {
|
|
117
113
|
// the operand is still evaluated for an unknown operator, as before
|
|
118
|
-
return (
|
|
119
|
-
right(
|
|
114
|
+
return (ctx) => {
|
|
115
|
+
right(ctx);
|
|
120
116
|
return undefined;
|
|
121
117
|
};
|
|
122
118
|
}
|
|
123
|
-
return (
|
|
119
|
+
return (ctx) => fn(right(ctx));
|
|
124
120
|
}
|
|
125
121
|
case 'ConditionalExpression': {
|
|
126
122
|
const test = compileAst(node.test, grammar);
|
|
@@ -130,27 +126,21 @@ export function compileAst(ast, grammar) {
|
|
|
130
126
|
const alternate = node.alternate
|
|
131
127
|
? compileAst(node.alternate, grammar)
|
|
132
128
|
: undefined;
|
|
133
|
-
return (
|
|
134
|
-
const res = test(
|
|
129
|
+
return (ctx) => {
|
|
130
|
+
const res = test(ctx);
|
|
135
131
|
if (res) {
|
|
136
132
|
// an omitted consequent ("a ?: b") yields the test result
|
|
137
|
-
return consequent ? consequent(
|
|
133
|
+
return consequent ? consequent(ctx) : res;
|
|
138
134
|
}
|
|
139
|
-
return alternate ? alternate(
|
|
135
|
+
return alternate ? alternate(ctx) : undefined;
|
|
140
136
|
};
|
|
141
137
|
}
|
|
142
138
|
case 'FilterExpression': {
|
|
143
|
-
if (node.relative) {
|
|
144
|
-
// thrown on evaluation rather than compilation, as before
|
|
145
|
-
return () => {
|
|
146
|
-
throw new Error('Relative filter expressions are not supported');
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
139
|
const subject = compileAst(node.subject, grammar);
|
|
150
140
|
const index = compileAst(node.expr, grammar);
|
|
151
|
-
return (
|
|
152
|
-
const subjectVal = subject(
|
|
153
|
-
const indexVal = index(
|
|
141
|
+
return (ctx) => {
|
|
142
|
+
const subjectVal = subject(ctx);
|
|
143
|
+
const indexVal = index(ctx);
|
|
154
144
|
if (subjectVal == null) {
|
|
155
145
|
return undefined;
|
|
156
146
|
}
|
|
@@ -162,10 +152,10 @@ export function compileAst(ast, grammar) {
|
|
|
162
152
|
case 'ArrayLiteral': {
|
|
163
153
|
const items = node.value.map((item) => compileAst(item, grammar));
|
|
164
154
|
const len = items.length;
|
|
165
|
-
return (
|
|
155
|
+
return (ctx) => {
|
|
166
156
|
const out = new Array(len);
|
|
167
157
|
for (let i = 0; i < len; i++) {
|
|
168
|
-
out[i] = items[i](
|
|
158
|
+
out[i] = items[i](ctx);
|
|
169
159
|
}
|
|
170
160
|
return out;
|
|
171
161
|
};
|
|
@@ -177,10 +167,10 @@ export function compileAst(ast, grammar) {
|
|
|
177
167
|
const len = keys.length;
|
|
178
168
|
// resolved once, here, so the common case keeps its plain store
|
|
179
169
|
const store = keys.includes('__proto__') ? defineOwn : assignOwn;
|
|
180
|
-
return (
|
|
170
|
+
return (ctx) => {
|
|
181
171
|
const out = {};
|
|
182
172
|
for (let i = 0; i < len; i++) {
|
|
183
|
-
store(out, keys[i], values[i](
|
|
173
|
+
store(out, keys[i], values[i](ctx));
|
|
184
174
|
}
|
|
185
175
|
return out;
|
|
186
176
|
};
|
|
@@ -193,12 +183,12 @@ export function compileAst(ast, grammar) {
|
|
|
193
183
|
return () => value;
|
|
194
184
|
}
|
|
195
185
|
const expr = compileAst(part.value, grammar);
|
|
196
|
-
return (
|
|
186
|
+
return (ctx) => stringify(expr(ctx));
|
|
197
187
|
});
|
|
198
|
-
return (
|
|
188
|
+
return (ctx) => {
|
|
199
189
|
let out = '';
|
|
200
190
|
for (const part of parts) {
|
|
201
|
-
out += part(
|
|
191
|
+
out += part(ctx);
|
|
202
192
|
}
|
|
203
193
|
return out;
|
|
204
194
|
};
|
|
@@ -210,8 +200,8 @@ export function compileAst(ast, grammar) {
|
|
|
210
200
|
// and `constructor` aren't callable as Jexl functions. Resolved per call
|
|
211
201
|
// rather than baked in, since functions are routinely registered after
|
|
212
202
|
// an expression has been compiled.
|
|
213
|
-
const lookup = (
|
|
214
|
-
const { functions } =
|
|
203
|
+
const lookup = () => {
|
|
204
|
+
const { functions } = grammar;
|
|
215
205
|
if (!Object.hasOwn(functions, name)) {
|
|
216
206
|
throw new Error(`Jexl Function ${name} is not defined.`);
|
|
217
207
|
}
|
|
@@ -221,28 +211,28 @@ export function compileAst(ast, grammar) {
|
|
|
221
211
|
// argument array and needs no spread
|
|
222
212
|
switch (args.length) {
|
|
223
213
|
case 0: {
|
|
224
|
-
return (
|
|
214
|
+
return () => lookup()();
|
|
225
215
|
}
|
|
226
216
|
case 1: {
|
|
227
217
|
const [a0] = args;
|
|
228
|
-
return (
|
|
218
|
+
return (ctx) => lookup()(a0(ctx));
|
|
229
219
|
}
|
|
230
220
|
case 2: {
|
|
231
221
|
const [a0, a1] = args;
|
|
232
|
-
return (
|
|
222
|
+
return (ctx) => lookup()(a0(ctx), a1(ctx));
|
|
233
223
|
}
|
|
234
224
|
case 3: {
|
|
235
225
|
const [a0, a1, a2] = args;
|
|
236
|
-
return (
|
|
226
|
+
return (ctx) => lookup()(a0(ctx), a1(ctx), a2(ctx));
|
|
237
227
|
}
|
|
238
228
|
default: {
|
|
239
229
|
const len = args.length;
|
|
240
|
-
return (
|
|
230
|
+
return (ctx) => {
|
|
241
231
|
const vals = new Array(len);
|
|
242
232
|
for (let i = 0; i < len; i++) {
|
|
243
|
-
vals[i] = args[i](
|
|
233
|
+
vals[i] = args[i](ctx);
|
|
244
234
|
}
|
|
245
|
-
return lookup(
|
|
235
|
+
return lookup()(...vals);
|
|
246
236
|
};
|
|
247
237
|
}
|
|
248
238
|
}
|
|
@@ -250,10 +240,10 @@ export function compileAst(ast, grammar) {
|
|
|
250
240
|
case 'SequenceExpression': {
|
|
251
241
|
const exprs = node.expressions.map((expr) => compileAst(expr, grammar));
|
|
252
242
|
const len = exprs.length;
|
|
253
|
-
return (
|
|
243
|
+
return (ctx) => {
|
|
254
244
|
let last;
|
|
255
245
|
for (let i = 0; i < len; i++) {
|
|
256
|
-
last = exprs[i](
|
|
246
|
+
last = exprs[i](ctx);
|
|
257
247
|
}
|
|
258
248
|
return last;
|
|
259
249
|
};
|
|
@@ -262,9 +252,9 @@ export function compileAst(ast, grammar) {
|
|
|
262
252
|
const name = node.left.value;
|
|
263
253
|
const right = compileAst(node.right, grammar);
|
|
264
254
|
const store = name === '__proto__' ? defineOwn : assignOwn;
|
|
265
|
-
return (
|
|
266
|
-
const value = right(
|
|
267
|
-
store(
|
|
255
|
+
return (ctx) => {
|
|
256
|
+
const value = right(ctx);
|
|
257
|
+
store(ctx, name, value);
|
|
268
258
|
return value;
|
|
269
259
|
};
|
|
270
260
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile.js","sourceRoot":"","sources":["../../src/evaluator/compile.ts"],"names":[],"mappings":"AAAA;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AU,CAAC,IAAI,CAAC,KAAM,EAAE,OAAO,CAAC,CAAA;YAC9C,MAAM,KAAK,GAAG,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAA;YAC1D,OAAO,CAAC,GAAG,EAAE,EAAE;gBACb,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAA;gBACxB,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,KAAK,CAAC,CAAA;gBACvB,OAAO,KAAK,CAAA;YACd,CAAC,CAAA;QACH,CAAC;QAED,OAAO,CAAC,CAAC,CAAC;YACR,MAAM,IAAI,KAAK,CAAC,mCAAmC,GAAG,CAAC,IAAI,GAAG,CAAC,CAAA;QACjE,CAAC;IACH,CAAC;AACH,CAAC"}
|
package/esm/grammar.d.ts
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
import type { JexlValue } from './types.ts';
|
|
2
2
|
export type BinaryOpEval = (left: JexlValue, right: JexlValue) => JexlValue;
|
|
3
|
+
/**
|
|
4
|
+
* A function or operator implementation as its author writes it, for the
|
|
5
|
+
* registration methods on {@link Jexl} to accept.
|
|
6
|
+
*
|
|
7
|
+
* Jexl cannot check what a registered callback will be handed. The arguments
|
|
8
|
+
* are whatever the expression evaluated to, drawn from a context supplied at
|
|
9
|
+
* evaluation time, and that context routinely holds values jexl has no literal
|
|
10
|
+
* for — a host object with methods, a callback, a class instance. Requiring
|
|
11
|
+
* {@link JexlValue} parameters therefore rejected every callback actually
|
|
12
|
+
* written against such a value, since parameters are contravariant. The
|
|
13
|
+
* argument types are the caller's business; jexl only promises to pass along
|
|
14
|
+
* whatever the operands evaluated to.
|
|
15
|
+
*/
|
|
16
|
+
export type UncheckedFn = (...args: never[]) => unknown;
|
|
3
17
|
export type BinaryOpEvalOnDemand = (left: {
|
|
4
18
|
eval: () => JexlValue;
|
|
5
19
|
}, right: {
|
|
@@ -17,10 +31,11 @@ export interface BinaryOp {
|
|
|
17
31
|
*/
|
|
18
32
|
unaryEval?: (right: JexlValue) => JexlValue;
|
|
19
33
|
}
|
|
34
|
+
export type UnaryOpEval = (right: JexlValue) => JexlValue;
|
|
20
35
|
export interface UnaryOp {
|
|
21
36
|
type: 'unaryOp';
|
|
22
37
|
precedence: number;
|
|
23
|
-
eval:
|
|
38
|
+
eval: UnaryOpEval;
|
|
24
39
|
}
|
|
25
40
|
/**
|
|
26
41
|
* The punctuation elements of the grammar. Unlike operators these carry no
|
|
@@ -32,9 +47,11 @@ export interface SimpleElement {
|
|
|
32
47
|
type: 'dot' | 'openBracket' | 'closeBracket' | 'openCurl' | 'closeCurl' | 'colon' | 'comma' | 'openParen' | 'closeParen' | 'question' | 'semicolon';
|
|
33
48
|
}
|
|
34
49
|
export type GrammarElement = BinaryOp | UnaryOp | SimpleElement;
|
|
50
|
+
/** A registered function, as jexl calls it once the operands are evaluated. */
|
|
51
|
+
export type GrammarFn = (...args: JexlValue[]) => JexlValue;
|
|
35
52
|
export interface Grammar {
|
|
36
53
|
elements: Record<string, GrammarElement>;
|
|
37
|
-
functions: Record<string,
|
|
54
|
+
functions: Record<string, GrammarFn>;
|
|
38
55
|
}
|
|
39
56
|
/**
|
|
40
57
|
* Returns the binding power of a grammar element, or 0 for elements that
|
package/esm/grammar.js
CHANGED
|
@@ -150,7 +150,7 @@ export const getGrammar = () => ({
|
|
|
150
150
|
},
|
|
151
151
|
/**
|
|
152
152
|
* A map of function names to javascript functions. A Jexl function
|
|
153
|
-
* takes zero
|
|
153
|
+
* takes zero or more arguments:
|
|
154
154
|
*
|
|
155
155
|
* - {*} ...args: A variable number of arguments passed to this function.
|
|
156
156
|
* All of these are pre-evaluated to their actual values before calling
|
package/esm/grammar.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grammar.js","sourceRoot":"","sources":["../src/grammar.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"grammar.js","sourceRoot":"","sources":["../src/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,EAAE,CAAC;oBAC9B,iEAAiE;oBACjE,gEAAgE;oBAChE,kEAAkE;oBAClE,qEAAqE;oBACrE,OAAO,OAAO,IAAI,KAAK,QAAQ;wBAC7B,OAAO,IAAI,KAAK,QAAQ;wBACxB,OAAO,IAAI,KAAK,SAAS;wBACzB,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;wBAC9B,CAAC,CAAC,KAAK,CAAA;gBACX,CAAC;gBACD,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;YAC5D,CAAC;SACF;QACD,GAAG,EAAE;YACH,IAAI,EAAE,SAAS;YACf,UAAU,EAAE,QAAQ;YACpB,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK;SACxB;QACD,GAAG,EAAE;YACH,IAAI,EAAE,UAAU;YAChB,UAAU,EAAE,CAAC;YACb,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;gBACtB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;YACjD,CAAC;SACF;KACF;IAED;;;;;;;;;;;;;OAaG;IACH,SAAS,EAAE,EAAE;CACd,CAAC,CAAA"}
|
package/esm/parser/Parser.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { AstNode, Token } from '../types.ts';
|
|
|
4
4
|
/**
|
|
5
5
|
* The Parser is a state machine that converts tokens from the {@link Lexer}
|
|
6
6
|
* into an Abstract Syntax Tree (AST), capable of being evaluated in any
|
|
7
|
-
* context by
|
|
7
|
+
* context by {@link compileAst}. The Parser expects that all tokens
|
|
8
8
|
* provided to it are legal and typed properly according to the grammar, but
|
|
9
9
|
* accepts that the tokens may still be in an invalid order or in some other
|
|
10
10
|
* unparsable configuration that requires it to throw an Error.
|
|
@@ -24,13 +24,11 @@ declare class Parser {
|
|
|
24
24
|
_state: string;
|
|
25
25
|
_tree: AstNode | null;
|
|
26
26
|
_exprStr: string;
|
|
27
|
-
_relative: boolean;
|
|
28
27
|
_stopMap: Record<string, string>;
|
|
29
28
|
_cursor?: AstNode | null;
|
|
30
29
|
_subParser?: Parser;
|
|
31
30
|
_parentStop?: boolean;
|
|
32
31
|
_nextIdentEncapsulate?: boolean;
|
|
33
|
-
_nextIdentRelative?: boolean;
|
|
34
32
|
_curObjKey?: string;
|
|
35
33
|
_sequenceExpressions?: AstNode[];
|
|
36
34
|
constructor(grammar: Grammar, lexer: Lexer, prefix?: string, stopMap?: Record<string, string>);
|
|
@@ -55,17 +53,12 @@ declare class Parser {
|
|
|
55
53
|
/**
|
|
56
54
|
* Marks this Parser instance as completed and retrieves the full AST.
|
|
57
55
|
* @returns {{}|null} a full expression tree, ready for evaluation by the
|
|
58
|
-
* {@link
|
|
56
|
+
* {@link compileAst} function, or null if no tokens were passed to
|
|
59
57
|
* the parser before complete was called
|
|
60
58
|
* @throws {Error} if the parser is not in a state where it's legal to end
|
|
61
59
|
* the expression, indicating that the expression is incomplete
|
|
62
60
|
*/
|
|
63
61
|
complete(): AstNode | null;
|
|
64
|
-
/**
|
|
65
|
-
* Indicates whether the expression tree contains a relative path identifier.
|
|
66
|
-
* @returns {boolean} true if a relative identifier exists false otherwise.
|
|
67
|
-
*/
|
|
68
|
-
isRelative(): boolean;
|
|
69
62
|
/**
|
|
70
63
|
* Ends a subexpression by completing the subParser and passing its result
|
|
71
64
|
* to the subHandler configured in the current state.
|