pacc 8.1.1 → 8.1.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pacc",
3
- "version": "8.1.1",
3
+ "version": "8.1.3",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
package/src/ast.mjs CHANGED
@@ -60,6 +60,10 @@ export function binop(op, left, right, fallback) {
60
60
  return fallback(op, left, right);
61
61
  }
62
62
 
63
+ export const ASTNodeTrue = {
64
+ eval: () => true
65
+ };
66
+
63
67
  export function binopEval(node, current, context) {
64
68
  return binop(
65
69
  node.token,
@@ -72,8 +76,7 @@ export function binopEval(node, current, context) {
72
76
  }
73
77
 
74
78
  export function predicateIteratorEval(node, current, context) {
75
-
76
- if(current.values) {
79
+ if (current.values) {
77
80
  current = current.values();
78
81
  }
79
82
 
@@ -83,44 +86,45 @@ export function predicateIteratorEval(node, current, context) {
83
86
  }
84
87
 
85
88
  export function pathEval(node, current, context) {
86
- let result = current;
87
-
88
- for (const p of node.path) {
89
- switch (typeof p) {
89
+ for (const item of node.path) {
90
+ switch (typeof item) {
90
91
  case "string":
91
92
  case "number":
92
- if (typeof result === "function") {
93
- const r = [];
94
- for (const x of result()) {
95
- r.push(x[p]);
96
- }
97
- result = r;
98
- } else {
99
- if (result === undefined) {
100
- result = context.getGlobal(p);
101
- } else {
102
- if (result instanceof Map) {
103
- result = result.get(p);
93
+ switch (typeof current) {
94
+ case "function":
95
+ {
96
+ const r = [];
97
+ for (const x of current()) {
98
+ r.push(x[item]);
99
+ }
100
+ current = r;
101
+ }
102
+ break;
103
+ case "undefined":
104
+ current = context.getGlobal(item);
105
+ break;
106
+ default:
107
+ if (current instanceof Map) {
108
+ current = current.get(item);
104
109
  } else {
105
- result = result[p] ?? context.getGlobal(p);
110
+ current = current[item] ?? context.getGlobal(item);
106
111
  }
107
- }
108
112
  }
109
113
  break;
110
114
  case "object":
111
- const r = result;
115
+ const r = current;
112
116
  function* filter() {
113
117
  for (const x of r) {
114
- if (p.eval(p, x, context)) {
118
+ if (item.eval(item, x, context)) {
115
119
  yield x;
116
120
  }
117
121
  }
118
122
  }
119
- result = filter;
123
+ current = filter;
120
124
  }
121
125
  }
122
126
 
123
- return result;
127
+ return current;
124
128
  }
125
129
 
126
130
  export function functionEval(node, current, context) {
@@ -16,7 +16,8 @@ import {
16
16
  binopEval,
17
17
  predicateIteratorEval,
18
18
  pathEval,
19
- functionEval
19
+ functionEval,
20
+ ASTNodeTrue
20
21
  } from "./ast.mjs";
21
22
 
22
23
  /**
@@ -63,6 +64,11 @@ export function parse(input, context = {}) {
63
64
  return node;
64
65
  }
65
66
  case OPEN_BRACKET: {
67
+ if(token === CLOSE_BRACKET) {
68
+ advance();
69
+ return ASTNodeTrue;
70
+ }
71
+
66
72
  const node = expression(0);
67
73
  expect(CLOSE_BRACKET);
68
74
  switch (typeof node) {
@@ -124,6 +130,7 @@ export function parse(input, context = {}) {
124
130
  case "string":
125
131
  case "number":
126
132
  case "bigint":
133
+ case "boolean":
127
134
  return binop(last, left, right, binopError);
128
135
  }
129
136
  }
@@ -163,23 +170,21 @@ export function parse(input, context = {}) {
163
170
  }
164
171
  case "prefix":
165
172
  switch (last) {
166
- case OPEN_ROUND:
167
- {
168
- const args = [];
169
- while (token !== CLOSE_ROUND) {
170
- args.push(expression(0));
171
- if (token === COMMA) {
172
- advance();
173
- }
173
+ case OPEN_ROUND: {
174
+ const args = [];
175
+ while (token !== CLOSE_ROUND) {
176
+ args.push(expression(0));
177
+ if (token === COMMA) {
178
+ advance();
174
179
  }
175
- left.args = args;
176
- left.eval = functionEval;
180
+ }
181
+ left.args = args;
182
+ left.eval = functionEval;
177
183
 
178
- advance();
184
+ advance();
179
185
 
180
- return left;
181
- }
182
- break;
186
+ return left;
187
+ }
183
188
  case OPEN_BRACKET: {
184
189
  const predicate = expression(0);
185
190
  expect(CLOSE_BRACKET);
package/types/ast.d.mts CHANGED
@@ -15,6 +15,9 @@ export function binopEval(node: any, current: any, context: any): any;
15
15
  export function predicateIteratorEval(node: any, current: any, context: any): any;
16
16
  export function pathEval(node: any, current: any, context: any): any;
17
17
  export function functionEval(node: any, current: any, context: any): any;
18
+ export namespace ASTNodeTrue {
19
+ function eval(): boolean;
20
+ }
18
21
  export type AST = {
19
22
  eval?: Function;
20
23
  };