arc-lang 0.6.1 → 0.6.3
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 +30 -2
- package/dist/build.js +1 -1
- package/dist/index.js +104 -0
- package/dist/interpreter.js +385 -68
- package/dist/lexer.d.ts +41 -37
- package/dist/lexer.js +47 -39
- package/dist/modules.js +5 -1
- package/dist/parser.d.ts +2 -0
- package/dist/parser.js +76 -11
- package/dist/repl.js +63 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +4 -2
- package/stdlib/API_DESIGN.md +357 -0
- package/stdlib/ASYNC_DESIGN.md +815 -0
- package/stdlib/EXAMPLES.md +710 -0
- package/stdlib/MODULES.md +854 -0
- package/stdlib/README.md +64 -0
- package/stdlib/collections.arc +140 -0
- package/stdlib/crypto.arc +62 -0
- package/stdlib/csv.arc +40 -0
- package/stdlib/datetime.arc +75 -0
- package/stdlib/embed.arc +42 -0
- package/stdlib/env.arc +10 -0
- package/stdlib/error.arc +36 -0
- package/stdlib/html.arc +30 -0
- package/stdlib/http.arc +43 -0
- package/stdlib/io.arc +28 -0
- package/stdlib/json.arc +204 -0
- package/stdlib/llm.arc +193 -0
- package/stdlib/log.arc +20 -0
- package/stdlib/map.arc +72 -0
- package/stdlib/math.arc +133 -0
- package/stdlib/net.arc +17 -0
- package/stdlib/os.arc +81 -0
- package/stdlib/path.arc +11 -0
- package/stdlib/prompt.arc +49 -0
- package/stdlib/regex.arc +59 -0
- package/stdlib/result.arc +50 -0
- package/stdlib/store.arc +62 -0
- package/stdlib/strings.arc +44 -0
- package/stdlib/test.arc +61 -0
- package/stdlib/time.arc +19 -0
- package/stdlib/toml.arc +10 -0
- package/stdlib/yaml.arc +10 -0
package/dist/ast.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export interface Loc {
|
|
|
2
2
|
line: number;
|
|
3
3
|
col: number;
|
|
4
4
|
}
|
|
5
|
-
export type Expr = IntLiteral | FloatLiteral | BoolLiteral | NilLiteral | StringLiteral | StringInterp | Identifier | BinaryExpr | UnaryExpr | CallExpr | MemberExpr | IndexExpr | PipelineExpr | IfExpr | MatchExpr | LambdaExpr | ListLiteral | MapLiteral | ListComprehension | ToolCallExpr | RangeExpr | BlockExpr | AsyncExpr | AwaitExpr | FetchExpr | SpreadExpr | OptionalMemberExpr | TryExpr;
|
|
5
|
+
export type Expr = IntLiteral | FloatLiteral | BoolLiteral | NilLiteral | StringLiteral | StringInterp | Identifier | BinaryExpr | UnaryExpr | CallExpr | MemberExpr | IndexExpr | PipelineExpr | IfExpr | MatchExpr | LambdaExpr | ListLiteral | MapLiteral | ListComprehension | ToolCallExpr | RangeExpr | BlockExpr | AsyncExpr | AwaitExpr | FetchExpr | SpreadExpr | OptionalMemberExpr | TryExpr | TryCatchExpr;
|
|
6
6
|
export interface IntLiteral {
|
|
7
7
|
kind: "IntLiteral";
|
|
8
8
|
value: number;
|
|
@@ -170,6 +170,13 @@ export interface TryExpr {
|
|
|
170
170
|
expr: Expr;
|
|
171
171
|
loc: Loc;
|
|
172
172
|
}
|
|
173
|
+
export interface TryCatchExpr {
|
|
174
|
+
kind: "TryCatchExpr";
|
|
175
|
+
body: Expr;
|
|
176
|
+
catchVar: string;
|
|
177
|
+
catchBody: Expr;
|
|
178
|
+
loc: Loc;
|
|
179
|
+
}
|
|
173
180
|
export type Pattern = WildcardPattern | LiteralPattern | BindingPattern | ArrayPattern | OrPattern | ConstructorPattern;
|
|
174
181
|
export interface WildcardPattern {
|
|
175
182
|
kind: "WildcardPattern";
|
|
@@ -201,7 +208,7 @@ export interface ConstructorPattern {
|
|
|
201
208
|
args: Pattern[];
|
|
202
209
|
loc: Loc;
|
|
203
210
|
}
|
|
204
|
-
export type Stmt = LetStmt | FnStmt | ForStmt | DoStmt | ExprStmt | UseStmt | TypeStmt | AssignStmt | MemberAssignStmt | IndexAssignStmt | RetStmt;
|
|
211
|
+
export type Stmt = LetStmt | FnStmt | ForStmt | DoStmt | WhileStmt | ExprStmt | UseStmt | TypeStmt | AssignStmt | MemberAssignStmt | IndexAssignStmt | RetStmt | BreakStmt | ContinueStmt | TryCatchStmt;
|
|
205
212
|
export interface AssignStmt {
|
|
206
213
|
kind: "AssignStmt";
|
|
207
214
|
target: string;
|
|
@@ -270,6 +277,27 @@ export interface DoStmt {
|
|
|
270
277
|
isWhile: boolean;
|
|
271
278
|
loc: Loc;
|
|
272
279
|
}
|
|
280
|
+
export interface WhileStmt {
|
|
281
|
+
kind: "WhileStmt";
|
|
282
|
+
condition: Expr;
|
|
283
|
+
body: Expr;
|
|
284
|
+
loc: Loc;
|
|
285
|
+
}
|
|
286
|
+
export interface BreakStmt {
|
|
287
|
+
kind: "BreakStmt";
|
|
288
|
+
loc: Loc;
|
|
289
|
+
}
|
|
290
|
+
export interface ContinueStmt {
|
|
291
|
+
kind: "ContinueStmt";
|
|
292
|
+
loc: Loc;
|
|
293
|
+
}
|
|
294
|
+
export interface TryCatchStmt {
|
|
295
|
+
kind: "TryCatchStmt";
|
|
296
|
+
body: Expr;
|
|
297
|
+
catchVar: string;
|
|
298
|
+
catchBody: Expr;
|
|
299
|
+
loc: Loc;
|
|
300
|
+
}
|
|
273
301
|
export interface ExprStmt {
|
|
274
302
|
kind: "ExprStmt";
|
|
275
303
|
expr: Expr;
|
package/dist/build.js
CHANGED
|
@@ -127,7 +127,7 @@ export function newProject(name, parentDir) {
|
|
|
127
127
|
"dev-dependencies": {},
|
|
128
128
|
};
|
|
129
129
|
writeFileSync(resolve(projectDir, "arc.toml"), serializeArcToml(toml));
|
|
130
|
-
writeFileSync(resolve(projectDir, "src", "main.arc"),
|
|
130
|
+
writeFileSync(resolve(projectDir, "src", "main.arc"), `# Hello from ${name}!\nlet msg = "Hello from ${name}!"\nprint(msg)\n`);
|
|
131
131
|
writeFileSync(resolve(projectDir, "tests", "main.test.arc"), `fn test_main() {\n let x = 1 + 1\n print(x)\n}\n`);
|
|
132
132
|
writeFileSync(resolve(projectDir, "README.md"), `# ${name}\n\nAn Arc project.\n\n## Getting Started\n\n\`\`\`bash\narc build\narc run\n\`\`\`\n`);
|
|
133
133
|
console.log(`Created project '${name}'`);
|
package/dist/index.js
CHANGED
|
@@ -101,6 +101,108 @@ else if (command === "pkg") {
|
|
|
101
101
|
process.exit(1);
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
|
+
else if (command === "builtins") {
|
|
105
|
+
console.log("Arc Built-in Functions\n");
|
|
106
|
+
console.log("I/O:");
|
|
107
|
+
console.log(" print(...values) Print values to stdout\n");
|
|
108
|
+
console.log("Type Conversion:");
|
|
109
|
+
console.log(" int(v) Convert to integer (throws on bad input)");
|
|
110
|
+
console.log(" float(v) Convert to float (throws on bad input)");
|
|
111
|
+
console.log(" str(v) Convert to string");
|
|
112
|
+
console.log(" bool(v) Convert to boolean");
|
|
113
|
+
console.log(" type_of(v) Get type: \"int\" \"float\" \"string\" \"bool\" \"list\" \"map\" \"fn\" \"nil\"\n");
|
|
114
|
+
console.log("Strings:");
|
|
115
|
+
console.log(" len(s) Length (codepoints, not bytes)");
|
|
116
|
+
console.log(" trim(s) Strip whitespace");
|
|
117
|
+
console.log(" upper(s) / lower(s) Case conversion");
|
|
118
|
+
console.log(" split(s, sep) Split into list");
|
|
119
|
+
console.log(" join(list, sep) Join list into string");
|
|
120
|
+
console.log(" replace(s, old, new) Replace all occurrences");
|
|
121
|
+
console.log(" contains(s, sub) Check substring");
|
|
122
|
+
console.log(" starts(s, prefix) Starts with");
|
|
123
|
+
console.log(" ends(s, suffix) Ends with");
|
|
124
|
+
console.log(" repeat(s, n) Repeat string n times");
|
|
125
|
+
console.log(" chars(s) Split into character list");
|
|
126
|
+
console.log(" slice(s, start, end?) Substring");
|
|
127
|
+
console.log(" index_of(s, sub) Find index (nil if not found)");
|
|
128
|
+
console.log(" ord(s) Char to code point");
|
|
129
|
+
console.log(" chr(n) Code point to char");
|
|
130
|
+
console.log(" char_at(s, i) Character at index\n");
|
|
131
|
+
console.log("Lists:");
|
|
132
|
+
console.log(" len(list) Length");
|
|
133
|
+
console.log(" map(list, fn) Transform each element");
|
|
134
|
+
console.log(" filter(list, fn) Keep elements matching predicate");
|
|
135
|
+
console.log(" reduce(list, fn, init) Fold left");
|
|
136
|
+
console.log(" fold(list, init, fn) Fold (init-first arg order)");
|
|
137
|
+
console.log(" find(list, fn) First matching element");
|
|
138
|
+
console.log(" any(list, fn) Any element matches?");
|
|
139
|
+
console.log(" all(list, fn) All elements match?");
|
|
140
|
+
console.log(" sort(list) Sort (numbers or strings)");
|
|
141
|
+
console.log(" head(list) First element");
|
|
142
|
+
console.log(" tail(list) All but first");
|
|
143
|
+
console.log(" last(list) Last element");
|
|
144
|
+
console.log(" reverse(list) Reverse");
|
|
145
|
+
console.log(" take(list, n) First n elements");
|
|
146
|
+
console.log(" drop(list, n) Skip first n");
|
|
147
|
+
console.log(" flat(list) Flatten nested lists");
|
|
148
|
+
console.log(" zip(a, b) Zip two lists");
|
|
149
|
+
console.log(" enumerate(list) Add indices: [[0,a],[1,b],...]");
|
|
150
|
+
console.log(" push(list, item) Append (returns new list)");
|
|
151
|
+
console.log(" concat(a, b) Concatenate lists");
|
|
152
|
+
console.log(" sum(list) Sum numbers");
|
|
153
|
+
console.log(" range(a, b) Generate [a, a+1, ..., b-1]\n");
|
|
154
|
+
console.log("Maps:");
|
|
155
|
+
console.log(" keys(map) Get keys as list");
|
|
156
|
+
console.log(" values(map) Get values as list");
|
|
157
|
+
console.log(" entries(map) Key-value pairs\n");
|
|
158
|
+
console.log("Math:");
|
|
159
|
+
console.log(" abs(n) Absolute value");
|
|
160
|
+
console.log(" min(...) / max(...) Min/max (args or list)");
|
|
161
|
+
console.log(" round(n) Round to integer\n");
|
|
162
|
+
console.log("Other:");
|
|
163
|
+
console.log(" assert(cond, msg?) Assert truth (throws on false)");
|
|
164
|
+
console.log(" time_ms() Unix timestamp in milliseconds\n");
|
|
165
|
+
console.log("Operators: + - * / % ** ++ == != < > <= >= and or not |> .. ?.");
|
|
166
|
+
console.log("Strings: \"text {expr}\" (interpolation) \"ha\" * 3 (repetition)");
|
|
167
|
+
console.log("Comments: # or //");
|
|
168
|
+
console.log("Errors: try { ... } catch e { ... }\n");
|
|
169
|
+
console.log("Stdlib: arc builtins --modules (list all standard library modules)");
|
|
170
|
+
if (args.includes("--modules")) {
|
|
171
|
+
console.log("\nStandard Library Modules: (import with: use <module>)\n");
|
|
172
|
+
const mods = [
|
|
173
|
+
["math", "sqrt, pow, ceil, floor, clamp, PI, E, sin, cos, log, 25 functions"],
|
|
174
|
+
["strings", "pad_left, pad_right, capitalize, words"],
|
|
175
|
+
["collections", "group_by, chunk, flatten, zip_with, partition, sort_by, unique"],
|
|
176
|
+
["map", "merge, map_values, filter_map, from_pairs, pick, omit"],
|
|
177
|
+
["io", "read_file, write_file, read_lines, exists, append"],
|
|
178
|
+
["http", "get, post, put, delete — real HTTP requests"],
|
|
179
|
+
["json", "to_json, from_json, pretty, get_path"],
|
|
180
|
+
["csv", "parse_csv, to_csv, parse_csv_headers"],
|
|
181
|
+
["regex", "match, find, test, replace, split, capture"],
|
|
182
|
+
["datetime", "now, today, parse, format, add_days, diff_days"],
|
|
183
|
+
["os", "cwd, list_dir, mkdir, exec, platform, env, remove, copy"],
|
|
184
|
+
["env", "get, set, has, all — environment variables"],
|
|
185
|
+
["crypto", "sha256, sha512, hmac_sha256, uuid, random_bytes"],
|
|
186
|
+
["error", "try_catch, try_finally, throw, retry, assert"],
|
|
187
|
+
["result", "ok, err, is_ok, unwrap, map_result, try_fn"],
|
|
188
|
+
["net", "ws_connect, tcp_connect, dns_lookup, base64_encode"],
|
|
189
|
+
["yaml", "parse, stringify"],
|
|
190
|
+
["toml", "parse, stringify"],
|
|
191
|
+
["html", "parse, create_element, to_html"],
|
|
192
|
+
["path", "join, dirname, basename, extname"],
|
|
193
|
+
["log", "info, warn, error, debug"],
|
|
194
|
+
["store", "get, set, delete — persistent key-value storage"],
|
|
195
|
+
["test", "describe, it, expect_eq, run_tests"],
|
|
196
|
+
["prompt", "template, count_tokens, window"],
|
|
197
|
+
["embed", "similarity, cosine, search"],
|
|
198
|
+
["llm", "chat, complete — multi-provider LLM API"],
|
|
199
|
+
];
|
|
200
|
+
for (const [name, desc] of mods) {
|
|
201
|
+
console.log(` ${name.padEnd(14)} ${desc}`);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
process.exit(0);
|
|
205
|
+
}
|
|
104
206
|
else if (command === "help" || command === "--help" || command === "-h" || !command || !file) {
|
|
105
207
|
console.log(`Arc ${ARC_VERSION} — A programming language designed by AI agents, for AI agents.\n`);
|
|
106
208
|
console.log("Usage: arc <command> [options]\n");
|
|
@@ -117,6 +219,8 @@ else if (command === "help" || command === "--help" || command === "-h" || !comm
|
|
|
117
219
|
console.log(" build Build the current project");
|
|
118
220
|
console.log(" test Run project tests");
|
|
119
221
|
console.log(" new <name> Create a new project");
|
|
222
|
+
console.log(" builtins List all built-in functions");
|
|
223
|
+
console.log(" builtins --modules List all standard library modules");
|
|
120
224
|
console.log(" pkg <sub> Package manager (init|add|remove|list|install)");
|
|
121
225
|
console.log(" version Print version info");
|
|
122
226
|
console.log("\nOptions:");
|