@jbrowse/jexl 4.0.1 → 5.0.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 (110) hide show
  1. package/README.md +163 -20
  2. package/dist/Expression.d.ts +16 -0
  3. package/dist/Expression.js +28 -4
  4. package/dist/Expression.js.map +1 -1
  5. package/dist/Jexl.d.ts +20 -8
  6. package/dist/Jexl.js +34 -15
  7. package/dist/Jexl.js.map +1 -1
  8. package/dist/Lexer.d.ts +4 -3
  9. package/dist/Lexer.js +29 -21
  10. package/dist/Lexer.js.map +1 -1
  11. package/dist/analyze.d.ts +84 -0
  12. package/dist/analyze.js +259 -0
  13. package/dist/analyze.js.map +1 -0
  14. package/dist/check.d.ts +109 -0
  15. package/dist/check.js +1267 -0
  16. package/dist/check.js.map +1 -0
  17. package/dist/collections.d.ts +3 -0
  18. package/dist/collections.js +140 -0
  19. package/dist/collections.js.map +1 -0
  20. package/dist/conditions.d.ts +62 -0
  21. package/dist/conditions.js +207 -0
  22. package/dist/conditions.js.map +1 -0
  23. package/dist/errors.d.ts +5 -0
  24. package/dist/errors.js +18 -0
  25. package/dist/errors.js.map +1 -0
  26. package/dist/evaluator/compile.d.ts +10 -7
  27. package/dist/evaluator/compile.js +292 -99
  28. package/dist/evaluator/compile.js.map +1 -1
  29. package/dist/grammar.d.ts +22 -9
  30. package/dist/grammar.js +83 -55
  31. package/dist/grammar.js.map +1 -1
  32. package/dist/index.d.ts +9 -0
  33. package/dist/index.js +16 -1
  34. package/dist/index.js.map +1 -1
  35. package/dist/operators.d.ts +34 -0
  36. package/dist/operators.js +131 -0
  37. package/dist/operators.js.map +1 -0
  38. package/dist/parser/Parser.d.ts +48 -91
  39. package/dist/parser/Parser.js +347 -221
  40. package/dist/parser/Parser.js.map +1 -1
  41. package/dist/types.d.ts +11 -5
  42. package/esm/Expression.d.ts +16 -0
  43. package/esm/Expression.js +28 -4
  44. package/esm/Expression.js.map +1 -1
  45. package/esm/Jexl.d.ts +20 -8
  46. package/esm/Jexl.js +34 -15
  47. package/esm/Jexl.js.map +1 -1
  48. package/esm/Lexer.d.ts +4 -3
  49. package/esm/Lexer.js +29 -21
  50. package/esm/Lexer.js.map +1 -1
  51. package/esm/analyze.d.ts +84 -0
  52. package/esm/analyze.js +256 -0
  53. package/esm/analyze.js.map +1 -0
  54. package/esm/check.d.ts +109 -0
  55. package/esm/check.js +1260 -0
  56. package/esm/check.js.map +1 -0
  57. package/esm/collections.d.ts +3 -0
  58. package/esm/collections.js +137 -0
  59. package/esm/collections.js.map +1 -0
  60. package/esm/conditions.d.ts +62 -0
  61. package/esm/conditions.js +200 -0
  62. package/esm/conditions.js.map +1 -0
  63. package/esm/errors.d.ts +5 -0
  64. package/esm/errors.js +14 -0
  65. package/esm/errors.js.map +1 -0
  66. package/esm/evaluator/compile.d.ts +10 -7
  67. package/esm/evaluator/compile.js +292 -99
  68. package/esm/evaluator/compile.js.map +1 -1
  69. package/esm/grammar.d.ts +22 -9
  70. package/esm/grammar.js +79 -53
  71. package/esm/grammar.js.map +1 -1
  72. package/esm/index.d.ts +9 -0
  73. package/esm/index.js +4 -0
  74. package/esm/index.js.map +1 -1
  75. package/esm/operators.d.ts +34 -0
  76. package/esm/operators.js +123 -0
  77. package/esm/operators.js.map +1 -0
  78. package/esm/parser/Parser.d.ts +48 -91
  79. package/esm/parser/Parser.js +349 -192
  80. package/esm/parser/Parser.js.map +1 -1
  81. package/esm/types.d.ts +11 -5
  82. package/package.json +1 -1
  83. package/src/Expression.ts +34 -4
  84. package/src/Jexl.ts +52 -16
  85. package/src/Lexer.ts +32 -21
  86. package/src/analyze.ts +378 -0
  87. package/src/check.ts +1682 -0
  88. package/src/collections.ts +148 -0
  89. package/src/conditions.ts +262 -0
  90. package/src/errors.ts +15 -0
  91. package/src/evaluator/compile.ts +351 -102
  92. package/src/grammar.ts +137 -55
  93. package/src/index.ts +15 -0
  94. package/src/operators.ts +151 -0
  95. package/src/parser/Parser.ts +389 -199
  96. package/src/types.ts +13 -3
  97. package/dist/parser/handlers.d.ts +0 -115
  98. package/dist/parser/handlers.js +0 -352
  99. package/dist/parser/handlers.js.map +0 -1
  100. package/dist/parser/states.d.ts +0 -47
  101. package/dist/parser/states.js +0 -176
  102. package/dist/parser/states.js.map +0 -1
  103. package/esm/parser/handlers.d.ts +0 -115
  104. package/esm/parser/handlers.js +0 -328
  105. package/esm/parser/handlers.js.map +0 -1
  106. package/esm/parser/states.d.ts +0 -47
  107. package/esm/parser/states.js +0 -140
  108. package/esm/parser/states.js.map +0 -1
  109. package/src/parser/handlers.ts +0 -372
  110. package/src/parser/states.ts +0 -159
