pacc 8.1.0 → 8.1.2

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 CHANGED
@@ -26,6 +26,8 @@ const result = getAttribute({ a: [0,{ b: 4 }]}, "a[1].b");
26
26
 
27
27
  ### Table of Contents
28
28
 
29
+ * [AST](#ast)
30
+ * [Properties](#properties)
29
31
  * [binopError](#binoperror)
30
32
  * [Parameters](#parameters)
31
33
  * [prepareAttributesDefinitions](#prepareattributesdefinitions)
@@ -37,7 +39,7 @@ const result = getAttribute({ a: [0,{ b: 4 }]}, "a[1].b");
37
39
  * [parseBytes](#parsebytes)
38
40
  * [Parameters](#parameters-4)
39
41
  * [AttributeDefinition](#attributedefinition)
40
- * [Properties](#properties)
42
+ * [Properties](#properties-1)
41
43
  * [default\_attribute](#default_attribute)
42
44
  * [default\_attribute](#default_attribute-1)
43
45
  * [default\_attribute](#default_attribute-2)
@@ -121,7 +123,7 @@ const result = getAttribute({ a: [0,{ b: 4 }]}, "a[1].b");
121
123
  * [Parameters](#parameters-18)
122
124
  * [lookup](#lookup)
123
125
  * [Token](#token)
124
- * [Properties](#properties-1)
126
+ * [Properties](#properties-2)
125
127
  * [createToken](#createtoken)
126
128
  * [Parameters](#parameters-19)
127
129
  * [PLUS](#plus)
@@ -153,17 +155,25 @@ const result = getAttribute({ a: [0,{ b: 4 }]}, "a[1].b");
153
155
  * [IDENTIFIER](#identifier)
154
156
  * [EOF](#eof)
155
157
  * [Type](#type)
156
- * [Properties](#properties-2)
158
+ * [Properties](#properties-3)
157
159
  * [raiseOnUnknownType](#raiseonunknowntype)
158
160
  * [Parameters](#parameters-20)
159
161
 
162
+ ## AST
163
+
164
+ Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)
165
+
166
+ ### Properties
167
+
168
+ * `eval` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)?** 
169
+
160
170
  ## binopError
161
171
 
162
172
  ### Parameters
163
173
 
164
174
  * `op` **[Token](#token)** 
165
- * `left` **AST** 
166
- * `right` **AST** 
175
+ * `left` **[AST](#ast)** 
176
+ * `right` **[AST](#ast)** 
167
177
 
168
178
  ## prepareAttributesDefinitions
169
179
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pacc",
3
- "version": "8.1.0",
3
+ "version": "8.1.2",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
package/src/ast.mjs CHANGED
@@ -72,55 +72,55 @@ export function binopEval(node, current, context) {
72
72
  }
73
73
 
74
74
  export function predicateIteratorEval(node, current, context) {
75
- if (current instanceof Set) {
76
- current = [...current];
77
- } else if (current instanceof Map) {
78
- current = [...current.values()];
75
+ if (current.values) {
76
+ current = current.values();
79
77
  }
78
+
80
79
  return current
81
80
  .filter(item => node.left.eval(node.left, item, context))
82
81
  .map(item => node.right.eval(node.right, item, context));
83
82
  }
84
83
 
85
84
  export function pathEval(node, current, context) {
86
- let result = current;
87
-
88
- for (const p of node.path) {
89
- switch (typeof p) {
85
+ for (const item of node.path) {
86
+ switch (typeof item) {
90
87
  case "string":
91
88
  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);
89
+ switch (typeof current) {
90
+ case "function":
91
+ {
92
+ const r = [];
93
+ for (const x of current()) {
94
+ r.push(x[item]);
95
+ }
96
+ current = r;
97
+ }
98
+ break;
99
+ case "undefined":
100
+ current = context.getGlobal(item);
101
+ break;
102
+ default:
103
+ if (current instanceof Map) {
104
+ current = current.get(item);
104
105
  } else {
105
- result = result[p] ?? context.getGlobal(p);
106
+ current = current[item] ?? context.getGlobal(item);
106
107
  }
107
- }
108
108
  }
109
109
  break;
110
110
  case "object":
111
- const r = result;
111
+ const r = current;
112
112
  function* filter() {
113
113
  for (const x of r) {
114
- if (p.eval(p, x, context)) {
114
+ if (item.eval(item, x, context)) {
115
115
  yield x;
116
116
  }
117
117
  }
118
118
  }
119
- result = filter;
119
+ current = filter;
120
120
  }
121
121
  }
122
122
 
123
- return result;
123
+ return current;
124
124
  }
125
125
 
126
126
  export function functionEval(node, current, context) {
@@ -63,6 +63,11 @@ export function parse(input, context = {}) {
63
63
  return node;
64
64
  }
65
65
  case OPEN_BRACKET: {
66
+ if(token === CLOSE_BRACKET) {
67
+ advance();
68
+ return { eval: () => true };
69
+ }
70
+
66
71
  const node = expression(0);
67
72
  expect(CLOSE_BRACKET);
68
73
  switch (typeof node) {
@@ -163,23 +168,21 @@ export function parse(input, context = {}) {
163
168
  }
164
169
  case "prefix":
165
170
  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
- }
171
+ case OPEN_ROUND: {
172
+ const args = [];
173
+ while (token !== CLOSE_ROUND) {
174
+ args.push(expression(0));
175
+ if (token === COMMA) {
176
+ advance();
174
177
  }
175
- left.args = args;
176
- left.eval = functionEval;
178
+ }
179
+ left.args = args;
180
+ left.eval = functionEval;
177
181
 
178
- advance();
182
+ advance();
179
183
 
180
- return left;
181
- }
182
- break;
184
+ return left;
185
+ }
183
186
  case OPEN_BRACKET: {
184
187
  const predicate = expression(0);
185
188
  expect(CLOSE_BRACKET);