pacc 8.11.3 → 8.11.5
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 +12 -28
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,38 +148,21 @@ export /** @type {Token} */ const OPEN_ROUND = createToken(
|
|
|
148
148
|
"(",
|
|
149
149
|
40,
|
|
150
150
|
"prefix",
|
|
151
|
-
|
|
152
|
-
const args =
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
if (parser.token === COMMA) {
|
|
156
|
-
parser.advance();
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
left.args = args;
|
|
151
|
+
(parser, left) => {
|
|
152
|
+
const args = parser.expression(0);
|
|
153
|
+
parser.expect(CLOSE_ROUND);
|
|
154
|
+
left.args = Array.isArray(args) ? args : [args];
|
|
160
155
|
left.eval = functionEval;
|
|
161
|
-
|
|
162
|
-
parser.advance();
|
|
163
|
-
|
|
164
156
|
return left;
|
|
165
157
|
},
|
|
166
158
|
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
|
-
}
|
|
159
|
+
const result = parser.expression(0);
|
|
175
160
|
parser.expect(CLOSE_ROUND);
|
|
176
|
-
|
|
177
|
-
// TODO always a sequence ?
|
|
178
|
-
return sequence.length > 1 ? sequence : sequence[0];
|
|
161
|
+
return result;
|
|
179
162
|
}
|
|
180
163
|
);
|
|
181
164
|
|
|
182
|
-
export /** @type {Token} */ const CLOSE_ROUND = createToken(")", 0
|
|
165
|
+
export /** @type {Token} */ const CLOSE_ROUND = createToken(")", 0);
|
|
183
166
|
export /** @type {Token} */ const OPEN_BRACKET = createToken(
|
|
184
167
|
"[",
|
|
185
168
|
10,
|
|
@@ -214,13 +197,14 @@ export /** @type {Token} */ const OPEN_BRACKET = createToken(
|
|
|
214
197
|
}
|
|
215
198
|
);
|
|
216
199
|
|
|
217
|
-
export /** @type {Token} */ const CLOSE_BRACKET = createToken("]", 0
|
|
200
|
+
export /** @type {Token} */ const CLOSE_BRACKET = createToken("]", 0);
|
|
218
201
|
export /** @type {Token} */ const OPEN_CURLY = createToken("{");
|
|
219
202
|
export /** @type {Token} */ const CLOSE_CURLY = createToken("}");
|
|
220
203
|
export /** @type {Token} */ const QUESTION = createToken("?", 20, "infix");
|
|
221
204
|
export /** @type {Token} */ const COLON = createToken(":", undefined, "infix");
|
|
222
205
|
export /** @type {Token} */ const SEMICOLON = createToken(";");
|
|
223
|
-
export /** @type {Token} */ const COMMA = createToken(",");
|
|
206
|
+
export /** @type {Token} */ const COMMA = createToken(",",20,"infix",(left,right)=>Array.isArray(left) ? [...left,right] : [left,right]);
|
|
207
|
+
|
|
224
208
|
export /** @type {Token} */ const DOT = createToken(
|
|
225
209
|
".",
|
|
226
210
|
80,
|
|
@@ -384,7 +368,7 @@ export function* tokens(string, options = {}) {
|
|
|
384
368
|
case "'":
|
|
385
369
|
switch (state) {
|
|
386
370
|
case "number":
|
|
387
|
-
yield [NUMBER,options.parseFloat(value)];
|
|
371
|
+
yield [NUMBER, options.parseFloat(value)];
|
|
388
372
|
case undefined:
|
|
389
373
|
startString(c);
|
|
390
374
|
break;
|