@@ -1,176 +0,0 @@
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
- * The tokens that may follow a finished operand: an operator to combine it
44
- * with, a dot or subscript to keep drilling into it, a question mark opening a
45
- * ternary, or a semicolon ending the statement. Shared by every state that
46
- * sits on a complete value, which is also why each of them is completable.
47
- */
48
- const afterOperand = {
49
- binaryOp: { toState: 'expectOperand' },
50
- dot: { toState: 'traverse' },
51
- openBracket: { toState: 'filter' },
52
- question: { toState: 'ternaryMid', handler: h.ternaryStart },
53
- semicolon: { handler: h.semicolon }
54
- };
55
- /**
56
- * A mapping of all states in the finite state machine to a set of instructions
57
- * for handling or transitioning into other states. Each state can be handled
58
- * in one of two schemes: a tokenType map, or a subHandler.
59
- *
60
- * Standard expression elements are handled through the tokenType object. This
61
- * is an object map of all legal token types to encounter in this state (and
62
- * any unexpected token types will generate a thrown error) to an options
63
- * object that defines how they're handled. The available options are:
64
- *
65
- * {string} toState: The name of the state to which to transition
66
- * immediately after handling this token
67
- * {string} handler: The handler function to call when this token type is
68
- * encountered in this state. If omitted, the default handler
69
- * matching the token's "type" property will be called. If the handler
70
- * function does not exist, no call will be made and no error will be
71
- * generated. This is useful for tokens whose sole purpose is to
72
- * transition to other states.
73
- *
74
- * States that consume a subexpression should define a subHandler, the
75
- * function to be called with an expression tree argument when the
76
- * subexpression is complete. Completeness is determined through the
77
- * endStates object, which maps tokens on which an expression should end to the
78
- * state to which to transition once the subHandler function has been called.
79
- *
80
- * Additionally, any state in which it is legal to mark the AST as completed
81
- * should have a 'completable' property set to boolean true. Attempting to
82
- * call {@link Parser#complete} in any state without this property will result
83
- * in a thrown Error.
84
- *
85
- * @type {{}}
86
- */
87
- exports.states = {
88
- expectOperand: {
89
- tokenTypes: {
90
- literal: { toState: 'expectBinOp' },
91
- templateString: { toState: 'expectBinOp' },
92
- identifier: { toState: 'identifier' },
93
- unaryOp: {},
94
- openParen: { toState: 'subExpression' },
95
- openCurl: { toState: 'expectObjKey', handler: h.objStart },
96
- dot: { toState: 'traverse' },
97
- openBracket: { toState: 'arrayVal', handler: h.arrayStart }
98
- }
99
- },
100
- expectBinOp: {
101
- tokenTypes: afterOperand,
102
- completable: true
103
- },
104
- expectObjKey: {
105
- tokenTypes: {
106
- literal: { toState: 'expectKeyValSep', handler: h.objKey },
107
- identifier: { toState: 'expectKeyValSep', handler: h.objKey },
108
- closeCurl: { toState: 'expectBinOp' }
109
- }
110
- },
111
- expectKeyValSep: {
112
- tokenTypes: {
113
- colon: { toState: 'objVal' }
114
- }
115
- },
116
- identifier: {
117
- tokenTypes: {
118
- ...afterOperand,
119
- // a name is the only operand that can be followed by an argument list,
120
- // since a function is called by name rather than evaluated as a value
121
- openParen: { toState: 'argVal', handler: h.functionCall }
122
- },
123
- completable: true
124
- },
125
- traverse: {
126
- tokenTypes: {
127
- identifier: { toState: 'identifier' }
128
- }
129
- },
130
- filter: {
131
- subHandler: h.filter,
132
- endStates: {
133
- closeBracket: 'identifier'
134
- }
135
- },
136
- subExpression: {
137
- subHandler: h.subExpression,
138
- endStates: {
139
- closeParen: 'expectBinOp'
140
- }
141
- },
142
- argVal: {
143
- subHandler: h.argVal,
144
- endStates: {
145
- comma: 'argVal',
146
- // a call's result is an ordinary operand: it can be operated on or
147
- // drilled into, but not called again, since only a name can be called
148
- closeParen: 'expectBinOp'
149
- }
150
- },
151
- objVal: {
152
- subHandler: h.objVal,
153
- endStates: {
154
- comma: 'expectObjKey',
155
- closeCurl: 'expectBinOp'
156
- }
157
- },
158
- arrayVal: {
159
- subHandler: h.arrayVal,
160
- endStates: {
161
- comma: 'arrayVal',
162
- closeBracket: 'expectBinOp'
163
- }
164
- },
165
- ternaryMid: {
166
- subHandler: h.ternaryMid,
167
- endStates: {
168
- colon: 'ternaryEnd'
169
- }
170
- },
171
- ternaryEnd: {
172
- subHandler: h.ternaryEnd,
173
- completable: true
174
- }
175
- };
176
- //# sourceMappingURL=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AAU;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"}
@@ -1,115 +0,0 @@
1
- import Parser from './Parser.ts';
2
- import type { AstNode, Token } from '../types.ts';
3
- /**
4
- * Handles a subexpression that's used to define a transform argument's value.
5
- * @param {{type: <string>}} ast The subexpression tree
6
- */
7
- export declare function argVal(this: Parser, ast: AstNode | null): void;
8
- /**
9
- * Handles new array literals by adding them as a new node in the AST,
10
- * initialized with an empty array.
11
- */
12
- export declare function arrayStart(this: Parser): void;
13
- /**
14
- * Handles a subexpression representing an element of an array literal.
15
- * @param {{type: <string>}} ast The subexpression tree
16
- */
17
- export declare function arrayVal(this: Parser, ast: AstNode | null): void;
18
- /**
19
- * Handles tokens of type 'binaryOp', indicating an operation that has two
20
- * inputs: a left side and a right side.
21
- * @param {{type: <string>}} token A token object
22
- */
23
- export declare function binaryOp(this: Parser, token: Token): void;
24
- /**
25
- * Handles successive nodes in an identifier chain. More specifically, it
26
- * sets values that determine how the following identifier gets placed in the
27
- * AST.
28
- */
29
- export declare function dot(this: Parser): void;
30
- /**
31
- * Handles a subexpression used for filtering an array returned by an
32
- * identifier chain.
33
- * @param {{type: <string>}} ast The subexpression tree
34
- */
35
- export declare function filter(this: Parser, ast: AstNode | null): void;
36
- /**
37
- * Handles identifier tokens when used to indicate the name of a function to
38
- * be called.
39
- *
40
- * A call written against a value, `a.b(x)`, becomes `b(a, x)`: jexl functions
41
- * live in one global pool and have no receiver, so the value the name was read
42
- * from is passed as the first argument instead. Every function in the pool is
43
- * already written that way — `get(feature, key)`, `split(str, sep)` — which is
44
- * what makes the two spellings equivalent. Previously the receiver was simply
45
- * dropped, so `refName.split(' ')` quietly called `split(' ')`.
46
- */
47
- export declare function functionCall(this: Parser): void;
48
- /**
49
- * Handles identifier tokens by adding them as a new node in the AST.
50
- * @param {{type: <string>}} token A token object
51
- */
52
- export declare function identifier(this: Parser, token: Token): void;
53
- /**
54
- * Handles literal values, such as strings, booleans, and numerics, by adding
55
- * them as a new node in the AST.
56
- * @param {{type: <string>}} token A token object
57
- */
58
- export declare function literal(this: Parser, token: Token): void;
59
- /**
60
- * Handles template string tokens by parsing their interpolation expressions
61
- * and creating a TemplateLiteral AST node.
62
- * @param {{type: <string>}} token A token object
63
- */
64
- export declare function templateString(this: Parser, token: Token): void;
65
- /**
66
- * Queues a new object literal key to be written once a value is collected.
67
- * @param {{type: <string>}} token A token object
68
- */
69
- export declare function objKey(this: Parser, token: Token): void;
70
- /**
71
- * Handles new object literals by adding them as a new node in the AST,
72
- * initialized with an empty object.
73
- */
74
- export declare function objStart(this: Parser): void;
75
- /**
76
- * Handles an object value by adding its AST to the queued key on the object
77
- * literal node currently at the cursor.
78
- * @param {{type: <string>}} ast The subexpression tree
79
- */
80
- export declare function objVal(this: Parser, ast: AstNode | null): void;
81
- /**
82
- * Handles traditional subexpressions, delineated with the groupStart and
83
- * groupEnd elements.
84
- * @param {{type: <string>}} ast The subexpression tree
85
- */
86
- export declare function subExpression(this: Parser, ast: AstNode | null): void;
87
- /**
88
- * Handles a completed alternate subexpression of a ternary operator.
89
- * @param {{type: <string>}} ast The subexpression tree
90
- */
91
- export declare function ternaryEnd(this: Parser, ast: AstNode | null): void;
92
- /**
93
- * Handles a completed consequent subexpression of a ternary operator.
94
- * @param {{type: <string>}} ast The subexpression tree
95
- */
96
- export declare function ternaryMid(this: Parser, ast: AstNode | null): void;
97
- /**
98
- * Handles the start of a new ternary expression by encapsulating the tree so
99
- * far in a ConditionalExpression node, and using it as the test element.
100
- *
101
- * Every operator binds tighter than the conditional and so belongs in the test
102
- * — except `=`, which binds looser. `x = a ? b : c` therefore assigns the
103
- * conditional rather than testing the assignment, which had stored `a` in `x`.
104
- */
105
- export declare function ternaryStart(this: Parser): void;
106
- /**
107
- * Handles token of type 'unaryOp', indicating that the operation has only
108
- * one input: a right side.
109
- * @param {{type: <string>}} token A token object
110
- */
111
- export declare function unaryOp(this: Parser, token: Token): void;
112
- /**
113
- * Handles semicolon separator between expressions
114
- */
115
- export declare function semicolon(this: Parser): void;
@@ -1,328 +0,0 @@
1
- /*
2
- * Jexl
3
- * Copyright 2020 Tom Shawver
4
- */
5
- import { precedenceOf } from "../grammar.js";
6
- // circular with Parser.ts, which is fine: the binding is only read from inside
7
- // a handler, long after both modules have finished evaluating
8
- import Parser from "./Parser.js";
9
- /**
10
- * Handles a subexpression that's used to define a transform argument's value.
11
- * @param {{type: <string>}} ast The subexpression tree
12
- */
13
- export function argVal(ast) {
14
- if (ast) {
15
- ;
16
- this._cursor.args.push(ast);
17
- }
18
- }
19
- /**
20
- * Handles new array literals by adding them as a new node in the AST,
21
- * initialized with an empty array.
22
- */
23
- export function arrayStart() {
24
- const node = {
25
- type: 'ArrayLiteral',
26
- value: []
27
- };
28
- this._placeAtCursor(node);
29
- }
30
- /**
31
- * Handles a subexpression representing an element of an array literal.
32
- * @param {{type: <string>}} ast The subexpression tree
33
- */
34
- export function arrayVal(ast) {
35
- if (ast) {
36
- ;
37
- this._cursor.value.push(ast);
38
- }
39
- }
40
- /**
41
- * Handles tokens of type 'binaryOp', indicating an operation that has two
42
- * inputs: a left side and a right side.
43
- * @param {{type: <string>}} token A token object
44
- */
45
- export function binaryOp(token) {
46
- if (token.value === '=') {
47
- // `from` marks a member access such as `a.b`; only a bare name can be
48
- // assigned to, since the compiled closure writes straight into the context
49
- if (this._cursor?.type !== 'Identifier' ||
50
- this._cursor.from) {
51
- throw new Error('Left side of assignment must be a variable name');
52
- }
53
- const node = {
54
- type: 'AssignmentExpression',
55
- operator: '=',
56
- left: this._cursor
57
- };
58
- this._cursor = this._cursor._parent;
59
- this._placeAtCursor(node);
60
- return;
61
- }
62
- const tokenValue = token.value;
63
- const precedence = precedenceOf(this._grammar.elements[tokenValue]);
64
- let parent = this._cursor?._parent;
65
- while (parent) {
66
- const parentExpr = parent;
67
- if (!parentExpr.operator) {
68
- break;
69
- }
70
- // a prefix operator binds tighter than any binary one, so `-x ^ 2` groups
71
- // as `(-x) ^ 2` — the same way `-2 ^ 2` already does, since the Lexer folds
72
- // that sign into the literal. Looking `-` up in the grammar finds its
73
- // binary precedence instead, which is lower than `^`'s and gave `-(x ^ 2)`
74
- const parentPrecedence = parent.type === 'UnaryExpression'
75
- ? Infinity
76
- : precedenceOf(this._grammar.elements[parentExpr.operator]);
77
- if (parentPrecedence < precedence) {
78
- break;
79
- }
80
- this._cursor = parent;
81
- parent = parent._parent;
82
- }
83
- const node = {
84
- type: 'BinaryExpression',
85
- operator: tokenValue,
86
- left: this._cursor
87
- };
88
- this._setParent(this._cursor, node);
89
- this._cursor = parent;
90
- this._placeAtCursor(node);
91
- }
92
- /**
93
- * Handles successive nodes in an identifier chain. More specifically, it
94
- * sets values that determine how the following identifier gets placed in the
95
- * AST.
96
- */
97
- export function dot() {
98
- const cursor = this._cursor;
99
- // a dot continues an identifier chain. With nothing to continue — no cursor,
100
- // or an operator still waiting on its right-hand side — it would instead open
101
- // a relative path, the leading dot of `list[.price > 5]`. This fork removed
102
- // array filtering expressions, which are the only construct that gives a
103
- // relative path a root to resolve against, so it is rejected here rather than
104
- // parsed into a tree that can only fail once it is evaluated.
105
- if (!cursor ||
106
- cursor.type === 'UnaryExpression' ||
107
- (cursor.type === 'BinaryExpression' && !cursor.right)) {
108
- throw new Error(`Relative paths are not supported: ${this._exprStr}`);
109
- }
110
- this._nextIdentEncapsulate = true;
111
- }
112
- /**
113
- * Handles a subexpression used for filtering an array returned by an
114
- * identifier chain.
115
- * @param {{type: <string>}} ast The subexpression tree
116
- */
117
- export function filter(ast) {
118
- const node = {
119
- type: 'FilterExpression',
120
- expr: ast,
121
- subject: this._cursor
122
- };
123
- this._placeBeforeCursor(node);
124
- }
125
- /**
126
- * Handles identifier tokens when used to indicate the name of a function to
127
- * be called.
128
- *
129
- * A call written against a value, `a.b(x)`, becomes `b(a, x)`: jexl functions
130
- * live in one global pool and have no receiver, so the value the name was read
131
- * from is passed as the first argument instead. Every function in the pool is
132
- * already written that way — `get(feature, key)`, `split(str, sep)` — which is
133
- * what makes the two spellings equivalent. Previously the receiver was simply
134
- * dropped, so `refName.split(' ')` quietly called `split(' ')`.
135
- */
136
- export function functionCall() {
137
- const cursor = this._cursor;
138
- if (cursor?.type !== 'Identifier') {
139
- // reached by `a[expr]()`, whose subject is a filter rather than a name;
140
- // there is nothing to look up in the function pool
141
- throw new Error(`Functions must be called by name: ${this._exprStr}`);
142
- }
143
- const { from, value } = cursor;
144
- const node = {
145
- type: 'FunctionCall',
146
- name: value,
147
- args: from ? [from] : []
148
- };
149
- this._placeBeforeCursor(node);
150
- }
151
- /**
152
- * Handles identifier tokens by adding them as a new node in the AST.
153
- * @param {{type: <string>}} token A token object
154
- */
155
- export function identifier(token) {
156
- const node = {
157
- type: 'Identifier',
158
- value: token.value
159
- };
160
- if (this._nextIdentEncapsulate) {
161
- node.from = this._cursor;
162
- this._placeBeforeCursor(node);
163
- this._nextIdentEncapsulate = false;
164
- }
165
- else {
166
- this._placeAtCursor(node);
167
- }
168
- }
169
- /**
170
- * Handles literal values, such as strings, booleans, and numerics, by adding
171
- * them as a new node in the AST.
172
- * @param {{type: <string>}} token A token object
173
- */
174
- export function literal(token) {
175
- const node = {
176
- type: 'Literal',
177
- value: token.value
178
- };
179
- this._placeAtCursor(node);
180
- }
181
- /**
182
- * Handles template string tokens by parsing their interpolation expressions
183
- * and creating a TemplateLiteral AST node.
184
- * @param {{type: <string>}} token A token object
185
- */
186
- export function templateString(token) {
187
- const parts = [];
188
- const tokenParts = Array.isArray(token.value) ? token.value : [];
189
- for (const part of tokenParts) {
190
- if (part.type === 'static') {
191
- parts.push({
192
- type: 'static',
193
- value: this._lexer._unescapeTemplateString(part.value)
194
- });
195
- }
196
- else {
197
- const subTokens = this._lexer.tokenize(part.value);
198
- const subParser = new Parser(this._grammar, this._lexer);
199
- subParser.addTokens(subTokens);
200
- const subAst = subParser.complete();
201
- if (!subAst) {
202
- throw new Error('Empty interpolation in template string');
203
- }
204
- parts.push({
205
- type: 'expression',
206
- value: subAst
207
- });
208
- }
209
- }
210
- const node = {
211
- type: 'TemplateLiteral',
212
- parts
213
- };
214
- this._placeAtCursor(node);
215
- }
216
- /**
217
- * Queues a new object literal key to be written once a value is collected.
218
- * @param {{type: <string>}} token A token object
219
- */
220
- export function objKey(token) {
221
- this._curObjKey = token.value;
222
- }
223
- /**
224
- * Handles new object literals by adding them as a new node in the AST,
225
- * initialized with an empty object.
226
- */
227
- export function objStart() {
228
- const node = {
229
- type: 'ObjectLiteral',
230
- value: {}
231
- };
232
- this._placeAtCursor(node);
233
- }
234
- /**
235
- * Handles an object value by adding its AST to the queued key on the object
236
- * literal node currently at the cursor.
237
- * @param {{type: <string>}} ast The subexpression tree
238
- */
239
- export function objVal(ast) {
240
- // defined rather than assigned so that the key "__proto__" becomes an
241
- // ordinary entry of the node's key map instead of re-pointing its prototype,
242
- // which dropped the entry before it could be compiled
243
- Object.defineProperty(this._cursor.value, this._curObjKey, {
244
- value: ast,
245
- writable: true,
246
- enumerable: true,
247
- configurable: true
248
- });
249
- }
250
- /**
251
- * Handles traditional subexpressions, delineated with the groupStart and
252
- * groupEnd elements.
253
- * @param {{type: <string>}} ast The subexpression tree
254
- */
255
- export function subExpression(ast) {
256
- this._placeAtCursor(ast);
257
- }
258
- /**
259
- * Handles a completed alternate subexpression of a ternary operator.
260
- * @param {{type: <string>}} ast The subexpression tree
261
- */
262
- export function ternaryEnd(ast) {
263
- ;
264
- this._cursor.alternate = ast ?? undefined;
265
- }
266
- /**
267
- * Handles a completed consequent subexpression of a ternary operator.
268
- * @param {{type: <string>}} ast The subexpression tree
269
- */
270
- export function ternaryMid(ast) {
271
- ;
272
- this._cursor.consequent = ast ?? undefined;
273
- }
274
- /**
275
- * Handles the start of a new ternary expression by encapsulating the tree so
276
- * far in a ConditionalExpression node, and using it as the test element.
277
- *
278
- * Every operator binds tighter than the conditional and so belongs in the test
279
- * — except `=`, which binds looser. `x = a ? b : c` therefore assigns the
280
- * conditional rather than testing the assignment, which had stored `a` in `x`.
281
- */
282
- export function ternaryStart() {
283
- let assignment;
284
- let test = this._tree;
285
- while (test.type === 'AssignmentExpression' && test.right) {
286
- assignment = test;
287
- test = test.right;
288
- }
289
- const node = {
290
- type: 'ConditionalExpression',
291
- test
292
- };
293
- if (assignment) {
294
- assignment.right = node;
295
- this._setParent(node, assignment);
296
- }
297
- else {
298
- this._tree = node;
299
- }
300
- this._cursor = node;
301
- }
302
- /**
303
- * Handles token of type 'unaryOp', indicating that the operation has only
304
- * one input: a right side.
305
- * @param {{type: <string>}} token A token object
306
- */
307
- export function unaryOp(token) {
308
- const node = {
309
- type: 'UnaryExpression',
310
- operator: token.value
311
- };
312
- this._placeAtCursor(node);
313
- }
314
- /**
315
- * Handles semicolon separator between expressions
316
- */
317
- export function semicolon() {
318
- if (!this._sequenceExpressions) {
319
- this._sequenceExpressions = [this._tree];
320
- }
321
- else {
322
- this._sequenceExpressions.push(this._tree);
323
- }
324
- this._tree = null;
325
- this._cursor = null;
326
- this._state = 'expectOperand';
327
- }
328
- //# sourceMappingURL=handlers.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"handlers.js","sourceRoot":"","sources":["../../src/parser/handlers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,+EAA+E;AAC/E,8DAA8D;AAC9D,OAAO,MAAM,MAAM,aAAa,CAAA;AAkBhC;;;GAGG;AACH,MAAM,UAAU,MAAM,CAAe,GAAmB;IACtD,IAAI,GAAG,EAAE,CAAC;QACR,CAAC;QAAC,IAAI,CAAC,OAAwB,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAChD,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,UAAU;IACxB,MAAM,IAAI,GAAiB;QACzB,IAAI,EAAE,cAAc;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K,EAAE,CAAC;QAC1D,UAAU,GAAG,IAAI,CAAA;QACjB,IAAI,GAAG,IAAI,CAAC,KAAK,CAAA;IACnB,CAAC;IAED,MAAM,IAAI,GAA0B;QAClC,IAAI,EAAE,uBAAuB;QAC7B,IAAI;KACL,CAAA;IACD,IAAI,UAAU,EAAE,CAAC;QACf,UAAU,CAAC,KAAK,GAAG,IAAI,CAAA;QACvB,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,UAAU,CAAC,CAAA;IACnC,CAAC;SAAM,CAAC;QACN,IAAI,CAAC,KAAK,GAAG,IAAI,CAAA;IACnB,CAAC;IACD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA;AACrB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,OAAO,CAAe,KAAY;IAChD,MAAM,IAAI,GAAoB;QAC5B,IAAI,EAAE,iBAAiB;QACvB,QAAQ,EAAE,KAAK,CAAC,KAAe;KAChC,CAAA;IACD,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAA;AAC3B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,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"}
@@ -1,47 +0,0 @@
1
- import type { AstNode, Token } from '../types.ts';
2
- import type Parser from './Parser.ts';
3
- interface TokenTypeOptions {
4
- toState?: string;
5
- handler?: (this: Parser, token: Token) => 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 {};