@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.
Files changed (89) hide show
  1. package/CHANGELOG.md +222 -0
  2. package/LICENSE.txt +19 -0
  3. package/README.md +216 -0
  4. package/dist/Expression.d.ts +38 -0
  5. package/dist/Expression.js +75 -0
  6. package/dist/Expression.js.map +1 -0
  7. package/dist/Jexl.d.ts +148 -0
  8. package/dist/Jexl.js +208 -0
  9. package/dist/Jexl.js.map +1 -0
  10. package/dist/Lexer.d.ts +130 -0
  11. package/dist/Lexer.js +321 -0
  12. package/dist/Lexer.js.map +1 -0
  13. package/dist/PromiseSync.d.ts +13 -0
  14. package/dist/PromiseSync.js +80 -0
  15. package/dist/PromiseSync.js.map +1 -0
  16. package/dist/evaluator/Evaluator.d.ts +92 -0
  17. package/dist/evaluator/Evaluator.js +153 -0
  18. package/dist/evaluator/Evaluator.js.map +1 -0
  19. package/dist/evaluator/handlers.d.ts +111 -0
  20. package/dist/evaluator/handlers.js +216 -0
  21. package/dist/evaluator/handlers.js.map +1 -0
  22. package/dist/grammar.d.ts +25 -0
  23. package/dist/grammar.js +179 -0
  24. package/dist/grammar.js.map +1 -0
  25. package/dist/index.d.ts +5 -0
  26. package/dist/index.js +20 -0
  27. package/dist/index.js.map +1 -0
  28. package/dist/package.json +1 -0
  29. package/dist/parser/Parser.d.ts +112 -0
  30. package/dist/parser/Parser.js +233 -0
  31. package/dist/parser/Parser.js.map +1 -0
  32. package/dist/parser/handlers.d.ts +112 -0
  33. package/dist/parser/handlers.js +302 -0
  34. package/dist/parser/handlers.js.map +1 -0
  35. package/dist/parser/states.d.ts +47 -0
  36. package/dist/parser/states.js +195 -0
  37. package/dist/parser/states.js.map +1 -0
  38. package/dist/types.d.ts +77 -0
  39. package/dist/types.js +7 -0
  40. package/dist/types.js.map +1 -0
  41. package/esm/Expression.d.ts +38 -0
  42. package/esm/Expression.js +70 -0
  43. package/esm/Expression.js.map +1 -0
  44. package/esm/Jexl.d.ts +148 -0
  45. package/esm/Jexl.js +202 -0
  46. package/esm/Jexl.js.map +1 -0
  47. package/esm/Lexer.d.ts +130 -0
  48. package/esm/Lexer.js +319 -0
  49. package/esm/Lexer.js.map +1 -0
  50. package/esm/PromiseSync.d.ts +13 -0
  51. package/esm/PromiseSync.js +78 -0
  52. package/esm/PromiseSync.js.map +1 -0
  53. package/esm/evaluator/Evaluator.d.ts +92 -0
  54. package/esm/evaluator/Evaluator.js +118 -0
  55. package/esm/evaluator/Evaluator.js.map +1 -0
  56. package/esm/evaluator/handlers.d.ts +111 -0
  57. package/esm/evaluator/handlers.js +202 -0
  58. package/esm/evaluator/handlers.js.map +1 -0
  59. package/esm/grammar.d.ts +25 -0
  60. package/esm/grammar.js +175 -0
  61. package/esm/grammar.js.map +1 -0
  62. package/esm/index.d.ts +5 -0
  63. package/esm/index.js +9 -0
  64. package/esm/index.js.map +1 -0
  65. package/esm/parser/Parser.d.ts +112 -0
  66. package/esm/parser/Parser.js +198 -0
  67. package/esm/parser/Parser.js.map +1 -0
  68. package/esm/parser/handlers.d.ts +112 -0
  69. package/esm/parser/handlers.js +280 -0
  70. package/esm/parser/handlers.js.map +1 -0
  71. package/esm/parser/states.d.ts +47 -0
  72. package/esm/parser/states.js +159 -0
  73. package/esm/parser/states.js.map +1 -0
  74. package/esm/types.d.ts +77 -0
  75. package/esm/types.js +6 -0
  76. package/esm/types.js.map +1 -0
  77. package/package.json +67 -0
  78. package/src/Expression.ts +95 -0
  79. package/src/Jexl.ts +232 -0
  80. package/src/Lexer.ts +344 -0
  81. package/src/PromiseSync.ts +86 -0
  82. package/src/evaluator/Evaluator.ts +153 -0
  83. package/src/evaluator/handlers.ts +226 -0
  84. package/src/grammar.ts +200 -0
  85. package/src/index.ts +10 -0
  86. package/src/parser/Parser.ts +235 -0
  87. package/src/parser/handlers.ts +309 -0
  88. package/src/parser/states.ts +177 -0
  89. package/src/types.ts +107 -0
