@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/dist/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/dist/grammar.js
CHANGED
|
@@ -154,7 +154,7 @@ const getGrammar = () => ({
|
|
|
154
154
|
},
|
|
155
155
|
/**
|
|
156
156
|
* A map of function names to javascript functions. A Jexl function
|
|
157
|
-
* takes zero
|
|
157
|
+
* takes zero or more arguments:
|
|
158
158
|
*
|
|
159
159
|
* - {*} ...args: A variable number of arguments passed to this function.
|
|
160
160
|
* All of these are pre-evaluated to their actual values before calling
|
package/dist/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/grammar.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAoFH,oCAIC;AARD;;;GAGG;AACH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AAqE;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;AAzJW,QAAA,UAAU,cAyJrB"}
|
package/dist/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.
|
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"],"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;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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;;;;;AA2BH,wBAIC;AAMD,gCAMC;AAMD,4BAIC;AAOD,
|
|
1
|
+
{"version":3,"file":"handlers.js","sourceRoot":"","sources":["../../src/parser/handlers.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;AA2BH,wBAIC;AAMD,gCAMC;AAMD,4BAIC;AAOD,4BAmDC;AAOD,kBAgBC;AAOD,wBAOC;AAaD,oCAcC;AAMD,gCAYC;AAOD,0BAMC;AAOD,wCAgCC;AAMD,wBAEC;AAMD,4BAMC;AAOD,wBAcC;AAOD,sCAEC;AAMD,gCAEC;AAMD,gCAEC;AAUD,oCAmBC;AAOD,0BAMC;AAKD,8BAUC;AA9WD,8CAA4C;AAC5C,+EAA+E;AAC/E,8DAA8D;AAC9D,4DAAgC;AAkBhC;;;GAGG;AACH,SAAgB,MAAM,CAAe,GAAmB;IACtD,IAAI,GAAG,EAAE,CAAC;QACR,CAAC;QA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on: { 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,QAAQ,EAAE,EAAE,OAAO,EAAE,eAAe,EAAE;IACtC,GAAG,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE;IAC5B,WAAW,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE;IAClC,QAAQ,EAAE,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,CAAC,CAAC,YAAY,EAAE;IAC5D,SAAS,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,SAAS,EAAE;CACpC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACU,QAAA,MAAM,GAAW;IAC5B,aAAa,EAAE;QACb,UAAU,EAAE;YACV,OAAO,EAAE,EAAE,OAAO,EAAE,aAAa,EAAE;YACnC,cAAc,EAAE,EAAE,OAAO,EAAE,aAAa,EAAE;YAC1C,UAAU,EAAE,EAAE,OAAO,EAAE,YAAY,EAAE;YACrC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,EAAE,EAAE,OAAO,EAAE,YAAY,EAAE;SACtC;KACF;IACD,MAAM,EAAE;QACN,UAAU,EAAE,CAAC,CAAC,MAAM;QACpB,SAAS,EAAE;YACT,YAAY,EAAE,YAAY;SAC3B;KACF;IACD,aAAa,EAAE;QACb,UAAU,EAAE,CAAC,CAAC,aAAa;QAC3B,SAAS,EAAE;YACT,UAAU,EAAE,aAAa;SAC1B;KACF;IACD,MAAM,EAAE;QACN,UAAU,EAAE,CAAC,CAAC,MAAM;QACpB,SAAS,EAAE;YACT,KAAK,EAAE,QAAQ;YACf,mEAAmE;YACnE,sEAAsE;YACtE,UAAU,EAAE,aAAa;SAC1B;KACF;IACD,MAAM,EAAE;QACN,UAAU,EAAE,CAAC,CAAC,MAAM;QACpB,SAAS,EAAE;YACT,KAAK,EAAE,cAAc;YACrB,SAAS,EAAE,aAAa;SACzB;KACF;IACD,QAAQ,EAAE;QACR,UAAU,EAAE,CAAC,CAAC,QAAQ;QACtB,SAAS,EAAE;YACT,KAAK,EAAE,UAAU;YACjB,YAAY,EAAE,aAAa;SAC5B;KACF;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;;;;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 @@
|
|
|
1
1
|
import Expression from './Expression.ts';
|
|
2
2
|
import Lexer from './Lexer.ts';
|
|
3
|
-
import type {
|
|
3
|
+
import type { BinaryOpEvalOnDemand, Grammar, GrammarElement, GrammarFn, UncheckedFn } from './grammar.ts';
|
|
4
4
|
import type { JexlValue } from './types.ts';
|
|
5
5
|
/**
|
|
6
6
|
* Jexl is the Javascript Expression Language, capable of parsing and
|
|
@@ -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
|
|
@@ -31,7 +31,7 @@ declare class Jexl {
|
|
|
31
31
|
* left.eval() or right.eval() will return that operand's actual value.
|
|
32
32
|
* This is useful to conditionally evaluate operands.
|
|
33
33
|
*/
|
|
34
|
-
addBinaryOp(operator: string, precedence: number, fn:
|
|
34
|
+
addBinaryOp(operator: string, precedence: number, fn: UncheckedFn, manualEval?: false): void;
|
|
35
35
|
addBinaryOp(operator: string, precedence: number, fn: BinaryOpEvalOnDemand, manualEval: true): void;
|
|
36
36
|
/**
|
|
37
37
|
* Adds or replaces an expression function in this Jexl instance.
|
|
@@ -41,14 +41,14 @@ declare class Jexl {
|
|
|
41
41
|
* expression function is invoked. It will be provided with each argument
|
|
42
42
|
* supplied in the expression, in the same order.
|
|
43
43
|
*/
|
|
44
|
-
addFunction(name: string, fn:
|
|
44
|
+
addFunction(name: string, fn: UncheckedFn): void;
|
|
45
45
|
/**
|
|
46
46
|
* Syntactic sugar for calling {@link #addFunction} repeatedly. This function
|
|
47
47
|
* accepts a map of one or more expression function names to their javascript
|
|
48
48
|
* function counterpart.
|
|
49
49
|
* @param {{}} map A map of expression function names to javascript functions
|
|
50
50
|
*/
|
|
51
|
-
addFunctions(map: Record<string,
|
|
51
|
+
addFunctions(map: Record<string, UncheckedFn>): void;
|
|
52
52
|
/**
|
|
53
53
|
* Adds a unary operator to Jexl. Unary operators are currently only supported
|
|
54
54
|
* on the left side of the value on which it will operate.
|
|
@@ -57,7 +57,7 @@ declare class Jexl {
|
|
|
57
57
|
* will be called with one argument: the literal value to the right of the
|
|
58
58
|
* operator. It should return the resulting value.
|
|
59
59
|
*/
|
|
60
|
-
addUnaryOp(operator: string, fn:
|
|
60
|
+
addUnaryOp(operator: string, fn: UncheckedFn): void;
|
|
61
61
|
/**
|
|
62
62
|
* Creates an Expression object from the given Jexl expression string, and
|
|
63
63
|
* immediately compiles it. The returned Expression object can then be
|
|
@@ -79,7 +79,7 @@ declare class Jexl {
|
|
|
79
79
|
* @param {string} name The name of the expression function
|
|
80
80
|
* @returns {function} The expression function
|
|
81
81
|
*/
|
|
82
|
-
getFunction(name: string):
|
|
82
|
+
getFunction(name: string): GrammarFn | undefined;
|
|
83
83
|
/**
|
|
84
84
|
* Evaluates a Jexl string within an optional context.
|
|
85
85
|
* @param {string} expression The Jexl expression to be evaluated
|
package/esm/Jexl.js
CHANGED
|
@@ -30,7 +30,11 @@ class Jexl {
|
|
|
30
30
|
precedence,
|
|
31
31
|
evalOnDemand: fn
|
|
32
32
|
}
|
|
33
|
-
: {
|
|
33
|
+
: {
|
|
34
|
+
type: 'binaryOp',
|
|
35
|
+
precedence,
|
|
36
|
+
eval: fn
|
|
37
|
+
});
|
|
34
38
|
}
|
|
35
39
|
/**
|
|
36
40
|
* Adds or replaces an expression function in this Jexl instance.
|
|
@@ -41,6 +45,8 @@ class Jexl {
|
|
|
41
45
|
* supplied in the expression, in the same order.
|
|
42
46
|
*/
|
|
43
47
|
addFunction(name, fn) {
|
|
48
|
+
// jexl hands the function whatever the operands evaluated to, which it
|
|
49
|
+
// cannot reconcile with the caller's parameter types — see UncheckedFn
|
|
44
50
|
this._grammar.functions[name] = fn;
|
|
45
51
|
}
|
|
46
52
|
/**
|
package/esm/Jexl.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Jexl.js","sourceRoot":"","sources":["../src/Jexl.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,UAAU,MAAM,iBAAiB,CAAA;AACxC,OAAO,KAAK,MAAM,YAAY,CAAA;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"Jexl.js","sourceRoot":"","sources":["../src/Jexl.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,UAAU,MAAM,iBAAiB,CAAA;AACxC,OAAO,KAAK,MAAM,YAAY,CAAA;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAazC;;;;;GAKG;AACH,MAAM,IAAI;IACR,QAAQ,CAAS;IACjB,0EAA0E;IAC1E,gEAAgE;IAChE,MAAM,CAAO;IAEb;QACE,IAAI,CAAC,QAAQ,GAAG,UAAU,EAAE,CAAA;QAC5B,IAAI,CAAC,MAAM,GAAG,IAAI,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QACtC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAClC,CAAC;IAiCD,WAAW,CACT,QAAgB,EAChB,UAAkB,EAClB,EAAsC,EACtC,UAAoB;QAEpB,sEAAsE;QACtE,iEAAiE;QACjE,IAAI,CAAC,kBAAkB,CACrB,QAAQ,EACR,UAAU;YACR,CAAC,CAAC;gBACE,IAAI,EAAE,UAAU;gBAChB,UAAU;gBACV,YAAY,EAAE,EAA0B;aACzC;YACH,CAAC,CAAC;gBACE,IAAI,EAAE,UAAU;gBAChB,UAAU;gBACV,IAAI,EAAE,EAA6B;aACpC,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GAAG,IAAI,IAAI,EAAE,CAAA;AAC/B,eAAe,YAAY,CAAA;AAC3B,OAAO,EAAE,IAAI,EAAE,CAAA"}
|
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;
|