arc-lang 0.6.13 → 0.6.15
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/ast.d.ts +7 -1
- package/dist/interpreter.js +10 -2
- package/dist/parser.js +11 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -1
package/dist/ast.d.ts
CHANGED
|
@@ -182,7 +182,7 @@ export interface GroupExpr {
|
|
|
182
182
|
expr: Expr;
|
|
183
183
|
loc: Loc;
|
|
184
184
|
}
|
|
185
|
-
export type Pattern = WildcardPattern | LiteralPattern | BindingPattern | ArrayPattern | OrPattern | ConstructorPattern;
|
|
185
|
+
export type Pattern = WildcardPattern | LiteralPattern | BindingPattern | ArrayPattern | OrPattern | ConstructorPattern | RangePattern;
|
|
186
186
|
export interface WildcardPattern {
|
|
187
187
|
kind: "WildcardPattern";
|
|
188
188
|
loc: Loc;
|
|
@@ -213,6 +213,12 @@ export interface ConstructorPattern {
|
|
|
213
213
|
args: Pattern[];
|
|
214
214
|
loc: Loc;
|
|
215
215
|
}
|
|
216
|
+
export interface RangePattern {
|
|
217
|
+
kind: "RangePattern";
|
|
218
|
+
from: number;
|
|
219
|
+
to: number;
|
|
220
|
+
loc: Loc;
|
|
221
|
+
}
|
|
216
222
|
export type Stmt = LetStmt | FnStmt | ForStmt | DoStmt | WhileStmt | ExprStmt | UseStmt | TypeStmt | AssignStmt | MemberAssignStmt | IndexAssignStmt | RetStmt | BreakStmt | ContinueStmt | TryCatchStmt;
|
|
217
223
|
export interface AssignStmt {
|
|
218
224
|
kind: "AssignStmt";
|
package/dist/interpreter.js
CHANGED
|
@@ -236,13 +236,15 @@ function makePrelude(env) {
|
|
|
236
236
|
return null;
|
|
237
237
|
},
|
|
238
238
|
len: (v) => {
|
|
239
|
+
if (v === undefined || v === null)
|
|
240
|
+
throw new Error("len() requires an argument — pass a string, list, or map");
|
|
239
241
|
if (typeof v === "string")
|
|
240
242
|
return [...v].length; // codepoint count, not UTF-16
|
|
241
243
|
if (Array.isArray(v))
|
|
242
244
|
return v.length;
|
|
243
245
|
if (v && typeof v === "object" && "__map" in v)
|
|
244
246
|
return v.entries.size;
|
|
245
|
-
|
|
247
|
+
throw new Error("len() expects a string, list, or map — got " + typeof v);
|
|
246
248
|
},
|
|
247
249
|
map: (list, fn) => {
|
|
248
250
|
if (!Array.isArray(list))
|
|
@@ -2792,10 +2794,14 @@ function evalExpr(expr, env) {
|
|
|
2792
2794
|
if (idx !== Math.floor(idx))
|
|
2793
2795
|
throw new ArcRuntimeError("String index must be an integer");
|
|
2794
2796
|
let i = idx < 0 ? obj.length + idx : idx;
|
|
2795
|
-
|
|
2797
|
+
if (i < 0 || i >= obj.length)
|
|
2798
|
+
throw new ArcRuntimeError(`String index out of bounds: index ${idx} but length is ${obj.length}`);
|
|
2799
|
+
return obj.charAt(i);
|
|
2796
2800
|
}
|
|
2797
2801
|
if (Array.isArray(obj) && typeof idx === "number") {
|
|
2798
2802
|
let i = idx < 0 ? obj.length + idx : idx;
|
|
2803
|
+
if (i < 0 || i >= obj.length)
|
|
2804
|
+
throw new ArcRuntimeError(`Index out of bounds: index ${idx} but length is ${obj.length}`);
|
|
2799
2805
|
return obj[i] ?? null;
|
|
2800
2806
|
}
|
|
2801
2807
|
if (obj && typeof obj === "object" && "__map" in obj) {
|
|
@@ -2999,6 +3005,8 @@ function matchPattern(pattern, value, env) {
|
|
|
2999
3005
|
return false;
|
|
3000
3006
|
return pattern.elements.every((p, i) => matchPattern(p, value[i], env));
|
|
3001
3007
|
}
|
|
3008
|
+
case "RangePattern":
|
|
3009
|
+
return typeof value === "number" && value >= pattern.from && value <= pattern.to;
|
|
3002
3010
|
case "OrPattern":
|
|
3003
3011
|
return pattern.patterns.some(p => matchPattern(p, value, env));
|
|
3004
3012
|
case "ConstructorPattern": {
|
package/dist/parser.js
CHANGED
|
@@ -1026,7 +1026,17 @@ export class Parser {
|
|
|
1026
1026
|
}
|
|
1027
1027
|
if (t.type === TokenType.Int || t.type === TokenType.Float) {
|
|
1028
1028
|
this.advance();
|
|
1029
|
-
|
|
1029
|
+
const fromVal = parseFloat(t.value);
|
|
1030
|
+
if (this.at(TokenType.Range)) {
|
|
1031
|
+
this.advance();
|
|
1032
|
+
const toTok = this.peek();
|
|
1033
|
+
if (toTok.type !== TokenType.Int && toTok.type !== TokenType.Float) {
|
|
1034
|
+
throw new ParseError(`Expected number after '..' in range pattern`, this.loc());
|
|
1035
|
+
}
|
|
1036
|
+
this.advance();
|
|
1037
|
+
return { kind: "RangePattern", from: fromVal, to: parseFloat(toTok.value), loc };
|
|
1038
|
+
}
|
|
1039
|
+
return { kind: "LiteralPattern", value: fromVal, loc };
|
|
1030
1040
|
}
|
|
1031
1041
|
if (t.type === TokenType.String) {
|
|
1032
1042
|
this.advance();
|
package/dist/version.d.ts
CHANGED
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "arc-lang",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.15",
|
|
4
4
|
"description": "Arc ⚡ — A programming language designed by AI agents, for AI agents. 27-63% fewer tokens than JavaScript.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"scripts": {
|
|
17
17
|
"build": "tsc",
|
|
18
18
|
"copy-stdlib": "node -e \"const fs=require('fs');const p=require('path');function cp(s,d){fs.mkdirSync(d,{recursive:true});for(const f of fs.readdirSync(s)){const sp=p.join(s,f),dp=p.join(d,f);fs.statSync(sp).isDirectory()?cp(sp,dp):fs.copyFileSync(sp,dp)}}cp(p.join(__dirname,'..','stdlib'),p.join(__dirname,'stdlib'))\"",
|
|
19
|
+
"postinstall": "node -e \"console.log('\\n ⚡ Arc installed! Try: arc repl\\n Docs: https://docs.arclang.dev\\n Playground: https://play.arclang.dev\\n')\"",
|
|
19
20
|
"prepublishOnly": "npm run copy-stdlib && tsc",
|
|
20
21
|
"run": "tsx src/index.ts run",
|
|
21
22
|
"parse": "tsx src/index.ts parse"
|