@@ -0,0 +1,302 @@
1
+ "use strict";
2
+ /*
3
+ * Jexl
4
+ * Copyright 2020 Tom Shawver
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.argVal = argVal;
8
+ exports.arrayStart = arrayStart;
9
+ exports.arrayVal = arrayVal;
10
+ exports.binaryOp = binaryOp;
11
+ exports.dot = dot;
12
+ exports.filter = filter;
13
+ exports.functionCall = functionCall;
14
+ exports.identifier = identifier;
15
+ exports.literal = literal;
16
+ exports.templateString = templateString;
17
+ exports.objKey = objKey;
18
+ exports.objStart = objStart;
19
+ exports.objVal = objVal;
20
+ exports.subExpression = subExpression;
21
+ exports.ternaryEnd = ternaryEnd;
22
+ exports.ternaryMid = ternaryMid;
23
+ exports.ternaryStart = ternaryStart;
24
+ exports.transform = transform;
25
+ exports.unaryOp = unaryOp;
26
+ exports.semicolon = semicolon;
27
+ /**
28
+ * Handles a subexpression that's used to define a transform argument's value.
29
+ * @param {{type: <string>}} ast The subexpression tree
30
+ */
31
+ function argVal(ast) {
32
+ if (ast) {
33
+ ;
34
+ this._cursor.args.push(ast);
35
+ }
36
+ }
37
+ /**
38
+ * Handles new array literals by adding them as a new node in the AST,
39
+ * initialized with an empty array.
40
+ */
41
+ function arrayStart() {
42
+ this._placeAtCursor({
43
+ type: 'ArrayLiteral',
44
+ value: []
45
+ });
46
+ }
47
+ /**
48
+ * Handles a subexpression representing an element of an array literal.
49
+ * @param {{type: <string>}} ast The subexpression tree
50
+ */
51
+ function arrayVal(ast) {
52
+ if (ast) {
53
+ ;
54
+ this._cursor.value.push(ast);
55
+ }
56
+ }
57
+ /**
58
+ * Handles tokens of type 'binaryOp', indicating an operation that has two
59
+ * inputs: a left side and a right side.
60
+ * @param {{type: <string>}} token A token object
61
+ */
62
+ function binaryOp(token) {
63
+ if (token.value === '=') {
64
+ if (this._cursor?.type !== 'Identifier') {
65
+ throw new Error('Left side of assignment must be a variable name');
66
+ }
67
+ const node = {
68
+ type: 'AssignmentExpression',
69
+ operator: '=',
70
+ left: this._cursor
71
+ };
72
+ this._cursor = this._cursor._parent;
73
+ this._placeAtCursor(node);
74
+ return;
75
+ }
76
+ const precedence = this._grammar.elements[token.value].precedence || 0;
77
+ let parent = this._cursor?._parent;
78
+ while (parent &&
79
+ parent.operator &&
80
+ this._grammar.elements[parent.operator].precedence >= precedence) {
81
+ this._cursor = parent;
82
+ parent = parent._parent;
83
+ }
84
+ const node = {
85
+ type: 'BinaryExpression',
86
+ operator: token.value,
87
+ left: this._cursor
88
+ };
89
+ this._setParent(this._cursor, node);
90
+ this._cursor = parent;
91
+ this._placeAtCursor(node);
92
+ }
93
+ /**
94
+ * Handles successive nodes in an identifier chain. More specifically, it
95
+ * sets values that determine how the following identifier gets placed in the
96
+ * AST.
97
+ */
98
+ function dot() {
99
+ const isBinaryExprWithRight = (node) => node.type === 'BinaryExpression' && node.right;
100
+ this._nextIdentEncapsulate =
101
+ this._cursor &&
102
+ this._cursor.type !== 'UnaryExpression' &&
103
+ (this._cursor.type !== 'BinaryExpression' ||
104
+ isBinaryExprWithRight(this._cursor));
105
+ this._nextIdentRelative = !this._cursor || !this._nextIdentEncapsulate;
106
+ if (this._nextIdentRelative) {
107
+ this._relative = true;
108
+ }
109
+ }
110
+ /**
111
+ * Handles a subexpression used for filtering an array returned by an
112
+ * identifier chain.
113
+ * @param {{type: <string>}} ast The subexpression tree
114
+ */
115
+ function filter(ast) {
116
+ this._placeBeforeCursor({
117
+ type: 'FilterExpression',
118
+ expr: ast,
119
+ relative: this._subParser.isRelative(),
120
+ subject: this._cursor
121
+ });
122
+ }
123
+ /**
124
+ * Handles identifier tokens when used to indicate the name of a function to
125
+ * be called.
126
+ * @param {{type: <string>}} token A token object
127
+ */
128
+ function functionCall() {
129
+ this._placeBeforeCursor({
130
+ type: 'FunctionCall',
131
+ name: this._cursor.value,
132
+ args: [],
133
+ pool: 'functions'
134
+ });
135
+ }
136
+ /**
137
+ * Handles identifier tokens by adding them as a new node in the AST.
138
+ * @param {{type: <string>}} token A token object
139
+ */
140
+ function identifier(token) {
141
+ const node = {
142
+ type: 'Identifier',
143
+ value: token.value
144
+ };
145
+ if (this._nextIdentEncapsulate) {
146
+ node.from = this._cursor;
147
+ this._placeBeforeCursor(node);
148
+ this._nextIdentEncapsulate = false;
149
+ }
150
+ else {
151
+ if (this._nextIdentRelative) {
152
+ node.relative = true;
153
+ this._nextIdentRelative = false;
154
+ }
155
+ this._placeAtCursor(node);
156
+ }
157
+ }
158
+ /**
159
+ * Handles literal values, such as strings, booleans, and numerics, by adding
160
+ * them as a new node in the AST.
161
+ * @param {{type: <string>}} token A token object
162
+ */
163
+ function literal(token) {
164
+ this._placeAtCursor({
165
+ type: 'Literal',
166
+ value: token.value
167
+ });
168
+ }
169
+ /**
170
+ * Handles template string tokens by parsing their interpolation expressions
171
+ * and creating a TemplateLiteral AST node.
172
+ * @param {{type: <string>}} token A token object
173
+ */
174
+ function templateString(token) {
175
+ const parts = [];
176
+ for (const part of token.value) {
177
+ if (part.type === 'static') {
178
+ parts.push({
179
+ type: 'static',
180
+ value: this._lexer._unescapeTemplateString(part.value)
181
+ });
182
+ }
183
+ else {
184
+ const subTokens = this._lexer.tokenize(part.value);
185
+ const subParser = new this.constructor(this._grammar, this._lexer);
186
+ subParser.addTokens(subTokens);
187
+ const subAst = subParser.complete();
188
+ if (!subAst) {
189
+ throw new Error('Empty interpolation in template string');
190
+ }
191
+ parts.push({
192
+ type: 'expression',
193
+ value: subAst
194
+ });
195
+ }
196
+ }
197
+ this._placeAtCursor({
198
+ type: 'TemplateLiteral',
199
+ parts: parts
200
+ });
201
+ }
202
+ /**
203
+ * Queues a new object literal key to be written once a value is collected.
204
+ * @param {{type: <string>}} token A token object
205
+ */
206
+ function objKey(token) {
207
+ this._curObjKey = token.value;
208
+ }
209
+ /**
210
+ * Handles new object literals by adding them as a new node in the AST,
211
+ * initialized with an empty object.
212
+ */
213
+ function objStart() {
214
+ this._placeAtCursor({
215
+ type: 'ObjectLiteral',
216
+ value: {}
217
+ });
218
+ }
219
+ /**
220
+ * Handles an object value by adding its AST to the queued key on the object
221
+ * literal node currently at the cursor.
222
+ * @param {{type: <string>}} ast The subexpression tree
223
+ */
224
+ function objVal(ast) {
225
+ ;
226
+ this._cursor.value[this._curObjKey] = ast;
227
+ }
228
+ /**
229
+ * Handles traditional subexpressions, delineated with the groupStart and
230
+ * groupEnd elements.
231
+ * @param {{type: <string>}} ast The subexpression tree
232
+ */
233
+ function subExpression(ast) {
234
+ this._placeAtCursor(ast);
235
+ }
236
+ /**
237
+ * Handles a completed alternate subexpression of a ternary operator.
238
+ * @param {{type: <string>}} ast The subexpression tree
239
+ */
240
+ function ternaryEnd(ast) {
241
+ ;
242
+ this._cursor.alternate = ast;
243
+ }
244
+ /**
245
+ * Handles a completed consequent subexpression of a ternary operator.
246
+ * @param {{type: <string>}} ast The subexpression tree
247
+ */
248
+ function ternaryMid(ast) {
249
+ ;
250
+ this._cursor.consequent = ast;
251
+ }
252
+ /**
253
+ * Handles the start of a new ternary expression by encapsulating the entire
254
+ * AST in a ConditionalExpression node, and using the existing tree as the
255
+ * test element.
256
+ */
257
+ function ternaryStart() {
258
+ this._tree = {
259
+ type: 'ConditionalExpression',
260
+ test: this._tree
261
+ };
262
+ this._cursor = this._tree;
263
+ }
264
+ /**
265
+ * Handles identifier tokens when used to indicate the name of a transform to
266
+ * be applied.
267
+ * @param {{type: <string>}} token A token object
268
+ */
269
+ function transform(token) {
270
+ this._placeBeforeCursor({
271
+ type: 'FunctionCall',
272
+ name: token.value,
273
+ args: [this._cursor],
274
+ pool: 'transforms'
275
+ });
276
+ }
277
+ /**
278
+ * Handles token of type 'unaryOp', indicating that the operation has only
279
+ * one input: a right side.
280
+ * @param {{type: <string>}} token A token object
281
+ */
282
+ function unaryOp(token) {
283
+ this._placeAtCursor({
284
+ type: 'UnaryExpression',
285
+ operator: token.value
286
+ });
287
+ }
288
+ /**
289
+ * Handles semicolon separator between expressions
290
+ */
291
+ function semicolon() {
292
+ if (!this._sequenceExpressions) {
293
+ this._sequenceExpressions = [this._tree];
294
+ }
295
+ else {
296
+ this._sequenceExpressions.push(this._tree);
297
+ }
298
+ this._tree = null;
299
+ this._cursor = null;
300
+ this._state = 'expectOperand';
301
+ }
302
+ //# sourceMappingURL=handlers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handlers.js","sourceRoot":"","sources":["../../src/parser/handlers.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AASH,wBAIC;AAMD,gCAKC;AAMD,4BAIC;AAOD,4BAkCC;AAOD,kBAcC;AAOD,wBAOC;AAOD,oCAOC;AAMD,gCAgBC;AAOD,0BAKC;AAOD,wCAiCC;AAMD,wBAEC;AAMD,4BAKC;AAOD,wBAEC;AAOD,sCAEC;AAMD,gCAEC;AAMD,gCAEC;AAOD,oCAMC;AAOD,8BAOC;AAOD,0BAKC;AAKD,8BAUC;AA5SD;;;GAGG;AACH,SAAgB,MAAM,CAAe,GAAmB;IACtD,IAAI,GAAG,EAAE,CAAC;QACR,CAAC;QAAC,IAAI,CAAC,OAAe,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IACvC,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,SAAgB,UAAU;IACxB,IAAI,CAAC,cAAc,CAAC;QAClB,IAAI,EAAE,cAAc;QACpB,KAAK,EAAE,EAAE;KACH,CAAC,CAAA;AACX,CAAC;AAED;;;GAGG;AACH,SAAgB,QAAQ,CAAe,GAAmB;IACxD,IAAI,GAAG,EAAE,CAAC;QACR,CAAC;QAAC,IAAI,CAAC,OAAe,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IACxC,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,SAAgB,QAAQ,CAAe,KAAY;IACjD,IAAI,KAAK,CAAC,KAAK,KAAK,GAAG,EAAE,CAAC;QACxB,IAAI,IAAI,CAAC,OAAO,EAAE,IAAI,KAAK,YAAY,EAAE,CAAC;YACxC,MAAM,IAAI,KAAK,C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CAAC,IAAI,CAAC,OAAO,CAAC;QACpB,IAAI,EAAE,YAAY;KACZ,CAAC,CAAA;AACX,CAAC;AAED;;;;GAIG;AACH,SAAgB,OAAO,CAAe,KAAY;IAChD,IAAI,CAAC,cAAc,CAAC;QAClB,IAAI,EAAE,iBAAiB;QACvB,QAAQ,EAAE,KAAK,CAAC,KAAK;KACf,CAAC,CAAA;AACX,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"}
@@ -0,0 +1,47 @@
1
+ import type { AstNode } from '../types.ts';
2
+ import type Parser from './Parser.ts';
3
+ interface TokenTypeOptions {
4
+ toState?: string;
5
+ handler?: (this: Parser, ...args: any[]) => void;
6
+ }
7
+ interface StateDefinition {
8
+ tokenTypes?: Record<string, TokenTypeOptions>;
9
+ subHandler?: (this: Parser, ast: AstNode | null) => void;
10
+ endStates?: Record<string, string>;
11
+ completable?: boolean;
12
+ }
13
+ type States = Record<string, StateDefinition>;
14
+ /**
15
+ * A mapping of all states in the finite state machine to a set of instructions
16
+ * for handling or transitioning into other states. Each state can be handled
17
+ * in one of two schemes: a tokenType map, or a subHandler.
18
+ *
19
+ * Standard expression elements are handled through the tokenType object. This
20
+ * is an object map of all legal token types to encounter in this state (and
21
+ * any unexpected token types will generate a thrown error) to an options
22
+ * object that defines how they're handled. The available options are:
23
+ *
24
+ * {string} toState: The name of the state to which to transition
25
+ * immediately after handling this token
26
+ * {string} handler: The handler function to call when this token type is
27
+ * encountered in this state. If omitted, the default handler
28
+ * matching the token's "type" property will be called. If the handler
29
+ * function does not exist, no call will be made and no error will be
30
+ * generated. This is useful for tokens whose sole purpose is to
31
+ * transition to other states.
32
+ *
33
+ * States that consume a subexpression should define a subHandler, the
34
+ * function to be called with an expression tree argument when the
35
+ * subexpression is complete. Completeness is determined through the
36
+ * endStates object, which maps tokens on which an expression should end to the
37
+ * state to which to transition once the subHandler function has been called.
38
+ *
39
+ * Additionally, any state in which it is legal to mark the AST as completed
40
+ * should have a 'completable' property set to boolean true. Attempting to
41
+ * call {@link Parser#complete} in any state without this property will result
42
+ * in a thrown Error.
43
+ *
44
+ * @type {{}}
45
+ */
46
+ export declare const states: States;
47
+ export {};
@@ -0,0 +1,195 @@
1
+ "use strict";
2
+ /*
3
+ * Jexl
4
+ * Copyright 2020 Tom Shawver
5
+ */
6
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
+ desc = { enumerable: true, get: function() { return m[k]; } };
11
+ }
12
+ Object.defineProperty(o, k2, desc);
13
+ }) : (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ o[k2] = m[k];
16
+ }));
17
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
18
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
19
+ }) : function(o, v) {
20
+ o["default"] = v;
21
+ });
22
+ var __importStar = (this && this.__importStar) || (function () {
23
+ var ownKeys = function(o) {
24
+ ownKeys = Object.getOwnPropertyNames || function (o) {
25
+ var ar = [];
26
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
27
+ return ar;
28
+ };
29
+ return ownKeys(o);
30
+ };
31
+ return function (mod) {
32
+ if (mod && mod.__esModule) return mod;
33
+ var result = {};
34
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
35
+ __setModuleDefault(result, mod);
36
+ return result;
37
+ };
38
+ })();
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ exports.states = void 0;
41
+ const h = __importStar(require("./handlers.js"));
42
+ /**
43
+ * A mapping of all states in the finite state machine to a set of instructions
44
+ * for handling or transitioning into other states. Each state can be handled
45
+ * in one of two schemes: a tokenType map, or a subHandler.
46
+ *
47
+ * Standard expression elements are handled through the tokenType object. This
48
+ * is an object map of all legal token types to encounter in this state (and
49
+ * any unexpected token types will generate a thrown error) to an options
50
+ * object that defines how they're handled. The available options are:
51
+ *
52
+ * {string} toState: The name of the state to which to transition
53
+ * immediately after handling this token
54
+ * {string} handler: The handler function to call when this token type is
55
+ * encountered in this state. If omitted, the default handler
56
+ * matching the token's "type" property will be called. If the handler
57
+ * function does not exist, no call will be made and no error will be
58
+ * generated. This is useful for tokens whose sole purpose is to
59
+ * transition to other states.
60
+ *
61
+ * States that consume a subexpression should define a subHandler, the
62
+ * function to be called with an expression tree argument when the
63
+ * subexpression is complete. Completeness is determined through the
64
+ * endStates object, which maps tokens on which an expression should end to the
65
+ * state to which to transition once the subHandler function has been called.
66
+ *
67
+ * Additionally, any state in which it is legal to mark the AST as completed
68
+ * should have a 'completable' property set to boolean true. Attempting to
69
+ * call {@link Parser#complete} in any state without this property will result
70
+ * in a thrown Error.
71
+ *
72
+ * @type {{}}
73
+ */
74
+ exports.states = {
75
+ expectOperand: {
76
+ tokenTypes: {
77
+ literal: { toState: 'expectBinOp' },
78
+ templateString: { toState: 'expectBinOp' },
79
+ identifier: { toState: 'identifier' },
80
+ unaryOp: {},
81
+ openParen: { toState: 'subExpression' },
82
+ openCurl: { toState: 'expectObjKey', handler: h.objStart },
83
+ dot: { toState: 'traverse' },
84
+ openBracket: { toState: 'arrayVal', handler: h.arrayStart }
85
+ }
86
+ },
87
+ expectBinOp: {
88
+ tokenTypes: {
89
+ binaryOp: { toState: 'expectOperand' },
90
+ pipe: { toState: 'expectTransform' },
91
+ dot: { toState: 'traverse' },
92
+ question: { toState: 'ternaryMid', handler: h.ternaryStart },
93
+ semicolon: { handler: h.semicolon }
94
+ },
95
+ completable: true
96
+ },
97
+ expectTransform: {
98
+ tokenTypes: {
99
+ identifier: { toState: 'postTransform', handler: h.transform }
100
+ }
101
+ },
102
+ expectObjKey: {
103
+ tokenTypes: {
104
+ literal: { toState: 'expectKeyValSep', handler: h.objKey },
105
+ identifier: { toState: 'expectKeyValSep', handler: h.objKey },
106
+ closeCurl: { toState: 'expectBinOp' }
107
+ }
108
+ },
109
+ expectKeyValSep: {
110
+ tokenTypes: {
111
+ colon: { toState: 'objVal' }
112
+ }
113
+ },
114
+ postTransform: {
115
+ tokenTypes: {
116
+ openParen: { toState: 'argVal' },
117
+ binaryOp: { toState: 'expectOperand' },
118
+ dot: { toState: 'traverse' },
119
+ openBracket: { toState: 'filter' },
120
+ pipe: { toState: 'expectTransform' },
121
+ question: { toState: 'ternaryMid', handler: h.ternaryStart }
122
+ },
123
+ completable: true
124
+ },
125
+ postArgs: {
126
+ tokenTypes: {
127
+ binaryOp: { toState: 'expectOperand' },
128
+ dot: { toState: 'traverse' },
129
+ openBracket: { toState: 'filter' },
130
+ pipe: { toState: 'expectTransform' },
131
+ question: { toState: 'ternaryMid', handler: h.ternaryStart }
132
+ },
133
+ completable: true
134
+ },
135
+ identifier: {
136
+ tokenTypes: {
137
+ binaryOp: { toState: 'expectOperand' },
138
+ dot: { toState: 'traverse' },
139
+ openBracket: { toState: 'filter' },
140
+ openParen: { toState: 'argVal', handler: h.functionCall },
141
+ pipe: { toState: 'expectTransform' },
142
+ question: { toState: 'ternaryMid', handler: h.ternaryStart }
143
+ },
144
+ completable: true
145
+ },
146
+ traverse: {
147
+ tokenTypes: {
148
+ identifier: { toState: 'identifier' }
149
+ }
150
+ },
151
+ filter: {
152
+ subHandler: h.filter,
153
+ endStates: {
154
+ closeBracket: 'identifier'
155
+ }
156
+ },
157
+ subExpression: {
158
+ subHandler: h.subExpression,
159
+ endStates: {
160
+ closeParen: 'expectBinOp'
161
+ }
162
+ },
163
+ argVal: {
164
+ subHandler: h.argVal,
165
+ endStates: {
166
+ comma: 'argVal',
167
+ closeParen: 'postArgs'
168
+ }
169
+ },
170
+ objVal: {
171
+ subHandler: h.objVal,
172
+ endStates: {
173
+ comma: 'expectObjKey',
174
+ closeCurl: 'expectBinOp'
175
+ }
176
+ },
177
+ arrayVal: {
178
+ subHandler: h.arrayVal,
179
+ endStates: {
180
+ comma: 'arrayVal',
181
+ closeBracket: 'expectBinOp'
182
+ }
183
+ },
184
+ ternaryMid: {
185
+ subHandler: h.ternaryMid,
186
+ endStates: {
187
+ colon: 'ternaryEnd'
188
+ }
189
+ },
190
+ ternaryEnd: {
191
+ subHandler: h.ternaryEnd,
192
+ completable: true
193
+ }
194
+ };
195
+ //# sourceMappingURL=states.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"states.js","sourceRoot":"","sources":["../../src/parser/states.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,iDAAkC;AAmBlC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,OAAO,EAAE,EAAE;YACX,SAAS,EAAE,EAAE,OAAO,EAAE,eAAe,EAAE;YACvC,QAAQ,EAAE,EAAE,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,CAAC,CAAC,QAAQ,EAAE;YAC1D,GAAG,EAAE,EAAE,OAAO,EAAE,UAAU,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,EAAE;QACN,UAAU,EAAE,CAAC,CAAC,MAAM;QACpB,SAAS,EAAE;YACT,KAAK,EAAE,QAAQ;YACf,UAAU,EAAE,UAAU;SACvB;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"}
@@ -0,0 +1,77 @@
1
+ export interface Token {
2
+ type: string;
3
+ value: any;
4
+ raw: string;
5
+ }
6
+ export interface AstNode {
7
+ type: string;
8
+ _parent?: AstNode;
9
+ }
10
+ export interface Literal extends AstNode {
11
+ type: 'Literal';
12
+ value: string | number | boolean;
13
+ }
14
+ export interface Identifier extends AstNode {
15
+ type: 'Identifier';
16
+ value: string;
17
+ from?: AstNode;
18
+ relative?: boolean;
19
+ }
20
+ export interface BinaryExpression extends AstNode {
21
+ type: 'BinaryExpression';
22
+ operator: string;
23
+ left: AstNode;
24
+ right?: AstNode;
25
+ }
26
+ export interface UnaryExpression extends AstNode {
27
+ type: 'UnaryExpression';
28
+ operator: string;
29
+ right?: AstNode;
30
+ }
31
+ export interface ArrayLiteral extends AstNode {
32
+ type: 'ArrayLiteral';
33
+ value: AstNode[];
34
+ }
35
+ export interface ObjectLiteral extends AstNode {
36
+ type: 'ObjectLiteral';
37
+ value: Record<string, AstNode>;
38
+ }
39
+ export interface TemplateLiteral extends AstNode {
40
+ type: 'TemplateLiteral';
41
+ parts: {
42
+ type: 'static' | 'expression';
43
+ value: string | AstNode;
44
+ }[];
45
+ }
46
+ export interface FunctionCall extends AstNode {
47
+ type: 'FunctionCall';
48
+ name: string;
49
+ args: AstNode[];
50
+ pool: 'functions' | 'transforms';
51
+ }
52
+ export interface FilterExpression extends AstNode {
53
+ type: 'FilterExpression';
54
+ expr: AstNode;
55
+ relative: boolean;
56
+ subject: AstNode;
57
+ }
58
+ export interface ConditionalExpression extends AstNode {
59
+ type: 'ConditionalExpression';
60
+ test: AstNode;
61
+ consequent?: AstNode;
62
+ alternate?: AstNode;
63
+ }
64
+ export interface SequenceExpression extends AstNode {
65
+ type: 'SequenceExpression';
66
+ expressions: AstNode[];
67
+ }
68
+ export interface AssignmentExpression extends AstNode {
69
+ type: 'AssignmentExpression';
70
+ operator: '=';
71
+ left: Identifier;
72
+ right: AstNode;
73
+ }
74
+ export type AstNodeUnion = Literal | Identifier | BinaryExpression | UnaryExpression | ArrayLiteral | ObjectLiteral | TemplateLiteral | FunctionCall | FilterExpression | ConditionalExpression | SequenceExpression | AssignmentExpression;
75
+ export type NodeByType<T extends AstNodeUnion['type']> = Extract<AstNodeUnion, {
76
+ type: T;
77
+ }>;
package/dist/types.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /*
3
+ * Jexl
4
+ * Copyright 2020 Tom Shawver
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA;;;GAGG"}
@@ -0,0 +1,38 @@
1
+ import PromiseSync from './PromiseSync.ts';
2
+ import type { AstNode } from './types.ts';
3
+ interface Grammar {
4
+ elements: Record<string, any>;
5
+ [key: string]: any;
6
+ }
7
+ type PromiseConstructor = typeof Promise | typeof PromiseSync;
8
+ declare class Expression {
9
+ _grammar: Grammar;
10
+ _exprStr: string;
11
+ _ast: AstNode | null;
12
+ constructor(grammar: Grammar, exprStr: string);
13
+ /**
14
+ * Forces a compilation of the expression string that this Expression object
15
+ * was constructed with. This function can be called multiple times; useful
16
+ * if the language elements of the associated Jexl instance change.
17
+ * @returns {Expression} this Expression instance, for convenience
18
+ */
19
+ compile(): this;
20
+ /**
21
+ * Asynchronously evaluates the expression within an optional context.
22
+ * @param {Object} [context] A mapping of variables to values, which will be
23
+ * made accessible to the Jexl expression when evaluating it
24
+ * @returns {Promise<*>} resolves with the result of the evaluation.
25
+ */
26
+ eval(context?: {}): Promise<any> | PromiseSync<any>;
27
+ /**
28
+ * Synchronously evaluates the expression within an optional context.
29
+ * @param {Object} [context] A mapping of variables to values, which will be
30
+ * made accessible to the Jexl expression when evaluating it
31
+ * @returns {*} the result of the evaluation.
32
+ * @throws {*} on error
33
+ */
34
+ evalSync(context?: {}): unknown;
35
+ _eval(context: any, promise: PromiseConstructor): Promise<any> | PromiseSync<any>;
36
+ _getAst(): AstNode | null;
37
+ }
38
+ export default Expression;