pacc 4.9.0 → 4.9.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 CHANGED
@@ -122,6 +122,7 @@ const result = getAttribute({ a: [0,{ b: 4 }]}, "a[1].b");
122
122
  * [DOUBLE\_AMPERSAND](#double_ampersand)
123
123
  * [BAR](#bar)
124
124
  * [DOUBLE\_BAR](#double_bar)
125
+ * [EOF](#eof)
125
126
 
126
127
  ## prepareAttributesDefinitions
127
128
 
@@ -444,6 +445,8 @@ Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Globa
444
445
  ### Parameters
445
446
 
446
447
  * `str` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** 
448
+ * `precedence` (optional, default `0`)
449
+ * `type`  
447
450
 
448
451
  Returns **[Token](#token)** 
449
452
 
@@ -551,6 +554,10 @@ Type: [Token](#token)
551
554
 
552
555
  Type: [Token](#token)
553
556
 
557
+ ## EOF
558
+
559
+ Type: [Token](#token)
560
+
554
561
  # install
555
562
 
556
563
  With [npm](http://npmjs.org) do:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pacc",
3
- "version": "4.9.0",
3
+ "version": "4.9.1",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
@@ -21,6 +21,11 @@ import {
21
21
  export function parse(context) {
22
22
  let node, token;
23
23
 
24
+ function error(message) {
25
+ const error = new Error(message);
26
+ throw error;
27
+ }
28
+
24
29
  const advance = () => {
25
30
  const { value, done } = context.tokens.next();
26
31
  token = done ? EOF : value;
@@ -28,10 +33,7 @@ export function parse(context) {
28
33
 
29
34
  const expect = expected => {
30
35
  if (token !== expected) {
31
- const error = new Error(
32
- `unexpected '${token.str}' expecting '${expected.str}'`
33
- );
34
- throw error;
36
+ error(`unexpected '${token.str}' expecting '${expected.str}'`);
35
37
  }
36
38
  advance();
37
39
  };
@@ -52,6 +54,8 @@ export function parse(context) {
52
54
  }
53
55
  }
54
56
  return { token, left, right: expression(token.precedence) };
57
+ case "eof":
58
+ error("unexpected EOF");
55
59
  }
56
60
 
57
61
  switch (typeof token) {
@@ -85,9 +89,16 @@ export function parse(context) {
85
89
  left.path.push(...right.path);
86
90
  return left;
87
91
  }
92
+ if (typeof left === "number") {
93
+ right.path.unshift(left);
94
+ return right;
95
+ }
88
96
  return { path: [left.token, right.token] };
89
97
  }
90
98
 
99
+ if (right.token === EOF) {
100
+ error("unexpeced EOF");
101
+ }
91
102
  return {
92
103
  token,
93
104
  left,
package/src/tokens.mjs CHANGED
@@ -53,7 +53,7 @@ export /** @type {Token} */ const DOUBLE_AMPERSAND = createToken(
53
53
  );
54
54
  export /** @type {Token} */ const BAR = createToken("|");
55
55
  export /** @type {Token} */ const DOUBLE_BAR = createToken("||", 30, "infixr");
56
- export /** @type {Token} */ const EOF = createToken("EOF", -1);
56
+ export /** @type {Token} */ const EOF = createToken("EOF", -1, "eof");
57
57
 
58
58
  /**
59
59
  * Split property path into tokens