@jbrowse/jexl 2.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/CHANGELOG.md +222 -0
- package/LICENSE.txt +19 -0
- package/README.md +216 -0
- package/dist/Expression.d.ts +38 -0
- package/dist/Expression.js +75 -0
- package/dist/Expression.js.map +1 -0
- package/dist/Jexl.d.ts +148 -0
- package/dist/Jexl.js +208 -0
- package/dist/Jexl.js.map +1 -0
- package/dist/Lexer.d.ts +130 -0
- package/dist/Lexer.js +321 -0
- package/dist/Lexer.js.map +1 -0
- package/dist/PromiseSync.d.ts +13 -0
- package/dist/PromiseSync.js +80 -0
- package/dist/PromiseSync.js.map +1 -0
- package/dist/evaluator/Evaluator.d.ts +92 -0
- package/dist/evaluator/Evaluator.js +153 -0
- package/dist/evaluator/Evaluator.js.map +1 -0
- package/dist/evaluator/handlers.d.ts +111 -0
- package/dist/evaluator/handlers.js +216 -0
- package/dist/evaluator/handlers.js.map +1 -0
- package/dist/grammar.d.ts +25 -0
- package/dist/grammar.js +179 -0
- package/dist/grammar.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/package.json +1 -0
- package/dist/parser/Parser.d.ts +112 -0
- package/dist/parser/Parser.js +233 -0
- package/dist/parser/Parser.js.map +1 -0
- package/dist/parser/handlers.d.ts +112 -0
- package/dist/parser/handlers.js +302 -0
- package/dist/parser/handlers.js.map +1 -0
- package/dist/parser/states.d.ts +47 -0
- package/dist/parser/states.js +195 -0
- package/dist/parser/states.js.map +1 -0
- package/dist/types.d.ts +77 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/esm/Expression.d.ts +38 -0
- package/esm/Expression.js +70 -0
- package/esm/Expression.js.map +1 -0
- package/esm/Jexl.d.ts +148 -0
- package/esm/Jexl.js +202 -0
- package/esm/Jexl.js.map +1 -0
- package/esm/Lexer.d.ts +130 -0
- package/esm/Lexer.js +319 -0
- package/esm/Lexer.js.map +1 -0
- package/esm/PromiseSync.d.ts +13 -0
- package/esm/PromiseSync.js +78 -0
- package/esm/PromiseSync.js.map +1 -0
- package/esm/evaluator/Evaluator.d.ts +92 -0
- package/esm/evaluator/Evaluator.js +118 -0
- package/esm/evaluator/Evaluator.js.map +1 -0
- package/esm/evaluator/handlers.d.ts +111 -0
- package/esm/evaluator/handlers.js +202 -0
- package/esm/evaluator/handlers.js.map +1 -0
- package/esm/grammar.d.ts +25 -0
- package/esm/grammar.js +175 -0
- package/esm/grammar.js.map +1 -0
- package/esm/index.d.ts +5 -0
- package/esm/index.js +9 -0
- package/esm/index.js.map +1 -0
- package/esm/parser/Parser.d.ts +112 -0
- package/esm/parser/Parser.js +198 -0
- package/esm/parser/Parser.js.map +1 -0
- package/esm/parser/handlers.d.ts +112 -0
- package/esm/parser/handlers.js +280 -0
- package/esm/parser/handlers.js.map +1 -0
- package/esm/parser/states.d.ts +47 -0
- package/esm/parser/states.js +159 -0
- package/esm/parser/states.js.map +1 -0
- package/esm/types.d.ts +77 -0
- package/esm/types.js +6 -0
- package/esm/types.js.map +1 -0
- package/package.json +67 -0
- package/src/Expression.ts +95 -0
- package/src/Jexl.ts +232 -0
- package/src/Lexer.ts +344 -0
- package/src/PromiseSync.ts +86 -0
- package/src/evaluator/Evaluator.ts +153 -0
- package/src/evaluator/handlers.ts +226 -0
- package/src/grammar.ts +200 -0
- package/src/index.ts +10 -0
- package/src/parser/Parser.ts +235 -0
- package/src/parser/handlers.ts +309 -0
- package/src/parser/states.ts +177 -0
- package/src/types.ts +107 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Evaluator.js","sourceRoot":"","sources":["../../src/evaluator/Evaluator.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,wDAAyC;AAYzC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,SAAS;IAMb,YACE,O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
+
/**
|
|
3
|
+
* Evaluates an ArrayLiteral by returning its value, with each element
|
|
4
|
+
* independently run through the evaluator.
|
|
5
|
+
* @param {{type: 'ObjectLiteral', value: <{}>}} ast An expression tree with an
|
|
6
|
+
* ObjectLiteral as the top node
|
|
7
|
+
* @returns {Promise.<[]>} resolves to a map contained evaluated values.
|
|
8
|
+
* @private
|
|
9
|
+
*/
|
|
10
|
+
export declare function ArrayLiteral(this: Evaluator, ast: any): any;
|
|
11
|
+
/**
|
|
12
|
+
* Evaluates a BinaryExpression node by running the Grammar's evaluator for
|
|
13
|
+
* the given operator. Note that binary expressions support two types of
|
|
14
|
+
* evaluators: `eval` is called with the left and right operands pre-evaluated.
|
|
15
|
+
* `evalOnDemand`, if it exists, will be called with the left and right operands
|
|
16
|
+
* each individually wrapped in an object with an "eval" function that returns
|
|
17
|
+
* a promise with the resulting value. This allows the binary expression to
|
|
18
|
+
* evaluate the operands conditionally.
|
|
19
|
+
* @param {{type: 'BinaryExpression', operator: <string>, left: {},
|
|
20
|
+
* right: {}}} ast An expression tree with a BinaryExpression as the top
|
|
21
|
+
* node
|
|
22
|
+
* @returns {Promise<*>} resolves with the value of the BinaryExpression.
|
|
23
|
+
* @private
|
|
24
|
+
*/
|
|
25
|
+
export declare function BinaryExpression(this: Evaluator, ast: any): any;
|
|
26
|
+
/**
|
|
27
|
+
* Evaluates a ConditionalExpression node by first evaluating its test branch,
|
|
28
|
+
* and resolving with the consequent branch if the test is truthy, or the
|
|
29
|
+
* alternate branch if it is not. If there is no consequent branch, the test
|
|
30
|
+
* result will be used instead.
|
|
31
|
+
* @param {{type: 'ConditionalExpression', test: {}, consequent: {},
|
|
32
|
+
* alternate: {}}} ast An expression tree with a ConditionalExpression as
|
|
33
|
+
* the top node
|
|
34
|
+
* @private
|
|
35
|
+
*/
|
|
36
|
+
export declare function ConditionalExpression(this: Evaluator, ast: any): any;
|
|
37
|
+
/**
|
|
38
|
+
* Evaluates a FilterExpression by applying it to the subject value.
|
|
39
|
+
* @param {{type: 'FilterExpression', relative: <boolean>, expr: {},
|
|
40
|
+
* subject: {}}} ast An expression tree with a FilterExpression as the top
|
|
41
|
+
* node
|
|
42
|
+
* @returns {Promise<*>} resolves with the value of the FilterExpression.
|
|
43
|
+
* @private
|
|
44
|
+
*/
|
|
45
|
+
export declare function FilterExpression(this: Evaluator, ast: any): any;
|
|
46
|
+
/**
|
|
47
|
+
* Evaluates an Identifier by either stemming from the evaluated 'from'
|
|
48
|
+
* expression tree or accessing the context provided when this Evaluator was
|
|
49
|
+
* constructed.
|
|
50
|
+
* @param {{type: 'Identifier', value: <string>, [from]: {}}} ast An expression
|
|
51
|
+
* tree with an Identifier as the top node
|
|
52
|
+
* @returns {Promise<*>|*} either the identifier's value, or a Promise that
|
|
53
|
+
* will resolve with the identifier's value.
|
|
54
|
+
* @private
|
|
55
|
+
*/
|
|
56
|
+
export declare function Identifier(this: Evaluator, ast: any): any;
|
|
57
|
+
/**
|
|
58
|
+
* Evaluates a Literal by returning its value property.
|
|
59
|
+
* @param {{type: 'Literal', value: <string|number|boolean>}} ast An expression
|
|
60
|
+
* tree with a Literal as its only node
|
|
61
|
+
* @returns {string|number|boolean} The value of the Literal node
|
|
62
|
+
* @private
|
|
63
|
+
*/
|
|
64
|
+
export declare function Literal(this: Evaluator, ast: any): any;
|
|
65
|
+
/**
|
|
66
|
+
* Evaluates a TemplateLiteral by evaluating each interpolated expression
|
|
67
|
+
* and concatenating all parts into a final string.
|
|
68
|
+
* @param {{type: 'TemplateLiteral', parts: Array<{}>}} ast An expression
|
|
69
|
+
* tree with a TemplateLiteral as the top node
|
|
70
|
+
* @returns {Promise<string>} resolves with the final interpolated string
|
|
71
|
+
* @private
|
|
72
|
+
*/
|
|
73
|
+
export declare function TemplateLiteral(this: Evaluator, ast: any): any;
|
|
74
|
+
/**
|
|
75
|
+
* Evaluates an ObjectLiteral by returning its value, with each key
|
|
76
|
+
* independently run through the evaluator.
|
|
77
|
+
* @param {{type: 'ObjectLiteral', value: <{}>}} ast An expression tree with an
|
|
78
|
+
* ObjectLiteral as the top node
|
|
79
|
+
* @returns {Promise<{}>} resolves to a map contained evaluated values.
|
|
80
|
+
* @private
|
|
81
|
+
*/
|
|
82
|
+
export declare function ObjectLiteral(this: Evaluator, ast: any): any;
|
|
83
|
+
/**
|
|
84
|
+
* Evaluates a FunctionCall node by applying the supplied arguments to a
|
|
85
|
+
* function defined in one of the grammar's function pools.
|
|
86
|
+
* @param {{type: 'FunctionCall', name: <string>}} ast An
|
|
87
|
+
* expression tree with a FunctionCall as the top node
|
|
88
|
+
* @returns {Promise<*>|*} the value of the function call, or a Promise that
|
|
89
|
+
* will resolve with the resulting value.
|
|
90
|
+
* @private
|
|
91
|
+
*/
|
|
92
|
+
export declare function FunctionCall(this: Evaluator, ast: any): any;
|
|
93
|
+
/**
|
|
94
|
+
* Evaluates a Unary expression by passing the right side through the
|
|
95
|
+
* operator's eval function.
|
|
96
|
+
* @param {{type: 'UnaryExpression', operator: <string>, right: {}}} ast An
|
|
97
|
+
* expression tree with a UnaryExpression as the top node
|
|
98
|
+
* @returns {Promise<*>} resolves with the value of the UnaryExpression.
|
|
99
|
+
* @constructor
|
|
100
|
+
*/
|
|
101
|
+
export declare function UnaryExpression(this: Evaluator, ast: any): any;
|
|
102
|
+
/**
|
|
103
|
+
* Evaluates a SequenceExpression by evaluating each expression in order
|
|
104
|
+
* and returning the value of the last expression.
|
|
105
|
+
*/
|
|
106
|
+
export declare function SequenceExpression(this: Evaluator, ast: any): any;
|
|
107
|
+
/**
|
|
108
|
+
* Evaluates an AssignmentExpression by evaluating the right side
|
|
109
|
+
* and assigning it to the variable name on the left side.
|
|
110
|
+
*/
|
|
111
|
+
export declare function AssignmentExpression(this: Evaluator, ast: any): any;
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Jexl
|
|
4
|
+
* Copyright 2020 Tom Shawver
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.ArrayLiteral = ArrayLiteral;
|
|
8
|
+
exports.BinaryExpression = BinaryExpression;
|
|
9
|
+
exports.ConditionalExpression = ConditionalExpression;
|
|
10
|
+
exports.FilterExpression = FilterExpression;
|
|
11
|
+
exports.Identifier = Identifier;
|
|
12
|
+
exports.Literal = Literal;
|
|
13
|
+
exports.TemplateLiteral = TemplateLiteral;
|
|
14
|
+
exports.ObjectLiteral = ObjectLiteral;
|
|
15
|
+
exports.FunctionCall = FunctionCall;
|
|
16
|
+
exports.UnaryExpression = UnaryExpression;
|
|
17
|
+
exports.SequenceExpression = SequenceExpression;
|
|
18
|
+
exports.AssignmentExpression = AssignmentExpression;
|
|
19
|
+
const poolNames = {
|
|
20
|
+
functions: 'Jexl Function',
|
|
21
|
+
transforms: 'Transform'
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Evaluates an ArrayLiteral by returning its value, with each element
|
|
25
|
+
* independently run through the evaluator.
|
|
26
|
+
* @param {{type: 'ObjectLiteral', value: <{}>}} ast An expression tree with an
|
|
27
|
+
* ObjectLiteral as the top node
|
|
28
|
+
* @returns {Promise.<[]>} resolves to a map contained evaluated values.
|
|
29
|
+
* @private
|
|
30
|
+
*/
|
|
31
|
+
function ArrayLiteral(ast) {
|
|
32
|
+
return this.evalArray(ast.value);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Evaluates a BinaryExpression node by running the Grammar's evaluator for
|
|
36
|
+
* the given operator. Note that binary expressions support two types of
|
|
37
|
+
* evaluators: `eval` is called with the left and right operands pre-evaluated.
|
|
38
|
+
* `evalOnDemand`, if it exists, will be called with the left and right operands
|
|
39
|
+
* each individually wrapped in an object with an "eval" function that returns
|
|
40
|
+
* a promise with the resulting value. This allows the binary expression to
|
|
41
|
+
* evaluate the operands conditionally.
|
|
42
|
+
* @param {{type: 'BinaryExpression', operator: <string>, left: {},
|
|
43
|
+
* right: {}}} ast An expression tree with a BinaryExpression as the top
|
|
44
|
+
* node
|
|
45
|
+
* @returns {Promise<*>} resolves with the value of the BinaryExpression.
|
|
46
|
+
* @private
|
|
47
|
+
*/
|
|
48
|
+
function BinaryExpression(ast) {
|
|
49
|
+
const grammarOp = this._grammar.elements[ast.operator];
|
|
50
|
+
if (grammarOp.evalOnDemand) {
|
|
51
|
+
const wrap = (subAst) => ({ eval: () => this.eval(subAst) });
|
|
52
|
+
return grammarOp.evalOnDemand(wrap(ast.left), wrap(ast.right));
|
|
53
|
+
}
|
|
54
|
+
return this.Promise.all([this.eval(ast.left), this.eval(ast.right)]).then((arr) => grammarOp.eval(arr[0], arr[1]));
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Evaluates a ConditionalExpression node by first evaluating its test branch,
|
|
58
|
+
* and resolving with the consequent branch if the test is truthy, or the
|
|
59
|
+
* alternate branch if it is not. If there is no consequent branch, the test
|
|
60
|
+
* result will be used instead.
|
|
61
|
+
* @param {{type: 'ConditionalExpression', test: {}, consequent: {},
|
|
62
|
+
* alternate: {}}} ast An expression tree with a ConditionalExpression as
|
|
63
|
+
* the top node
|
|
64
|
+
* @private
|
|
65
|
+
*/
|
|
66
|
+
function ConditionalExpression(ast) {
|
|
67
|
+
return this.eval(ast.test).then((res) => {
|
|
68
|
+
if (res) {
|
|
69
|
+
if (ast.consequent) {
|
|
70
|
+
return this.eval(ast.consequent);
|
|
71
|
+
}
|
|
72
|
+
return res;
|
|
73
|
+
}
|
|
74
|
+
return this.eval(ast.alternate);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Evaluates a FilterExpression by applying it to the subject value.
|
|
79
|
+
* @param {{type: 'FilterExpression', relative: <boolean>, expr: {},
|
|
80
|
+
* subject: {}}} ast An expression tree with a FilterExpression as the top
|
|
81
|
+
* node
|
|
82
|
+
* @returns {Promise<*>} resolves with the value of the FilterExpression.
|
|
83
|
+
* @private
|
|
84
|
+
*/
|
|
85
|
+
function FilterExpression(ast) {
|
|
86
|
+
return this.eval(ast.subject).then((subject) => {
|
|
87
|
+
if (ast.relative) {
|
|
88
|
+
return this._filterRelative(subject, ast.expr);
|
|
89
|
+
}
|
|
90
|
+
return this._filterStatic(subject, ast.expr);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Evaluates an Identifier by either stemming from the evaluated 'from'
|
|
95
|
+
* expression tree or accessing the context provided when this Evaluator was
|
|
96
|
+
* constructed.
|
|
97
|
+
* @param {{type: 'Identifier', value: <string>, [from]: {}}} ast An expression
|
|
98
|
+
* tree with an Identifier as the top node
|
|
99
|
+
* @returns {Promise<*>|*} either the identifier's value, or a Promise that
|
|
100
|
+
* will resolve with the identifier's value.
|
|
101
|
+
* @private
|
|
102
|
+
*/
|
|
103
|
+
function Identifier(ast) {
|
|
104
|
+
if (!ast.from) {
|
|
105
|
+
const contextSource = ast.relative ? this._relContext : this._context;
|
|
106
|
+
return contextSource[ast.value];
|
|
107
|
+
}
|
|
108
|
+
return this.eval(ast.from).then((context) => {
|
|
109
|
+
if (context == null) {
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
const ctx = Array.isArray(context) ? context[0] : context;
|
|
113
|
+
return ctx?.[ast.value];
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Evaluates a Literal by returning its value property.
|
|
118
|
+
* @param {{type: 'Literal', value: <string|number|boolean>}} ast An expression
|
|
119
|
+
* tree with a Literal as its only node
|
|
120
|
+
* @returns {string|number|boolean} The value of the Literal node
|
|
121
|
+
* @private
|
|
122
|
+
*/
|
|
123
|
+
function Literal(ast) {
|
|
124
|
+
return ast.value;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Evaluates a TemplateLiteral by evaluating each interpolated expression
|
|
128
|
+
* and concatenating all parts into a final string.
|
|
129
|
+
* @param {{type: 'TemplateLiteral', parts: Array<{}>}} ast An expression
|
|
130
|
+
* tree with a TemplateLiteral as the top node
|
|
131
|
+
* @returns {Promise<string>} resolves with the final interpolated string
|
|
132
|
+
* @private
|
|
133
|
+
*/
|
|
134
|
+
function TemplateLiteral(ast) {
|
|
135
|
+
const promises = ast.parts.map((part) => {
|
|
136
|
+
if (part.type === 'static') {
|
|
137
|
+
return this.Promise.resolve(part.value);
|
|
138
|
+
}
|
|
139
|
+
return this.eval(part.value).then((result) => {
|
|
140
|
+
if (result == null) {
|
|
141
|
+
return '';
|
|
142
|
+
}
|
|
143
|
+
return String(result);
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
return this.Promise.all(promises).then((values) => values.join(''));
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Evaluates an ObjectLiteral by returning its value, with each key
|
|
150
|
+
* independently run through the evaluator.
|
|
151
|
+
* @param {{type: 'ObjectLiteral', value: <{}>}} ast An expression tree with an
|
|
152
|
+
* ObjectLiteral as the top node
|
|
153
|
+
* @returns {Promise<{}>} resolves to a map contained evaluated values.
|
|
154
|
+
* @private
|
|
155
|
+
*/
|
|
156
|
+
function ObjectLiteral(ast) {
|
|
157
|
+
return this.evalMap(ast.value);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Evaluates a FunctionCall node by applying the supplied arguments to a
|
|
161
|
+
* function defined in one of the grammar's function pools.
|
|
162
|
+
* @param {{type: 'FunctionCall', name: <string>}} ast An
|
|
163
|
+
* expression tree with a FunctionCall as the top node
|
|
164
|
+
* @returns {Promise<*>|*} the value of the function call, or a Promise that
|
|
165
|
+
* will resolve with the resulting value.
|
|
166
|
+
* @private
|
|
167
|
+
*/
|
|
168
|
+
function FunctionCall(ast) {
|
|
169
|
+
const poolName = poolNames[ast.pool];
|
|
170
|
+
if (!poolName) {
|
|
171
|
+
throw new Error(`Corrupt AST: Pool '${ast.pool}' not found`);
|
|
172
|
+
}
|
|
173
|
+
const pool = this._grammar[ast.pool];
|
|
174
|
+
const func = pool?.[ast.name];
|
|
175
|
+
if (!func) {
|
|
176
|
+
throw new Error(`${poolName} ${ast.name} is not defined.`);
|
|
177
|
+
}
|
|
178
|
+
return this.evalArray(ast.args || []).then((args) => func(...args));
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Evaluates a Unary expression by passing the right side through the
|
|
182
|
+
* operator's eval function.
|
|
183
|
+
* @param {{type: 'UnaryExpression', operator: <string>, right: {}}} ast An
|
|
184
|
+
* expression tree with a UnaryExpression as the top node
|
|
185
|
+
* @returns {Promise<*>} resolves with the value of the UnaryExpression.
|
|
186
|
+
* @constructor
|
|
187
|
+
*/
|
|
188
|
+
function UnaryExpression(ast) {
|
|
189
|
+
return this.eval(ast.right).then((right) => this._grammar.elements[ast.operator].eval(right));
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Evaluates a SequenceExpression by evaluating each expression in order
|
|
193
|
+
* and returning the value of the last expression.
|
|
194
|
+
*/
|
|
195
|
+
function SequenceExpression(ast) {
|
|
196
|
+
let lastValue;
|
|
197
|
+
let promise = this.Promise.resolve();
|
|
198
|
+
for (const expr of ast.expressions) {
|
|
199
|
+
promise = promise.then(() => this.eval(expr).then((val) => {
|
|
200
|
+
lastValue = val;
|
|
201
|
+
}));
|
|
202
|
+
}
|
|
203
|
+
return promise.then(() => lastValue);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Evaluates an AssignmentExpression by evaluating the right side
|
|
207
|
+
* and assigning it to the variable name on the left side.
|
|
208
|
+
*/
|
|
209
|
+
function AssignmentExpression(ast) {
|
|
210
|
+
return this.eval(ast.right).then((value) => {
|
|
211
|
+
const varName = ast.left.value;
|
|
212
|
+
this._context[varName] = value;
|
|
213
|
+
return value;
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
//# sourceMappingURL=handlers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handlers.js","sourceRoot":"","sources":["../../src/evaluator/handlers.ts"],"names":[],"mappings":";AAAA;;;GAGG;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AAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,GAAQ,EAAE,EAAE;YAChC,SAAS,GAAG,GAAG,CAAA;QACjB,CAAC,CAAC,CACH,CAAA;IACH,CAAC;IAED,OAAO,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAA;AACtC,CAAC;AAED;;;GAGG;AACH,SAAgB,oBAAoB,CAAkB,GAAQ;IAC5D,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,KAAU,EAAE,EAAE;QAC9C,MAAM,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,KAAK,CAAA;QAC9B,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,KAAK,CAAA;QAC9B,OAAO,KAAK,CAAA;IACd,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface BinaryOp {
|
|
2
|
+
type: 'binaryOp';
|
|
3
|
+
precedence: number;
|
|
4
|
+
eval?: (left: any, right: any) => any;
|
|
5
|
+
evalOnDemand?: (left: {
|
|
6
|
+
eval: () => Promise<any>;
|
|
7
|
+
}, right: {
|
|
8
|
+
eval: () => Promise<any>;
|
|
9
|
+
}) => Promise<any>;
|
|
10
|
+
}
|
|
11
|
+
export interface UnaryOp {
|
|
12
|
+
type: 'unaryOp';
|
|
13
|
+
precedence: number;
|
|
14
|
+
eval: (right: any) => any;
|
|
15
|
+
}
|
|
16
|
+
export interface SimpleElement {
|
|
17
|
+
type: string;
|
|
18
|
+
}
|
|
19
|
+
export type GrammarElement = BinaryOp | UnaryOp | SimpleElement;
|
|
20
|
+
export interface Grammar {
|
|
21
|
+
elements: Record<string, GrammarElement>;
|
|
22
|
+
functions: Record<string, (...args: any[]) => any>;
|
|
23
|
+
transforms: Record<string, (val: any, ...args: any[]) => any>;
|
|
24
|
+
}
|
|
25
|
+
export declare const getGrammar: () => Grammar;
|
package/dist/grammar.js
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Jexl
|
|
4
|
+
* Copyright 2020 Tom Shawver
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.getGrammar = void 0;
|
|
8
|
+
const getGrammar = () => ({
|
|
9
|
+
/**
|
|
10
|
+
* A map of all expression elements to their properties. Note that changes
|
|
11
|
+
* here may require changes in the Lexer or Parser.
|
|
12
|
+
* @type {{}}
|
|
13
|
+
*/
|
|
14
|
+
elements: {
|
|
15
|
+
'.': { type: 'dot' },
|
|
16
|
+
'[': { type: 'openBracket' },
|
|
17
|
+
']': { type: 'closeBracket' },
|
|
18
|
+
'|': { type: 'pipe' },
|
|
19
|
+
'{': { type: 'openCurl' },
|
|
20
|
+
'}': { type: 'closeCurl' },
|
|
21
|
+
':': { type: 'colon' },
|
|
22
|
+
',': { type: 'comma' },
|
|
23
|
+
'(': { type: 'openParen' },
|
|
24
|
+
')': { type: 'closeParen' },
|
|
25
|
+
'?': { type: 'question' },
|
|
26
|
+
';': { type: 'semicolon' },
|
|
27
|
+
'+': {
|
|
28
|
+
type: 'binaryOp',
|
|
29
|
+
precedence: 30,
|
|
30
|
+
eval: (left, right) => left + right
|
|
31
|
+
},
|
|
32
|
+
'-': {
|
|
33
|
+
type: 'binaryOp',
|
|
34
|
+
precedence: 30,
|
|
35
|
+
eval: (left, right) => left - right
|
|
36
|
+
},
|
|
37
|
+
'*': {
|
|
38
|
+
type: 'binaryOp',
|
|
39
|
+
precedence: 40,
|
|
40
|
+
eval: (left, right) => left * right
|
|
41
|
+
},
|
|
42
|
+
'/': {
|
|
43
|
+
type: 'binaryOp',
|
|
44
|
+
precedence: 40,
|
|
45
|
+
eval: (left, right) => left / right
|
|
46
|
+
},
|
|
47
|
+
'//': {
|
|
48
|
+
type: 'binaryOp',
|
|
49
|
+
precedence: 40,
|
|
50
|
+
eval: (left, right) => Math.floor(left / right)
|
|
51
|
+
},
|
|
52
|
+
'%': {
|
|
53
|
+
type: 'binaryOp',
|
|
54
|
+
precedence: 50,
|
|
55
|
+
eval: (left, right) => left % right
|
|
56
|
+
},
|
|
57
|
+
'^': {
|
|
58
|
+
type: 'binaryOp',
|
|
59
|
+
precedence: 50,
|
|
60
|
+
eval: (left, right) => Math.pow(left, right)
|
|
61
|
+
},
|
|
62
|
+
'==': {
|
|
63
|
+
type: 'binaryOp',
|
|
64
|
+
precedence: 20,
|
|
65
|
+
eval: (left, right) => left == right
|
|
66
|
+
},
|
|
67
|
+
'!=': {
|
|
68
|
+
type: 'binaryOp',
|
|
69
|
+
precedence: 20,
|
|
70
|
+
eval: (left, right) => left != right
|
|
71
|
+
},
|
|
72
|
+
'>': {
|
|
73
|
+
type: 'binaryOp',
|
|
74
|
+
precedence: 20,
|
|
75
|
+
eval: (left, right) => left > right
|
|
76
|
+
},
|
|
77
|
+
'>=': {
|
|
78
|
+
type: 'binaryOp',
|
|
79
|
+
precedence: 20,
|
|
80
|
+
eval: (left, right) => left >= right
|
|
81
|
+
},
|
|
82
|
+
'<': {
|
|
83
|
+
type: 'binaryOp',
|
|
84
|
+
precedence: 20,
|
|
85
|
+
eval: (left, right) => left < right
|
|
86
|
+
},
|
|
87
|
+
'<=': {
|
|
88
|
+
type: 'binaryOp',
|
|
89
|
+
precedence: 20,
|
|
90
|
+
eval: (left, right) => left <= right
|
|
91
|
+
},
|
|
92
|
+
'&&': {
|
|
93
|
+
type: 'binaryOp',
|
|
94
|
+
precedence: 10,
|
|
95
|
+
evalOnDemand: (left, right) => {
|
|
96
|
+
return left.eval().then((leftVal) => {
|
|
97
|
+
if (!leftVal) {
|
|
98
|
+
return leftVal;
|
|
99
|
+
}
|
|
100
|
+
return right.eval();
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
'||': {
|
|
105
|
+
type: 'binaryOp',
|
|
106
|
+
precedence: 10,
|
|
107
|
+
evalOnDemand: (left, right) => {
|
|
108
|
+
return left.eval().then((leftVal) => {
|
|
109
|
+
if (leftVal) {
|
|
110
|
+
return leftVal;
|
|
111
|
+
}
|
|
112
|
+
return right.eval();
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
in: {
|
|
117
|
+
type: 'binaryOp',
|
|
118
|
+
precedence: 20,
|
|
119
|
+
eval: (left, right) => {
|
|
120
|
+
if (typeof right === 'string') {
|
|
121
|
+
return right.includes(left);
|
|
122
|
+
}
|
|
123
|
+
if (Array.isArray(right)) {
|
|
124
|
+
return right.includes(left);
|
|
125
|
+
}
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
'!': {
|
|
130
|
+
type: 'unaryOp',
|
|
131
|
+
precedence: Infinity,
|
|
132
|
+
eval: (right) => !right
|
|
133
|
+
},
|
|
134
|
+
'=': {
|
|
135
|
+
type: 'binaryOp',
|
|
136
|
+
precedence: 2,
|
|
137
|
+
eval: (_left, _right) => {
|
|
138
|
+
throw new Error('Assignment handled specially');
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
/**
|
|
143
|
+
* A map of function names to javascript functions. A Jexl function
|
|
144
|
+
* takes zero ore more arguemnts:
|
|
145
|
+
*
|
|
146
|
+
* - {*} ...args: A variable number of arguments passed to this function.
|
|
147
|
+
* All of these are pre-evaluated to their actual values before calling
|
|
148
|
+
* the function.
|
|
149
|
+
*
|
|
150
|
+
* The Jexl function should return either the transformed value, or
|
|
151
|
+
* a Promises/A+ Promise object that resolves with the value and rejects
|
|
152
|
+
* or throws only when an unrecoverable error occurs. Functions should
|
|
153
|
+
* generally return undefined when they don't make sense to be used on the
|
|
154
|
+
* given value type, rather than throw/reject. An error is only
|
|
155
|
+
* appropriate when the function would normally return a value, but
|
|
156
|
+
* cannot due to some other failure.
|
|
157
|
+
*/
|
|
158
|
+
functions: {},
|
|
159
|
+
/**
|
|
160
|
+
* A map of transform names to transform functions. A transform function
|
|
161
|
+
* takes one ore more arguemnts:
|
|
162
|
+
*
|
|
163
|
+
* - {*} val: A value to be transformed
|
|
164
|
+
* - {*} ...args: A variable number of arguments passed to this transform.
|
|
165
|
+
* All of these are pre-evaluated to their actual values before calling
|
|
166
|
+
* the function.
|
|
167
|
+
*
|
|
168
|
+
* The transform function should return either the transformed value, or
|
|
169
|
+
* a Promises/A+ Promise object that resolves with the value and rejects
|
|
170
|
+
* or throws only when an unrecoverable error occurs. Transforms should
|
|
171
|
+
* generally return undefined when they don't make sense to be used on the
|
|
172
|
+
* given value type, rather than throw/reject. An error is only
|
|
173
|
+
* appropriate when the transform would normally return a value, but
|
|
174
|
+
* cannot due to some other failure.
|
|
175
|
+
*/
|
|
176
|
+
transforms: {}
|
|
177
|
+
});
|
|
178
|
+
exports.getGrammar = getGrammar;
|
|
179
|
+
//# sourceMappingURL=grammar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grammar.js","sourceRoot":"","sources":["../src/grammar.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AA6BI,MAAM,UAAU,GAAG,GAAY,EAAE,CAAC,CAAC;IACxC;;;;OAIG;IACH,QAAQ,EAAE;QACR,GAAG,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE;QACpB,GAAG,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE;QAC5B,GAAG,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE;QAC7B,GAAG,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;QACrB,GAAG,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE;QACzB,GAAG,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE;QAC1B,GAAG,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE;QACtB,GAAG,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE;QACtB,GAAG,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE;QAC1B,GAAG,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U,cAuKrB"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Jexl
|
|
4
|
+
* Copyright 2020 Tom Shawver
|
|
5
|
+
*/
|
|
6
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.getGrammar = exports.Lexer = exports.Expression = exports.default = exports.Jexl = void 0;
|
|
11
|
+
var Jexl_ts_1 = require("./Jexl.js");
|
|
12
|
+
Object.defineProperty(exports, "Jexl", { enumerable: true, get: function () { return Jexl_ts_1.Jexl; } });
|
|
13
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(Jexl_ts_1).default; } });
|
|
14
|
+
var Expression_ts_1 = require("./Expression.js");
|
|
15
|
+
Object.defineProperty(exports, "Expression", { enumerable: true, get: function () { return __importDefault(Expression_ts_1).default; } });
|
|
16
|
+
var Lexer_ts_1 = require("./Lexer.js");
|
|
17
|
+
Object.defineProperty(exports, "Lexer", { enumerable: true, get: function () { return __importDefault(Lexer_ts_1).default; } });
|
|
18
|
+
var grammar_ts_1 = require("./grammar.js");
|
|
19
|
+
Object.defineProperty(exports, "getGrammar", { enumerable: true, get: function () { return grammar_ts_1.getGrammar; } });
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAEH,qCAAyC;AAAhC,+FAAA,IAAI,OAAA;AAAE,mHAAA,OAAO,OAAA;AACtB,iDAAuD;AAA9C,4HAAA,OAAO,OAAc;AAC9B,uCAA6C;AAApC,kHAAA,OAAO,OAAS;AACzB,2CAAyC;AAAhC,wGAAA,UAAU,OAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type": "commonjs"}
|