arc-lang 0.6.10 → 0.6.11
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/dist/interpreter.js +5 -4
- package/dist/lexer.js +13 -0
- package/package.json +1 -1
- package/stdlib/json.arc +7 -0
package/dist/interpreter.js
CHANGED
|
@@ -2562,10 +2562,11 @@ function evalExpr(expr, env) {
|
|
|
2562
2562
|
const right = evalExpr(expr.right, env);
|
|
2563
2563
|
switch (expr.op) {
|
|
2564
2564
|
case "+": {
|
|
2565
|
-
if (typeof left === "string"
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2565
|
+
if (typeof left === "string" && typeof right === "string") {
|
|
2566
|
+
return left + right;
|
|
2567
|
+
}
|
|
2568
|
+
if ((typeof left === "string" && typeof right !== "string") || (typeof left !== "string" && typeof right === "string")) {
|
|
2569
|
+
throw new ArcRuntimeError(`TypeError: cannot add ${typeof left} and ${typeof right} — use str() to convert, or ++ for string concatenation`, { code: ErrorCode.INVALID_OPERATOR, loc: expr.loc });
|
|
2569
2570
|
}
|
|
2570
2571
|
if (left === null || right === null)
|
|
2571
2572
|
throw new ArcRuntimeError(`TypeError: cannot add nil`, { code: ErrorCode.INVALID_OPERATOR, loc: expr.loc });
|
package/dist/lexer.js
CHANGED
|
@@ -338,6 +338,19 @@ export function lex(source) {
|
|
|
338
338
|
}
|
|
339
339
|
num += advance();
|
|
340
340
|
}
|
|
341
|
+
// Scientific notation: e.g. 1e10, 1.5e-3, 2E+6
|
|
342
|
+
if (i < source.length && (peek() === "e" || peek() === "E")) {
|
|
343
|
+
const next = peek(1);
|
|
344
|
+
if (next >= "0" && next <= "9" || next === "+" || next === "-") {
|
|
345
|
+
isFloat = true;
|
|
346
|
+
num += advance(); // consume e/E
|
|
347
|
+
if (peek() === "+" || peek() === "-")
|
|
348
|
+
num += advance(); // consume sign
|
|
349
|
+
while (i < source.length && peek() >= "0" && peek() <= "9") {
|
|
350
|
+
num += advance();
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
341
354
|
tokens.push(tok(isFloat ? TokenType.Float : TokenType.Int, num, sl, sc));
|
|
342
355
|
continue;
|
|
343
356
|
}
|
package/package.json
CHANGED
package/stdlib/json.arc
CHANGED
|
@@ -198,6 +198,13 @@ pub fn get_path(obj, path) {
|
|
|
198
198
|
for part in parts {
|
|
199
199
|
if type_of(current) == "map" {
|
|
200
200
|
current = current[part]
|
|
201
|
+
} el if type_of(current) == "list" {
|
|
202
|
+
let idx = int(part)
|
|
203
|
+
if idx != nil {
|
|
204
|
+
current = current[idx]
|
|
205
|
+
} el {
|
|
206
|
+
current = nil
|
|
207
|
+
}
|
|
201
208
|
} el {
|
|
202
209
|
current = nil
|
|
203
210
|
}
|