pacc 8.3.0 → 8.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/package.json +1 -1
- package/src/ast.mjs +2 -3
- package/src/expression.mjs +5 -25
- package/types/ast.d.mts +0 -13
package/README.md
CHANGED
|
@@ -635,8 +635,9 @@ Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Globa
|
|
|
635
635
|
### Parameters
|
|
636
636
|
|
|
637
637
|
* `str` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** 
|
|
638
|
-
* `precedence`
|
|
639
|
-
* `type`
|
|
638
|
+
* `precedence` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** (optional, default `0`)
|
|
639
|
+
* `type` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** 
|
|
640
|
+
* `binop`  
|
|
640
641
|
|
|
641
642
|
Returns **[Token](#token)** 
|
|
642
643
|
|
package/package.json
CHANGED
package/src/ast.mjs
CHANGED
|
@@ -25,18 +25,17 @@ import {
|
|
|
25
25
|
* @param {AST} right
|
|
26
26
|
*
|
|
27
27
|
*/
|
|
28
|
-
|
|
28
|
+
function binopError(op, left, right) {
|
|
29
29
|
throw new Error(`Unexpected '${op.str || op}'`, { cause: op });
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
export function binop(op, left, right, fallback) {
|
|
33
|
-
|
|
34
33
|
if(op.binop) { return op.binop(left,right); }
|
|
35
34
|
|
|
36
35
|
return fallback(op, left, right);
|
|
37
36
|
}
|
|
38
37
|
|
|
39
|
-
|
|
38
|
+
function binopEval(node, current, context) {
|
|
40
39
|
return binop(
|
|
41
40
|
node.token,
|
|
42
41
|
node.left.eval ? node.left.eval(node.left, current, context) : node.left,
|
package/src/expression.mjs
CHANGED
|
@@ -9,14 +9,7 @@ import {
|
|
|
9
9
|
COMMA,
|
|
10
10
|
EOF
|
|
11
11
|
} from "./tokens.mjs";
|
|
12
|
-
|
|
13
|
-
import {
|
|
14
|
-
binopEval,
|
|
15
|
-
pathEval,
|
|
16
|
-
functionEval,
|
|
17
|
-
ASTTrue,
|
|
18
|
-
ASTBinop
|
|
19
|
-
} from "./ast.mjs";
|
|
12
|
+
import { pathEval, functionEval, ASTTrue, ASTBinop } from "./ast.mjs";
|
|
20
13
|
|
|
21
14
|
/**
|
|
22
15
|
*
|
|
@@ -104,11 +97,7 @@ export function parse(input, context = {}) {
|
|
|
104
97
|
return ASTBinop(last, left, expression(last.precedence - 1));
|
|
105
98
|
|
|
106
99
|
case "infix": {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
if (last.binop) {
|
|
110
|
-
return ASTBinop(last, left, right);
|
|
111
|
-
}
|
|
100
|
+
const right = expression(last.precedence);
|
|
112
101
|
|
|
113
102
|
if (last === DOT) {
|
|
114
103
|
if (left.path) {
|
|
@@ -124,16 +113,7 @@ export function parse(input, context = {}) {
|
|
|
124
113
|
return { eval: pathEval, path: [left.token, right.token] };
|
|
125
114
|
}
|
|
126
115
|
|
|
127
|
-
|
|
128
|
-
error("unexpected EOF");
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
return {
|
|
132
|
-
eval: binopEval,
|
|
133
|
-
token: last,
|
|
134
|
-
left,
|
|
135
|
-
right
|
|
136
|
-
};
|
|
116
|
+
return ASTBinop(last, left, right);
|
|
137
117
|
}
|
|
138
118
|
case "prefix":
|
|
139
119
|
switch (last) {
|
|
@@ -190,9 +170,9 @@ export function parse(input, context = {}) {
|
|
|
190
170
|
if (context.exec !== false && result?.eval) {
|
|
191
171
|
result = result.eval(result, context.root, context);
|
|
192
172
|
|
|
193
|
-
if (typeof result === "function") {
|
|
173
|
+
/*if (typeof result === "function") {
|
|
194
174
|
return [...result()];
|
|
195
|
-
}
|
|
175
|
+
}*/
|
|
196
176
|
}
|
|
197
177
|
|
|
198
178
|
return result;
|
package/types/ast.d.mts
CHANGED
|
@@ -1,17 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @typedef {Object} AST
|
|
3
|
-
* @property {Function} [eval]
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
*
|
|
7
|
-
* @param {Token} op
|
|
8
|
-
* @param {AST} left
|
|
9
|
-
* @param {AST} right
|
|
10
|
-
*
|
|
11
|
-
*/
|
|
12
|
-
export function binopError(op: Token, left: AST, right: AST): void;
|
|
13
1
|
export function binop(op: any, left: any, right: any, fallback: any): any;
|
|
14
|
-
export function binopEval(node: any, current: any, context: any): any;
|
|
15
2
|
export function ASTBinop(token: any, left: any, right: any): any;
|
|
16
3
|
export function pathEval(node: any, current: any, context: any): any;
|
|
17
4
|
export function functionEval(node: any, current: any, context: any): any;
|