@jbrowse/jexl 5.0.1 → 6.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/README.md +8 -3
- package/dist/Expression.d.ts +0 -12
- package/dist/Expression.js +0 -16
- package/dist/Expression.js.map +1 -1
- package/dist/Jexl.js +12 -16
- package/dist/Jexl.js.map +1 -1
- package/dist/Lexer.d.ts +12 -94
- package/dist/Lexer.js +41 -142
- package/dist/Lexer.js.map +1 -1
- package/dist/analyze.d.ts +2 -0
- package/dist/analyze.js +7 -7
- package/dist/analyze.js.map +1 -1
- package/dist/check.d.ts +0 -5
- package/dist/check.js +62 -240
- package/dist/check.js.map +1 -1
- package/dist/collections.d.ts +7 -0
- package/dist/collections.js +9 -2
- package/dist/collections.js.map +1 -1
- package/dist/conditions.d.ts +1 -1
- package/dist/conditions.js +28 -50
- package/dist/conditions.js.map +1 -1
- package/dist/errors.d.ts +5 -0
- package/dist/errors.js +8 -0
- package/dist/errors.js.map +1 -1
- package/dist/evaluator/compile.js +37 -24
- package/dist/evaluator/compile.js.map +1 -1
- package/dist/grammar.d.ts +2 -2
- package/dist/grammar.js +1 -8
- package/dist/grammar.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/operators.d.ts +5 -0
- package/dist/operators.js +9 -5
- package/dist/operators.js.map +1 -1
- package/dist/parser/Parser.d.ts +11 -12
- package/dist/parser/Parser.js +4 -10
- package/dist/parser/Parser.js.map +1 -1
- package/dist/print.d.ts +9 -0
- package/dist/print.js +183 -0
- package/dist/print.js.map +1 -0
- package/dist/types.d.ts +18 -21
- package/esm/Expression.d.ts +0 -12
- package/esm/Expression.js +0 -16
- package/esm/Expression.js.map +1 -1
- package/esm/Jexl.js +12 -16
- package/esm/Jexl.js.map +1 -1
- package/esm/Lexer.d.ts +12 -94
- package/esm/Lexer.js +40 -142
- package/esm/Lexer.js.map +1 -1
- package/esm/analyze.d.ts +2 -0
- package/esm/analyze.js +6 -7
- package/esm/analyze.js.map +1 -1
- package/esm/check.d.ts +0 -5
- package/esm/check.js +29 -206
- package/esm/check.js.map +1 -1
- package/esm/collections.d.ts +7 -0
- package/esm/collections.js +8 -1
- package/esm/collections.js.map +1 -1
- package/esm/conditions.d.ts +1 -1
- package/esm/conditions.js +27 -49
- package/esm/conditions.js.map +1 -1
- package/esm/errors.d.ts +5 -0
- package/esm/errors.js +7 -0
- package/esm/errors.js.map +1 -1
- package/esm/evaluator/compile.js +37 -24
- package/esm/evaluator/compile.js.map +1 -1
- package/esm/grammar.d.ts +2 -2
- package/esm/grammar.js +1 -8
- package/esm/grammar.js.map +1 -1
- package/esm/index.d.ts +2 -1
- package/esm/index.js +2 -1
- package/esm/index.js.map +1 -1
- package/esm/operators.d.ts +5 -0
- package/esm/operators.js +8 -5
- package/esm/operators.js.map +1 -1
- package/esm/parser/Parser.d.ts +11 -12
- package/esm/parser/Parser.js +4 -8
- package/esm/parser/Parser.js.map +1 -1
- package/esm/print.d.ts +9 -0
- package/esm/print.js +177 -0
- package/esm/print.js.map +1 -0
- package/esm/types.d.ts +18 -21
- package/package.json +2 -1
- package/src/Expression.ts +0 -20
- package/src/Jexl.ts +13 -20
- package/src/Lexer.ts +42 -144
- package/src/analyze.ts +10 -10
- package/src/check.ts +48 -250
- package/src/collections.ts +11 -1
- package/src/conditions.ts +39 -62
- package/src/errors.ts +10 -0
- package/src/evaluator/compile.ts +49 -36
- package/src/grammar.ts +3 -9
- package/src/index.ts +2 -1
- package/src/operators.ts +10 -6
- package/src/parser/Parser.ts +13 -19
- package/src/print.ts +203 -0
- package/src/types.ts +19 -23
package/README.md
CHANGED
|
@@ -235,7 +235,10 @@ jexl.eval('map(xs, (x, i) => x * i)', { xs: [1, 2, 3] }) // [0, 2, 6]
|
|
|
235
235
|
jexl.eval('xs.filter(x => x > 1)', { xs: [1, 2, 3] }) // [2, 3]
|
|
236
236
|
```
|
|
237
237
|
|
|
238
|
-
A host function of the same name replaces the built-in one.
|
|
238
|
+
A host function of the same name replaces the built-in one. The built-in ones
|
|
239
|
+
call only a lambda the expression wrote, never a function it reads from the
|
|
240
|
+
context, and `a.constructor` and `a.__proto__` find only an own property, so an
|
|
241
|
+
expression cannot reach `Function` and build code to run.
|
|
239
242
|
|
|
240
243
|
### Variable Assignment
|
|
241
244
|
|
|
@@ -347,8 +350,10 @@ A name the expression assigns reads the assignment once it has run, and goes thr
|
|
|
347
350
|
its functions registered:
|
|
348
351
|
|
|
349
352
|
```javascript
|
|
350
|
-
|
|
351
|
-
|
|
353
|
+
import { analyze } from '@jbrowse/jexl'
|
|
354
|
+
|
|
355
|
+
const ast = jexl.parse("get(feature, 'score') > 10 ? feature.name : 'n/a'")
|
|
356
|
+
analyze(ast, { accessors: { get: [] }, row: 'feature' })
|
|
352
357
|
// {
|
|
353
358
|
// variables: ['feature'],
|
|
354
359
|
// fields: [{ path: ['score'] }, { path: ['name'] }],
|
package/dist/Expression.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import Lexer from './Lexer.ts';
|
|
2
|
-
import type { AnalyzeOptions } from './analyze.ts';
|
|
3
|
-
import type { CheckOptions } from './check.ts';
|
|
4
2
|
import type { CompiledNode } from './evaluator/compile.ts';
|
|
5
3
|
import type { Grammar } from './grammar.ts';
|
|
6
4
|
import type { AstNode } from './types.ts';
|
|
@@ -42,15 +40,5 @@ declare class Expression {
|
|
|
42
40
|
get source(): string;
|
|
43
41
|
/** The parsed tree, or null for an expression with no tokens. */
|
|
44
42
|
get ast(): AstNode | null;
|
|
45
|
-
/**
|
|
46
|
-
* Lists what the expression reads from its context, without evaluating it.
|
|
47
|
-
* See {@link analyze}.
|
|
48
|
-
*/
|
|
49
|
-
analyze(options?: AnalyzeOptions): import("./analyze.ts").Analysis;
|
|
50
|
-
/**
|
|
51
|
-
* Checks the expression against a host's fields and functions, without
|
|
52
|
-
* evaluating it. See {@link check}.
|
|
53
|
-
*/
|
|
54
|
-
check(options?: CheckOptions): import("./check.ts").CheckResult;
|
|
55
43
|
}
|
|
56
44
|
export default Expression;
|
package/dist/Expression.js
CHANGED
|
@@ -8,8 +8,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
8
8
|
};
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
const Lexer_ts_1 = __importDefault(require("./Lexer.js"));
|
|
11
|
-
const analyze_ts_1 = require("./analyze.js");
|
|
12
|
-
const check_ts_1 = require("./check.js");
|
|
13
11
|
const compile_ts_1 = require("./evaluator/compile.js");
|
|
14
12
|
const Parser_ts_1 = __importDefault(require("./parser/Parser.js"));
|
|
15
13
|
class Expression {
|
|
@@ -78,20 +76,6 @@ class Expression {
|
|
|
78
76
|
}
|
|
79
77
|
return this._ast;
|
|
80
78
|
}
|
|
81
|
-
/**
|
|
82
|
-
* Lists what the expression reads from its context, without evaluating it.
|
|
83
|
-
* See {@link analyze}.
|
|
84
|
-
*/
|
|
85
|
-
analyze(options) {
|
|
86
|
-
return (0, analyze_ts_1.analyze)(this.ast, options);
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Checks the expression against a host's fields and functions, without
|
|
90
|
-
* evaluating it. See {@link check}.
|
|
91
|
-
*/
|
|
92
|
-
check(options) {
|
|
93
|
-
return (0, check_ts_1.check)(this.ast, options);
|
|
94
|
-
}
|
|
95
79
|
}
|
|
96
80
|
exports.default = Expression;
|
|
97
81
|
//# sourceMappingURL=Expression.js.map
|
package/dist/Expression.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Expression.js","sourceRoot":"","sources":["../src/Expression.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;AAEH,0DAA8B;AAC9B,
|
|
1
|
+
{"version":3,"file":"Expression.js","sourceRoot":"","sources":["../src/Expression.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;AAEH,0DAA8B;AAC9B,uDAAmD;AACnD,mEAAuC;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AI,MAAM;QACR,OAAO,IAAI,CAAC,QAAQ,CAAA;IACtB,CAAC;IAED,iEAAiE;IACjE,IAAI,GAAG;QACL,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACpB,IAAI,CAAC,OAAO,EAAE,CAAA;QAChB,CAAC;QACD,OAAO,IAAI,CAAC,IAAI,CAAA;IAClB,CAAC;CACF;AAED,kBAAe,UAAU,CAAA"}
|
package/dist/Jexl.js
CHANGED
|
@@ -30,24 +30,21 @@ class Jexl {
|
|
|
30
30
|
this.expr = this.expr.bind(this);
|
|
31
31
|
}
|
|
32
32
|
addBinaryOp(operator, precedence, fn, manualEval) {
|
|
33
|
-
//
|
|
33
|
+
// a replacement keeps how the operator parses: `-` its prefix form, `^`
|
|
34
|
+
// its grouping from the right
|
|
34
35
|
const previous = this._grammar.elements[operator];
|
|
35
|
-
const unaryEval = previous?.type === 'binaryOp' ? previous
|
|
36
|
+
const { unaryEval, rightAssociative } = previous?.type === 'binaryOp' ? previous : {};
|
|
36
37
|
// the overloads above pair `fn` with `manualEval`; the implementation
|
|
37
38
|
// signature can't express that correlation, hence the assertions
|
|
38
|
-
this._addGrammarElement(operator,
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
precedence,
|
|
48
|
-
eval: fn,
|
|
49
|
-
unaryEval
|
|
50
|
-
});
|
|
39
|
+
this._addGrammarElement(operator, {
|
|
40
|
+
type: 'binaryOp',
|
|
41
|
+
precedence,
|
|
42
|
+
unaryEval,
|
|
43
|
+
rightAssociative,
|
|
44
|
+
...(manualEval
|
|
45
|
+
? { evalOnDemand: fn }
|
|
46
|
+
: { eval: fn })
|
|
47
|
+
});
|
|
51
48
|
}
|
|
52
49
|
/**
|
|
53
50
|
* Adds or replaces an expression function in this Jexl instance.
|
|
@@ -82,7 +79,6 @@ class Jexl {
|
|
|
82
79
|
addUnaryOp(operator, fn) {
|
|
83
80
|
this._addGrammarElement(operator, {
|
|
84
81
|
type: 'unaryOp',
|
|
85
|
-
precedence: Infinity,
|
|
86
82
|
eval: fn
|
|
87
83
|
});
|
|
88
84
|
}
|
package/dist/Jexl.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Jexl.js","sourceRoot":"","sources":["../src/Jexl.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAEH,oEAAwC;AACxC,0DAA8B;AAC9B,6CAAyC;AA0BzC,MAAM,YAAY,GAAG,MAAM,CAAA;AAE3B;;;;;GAKG;AACH,MAAM,IAAI;IACR,QAAQ,CAAS;IACjB,0EAA0E;IAC1E,gEAAgE;IAChE,MAAM,CAAO;IACb,SAAS,GAAG,IAAI,GAAG,EAAsB,CAAA;IAEzC,YAAY,EAAE,SAAS,EAAE,cAAc,KAAkB,EAAE;QACzD,IAAI,CAAC,QAAQ,GAAG,EAAE,GAAG,IAAA,uBAAU,GAAE,EAAE,SAAS,EAAE,cAAc,EAAE,CAAA;QAC9D,IAAI,CAAC,MAAM,GAAG,IAAI,kBAAK,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,
|
|
1
|
+
{"version":3,"file":"Jexl.js","sourceRoot":"","sources":["../src/Jexl.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAEH,oEAAwC;AACxC,0DAA8B;AAC9B,6CAAyC;AA0BzC,MAAM,YAAY,GAAG,MAAM,CAAA;AAE3B;;;;;GAKG;AACH,MAAM,IAAI;IACR,QAAQ,CAAS;IACjB,0EAA0E;IAC1E,gEAAgE;IAChE,MAAM,CAAO;IACb,SAAS,GAAG,IAAI,GAAG,EAAsB,CAAA;IAEzC,YAAY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GAAG,CAAC,GAAG,GAAG,CAAA;QACjC,IAAI,CAAC,eAAe,EAAE,CAAA;IACxB,CAAC;IAED,eAAe;QACb,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAA;QACzB,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAA;IACxB,CAAC;CACF;AAIQ,oBAAI;AAFb,MAAM,YAAY,GAAG,IAAI,IAAI,EAAE,CAAA;AAC/B,kBAAe,YAAY,CAAA"}
|
package/dist/Lexer.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Grammar } from './grammar.ts';
|
|
2
2
|
import type { TemplatePart, Token } from './types.ts';
|
|
3
|
+
export declare const identRegex: RegExp;
|
|
3
4
|
/**
|
|
4
5
|
* Lexer handles the lexical parsing of a Jexl string. Its responsibility is to
|
|
5
6
|
* identify the "parts of speech" of a Jexl expression, and tokenize and label
|
|
@@ -22,110 +23,27 @@ declare class Lexer {
|
|
|
22
23
|
* regex is derived from their keys.
|
|
23
24
|
*/
|
|
24
25
|
_clearCache(): void;
|
|
25
|
-
/**
|
|
26
|
-
* Splits a Jexl expression string into an array of expression elements.
|
|
27
|
-
* @param {string} str A Jexl expression string
|
|
28
|
-
* @returns {Array<string>} An array of substrings defining the functional
|
|
29
|
-
* elements of the expression.
|
|
30
|
-
*/
|
|
26
|
+
/** Splits a Jexl string into its elements: tokens and runs of whitespace. */
|
|
31
27
|
getElements(str: string): string[];
|
|
32
28
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* elements that consist only of whitespace get appended to the previous
|
|
36
|
-
* token's "raw" property. For the structure of a token object, please see
|
|
37
|
-
* {@link Lexer#tokenize}.
|
|
38
|
-
* @param {Array<string>} elements An array of Jexl expression elements to be
|
|
39
|
-
* converted to tokens
|
|
40
|
-
* @returns {Array<{type, value, raw}>} an array of token objects.
|
|
29
|
+
* The tokens for a list of elements. Whitespace makes no token of its own;
|
|
30
|
+
* it joins the `raw` of the token before it.
|
|
41
31
|
*/
|
|
42
32
|
getTokens(elements: string[]): Token[];
|
|
43
33
|
/**
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* [name]: <string>,
|
|
50
|
-
* value: <boolean|number|string>,
|
|
51
|
-
* raw: <string>
|
|
52
|
-
* }
|
|
53
|
-
*
|
|
54
|
-
* Type is one of the following:
|
|
55
|
-
*
|
|
56
|
-
* literal, identifier, binaryOp, unaryOp
|
|
57
|
-
*
|
|
58
|
-
* OR, if the token is a control character its type is the name of the element
|
|
59
|
-
* defined in the Grammar.
|
|
60
|
-
*
|
|
61
|
-
* Name appears only if the token is a control string found in
|
|
62
|
-
* {@link grammar#elements}, and is set to the name of the element.
|
|
63
|
-
*
|
|
64
|
-
* Value is the value of the token in the correct type (boolean or numeric as
|
|
65
|
-
* appropriate). Raw is the string representation of this value taken directly
|
|
66
|
-
* from the expression string, including any trailing spaces.
|
|
67
|
-
* @param {string} str The Jexl string to be tokenized
|
|
68
|
-
* @returns {Array<{type, value, raw}>} an array of token objects.
|
|
69
|
-
* @throws {Error} if the provided string contains an invalid token.
|
|
34
|
+
* Splits a Jexl string into tokens. A token's `type` is `literal`,
|
|
35
|
+
* `templateString`, `identifier` or the type of the grammar element it
|
|
36
|
+
* spells; its `value` is a literal's value or the template's parts; its `raw`
|
|
37
|
+
* is its source text and any whitespace after it.
|
|
38
|
+
* @throws {JexlSyntaxError} for text that is no token
|
|
70
39
|
*/
|
|
71
40
|
tokenize(str: string): Token[];
|
|
72
|
-
/**
|
|
73
|
-
* Creates a new token object from an element of a Jexl string. See
|
|
74
|
-
* {@link Lexer#tokenize} for a description of the token object.
|
|
75
|
-
* @param {string} element The element from which a token should be made
|
|
76
|
-
* @returns {{value: number|boolean|string, [name]: string, type: string,
|
|
77
|
-
* raw: string}} a token object describing the provided element.
|
|
78
|
-
* @throws {Error} if the provided string is not a valid expression element.
|
|
79
|
-
* @private
|
|
80
|
-
*/
|
|
81
41
|
_createToken(element: string, offset?: number): Token;
|
|
82
|
-
/**
|
|
83
|
-
*
|
|
84
|
-
* regular expression. A word such as `in` also stops matching inside a
|
|
85
|
-
* longer name.
|
|
86
|
-
* @param {string} str The string to be escaped
|
|
87
|
-
* @returns {string} the RegExp-escaped string.
|
|
88
|
-
* @see https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions
|
|
89
|
-
* @private
|
|
90
|
-
*/
|
|
42
|
+
/** A grammar element's text as a regex. A word such as `in` also stops
|
|
43
|
+
* matching inside a longer name. */
|
|
91
44
|
_escapeRegExp(str: string): string;
|
|
92
|
-
/**
|
|
93
|
-
* Gets a RegEx object appropriate for splitting a Jexl string into its core
|
|
94
|
-
* elements.
|
|
95
|
-
* @returns {RegExp} An element-splitting RegExp object
|
|
96
|
-
* @private
|
|
97
|
-
*/
|
|
98
45
|
_getSplitRegex(): RegExp;
|
|
99
|
-
/**
|
|
100
|
-
* Determines whether the addition of a '-' token should be interpreted as a
|
|
101
|
-
* negative symbol for an upcoming number, given an array of tokens already
|
|
102
|
-
* processed.
|
|
103
|
-
* @param {Array<Object>} tokens An array of tokens already processed
|
|
104
|
-
* @returns {boolean} true if adding a '-' should be considered a negative
|
|
105
|
-
* symbol; false otherwise
|
|
106
|
-
* @private
|
|
107
|
-
*/
|
|
108
|
-
_isNegative(tokens: Token[]): boolean;
|
|
109
|
-
/**
|
|
110
|
-
* A utility function to determine if a string consists of only space
|
|
111
|
-
* characters.
|
|
112
|
-
* @param {string} str A string to be tested
|
|
113
|
-
* @returns {boolean} true if the string is empty or consists of only spaces;
|
|
114
|
-
* false otherwise.
|
|
115
|
-
* @private
|
|
116
|
-
*/
|
|
117
|
-
_isWhitespace(str: string): boolean;
|
|
118
|
-
/**
|
|
119
|
-
* Removes the beginning and trailing quotes from a string, unescapes any
|
|
120
|
-
* escaped quotes on its interior, and unescapes any escaped escape
|
|
121
|
-
* characters. Note that this function is not defensive; it assumes that the
|
|
122
|
-
* provided string is not empty, and that its first and last characters are
|
|
123
|
-
* actually quotes.
|
|
124
|
-
* @param {string} str A string whose first and last characters are quotes
|
|
125
|
-
* @returns {string} a string with the surrounding quotes stripped and escapes
|
|
126
|
-
* properly processed.
|
|
127
|
-
* @private
|
|
128
|
-
*/
|
|
46
|
+
/** A quoted string literal's text, unquoted and unescaped. */
|
|
129
47
|
_unquote(str: string): string;
|
|
130
48
|
_parseTemplateString(str: string, offset?: number): TemplatePart[];
|
|
131
49
|
_unescapeTemplateString(str: string): string;
|
package/dist/Lexer.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Copyright 2020 Tom Shawver
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.identRegex = void 0;
|
|
7
8
|
const errors_ts_1 = require("./errors.js");
|
|
8
9
|
// what an identifier and a number look like, written once: the split regex
|
|
9
10
|
// below carves elements out of the expression with these, and _createToken
|
|
@@ -19,22 +20,20 @@ const wholeWord = (word) => `(?<!${identPart})${word}(?!${identPart})`;
|
|
|
19
20
|
// unsigned: whether a leading '-' negates is decided separately, in getTokens
|
|
20
21
|
const numberPattern = String.raw `(?:(?:[0-9]*\.[0-9]+)|[0-9]+)(?:[eE][+-]?[0-9]+)?`;
|
|
21
22
|
const numericRegex = new RegExp(`^-?${numberPattern}$`);
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
//
|
|
25
|
-
//
|
|
26
|
-
const
|
|
27
|
-
// the escapes a template string's static text recognizes. One pass, so the
|
|
28
|
-
// backslash an escaped backslash yields can't be re-read as the start of the
|
|
29
|
-
// escape that follows it
|
|
23
|
+
exports.identRegex = new RegExp(`^${identPattern}$`);
|
|
24
|
+
// the escapes each kind of literal recognizes. One pass, so the backslash an
|
|
25
|
+
// escaped backslash yields can't be re-read as the start of the escape that
|
|
26
|
+
// follows it
|
|
27
|
+
const quoteEscRegex = { "'": /\\([\\'])/g, '"': /\\([\\"])/g };
|
|
30
28
|
const templateEscRegex = /\\([`$\\])/g;
|
|
31
29
|
const whitespaceRegex = /^\s*$/;
|
|
30
|
+
// a backslash and the character after it are a pair, so an escaped backslash
|
|
31
|
+
// before the closing quote can't escape that quote
|
|
32
|
+
const quoted = (quote) => String.raw `${quote}(?:\\[\s\S]|[^${quote}\\])*${quote}`;
|
|
32
33
|
const preOpRegexElems = [
|
|
33
|
-
|
|
34
|
-
'
|
|
35
|
-
|
|
36
|
-
String.raw `'(?:(?:\\')|[^'])*'`,
|
|
37
|
-
String.raw `"(?:(?:\\")|[^"])*"`,
|
|
34
|
+
quoted('`'),
|
|
35
|
+
quoted("'"),
|
|
36
|
+
quoted('"'),
|
|
38
37
|
// Whitespace
|
|
39
38
|
String.raw `\s+`,
|
|
40
39
|
// ahead of the grammar's '.', so that '.5' is a number rather than a dot
|
|
@@ -55,8 +54,11 @@ const minusNegatesAfter = new Set([
|
|
|
55
54
|
'colon',
|
|
56
55
|
'comma',
|
|
57
56
|
'semicolon',
|
|
58
|
-
'arrow'
|
|
57
|
+
'arrow',
|
|
58
|
+
'assign'
|
|
59
59
|
]);
|
|
60
|
+
// whether a `-` after this token negates what follows rather than subtracting
|
|
61
|
+
const negates = (last) => !last || minusNegatesAfter.has(last.type);
|
|
60
62
|
/**
|
|
61
63
|
* Lexer handles the lexical parsing of a Jexl string. Its responsibility is to
|
|
62
64
|
* identify the "parts of speech" of a Jexl expression, and tokenize and label
|
|
@@ -83,25 +85,13 @@ class Lexer {
|
|
|
83
85
|
_clearCache() {
|
|
84
86
|
this._splitRegex = undefined;
|
|
85
87
|
}
|
|
86
|
-
/**
|
|
87
|
-
* Splits a Jexl expression string into an array of expression elements.
|
|
88
|
-
* @param {string} str A Jexl expression string
|
|
89
|
-
* @returns {Array<string>} An array of substrings defining the functional
|
|
90
|
-
* elements of the expression.
|
|
91
|
-
*/
|
|
88
|
+
/** Splits a Jexl string into its elements: tokens and runs of whitespace. */
|
|
92
89
|
getElements(str) {
|
|
93
|
-
|
|
94
|
-
return str.split(regex).filter(Boolean);
|
|
90
|
+
return str.split(this._getSplitRegex()).filter(Boolean);
|
|
95
91
|
}
|
|
96
92
|
/**
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
* elements that consist only of whitespace get appended to the previous
|
|
100
|
-
* token's "raw" property. For the structure of a token object, please see
|
|
101
|
-
* {@link Lexer#tokenize}.
|
|
102
|
-
* @param {Array<string>} elements An array of Jexl expression elements to be
|
|
103
|
-
* converted to tokens
|
|
104
|
-
* @returns {Array<{type, value, raw}>} an array of token objects.
|
|
93
|
+
* The tokens for a list of elements. Whitespace makes no token of its own;
|
|
94
|
+
* it joins the `raw` of the token before it.
|
|
105
95
|
*/
|
|
106
96
|
getTokens(elements) {
|
|
107
97
|
const tokens = [];
|
|
@@ -112,13 +102,13 @@ class Lexer {
|
|
|
112
102
|
let pendingMinus;
|
|
113
103
|
let offset = 0;
|
|
114
104
|
for (const element of elements) {
|
|
115
|
-
if (
|
|
105
|
+
if (whitespaceRegex.test(element)) {
|
|
116
106
|
const last = pendingMinus ?? tokens.at(-1);
|
|
117
107
|
if (last) {
|
|
118
108
|
last.raw += element;
|
|
119
109
|
}
|
|
120
110
|
}
|
|
121
|
-
else if (element === '-' &&
|
|
111
|
+
else if (element === '-' && negates(tokens.at(-1))) {
|
|
122
112
|
// a second prefix minus in a row ("- -x"): emit the pending one as a
|
|
123
113
|
// unary operator so this one can negate whatever comes next
|
|
124
114
|
if (pendingMinus) {
|
|
@@ -127,7 +117,7 @@ class Lexer {
|
|
|
127
117
|
pendingMinus = unaryMinusToken();
|
|
128
118
|
}
|
|
129
119
|
else if (pendingMinus) {
|
|
130
|
-
if (numericRegex.
|
|
120
|
+
if (numericRegex.test(element)) {
|
|
131
121
|
// fold the sign into the number, so "-1" stays a single literal
|
|
132
122
|
const token = this._createToken('-' + element, offset);
|
|
133
123
|
token.raw = pendingMinus.raw + element;
|
|
@@ -152,46 +142,15 @@ class Lexer {
|
|
|
152
142
|
return tokens;
|
|
153
143
|
}
|
|
154
144
|
/**
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
* [name]: <string>,
|
|
161
|
-
* value: <boolean|number|string>,
|
|
162
|
-
* raw: <string>
|
|
163
|
-
* }
|
|
164
|
-
*
|
|
165
|
-
* Type is one of the following:
|
|
166
|
-
*
|
|
167
|
-
* literal, identifier, binaryOp, unaryOp
|
|
168
|
-
*
|
|
169
|
-
* OR, if the token is a control character its type is the name of the element
|
|
170
|
-
* defined in the Grammar.
|
|
171
|
-
*
|
|
172
|
-
* Name appears only if the token is a control string found in
|
|
173
|
-
* {@link grammar#elements}, and is set to the name of the element.
|
|
174
|
-
*
|
|
175
|
-
* Value is the value of the token in the correct type (boolean or numeric as
|
|
176
|
-
* appropriate). Raw is the string representation of this value taken directly
|
|
177
|
-
* from the expression string, including any trailing spaces.
|
|
178
|
-
* @param {string} str The Jexl string to be tokenized
|
|
179
|
-
* @returns {Array<{type, value, raw}>} an array of token objects.
|
|
180
|
-
* @throws {Error} if the provided string contains an invalid token.
|
|
145
|
+
* Splits a Jexl string into tokens. A token's `type` is `literal`,
|
|
146
|
+
* `templateString`, `identifier` or the type of the grammar element it
|
|
147
|
+
* spells; its `value` is a literal's value or the template's parts; its `raw`
|
|
148
|
+
* is its source text and any whitespace after it.
|
|
149
|
+
* @throws {JexlSyntaxError} for text that is no token
|
|
181
150
|
*/
|
|
182
151
|
tokenize(str) {
|
|
183
|
-
|
|
184
|
-
return this.getTokens(elements);
|
|
152
|
+
return this.getTokens(this.getElements(str));
|
|
185
153
|
}
|
|
186
|
-
/**
|
|
187
|
-
* Creates a new token object from an element of a Jexl string. See
|
|
188
|
-
* {@link Lexer#tokenize} for a description of the token object.
|
|
189
|
-
* @param {string} element The element from which a token should be made
|
|
190
|
-
* @returns {{value: number|boolean|string, [name]: string, type: string,
|
|
191
|
-
* raw: string}} a token object describing the provided element.
|
|
192
|
-
* @throws {Error} if the provided string is not a valid expression element.
|
|
193
|
-
* @private
|
|
194
|
-
*/
|
|
195
154
|
_createToken(element, offset = 0) {
|
|
196
155
|
const token = {
|
|
197
156
|
type: 'literal',
|
|
@@ -206,7 +165,7 @@ class Lexer {
|
|
|
206
165
|
else if (element.startsWith('"') || element.startsWith("'")) {
|
|
207
166
|
token.value = this._unquote(element);
|
|
208
167
|
}
|
|
209
|
-
else if (numericRegex.
|
|
168
|
+
else if (numericRegex.test(element)) {
|
|
210
169
|
token.value = parseFloat(element);
|
|
211
170
|
}
|
|
212
171
|
else if (element === 'true' || element === 'false') {
|
|
@@ -218,7 +177,7 @@ class Lexer {
|
|
|
218
177
|
else if (Object.hasOwn(this._grammar.elements, element)) {
|
|
219
178
|
token.type = this._grammar.elements[element].type;
|
|
220
179
|
}
|
|
221
|
-
else if (identRegex.
|
|
180
|
+
else if (exports.identRegex.test(element)) {
|
|
222
181
|
token.type = 'identifier';
|
|
223
182
|
}
|
|
224
183
|
else {
|
|
@@ -226,86 +185,26 @@ class Lexer {
|
|
|
226
185
|
}
|
|
227
186
|
return token;
|
|
228
187
|
}
|
|
229
|
-
/**
|
|
230
|
-
*
|
|
231
|
-
* regular expression. A word such as `in` also stops matching inside a
|
|
232
|
-
* longer name.
|
|
233
|
-
* @param {string} str The string to be escaped
|
|
234
|
-
* @returns {string} the RegExp-escaped string.
|
|
235
|
-
* @see https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions
|
|
236
|
-
* @private
|
|
237
|
-
*/
|
|
188
|
+
/** A grammar element's text as a regex. A word such as `in` also stops
|
|
189
|
+
* matching inside a longer name. */
|
|
238
190
|
_escapeRegExp(str) {
|
|
239
191
|
const escaped = str.replaceAll(/[.*+?^${}()|[\]\\]/g, String.raw `\$&`);
|
|
240
|
-
return identRegex.
|
|
192
|
+
return exports.identRegex.test(str) ? wholeWord(escaped) : escaped;
|
|
241
193
|
}
|
|
242
|
-
/**
|
|
243
|
-
* Gets a RegEx object appropriate for splitting a Jexl string into its core
|
|
244
|
-
* elements.
|
|
245
|
-
* @returns {RegExp} An element-splitting RegExp object
|
|
246
|
-
* @private
|
|
247
|
-
*/
|
|
248
194
|
_getSplitRegex() {
|
|
249
195
|
if (!this._splitRegex) {
|
|
250
|
-
//
|
|
251
|
-
const
|
|
252
|
-
.sort((a, b) =>
|
|
253
|
-
|
|
254
|
-
})
|
|
255
|
-
.map((elem) => {
|
|
256
|
-
return this._escapeRegExp(elem);
|
|
257
|
-
});
|
|
258
|
-
this._splitRegex = new RegExp('(' +
|
|
259
|
-
[
|
|
260
|
-
preOpRegexElems.join('|'),
|
|
261
|
-
elemArray.join('|'),
|
|
262
|
-
postOpRegexElems.join('|')
|
|
263
|
-
].join('|') +
|
|
264
|
-
')');
|
|
196
|
+
// longest first, so that `==` wins over `=`
|
|
197
|
+
const elements = Object.keys(this._grammar.elements)
|
|
198
|
+
.sort((a, b) => b.length - a.length)
|
|
199
|
+
.map((element) => this._escapeRegExp(element));
|
|
200
|
+
this._splitRegex = new RegExp(`(${[...preOpRegexElems, ...elements, ...postOpRegexElems].join('|')})`);
|
|
265
201
|
}
|
|
266
202
|
return this._splitRegex;
|
|
267
203
|
}
|
|
268
|
-
/**
|
|
269
|
-
* Determines whether the addition of a '-' token should be interpreted as a
|
|
270
|
-
* negative symbol for an upcoming number, given an array of tokens already
|
|
271
|
-
* processed.
|
|
272
|
-
* @param {Array<Object>} tokens An array of tokens already processed
|
|
273
|
-
* @returns {boolean} true if adding a '-' should be considered a negative
|
|
274
|
-
* symbol; false otherwise
|
|
275
|
-
* @private
|
|
276
|
-
*/
|
|
277
|
-
_isNegative(tokens) {
|
|
278
|
-
const last = tokens.at(-1);
|
|
279
|
-
return !last || minusNegatesAfter.has(last.type);
|
|
280
|
-
}
|
|
281
|
-
/**
|
|
282
|
-
* A utility function to determine if a string consists of only space
|
|
283
|
-
* characters.
|
|
284
|
-
* @param {string} str A string to be tested
|
|
285
|
-
* @returns {boolean} true if the string is empty or consists of only spaces;
|
|
286
|
-
* false otherwise.
|
|
287
|
-
* @private
|
|
288
|
-
*/
|
|
289
|
-
_isWhitespace(str) {
|
|
290
|
-
return !!whitespaceRegex.exec(str);
|
|
291
|
-
}
|
|
292
|
-
/**
|
|
293
|
-
* Removes the beginning and trailing quotes from a string, unescapes any
|
|
294
|
-
* escaped quotes on its interior, and unescapes any escaped escape
|
|
295
|
-
* characters. Note that this function is not defensive; it assumes that the
|
|
296
|
-
* provided string is not empty, and that its first and last characters are
|
|
297
|
-
* actually quotes.
|
|
298
|
-
* @param {string} str A string whose first and last characters are quotes
|
|
299
|
-
* @returns {string} a string with the surrounding quotes stripped and escapes
|
|
300
|
-
* properly processed.
|
|
301
|
-
* @private
|
|
302
|
-
*/
|
|
204
|
+
/** A quoted string literal's text, unquoted and unescaped. */
|
|
303
205
|
_unquote(str) {
|
|
304
206
|
const quote = str.startsWith('"') ? '"' : "'";
|
|
305
|
-
return str
|
|
306
|
-
.slice(1, -1)
|
|
307
|
-
.replaceAll(escQuoteRegex[quote], quote)
|
|
308
|
-
.replaceAll(escEscRegex, '\\');
|
|
207
|
+
return str.slice(1, -1).replaceAll(quoteEscRegex[quote], '$1');
|
|
309
208
|
}
|
|
310
209
|
_parseTemplateString(str, offset = 0) {
|
|
311
210
|
const parts = [];
|
package/dist/Lexer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Lexer.js","sourceRoot":"","sources":["../src/Lexer.ts"],"names":[],"mappings":";AAAA;;;GAGG
|
|
1
|
+
{"version":3,"file":"Lexer.js","sourceRoot":"","sources":["../src/Lexer.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,2CAA6C;AAK7C,2EAA2E;AAC3E,2EAA2E;AAC3E,wEAAwE;AACxE,0EAA0E;AAC1E,0DAA0D;AAC1D,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAA,uDAAuD,CAAA;AACpF,MAAM,SAAS,GAAG,IAAI,UAAU,MAAM,CAAA;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interface AnalyzeOptions {
|
|
|
69
69
|
*/
|
|
70
70
|
env?: readonly string[];
|
|
71
71
|
}
|
|
72
|
+
/** A literal's value, or a template's with no interpolation. */
|
|
73
|
+
export declare function literalValue(node: AstNode): string | number | boolean | null | undefined;
|
|
72
74
|
/**
|
|
73
75
|
* Lists what an expression reads from its context, without evaluating it or
|
|
74
76
|
* consulting any registered function.
|