nomen-lang 0.0.11 → 0.0.13
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/core/System/Array.nm +104 -9
- package/core/System/Buffer.nm +144 -0
- package/core/System/ClassBuffer.nm +143 -0
- package/core/System/Graph.nm +4 -5
- package/core/System/Init.nm +3 -1
- package/core/System/LinkedList.nm +4 -5
- package/core/System/List.nm +25 -7
- package/core/System/Map.nm +29 -19
- package/core/System/Option.nm +4 -0
- package/core/System/Result.nm +4 -0
- package/core/System/Set.nm +59 -13
- package/core/System/String.nm +27 -1
- package/core/System/Test.nm +1 -3
- package/core/System/Text/JsonTree.nm +11 -3
- package/core/System/Text/Regex.nm +4 -1
- package/core/System/bool.nm +12 -1
- package/core/System/char.nm +12 -1
- package/core/System/int.nm +12 -1
- package/core/System/int64.nm +12 -1
- package/core/System/int8.nm +12 -1
- package/core/System/uint.nm +12 -1
- package/core/System/uint64.nm +12 -1
- package/core/System/uint8.nm +12 -1
- package/core/docs/System/Init.md +2 -1
- package/core/docs/System/Option.md +23 -0
- package/core/docs/System/Result.md +19 -0
- package/dist/index.mjs +7252 -5266
- package/package.json +34 -33
- package/src/args.ts +11 -9
- package/src/index.ts +22 -16
package/package.json
CHANGED
|
@@ -1,34 +1,35 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
2
|
+
"name": "nomen-lang",
|
|
3
|
+
"version": "0.0.13",
|
|
4
|
+
"description": "The CLI for the Nomen programming language.",
|
|
5
|
+
"keywords": [],
|
|
6
|
+
"license": "ISC",
|
|
7
|
+
"author": "",
|
|
8
|
+
"bin": {
|
|
9
|
+
"nomen": "dist/index.mjs"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"src",
|
|
14
|
+
"core",
|
|
15
|
+
"NOMEN_AGENTS.md"
|
|
16
|
+
],
|
|
17
|
+
"type": "module",
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "node scripts/bundle-assets.mjs && vp pack",
|
|
20
|
+
"dev": "node scripts/bundle-assets.mjs && vp pack --watch",
|
|
21
|
+
"test": "vp test",
|
|
22
|
+
"check": "vp check",
|
|
23
|
+
"format": "vp check --fix",
|
|
24
|
+
"prepare": "vp config",
|
|
25
|
+
"go": "tsx src/index.ts",
|
|
26
|
+
"register": "pnpm build && pnpm add -g ."
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/node": "^26.2.0",
|
|
30
|
+
"chokidar": "^5.0.0",
|
|
31
|
+
"tsx": "^4.23.12",
|
|
32
|
+
"typescript": "^7.0.2",
|
|
33
|
+
"vite-plus": "catalog:"
|
|
34
|
+
}
|
|
35
|
+
}
|
package/src/args.ts
CHANGED
|
@@ -12,6 +12,10 @@ export interface Args {
|
|
|
12
12
|
audit: boolean;
|
|
13
13
|
audit_runtime?: string;
|
|
14
14
|
check: boolean;
|
|
15
|
+
// Everything after a bare `--` on the command line — forwarded verbatim to
|
|
16
|
+
// the compiled program by `nomen run`. Lets a program receive its own argv
|
|
17
|
+
// (`nomen run --in app/main.nm -- arg1 arg2`).
|
|
18
|
+
program_args: string[];
|
|
15
19
|
}
|
|
16
20
|
|
|
17
21
|
// Canonical option name for each accepted long/short spelling.
|
|
@@ -53,9 +57,8 @@ function set(args: Args, key: string, value: string | boolean): void {
|
|
|
53
57
|
|
|
54
58
|
/** Parse `argv` (excluding the node binary and script path) into an `Args` object. */
|
|
55
59
|
export function parse_args(argv: string[] = process.argv.slice(2)): Args {
|
|
56
|
-
const args: Args = { command: undefined, ...DEFAULTS } as Args;
|
|
60
|
+
const args: Args = { command: undefined, ...DEFAULTS, program_args: [] } as Args;
|
|
57
61
|
const positional: string[] = [];
|
|
58
|
-
let only_positional = false;
|
|
59
62
|
|
|
60
63
|
const next_value = (i: number, spelling: string): string => {
|
|
61
64
|
if (i + 1 >= argv.length) throw new Error(`Option ${spelling} requires a value`);
|
|
@@ -65,14 +68,12 @@ export function parse_args(argv: string[] = process.argv.slice(2)): Args {
|
|
|
65
68
|
for (let i = 0; i < argv.length; i++) {
|
|
66
69
|
const arg = argv[i];
|
|
67
70
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
|
|
71
|
+
// A bare `--` ends nomen's own option parsing; everything that follows
|
|
72
|
+
// is captured verbatim as the compiled program's argv (forwarded by
|
|
73
|
+
// `nomen run`). This matches the conventional `--` passthrough.
|
|
73
74
|
if (arg === "--") {
|
|
74
|
-
|
|
75
|
-
|
|
75
|
+
args.program_args = argv.slice(i + 1);
|
|
76
|
+
break;
|
|
76
77
|
}
|
|
77
78
|
|
|
78
79
|
if (arg === "-h" || arg === "--help") {
|
|
@@ -145,6 +146,7 @@ export function print_help(): void {
|
|
|
145
146
|
[
|
|
146
147
|
"Usage:",
|
|
147
148
|
" nomen run --in [file/folder] Parse, check, build and run a program",
|
|
149
|
+
" (args after a bare -- are forwarded to the program)",
|
|
148
150
|
" nomen build --in [file/folder] Parse, check and build (no run)",
|
|
149
151
|
" nomen check --in [file/folder] Parse and check only",
|
|
150
152
|
" nomen format [--in folder] Reformat every .nm file",
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
|
-
import { execSync } from "node:child_process";
|
|
2
|
+
import { execFileSync, execSync } from "node:child_process";
|
|
3
3
|
import fs from "node:fs";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
|
|
@@ -167,9 +167,9 @@ try {
|
|
|
167
167
|
// Is the --in path a folder
|
|
168
168
|
if (fs.lstatSync(args.in).isDirectory()) {
|
|
169
169
|
if (args.watch) {
|
|
170
|
-
watchPath(args.in, config, mode);
|
|
170
|
+
watchPath(args.in, config, mode, args.program_args);
|
|
171
171
|
} else {
|
|
172
|
-
processFolder(args.in, config, mode);
|
|
172
|
+
processFolder(args.in, config, mode, args.program_args);
|
|
173
173
|
}
|
|
174
174
|
} else {
|
|
175
175
|
// Process the supplied file
|
|
@@ -178,9 +178,9 @@ try {
|
|
|
178
178
|
// NOTE: We get add notifications for all watched files immediately
|
|
179
179
|
// TODO: Is this the case on Windows etc too?
|
|
180
180
|
if (args.watch) {
|
|
181
|
-
watchPath(args.in, config, mode);
|
|
181
|
+
watchPath(args.in, config, mode, args.program_args);
|
|
182
182
|
} else {
|
|
183
|
-
processFile(args.in, config, mode);
|
|
183
|
+
processFile(args.in, config, mode, args.program_args);
|
|
184
184
|
}
|
|
185
185
|
} else {
|
|
186
186
|
console.log("Unsupported file type: " + extname);
|
|
@@ -289,20 +289,20 @@ function compile_audit_runtime(config: Config, input_path: string, buildDir: str
|
|
|
289
289
|
return audit_obj;
|
|
290
290
|
}
|
|
291
291
|
|
|
292
|
-
function watchPath(p: string, config: Config, mode: Mode) {
|
|
292
|
+
function watchPath(p: string, config: Config, mode: Mode, program_args: string[]) {
|
|
293
293
|
chokidar.watch(p).on("all", (event, filePath) => {
|
|
294
294
|
if (shouldProcessFile(filePath)) {
|
|
295
|
-
processFile(filePath, config, mode);
|
|
295
|
+
processFile(filePath, config, mode, program_args);
|
|
296
296
|
}
|
|
297
297
|
});
|
|
298
298
|
}
|
|
299
299
|
|
|
300
|
-
function processFolder(folder: string, config: Config, mode: Mode) {
|
|
300
|
+
function processFolder(folder: string, config: Config, mode: Mode, program_args: string[]) {
|
|
301
301
|
const dir = fs.opendirSync(folder);
|
|
302
302
|
let dirent;
|
|
303
303
|
while ((dirent = dir.readSync()) !== null) {
|
|
304
304
|
if (shouldProcessFile(dirent.name)) {
|
|
305
|
-
processFile(path.join(folder, dirent.name), config, mode);
|
|
305
|
+
processFile(path.join(folder, dirent.name), config, mode, program_args);
|
|
306
306
|
// @ts-ignore
|
|
307
307
|
let _ = fs.watch;
|
|
308
308
|
}
|
|
@@ -314,7 +314,7 @@ function shouldProcessFile(filename: string) {
|
|
|
314
314
|
return path.extname(filename) === SUPPORTED_EXTENSION;
|
|
315
315
|
}
|
|
316
316
|
|
|
317
|
-
function processFile(filename: string, config: Config, mode: Mode) {
|
|
317
|
+
function processFile(filename: string, config: Config, mode: Mode, program_args: string[]) {
|
|
318
318
|
console.log("Processing", filename);
|
|
319
319
|
|
|
320
320
|
const arch = config.arch || "aarch64";
|
|
@@ -399,10 +399,16 @@ function processFile(filename: string, config: Config, mode: Mode) {
|
|
|
399
399
|
return;
|
|
400
400
|
}
|
|
401
401
|
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
402
|
+
// `run` executes the linked binary, forwarding any program args that
|
|
403
|
+
// followed a bare `--` on the nomen command line. execFileSync runs the
|
|
404
|
+
// binary directly (no shell), so the args are passed as real argv without
|
|
405
|
+
// shell-escaping concerns.
|
|
406
|
+
if (mode === "run") {
|
|
407
|
+
execFileSync(outfile, program_args, { stdio: "inherit" });
|
|
408
|
+
|
|
409
|
+
const runTime = performance.now();
|
|
410
|
+
console.log("");
|
|
411
|
+
console.log("");
|
|
412
|
+
console.log(`Completed in ${(runTime - startTime).toFixed(2)}ms`);
|
|
413
|
+
}
|
|
408
414
|
}
|