@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,111 @@
1
+ import type Evaluator from './Evaluator.ts';
2
+ /**
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,202 @@
1
+ /*
2
+ * Jexl
3
+ * Copyright 2020 Tom Shawver
4
+ */
5
+ const poolNames = {
6
+ functions: 'Jexl Function',
7
+ transforms: 'Transform'
8
+ };
9
+ /**
10
+ * Evaluates an ArrayLiteral by returning its value, with each element
11
+ * independently run through the evaluator.
12
+ * @param {{type: 'ObjectLiteral', value: <{}>}} ast An expression tree with an
13
+ * ObjectLiteral as the top node
14
+ * @returns {Promise.<[]>} resolves to a map contained evaluated values.
15
+ * @private
16
+ */
17
+ export function ArrayLiteral(ast) {
18
+ return this.evalArray(ast.value);
19
+ }
20
+ /**
21
+ * Evaluates a BinaryExpression node by running the Grammar's evaluator for
22
+ * the given operator. Note that binary expressions support two types of
23
+ * evaluators: `eval` is called with the left and right operands pre-evaluated.
24
+ * `evalOnDemand`, if it exists, will be called with the left and right operands
25
+ * each individually wrapped in an object with an "eval" function that returns
26
+ * a promise with the resulting value. This allows the binary expression to
27
+ * evaluate the operands conditionally.
28
+ * @param {{type: 'BinaryExpression', operator: <string>, left: {},
29
+ * right: {}}} ast An expression tree with a BinaryExpression as the top
30
+ * node
31
+ * @returns {Promise<*>} resolves with the value of the BinaryExpression.
32
+ * @private
33
+ */
34
+ export function BinaryExpression(ast) {
35
+ const grammarOp = this._grammar.elements[ast.operator];
36
+ if (grammarOp.evalOnDemand) {
37
+ const wrap = (subAst) => ({ eval: () => this.eval(subAst) });
38
+ return grammarOp.evalOnDemand(wrap(ast.left), wrap(ast.right));
39
+ }
40
+ return this.Promise.all([this.eval(ast.left), this.eval(ast.right)]).then((arr) => grammarOp.eval(arr[0], arr[1]));
41
+ }
42
+ /**
43
+ * Evaluates a ConditionalExpression node by first evaluating its test branch,
44
+ * and resolving with the consequent branch if the test is truthy, or the
45
+ * alternate branch if it is not. If there is no consequent branch, the test
46
+ * result will be used instead.
47
+ * @param {{type: 'ConditionalExpression', test: {}, consequent: {},
48
+ * alternate: {}}} ast An expression tree with a ConditionalExpression as
49
+ * the top node
50
+ * @private
51
+ */
52
+ export function ConditionalExpression(ast) {
53
+ return this.eval(ast.test).then((res) => {
54
+ if (res) {
55
+ if (ast.consequent) {
56
+ return this.eval(ast.consequent);
57
+ }
58
+ return res;
59
+ }
60
+ return this.eval(ast.alternate);
61
+ });
62
+ }
63
+ /**
64
+ * Evaluates a FilterExpression by applying it to the subject value.
65
+ * @param {{type: 'FilterExpression', relative: <boolean>, expr: {},
66
+ * subject: {}}} ast An expression tree with a FilterExpression as the top
67
+ * node
68
+ * @returns {Promise<*>} resolves with the value of the FilterExpression.
69
+ * @private
70
+ */
71
+ export function FilterExpression(ast) {
72
+ return this.eval(ast.subject).then((subject) => {
73
+ if (ast.relative) {
74
+ return this._filterRelative(subject, ast.expr);
75
+ }
76
+ return this._filterStatic(subject, ast.expr);
77
+ });
78
+ }
79
+ /**
80
+ * Evaluates an Identifier by either stemming from the evaluated 'from'
81
+ * expression tree or accessing the context provided when this Evaluator was
82
+ * constructed.
83
+ * @param {{type: 'Identifier', value: <string>, [from]: {}}} ast An expression
84
+ * tree with an Identifier as the top node
85
+ * @returns {Promise<*>|*} either the identifier's value, or a Promise that
86
+ * will resolve with the identifier's value.
87
+ * @private
88
+ */
89
+ export function Identifier(ast) {
90
+ if (!ast.from) {
91
+ const contextSource = ast.relative ? this._relContext : this._context;
92
+ return contextSource[ast.value];
93
+ }
94
+ return this.eval(ast.from).then((context) => {
95
+ if (context == null) {
96
+ return undefined;
97
+ }
98
+ const ctx = Array.isArray(context) ? context[0] : context;
99
+ return ctx?.[ast.value];
100
+ });
101
+ }
102
+ /**
103
+ * Evaluates a Literal by returning its value property.
104
+ * @param {{type: 'Literal', value: <string|number|boolean>}} ast An expression
105
+ * tree with a Literal as its only node
106
+ * @returns {string|number|boolean} The value of the Literal node
107
+ * @private
108
+ */
109
+ export function Literal(ast) {
110
+ return ast.value;
111
+ }
112
+ /**
113
+ * Evaluates a TemplateLiteral by evaluating each interpolated expression
114
+ * and concatenating all parts into a final string.
115
+ * @param {{type: 'TemplateLiteral', parts: Array<{}>}} ast An expression
116
+ * tree with a TemplateLiteral as the top node
117
+ * @returns {Promise<string>} resolves with the final interpolated string
118
+ * @private
119
+ */
120
+ export function TemplateLiteral(ast) {
121
+ const promises = ast.parts.map((part) => {
122
+ if (part.type === 'static') {
123
+ return this.Promise.resolve(part.value);
124
+ }
125
+ return this.eval(part.value).then((result) => {
126
+ if (result == null) {
127
+ return '';
128
+ }
129
+ return String(result);
130
+ });
131
+ });
132
+ return this.Promise.all(promises).then((values) => values.join(''));
133
+ }
134
+ /**
135
+ * Evaluates an ObjectLiteral by returning its value, with each key
136
+ * independently run through the evaluator.
137
+ * @param {{type: 'ObjectLiteral', value: <{}>}} ast An expression tree with an
138
+ * ObjectLiteral as the top node
139
+ * @returns {Promise<{}>} resolves to a map contained evaluated values.
140
+ * @private
141
+ */
142
+ export function ObjectLiteral(ast) {
143
+ return this.evalMap(ast.value);
144
+ }
145
+ /**
146
+ * Evaluates a FunctionCall node by applying the supplied arguments to a
147
+ * function defined in one of the grammar's function pools.
148
+ * @param {{type: 'FunctionCall', name: <string>}} ast An
149
+ * expression tree with a FunctionCall as the top node
150
+ * @returns {Promise<*>|*} the value of the function call, or a Promise that
151
+ * will resolve with the resulting value.
152
+ * @private
153
+ */
154
+ export function FunctionCall(ast) {
155
+ const poolName = poolNames[ast.pool];
156
+ if (!poolName) {
157
+ throw new Error(`Corrupt AST: Pool '${ast.pool}' not found`);
158
+ }
159
+ const pool = this._grammar[ast.pool];
160
+ const func = pool?.[ast.name];
161
+ if (!func) {
162
+ throw new Error(`${poolName} ${ast.name} is not defined.`);
163
+ }
164
+ return this.evalArray(ast.args || []).then((args) => func(...args));
165
+ }
166
+ /**
167
+ * Evaluates a Unary expression by passing the right side through the
168
+ * operator's eval function.
169
+ * @param {{type: 'UnaryExpression', operator: <string>, right: {}}} ast An
170
+ * expression tree with a UnaryExpression as the top node
171
+ * @returns {Promise<*>} resolves with the value of the UnaryExpression.
172
+ * @constructor
173
+ */
174
+ export function UnaryExpression(ast) {
175
+ return this.eval(ast.right).then((right) => this._grammar.elements[ast.operator].eval(right));
176
+ }
177
+ /**
178
+ * Evaluates a SequenceExpression by evaluating each expression in order
179
+ * and returning the value of the last expression.
180
+ */
181
+ export function SequenceExpression(ast) {
182
+ let lastValue;
183
+ let promise = this.Promise.resolve();
184
+ for (const expr of ast.expressions) {
185
+ promise = promise.then(() => this.eval(expr).then((val) => {
186
+ lastValue = val;
187
+ }));
188
+ }
189
+ return promise.then(() => lastValue);
190
+ }
191
+ /**
192
+ * Evaluates an AssignmentExpression by evaluating the right side
193
+ * and assigning it to the variable name on the left side.
194
+ */
195
+ export function AssignmentExpression(ast) {
196
+ return this.eval(ast.right).then((value) => {
197
+ const varName = ast.left.value;
198
+ this._context[varName] = value;
199
+ return value;
200
+ });
201
+ }
202
+ //# sourceMappingURL=handlers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handlers.js","sourceRoot":"","sources":["../../src/evaluator/handlers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,MAAM,SAAS,GAA2B;IACxC,SAAS,EAAE,eAAe;IAC1B,UAAU,EAAE,WAAW;CACxB,CAAA;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAAkB,GAAQ;IACpD,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;AAClC,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,gBAA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,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/esm/grammar.js ADDED
@@ -0,0 +1,175 @@
1
+ /*
2
+ * Jexl
3
+ * Copyright 2020 Tom Shawver
4
+ */
5
+ export const getGrammar = () => ({
6
+ /**
7
+ * A map of all expression elements to their properties. Note that changes
8
+ * here may require changes in the Lexer or Parser.
9
+ * @type {{}}
10
+ */
11
+ elements: {
12
+ '.': { type: 'dot' },
13
+ '[': { type: 'openBracket' },
14
+ ']': { type: 'closeBracket' },
15
+ '|': { type: 'pipe' },
16
+ '{': { type: 'openCurl' },
17
+ '}': { type: 'closeCurl' },
18
+ ':': { type: 'colon' },
19
+ ',': { type: 'comma' },
20
+ '(': { type: 'openParen' },
21
+ ')': { type: 'closeParen' },
22
+ '?': { type: 'question' },
23
+ ';': { type: 'semicolon' },
24
+ '+': {
25
+ type: 'binaryOp',
26
+ precedence: 30,
27
+ eval: (left, right) => left + right
28
+ },
29
+ '-': {
30
+ type: 'binaryOp',
31
+ precedence: 30,
32
+ eval: (left, right) => left - right
33
+ },
34
+ '*': {
35
+ type: 'binaryOp',
36
+ precedence: 40,
37
+ eval: (left, right) => left * right
38
+ },
39
+ '/': {
40
+ type: 'binaryOp',
41
+ precedence: 40,
42
+ eval: (left, right) => left / right
43
+ },
44
+ '//': {
45
+ type: 'binaryOp',
46
+ precedence: 40,
47
+ eval: (left, right) => Math.floor(left / right)
48
+ },
49
+ '%': {
50
+ type: 'binaryOp',
51
+ precedence: 50,
52
+ eval: (left, right) => left % right
53
+ },
54
+ '^': {
55
+ type: 'binaryOp',
56
+ precedence: 50,
57
+ eval: (left, right) => Math.pow(left, right)
58
+ },
59
+ '==': {
60
+ type: 'binaryOp',
61
+ precedence: 20,
62
+ eval: (left, right) => left == right
63
+ },
64
+ '!=': {
65
+ type: 'binaryOp',
66
+ precedence: 20,
67
+ eval: (left, right) => left != right
68
+ },
69
+ '>': {
70
+ type: 'binaryOp',
71
+ precedence: 20,
72
+ eval: (left, right) => left > right
73
+ },
74
+ '>=': {
75
+ type: 'binaryOp',
76
+ precedence: 20,
77
+ eval: (left, right) => left >= right
78
+ },
79
+ '<': {
80
+ type: 'binaryOp',
81
+ precedence: 20,
82
+ eval: (left, right) => left < right
83
+ },
84
+ '<=': {
85
+ type: 'binaryOp',
86
+ precedence: 20,
87
+ eval: (left, right) => left <= right
88
+ },
89
+ '&&': {
90
+ type: 'binaryOp',
91
+ precedence: 10,
92
+ evalOnDemand: (left, right) => {
93
+ return left.eval().then((leftVal) => {
94
+ if (!leftVal) {
95
+ return leftVal;
96
+ }
97
+ return right.eval();
98
+ });
99
+ }
100
+ },
101
+ '||': {
102
+ type: 'binaryOp',
103
+ precedence: 10,
104
+ evalOnDemand: (left, right) => {
105
+ return left.eval().then((leftVal) => {
106
+ if (leftVal) {
107
+ return leftVal;
108
+ }
109
+ return right.eval();
110
+ });
111
+ }
112
+ },
113
+ in: {
114
+ type: 'binaryOp',
115
+ precedence: 20,
116
+ eval: (left, right) => {
117
+ if (typeof right === 'string') {
118
+ return right.includes(left);
119
+ }
120
+ if (Array.isArray(right)) {
121
+ return right.includes(left);
122
+ }
123
+ return false;
124
+ }
125
+ },
126
+ '!': {
127
+ type: 'unaryOp',
128
+ precedence: Infinity,
129
+ eval: (right) => !right
130
+ },
131
+ '=': {
132
+ type: 'binaryOp',
133
+ precedence: 2,
134
+ eval: (_left, _right) => {
135
+ throw new Error('Assignment handled specially');
136
+ }
137
+ }
138
+ },
139
+ /**
140
+ * A map of function names to javascript functions. A Jexl function
141
+ * takes zero ore more arguemnts:
142
+ *
143
+ * - {*} ...args: A variable number of arguments passed to this function.
144
+ * All of these are pre-evaluated to their actual values before calling
145
+ * the function.
146
+ *
147
+ * The Jexl function should return either the transformed value, or
148
+ * a Promises/A+ Promise object that resolves with the value and rejects
149
+ * or throws only when an unrecoverable error occurs. Functions should
150
+ * generally return undefined when they don't make sense to be used on the
151
+ * given value type, rather than throw/reject. An error is only
152
+ * appropriate when the function would normally return a value, but
153
+ * cannot due to some other failure.
154
+ */
155
+ functions: {},
156
+ /**
157
+ * A map of transform names to transform functions. A transform function
158
+ * takes one ore more arguemnts:
159
+ *
160
+ * - {*} val: A value to be transformed
161
+ * - {*} ...args: A variable number of arguments passed to this transform.
162
+ * All of these are pre-evaluated to their actual values before calling
163
+ * the function.
164
+ *
165
+ * The transform function should return either the transformed value, or
166
+ * a Promises/A+ Promise object that resolves with the value and rejects
167
+ * or throws only when an unrecoverable error occurs. Transforms should
168
+ * generally return undefined when they don't make sense to be used on the
169
+ * given value type, rather than throw/reject. An error is only
170
+ * appropriate when the transform would normally return a value, but
171
+ * cannot due to some other failure.
172
+ */
173
+ transforms: {}
174
+ });
175
+ //# sourceMappingURL=grammar.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grammar.js","sourceRoot":"","sources":["../src/grammar.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA6BH,MAAM,CAAC,MAAM,UAAU,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gBAC7B,CAAC;gBACD,OAAO,KAAK,CAAA;YACd,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;;;;;;;;;;;;;;;OAeG;IACH,SAAS,EAAE,EAAE;IAEb;;;;;;;;;;;;;;;;OAgBG;IACH,UAAU,EAAE,EAAE;CACf,CAAC,CAAA"}
package/esm/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export { Jexl, default } from './Jexl.ts';
2
+ export { default as Expression } from './Expression.ts';
3
+ export { default as Lexer } from './Lexer.ts';
4
+ export { getGrammar } from './grammar.ts';
5
+ export type * from './types.ts';
package/esm/index.js ADDED
@@ -0,0 +1,9 @@
1
+ /*
2
+ * Jexl
3
+ * Copyright 2020 Tom Shawver
4
+ */
5
+ export { Jexl, default } from "./Jexl.js";
6
+ export { default as Expression } from "./Expression.js";
7
+ export { default as Lexer } from "./Lexer.js";
8
+ export { getGrammar } from "./grammar.js";
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACvD,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,YAAY,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA"}
@@ -0,0 +1,112 @@
1
+ import type Lexer from '../Lexer.ts';
2
+ import type { AstNode, Token } from '../types.ts';
3
+ interface Grammar {
4
+ elements: Record<string, any>;
5
+ }
6
+ /**
7
+ * The Parser is a state machine that converts tokens from the {@link Lexer}
8
+ * into an Abstract Syntax Tree (AST), capable of being evaluated in any
9
+ * context by the {@link Evaluator}. The Parser expects that all tokens
10
+ * provided to it are legal and typed properly according to the grammar, but
11
+ * accepts that the tokens may still be in an invalid order or in some other
12
+ * unparsable configuration that requires it to throw an Error.
13
+ * @param {{}} grammar The grammar object to use to parse Jexl strings
14
+ * @param {string} [prefix] A string prefix to prepend to the expression string
15
+ * for error messaging purposes. This is useful for when a new Parser is
16
+ * instantiated to parse an subexpression, as the parent Parser's
17
+ * expression string thus far can be passed for a more user-friendly
18
+ * error message.
19
+ * @param {{}} [stopMap] A mapping of token types to any truthy value. When the
20
+ * token type is encountered, the parser will return the mapped value
21
+ * instead of boolean false.
22
+ */
23
+ declare class Parser {
24
+ _grammar: Grammar;
25
+ _lexer: Lexer;
26
+ _state: string;
27
+ _tree: AstNode | null;
28
+ _exprStr: string;
29
+ _relative: boolean;
30
+ _stopMap: Record<string, any>;
31
+ _cursor?: AstNode | null;
32
+ _subParser?: Parser;
33
+ _parentStop?: boolean;
34
+ _nextIdentEncapsulate?: boolean;
35
+ _nextIdentRelative?: boolean;
36
+ _curObjKey?: string;
37
+ _sequenceExpressions?: AstNode[];
38
+ constructor(grammar: Grammar, lexer: Lexer, prefix?: string, stopMap?: Record<string, any>);
39
+ /**
40
+ * Processes a new token into the AST and manages the transitions of the state
41
+ * machine.
42
+ * @param {{type: <string>}} token A token object, as provided by the
43
+ * {@link Lexer#tokenize} function.
44
+ * @throws {Error} if a token is added when the Parser has been marked as
45
+ * complete by {@link #complete}, or if an unexpected token type is added.
46
+ * @returns {boolean|*} the stopState value if this parser encountered a token
47
+ * in the stopState mapb false if tokens can continue.
48
+ */
49
+ addToken(token: Token): any;
50
+ /**
51
+ * Processes an array of tokens iteratively through the {@link #addToken}
52
+ * function.
53
+ * @param {Array<{type: <string>}>} tokens An array of tokens, as provided by
54
+ * the {@link Lexer#tokenize} function.
55
+ */
56
+ addTokens(tokens: Token[]): void;
57
+ /**
58
+ * Marks this Parser instance as completed and retrieves the full AST.
59
+ * @returns {{}|null} a full expression tree, ready for evaluation by the
60
+ * {@link Evaluator#eval} function, or null if no tokens were passed to
61
+ * the parser before complete was called
62
+ * @throws {Error} if the parser is not in a state where it's legal to end
63
+ * the expression, indicating that the expression is incomplete
64
+ */
65
+ complete(): any;
66
+ /**
67
+ * Indicates whether the expression tree contains a relative path identifier.
68
+ * @returns {boolean} true if a relative identifier exists false otherwise.
69
+ */
70
+ isRelative(): boolean;
71
+ /**
72
+ * Ends a subexpression by completing the subParser and passing its result
73
+ * to the subHandler configured in the current state.
74
+ * @private
75
+ */
76
+ _endSubExpression(): void;
77
+ /**
78
+ * Places a new tree node at the current position of the cursor (to the 'right'
79
+ * property) and then advances the cursor to the new node. This function also
80
+ * handles setting the parent of the new node.
81
+ * @param {{type: <string>}} node A node to be added to the AST
82
+ * @private
83
+ */
84
+ _placeAtCursor(node: AstNode): void;
85
+ /**
86
+ * Places a tree node before the current position of the cursor, replacing
87
+ * the node that the cursor currently points to. This should only be called in
88
+ * cases where the cursor is known to exist, and the provided node already
89
+ * contains a pointer to what's at the cursor currently.
90
+ * @param {{type: <string>}} node A node to be added to the AST
91
+ * @private
92
+ */
93
+ _placeBeforeCursor(node: AstNode): void;
94
+ /**
95
+ * Sets the parent of a node by creating a non-enumerable _parent property
96
+ * that points to the supplied parent argument.
97
+ * @param {{type: <string>}} node A node of the AST on which to set a new
98
+ * parent
99
+ * @param {{type: <string>}} parent An existing node of the AST to serve as the
100
+ * parent of the new node
101
+ * @private
102
+ */
103
+ _setParent(node: AstNode, parent: AstNode): void;
104
+ /**
105
+ * Prepares the Parser to accept a subexpression by (re)instantiating the
106
+ * subParser.
107
+ * @param {string} [exprStr] The expression string to prefix to the new Parser
108
+ * @private
109
+ */
110
+ _startSubExpression(exprStr?: string): void;
111
+ }
112
+ export default Parser;