@jbrowse/jexl 3.3.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 +2 -2
- 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.js +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 +2 -2
- 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.js +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 +2 -2
- package/src/Lexer.ts +47 -36
- package/src/evaluator/compile.ts +53 -68
- package/src/grammar.ts +1 -1
- 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/dist/parser/Parser.js
CHANGED
|
@@ -57,7 +57,7 @@ const tokenHandlers = {
|
|
|
57
57
|
/**
|
|
58
58
|
* The Parser is a state machine that converts tokens from the {@link Lexer}
|
|
59
59
|
* into an Abstract Syntax Tree (AST), capable of being evaluated in any
|
|
60
|
-
* context by
|
|
60
|
+
* context by {@link compileAst}. The Parser expects that all tokens
|
|
61
61
|
* provided to it are legal and typed properly according to the grammar, but
|
|
62
62
|
* accepts that the tokens may still be in an invalid order or in some other
|
|
63
63
|
* unparsable configuration that requires it to throw an Error.
|
|
@@ -77,13 +77,11 @@ class Parser {
|
|
|
77
77
|
_state;
|
|
78
78
|
_tree;
|
|
79
79
|
_exprStr;
|
|
80
|
-
_relative;
|
|
81
80
|
_stopMap;
|
|
82
81
|
_cursor;
|
|
83
82
|
_subParser;
|
|
84
83
|
_parentStop;
|
|
85
84
|
_nextIdentEncapsulate;
|
|
86
|
-
_nextIdentRelative;
|
|
87
85
|
_curObjKey;
|
|
88
86
|
_sequenceExpressions;
|
|
89
87
|
constructor(grammar, lexer, prefix, stopMap) {
|
|
@@ -92,7 +90,6 @@ class Parser {
|
|
|
92
90
|
this._state = 'expectOperand';
|
|
93
91
|
this._tree = null;
|
|
94
92
|
this._exprStr = prefix || '';
|
|
95
|
-
this._relative = false;
|
|
96
93
|
this._stopMap = stopMap || {};
|
|
97
94
|
}
|
|
98
95
|
/**
|
|
@@ -163,7 +160,7 @@ class Parser {
|
|
|
163
160
|
/**
|
|
164
161
|
* Marks this Parser instance as completed and retrieves the full AST.
|
|
165
162
|
* @returns {{}|null} a full expression tree, ready for evaluation by the
|
|
166
|
-
* {@link
|
|
163
|
+
* {@link compileAst} function, or null if no tokens were passed to
|
|
167
164
|
* the parser before complete was called
|
|
168
165
|
* @throws {Error} if the parser is not in a state where it's legal to end
|
|
169
166
|
* the expression, indicating that the expression is incomplete
|
|
@@ -194,13 +191,6 @@ class Parser {
|
|
|
194
191
|
this._state = 'complete';
|
|
195
192
|
return this._cursor ? this._tree : null;
|
|
196
193
|
}
|
|
197
|
-
/**
|
|
198
|
-
* Indicates whether the expression tree contains a relative path identifier.
|
|
199
|
-
* @returns {boolean} true if a relative identifier exists false otherwise.
|
|
200
|
-
*/
|
|
201
|
-
isRelative() {
|
|
202
|
-
return this._relative;
|
|
203
|
-
}
|
|
204
194
|
/**
|
|
205
195
|
* Ends a subexpression by completing the subParser and passing its result
|
|
206
196
|
* to the subHandler configured in the current state.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Parser.js","sourceRoot":"","sources":["../../src/parser/Parser.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,wDAAyC;AACzC,2CAAoC;AAMpC;;;;;GAKG;AACH,MAAM,aAAa,GAGf;IACF,QAAQ,EAAE,QAAQ,CAAC,QAAQ;IAC3B,GAAG,EAAE,QAAQ,CAAC,GAAG;IACjB,UAAU,EAAE,QAAQ,CAAC,UAAU;IAC/B,OAAO,EAAE,QAAQ,CAAC,OAAO;IACzB,SAAS,EAAE,QAAQ,CAAC,SAAS;IAC7B,cAAc,EAAE,QAAQ,CAAC,cAAc;IACvC,OAAO,EAAE,QAAQ,CAAC,OAAO;CAC1B,CAAA;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM;IACV,QAAQ,CAAS;IACjB,MAAM,CAAO;IACb,MAAM,CAAQ;IACd,KAAK,CAAgB;IACrB,QAAQ,CAAQ;IAChB,
|
|
1
|
+
{"version":3,"file":"Parser.js","sourceRoot":"","sources":["../../src/parser/Parser.ts"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AED;;;;;;OAMG;IACH,mBAAmB,CAAC,OAAgB;QAClC,IAAI,SAAS,GAAG,kBAAM,CAAC,IAAI,CAAC,MAAM,CAAE,CAAC,SAAS,CAAA;QAC9C,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,IAAI,CAAC,WAAW,GAAG,IAAI,CAAA;YACvB,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAA;QAC3B,CAAC;QACD,IAAI,kBAAM,CAAC,IAAI,CAAC,MAAM,CAAE,CAAC,WAAW,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,CAAC;YAC7D,SAAS,GAAG,EAAE,GAAG,SAAS,EAAE,SAAS,EAAE,YAAY,EAAE,CAAA;QACvD,CAAC;QACD,IAAI,CAAC,UAAU,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,SAAS,CAAC,CAAA;QAC5E,OAAO,IAAI,CAAC,UAAU,CAAA;IACxB,CAAC;CACF;AAED,kBAAe,MAAM,CAAA"}
|
|
@@ -95,9 +95,12 @@ export declare function ternaryEnd(this: Parser, ast: AstNode | null): void;
|
|
|
95
95
|
*/
|
|
96
96
|
export declare function ternaryMid(this: Parser, ast: AstNode | null): void;
|
|
97
97
|
/**
|
|
98
|
-
* Handles the start of a new ternary expression by encapsulating the
|
|
99
|
-
*
|
|
100
|
-
*
|
|
98
|
+
* Handles the start of a new ternary expression by encapsulating the tree so
|
|
99
|
+
* far in a ConditionalExpression node, and using it as the test element.
|
|
100
|
+
*
|
|
101
|
+
* Every operator binds tighter than the conditional and so belongs in the test
|
|
102
|
+
* — except `=`, which binds looser. `x = a ? b : c` therefore assigns the
|
|
103
|
+
* conditional rather than testing the assignment, which had stored `a` in `x`.
|
|
101
104
|
*/
|
|
102
105
|
export declare function ternaryStart(this: Parser): void;
|
|
103
106
|
/**
|
package/dist/parser/handlers.js
CHANGED
|
@@ -69,7 +69,7 @@ function arrayVal(ast) {
|
|
|
69
69
|
function binaryOp(token) {
|
|
70
70
|
if (token.value === '=') {
|
|
71
71
|
// `from` marks a member access such as `a.b`; only a bare name can be
|
|
72
|
-
// assigned to, since the
|
|
72
|
+
// assigned to, since the compiled closure writes straight into the context
|
|
73
73
|
if (this._cursor?.type !== 'Identifier' ||
|
|
74
74
|
this._cursor.from) {
|
|
75
75
|
throw new Error('Left side of assignment must be a variable name');
|
|
@@ -91,7 +91,14 @@ function binaryOp(token) {
|
|
|
91
91
|
if (!parentExpr.operator) {
|
|
92
92
|
break;
|
|
93
93
|
}
|
|
94
|
-
|
|
94
|
+
// a prefix operator binds tighter than any binary one, so `-x ^ 2` groups
|
|
95
|
+
// as `(-x) ^ 2` — the same way `-2 ^ 2` already does, since the Lexer folds
|
|
96
|
+
// that sign into the literal. Looking `-` up in the grammar finds its
|
|
97
|
+
// binary precedence instead, which is lower than `^`'s and gave `-(x ^ 2)`
|
|
98
|
+
const parentPrecedence = parent.type === 'UnaryExpression'
|
|
99
|
+
? Infinity
|
|
100
|
+
: (0, grammar_ts_1.precedenceOf)(this._grammar.elements[parentExpr.operator]);
|
|
101
|
+
if (parentPrecedence < precedence) {
|
|
95
102
|
break;
|
|
96
103
|
}
|
|
97
104
|
this._cursor = parent;
|
|
@@ -113,17 +120,18 @@ function binaryOp(token) {
|
|
|
113
120
|
*/
|
|
114
121
|
function dot() {
|
|
115
122
|
const cursor = this._cursor;
|
|
116
|
-
//
|
|
117
|
-
// still waiting on its right-hand side
|
|
118
|
-
//
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
this.
|
|
123
|
+
// a dot continues an identifier chain. With nothing to continue — no cursor,
|
|
124
|
+
// or an operator still waiting on its right-hand side — it would instead open
|
|
125
|
+
// a relative path, the leading dot of `list[.price > 5]`. This fork removed
|
|
126
|
+
// array filtering expressions, which are the only construct that gives a
|
|
127
|
+
// relative path a root to resolve against, so it is rejected here rather than
|
|
128
|
+
// parsed into a tree that can only fail once it is evaluated.
|
|
129
|
+
if (!cursor ||
|
|
130
|
+
cursor.type === 'UnaryExpression' ||
|
|
131
|
+
(cursor.type === 'BinaryExpression' && !cursor.right)) {
|
|
132
|
+
throw new Error(`Relative paths are not supported: ${this._exprStr}`);
|
|
126
133
|
}
|
|
134
|
+
this._nextIdentEncapsulate = true;
|
|
127
135
|
}
|
|
128
136
|
/**
|
|
129
137
|
* Handles a subexpression used for filtering an array returned by an
|
|
@@ -134,7 +142,6 @@ function filter(ast) {
|
|
|
134
142
|
const node = {
|
|
135
143
|
type: 'FilterExpression',
|
|
136
144
|
expr: ast,
|
|
137
|
-
relative: this._subParser.isRelative(),
|
|
138
145
|
subject: this._cursor
|
|
139
146
|
};
|
|
140
147
|
this._placeBeforeCursor(node);
|
|
@@ -157,12 +164,11 @@ function functionCall() {
|
|
|
157
164
|
// there is nothing to look up in the function pool
|
|
158
165
|
throw new Error(`Functions must be called by name: ${this._exprStr}`);
|
|
159
166
|
}
|
|
160
|
-
const { from } = cursor;
|
|
167
|
+
const { from, value } = cursor;
|
|
161
168
|
const node = {
|
|
162
169
|
type: 'FunctionCall',
|
|
163
|
-
name:
|
|
164
|
-
args: from ? [from] : []
|
|
165
|
-
pool: 'functions'
|
|
170
|
+
name: value,
|
|
171
|
+
args: from ? [from] : []
|
|
166
172
|
};
|
|
167
173
|
this._placeBeforeCursor(node);
|
|
168
174
|
}
|
|
@@ -181,10 +187,6 @@ function identifier(token) {
|
|
|
181
187
|
this._nextIdentEncapsulate = false;
|
|
182
188
|
}
|
|
183
189
|
else {
|
|
184
|
-
if (this._nextIdentRelative) {
|
|
185
|
-
node.relative = true;
|
|
186
|
-
this._nextIdentRelative = false;
|
|
187
|
-
}
|
|
188
190
|
this._placeAtCursor(node);
|
|
189
191
|
}
|
|
190
192
|
}
|
|
@@ -261,7 +263,7 @@ function objStart() {
|
|
|
261
263
|
function objVal(ast) {
|
|
262
264
|
// defined rather than assigned so that the key "__proto__" becomes an
|
|
263
265
|
// ordinary entry of the node's key map instead of re-pointing its prototype,
|
|
264
|
-
// which dropped the entry before
|
|
266
|
+
// which dropped the entry before it could be compiled
|
|
265
267
|
Object.defineProperty(this._cursor.value, this._curObjKey, {
|
|
266
268
|
value: ast,
|
|
267
269
|
writable: true,
|
|
@@ -294,17 +296,32 @@ function ternaryMid(ast) {
|
|
|
294
296
|
this._cursor.consequent = ast ?? undefined;
|
|
295
297
|
}
|
|
296
298
|
/**
|
|
297
|
-
* Handles the start of a new ternary expression by encapsulating the
|
|
298
|
-
*
|
|
299
|
-
*
|
|
299
|
+
* Handles the start of a new ternary expression by encapsulating the tree so
|
|
300
|
+
* far in a ConditionalExpression node, and using it as the test element.
|
|
301
|
+
*
|
|
302
|
+
* Every operator binds tighter than the conditional and so belongs in the test
|
|
303
|
+
* — except `=`, which binds looser. `x = a ? b : c` therefore assigns the
|
|
304
|
+
* conditional rather than testing the assignment, which had stored `a` in `x`.
|
|
300
305
|
*/
|
|
301
306
|
function ternaryStart() {
|
|
307
|
+
let assignment;
|
|
308
|
+
let test = this._tree;
|
|
309
|
+
while (test.type === 'AssignmentExpression' && test.right) {
|
|
310
|
+
assignment = test;
|
|
311
|
+
test = test.right;
|
|
312
|
+
}
|
|
302
313
|
const node = {
|
|
303
314
|
type: 'ConditionalExpression',
|
|
304
|
-
test
|
|
315
|
+
test
|
|
305
316
|
};
|
|
306
|
-
|
|
307
|
-
|
|
317
|
+
if (assignment) {
|
|
318
|
+
assignment.right = node;
|
|
319
|
+
this._setParent(node, assignment);
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
this._tree = node;
|
|
323
|
+
}
|
|
324
|
+
this._cursor = node;
|
|
308
325
|
}
|
|
309
326
|
/**
|
|
310
327
|
* Handles token of type 'unaryOp', indicating that the operation has only
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlers.js","sourceRoot":"","sources":["../../src/parser/handlers.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;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,CAAC,KAAe;KAChC,CAAA;IACD,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAA;AAC3B,CAAC;AAED;;GAEG;AACH,SAAgB,SAAS;IACvB,IAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC/B,IAAI,CAAC,oBAAoB,GAAG,CAAC,IAAI,CAAC,KAAM,CAAC,CAAA;IAC3C,CAAC;SAAM,CAAC;QACN,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,KAAM,CAAC,CAAA;IAC7C,CAAC;IAED,IAAI,CAAC,KAAK,GAAG,IAAI,CAAA;IACjB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA;IACnB,IAAI,CAAC,MAAM,GAAG,eAAe,CAAA;AAC/B,CAAC"}
|
package/dist/parser/states.js
CHANGED
|
@@ -113,10 +113,6 @@ exports.states = {
|
|
|
113
113
|
colon: { toState: 'objVal' }
|
|
114
114
|
}
|
|
115
115
|
},
|
|
116
|
-
postArgs: {
|
|
117
|
-
tokenTypes: afterOperand,
|
|
118
|
-
completable: true
|
|
119
|
-
},
|
|
120
116
|
identifier: {
|
|
121
117
|
tokenTypes: {
|
|
122
118
|
...afterOperand,
|
|
@@ -147,7 +143,9 @@ exports.states = {
|
|
|
147
143
|
subHandler: h.argVal,
|
|
148
144
|
endStates: {
|
|
149
145
|
comma: 'argVal',
|
|
150
|
-
|
|
146
|
+
// a call's result is an ordinary operand: it can be operated on or
|
|
147
|
+
// drilled into, but not called again, since only a name can be called
|
|
148
|
+
closeParen: 'expectBinOp'
|
|
151
149
|
}
|
|
152
150
|
},
|
|
153
151
|
objVal: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"states.js","sourceRoot":"","sources":["../../src/parser/states.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,iDAAkC;AAmBlC;;;;;GAKG;AACH,MAAM,YAAY,GAAqC;IACrD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;IACD,UAAU,EAAE;QACV,UAAU,EAAE,CAAC,CAAC,UAAU;QACxB,SAAS,EAAE;YACT,KAAK,EAAE,YAAY;SACpB;KACF;IACD,UAAU,EAAE;QACV,UAAU,EAAE,CAAC,CAAC,UAAU;QACxB,WAAW,EAAE,IAAI;KAClB;CACF,CAAA"}
|
package/dist/types.d.ts
CHANGED
|
@@ -23,7 +23,6 @@ export interface Identifier extends AstNode {
|
|
|
23
23
|
type: 'Identifier';
|
|
24
24
|
value: string;
|
|
25
25
|
from?: AstNode;
|
|
26
|
-
relative?: boolean;
|
|
27
26
|
}
|
|
28
27
|
export interface BinaryExpression extends AstNode {
|
|
29
28
|
type: 'BinaryExpression';
|
|
@@ -59,12 +58,10 @@ export interface FunctionCall extends AstNode {
|
|
|
59
58
|
type: 'FunctionCall';
|
|
60
59
|
name: string;
|
|
61
60
|
args: AstNode[];
|
|
62
|
-
pool: 'functions';
|
|
63
61
|
}
|
|
64
62
|
export interface FilterExpression extends AstNode {
|
|
65
63
|
type: 'FilterExpression';
|
|
66
64
|
expr: AstNode;
|
|
67
|
-
relative: boolean;
|
|
68
65
|
subject: AstNode;
|
|
69
66
|
}
|
|
70
67
|
export interface ConditionalExpression extends AstNode {
|
package/esm/Expression.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
* Copyright 2020 Tom Shawver
|
|
4
4
|
*/
|
|
5
5
|
import Lexer from "./Lexer.js";
|
|
6
|
-
import Evaluator from "./evaluator/Evaluator.js";
|
|
7
6
|
import { compileAst } from "./evaluator/compile.js";
|
|
8
7
|
import Parser from "./parser/Parser.js";
|
|
9
8
|
class Expression {
|
|
@@ -62,7 +61,7 @@ class Expression {
|
|
|
62
61
|
if (!this._fn) {
|
|
63
62
|
return undefined;
|
|
64
63
|
}
|
|
65
|
-
return this._fn(
|
|
64
|
+
return this._fn(context);
|
|
66
65
|
}
|
|
67
66
|
}
|
|
68
67
|
export default Expression;
|
package/esm/Expression.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Expression.js","sourceRoot":"","sources":["../src/Expression.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,MAAM,YAAY,CAAA;AAC9B,OAAO,
|
|
1
|
+
{"version":3,"file":"Expression.js","sourceRoot":"","sources":["../src/Expression.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,MAAM,YAAY,CAAA;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACnD,OAAO,MAAM,MAAM,oBAAoB,CAAA;AAMvC,MAAM,UAAU;IACd,QAAQ,CAAS;IACjB,QAAQ,CAAQ;IAChB;;oDAEgD;IAChD,IAAI,CAAgB;IACpB,MAAM,CAAO;IACb,SAAS,GAAG,KAAK,CAAA;IACjB,2EAA2E;IAC3E,GAAG,GAAwB,IAAI,CAAA;IAE/B;;;;;;;OAOG;IACH,YAAY,OAAgB,EAAE,OAAe,EAAE,KAAa;QAC1D,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAA;QACvB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAA;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,MAAM,GAAG,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,CAAA;IAC3C,CAAC;IAED;;;;;OAKG;IACH,OAAO;QACL,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;QACrD,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QAClD,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;QACxB,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAA;QAC7B,uEAAuE;QACvE,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;QAClE,IAAI,CAAC,SAAS,GAAG,IAAI,CAAA;QACrB,OAAO,IAAI,CAAA;IACb,CAAC;IAED;;;;;;OAMG;IACH,IAAI,CAAC,OAAO,GAAG,EAAE;QACf,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACpB,IAAI,CAAC,OAAO,EAAE,CAAA;QAChB,CAAC;QACD,qEAAqE;QACrE,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;YACd,OAAO,SAAS,CAAA;QAClB,CAAC;QACD,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;IAC1B,CAAC;CACF;AAED,eAAe,UAAU,CAAA"}
|
package/esm/Jexl.d.ts
CHANGED
|
@@ -16,9 +16,9 @@ declare class Jexl {
|
|
|
16
16
|
* Adds a binary operator to Jexl at the specified precedence. The higher the
|
|
17
17
|
* precedence, the earlier the operator is applied in the order of operations.
|
|
18
18
|
* For example, * has a higher precedence than +, because multiplication comes
|
|
19
|
-
* before
|
|
19
|
+
* before addition.
|
|
20
20
|
*
|
|
21
|
-
* Please see grammar.
|
|
21
|
+
* Please see grammar.ts for a listing of all default operators and their
|
|
22
22
|
* precedence values in order to choose the appropriate precedence for the
|
|
23
23
|
* new operator.
|
|
24
24
|
* @param {string} operator The operator string to be added
|
package/esm/Lexer.d.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import type { Grammar } from './grammar.ts';
|
|
2
2
|
import type { TemplatePart, Token } from './types.ts';
|
|
3
3
|
/**
|
|
4
|
-
* Lexer
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
4
|
+
* Lexer handles the lexical parsing of a Jexl string. Its responsibility is to
|
|
5
|
+
* identify the "parts of speech" of a Jexl expression, and tokenize and label
|
|
6
|
+
* each, but to do only the most minimal syntax checking; the only errors the
|
|
7
|
+
* Lexer should be concerned with are if it's unable to identify the utility of
|
|
8
|
+
* any of its tokens. Errors stemming from these tokens not being in a sensible
|
|
9
|
+
* configuration should be left for the Parser to handle.
|
|
10
|
+
*
|
|
11
|
+
* An instance is bound to one grammar and memoizes the regex that splits an
|
|
12
|
+
* expression into elements, which is expensive to build; {@link #_clearCache}
|
|
13
|
+
* discards it when the grammar's elements change.
|
|
12
14
|
*/
|
|
13
15
|
declare class Lexer {
|
|
14
16
|
_grammar: Grammar;
|
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.js","sourceRoot":"","sources":["../src/Lexer.ts"],"names":[],"mappings":"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A;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
|