pacc 8.11.4 → 8.11.6
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 +1 -1
- package/src/tokens.mjs +15 -27
package/package.json
CHANGED
package/src/tokens.mjs
CHANGED
|
@@ -93,7 +93,7 @@ export /** @type {Token} */ const MINUS = createBinopToken(
|
|
|
93
93
|
(left, right) => left - right
|
|
94
94
|
);
|
|
95
95
|
|
|
96
|
-
MINUS.nud =
|
|
96
|
+
MINUS.nud = parser => -parser.expression(100);
|
|
97
97
|
|
|
98
98
|
export /** @type {Token} */ const STAR = createBinopToken(
|
|
99
99
|
"*",
|
|
@@ -148,34 +148,21 @@ export /** @type {Token} */ const OPEN_ROUND = createToken(
|
|
|
148
148
|
"(",
|
|
149
149
|
40,
|
|
150
150
|
"prefix",
|
|
151
|
-
|
|
152
|
-
const args =
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
left.eval = functionEval;
|
|
161
|
-
|
|
162
|
-
parser.advance();
|
|
163
|
-
|
|
151
|
+
(parser, left) => {
|
|
152
|
+
const args = parser.expression(0);
|
|
153
|
+
parser.expect(CLOSE_ROUND);
|
|
154
|
+
|
|
155
|
+
// TODO why is there a right side ?
|
|
156
|
+
const node = left.right || left;
|
|
157
|
+
node.eval = functionEval;
|
|
158
|
+
node.args = Array.isArray(args) ? args : [args];
|
|
159
|
+
|
|
164
160
|
return left;
|
|
165
161
|
},
|
|
166
162
|
parser => {
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
while (parser.token !== CLOSE_ROUND) {
|
|
170
|
-
sequence.push(parser.expression(0));
|
|
171
|
-
if (parser.token === COMMA) {
|
|
172
|
-
parser.advance();
|
|
173
|
-
}
|
|
174
|
-
}
|
|
163
|
+
const result = parser.expression(0);
|
|
175
164
|
parser.expect(CLOSE_ROUND);
|
|
176
|
-
|
|
177
|
-
// TODO always a sequence ?
|
|
178
|
-
return sequence.length > 1 ? sequence : sequence[0];
|
|
165
|
+
return result;
|
|
179
166
|
}
|
|
180
167
|
);
|
|
181
168
|
|
|
@@ -220,7 +207,8 @@ export /** @type {Token} */ const CLOSE_CURLY = createToken("}");
|
|
|
220
207
|
export /** @type {Token} */ const QUESTION = createToken("?", 20, "infix");
|
|
221
208
|
export /** @type {Token} */ const COLON = createToken(":", undefined, "infix");
|
|
222
209
|
export /** @type {Token} */ const SEMICOLON = createToken(";");
|
|
223
|
-
export /** @type {Token} */ const COMMA = createToken(",");
|
|
210
|
+
export /** @type {Token} */ const COMMA = createToken(",",20,"infix",(left,right)=>Array.isArray(left) ? [...left,right] : [left,right]);
|
|
211
|
+
|
|
224
212
|
export /** @type {Token} */ const DOT = createToken(
|
|
225
213
|
".",
|
|
226
214
|
80,
|
|
@@ -384,7 +372,7 @@ export function* tokens(string, options = {}) {
|
|
|
384
372
|
case "'":
|
|
385
373
|
switch (state) {
|
|
386
374
|
case "number":
|
|
387
|
-
yield [NUMBER,options.parseFloat(value)];
|
|
375
|
+
yield [NUMBER, options.parseFloat(value)];
|
|
388
376
|
case undefined:
|
|
389
377
|
startString(c);
|
|
390
378
|
break;
|