nomen-lang 0.0.7 → 0.0.9

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.
Files changed (118) hide show
  1. package/NOMEN_AGENTS.md +235 -0
  2. package/core/System/Ansi.nm +150 -0
  3. package/core/System/Array.nm +358 -0
  4. package/core/System/BigInt.nm +887 -0
  5. package/core/System/Buffer.nm +526 -0
  6. package/core/System/Channel.nm +198 -0
  7. package/core/System/ClassBuffer.nm +229 -0
  8. package/core/System/Console.nm +211 -0
  9. package/core/System/Controls/Button.nm +138 -0
  10. package/core/System/Controls/CheckBox.nm +158 -0
  11. package/core/System/Controls/Container.nm +1562 -0
  12. package/core/System/Controls/Control.nm +28 -0
  13. package/core/System/Controls/Geometry.nm +101 -0
  14. package/core/System/Controls/Layout.nm +228 -0
  15. package/core/System/Controls/LayoutParams.nm +50 -0
  16. package/core/System/Controls/Text.nm +129 -0
  17. package/core/System/Controls/TextBox.nm +157 -0
  18. package/core/System/Controls/Window.nm +280 -0
  19. package/core/System/Disposable.nm +8 -0
  20. package/core/System/Enumerable.nm +10 -0
  21. package/core/System/Equatable.nm +10 -0
  22. package/core/System/Graph.nm +68 -0
  23. package/core/System/Hashable.nm +13 -0
  24. package/core/System/Init.nm +21 -0
  25. package/core/System/LinkedList.nm +64 -0
  26. package/core/System/List.nm +44 -0
  27. package/core/System/Map.nm +153 -0
  28. package/core/System/Math.nm +54 -0
  29. package/core/System/Mutex.nm +78 -0
  30. package/core/System/Nursery.nm +27 -0
  31. package/core/System/Sendable.nm +9 -0
  32. package/core/System/Set.nm +97 -0
  33. package/core/System/Stream/Directory.nm +176 -0
  34. package/core/System/Stream/File.nm +432 -0
  35. package/core/System/Stream/Http.nm +453 -0
  36. package/core/System/String.nm +154 -0
  37. package/core/System/StringBuilder.nm +249 -0
  38. package/core/System/Stringable.nm +8 -0
  39. package/core/System/Task.nm +263 -0
  40. package/core/System/Test.nm +241 -0
  41. package/core/System/Text/Json.nm +377 -0
  42. package/core/System/Text/JsonTree.nm +187 -0
  43. package/core/System/Text/Regex.nm +655 -0
  44. package/core/System/Time.nm +112 -0
  45. package/core/System/Tree.nm +70 -0
  46. package/core/System/Viewable.nm +27 -0
  47. package/core/System/bool.nm +66 -0
  48. package/core/System/char.nm +42 -0
  49. package/core/System/float.nm +43 -0
  50. package/core/System/int.nm +54 -0
  51. package/core/System/int64.nm +42 -0
  52. package/core/System/int8.nm +42 -0
  53. package/core/System/uint.nm +42 -0
  54. package/core/System/uint64.nm +42 -0
  55. package/core/System/uint8.nm +42 -0
  56. package/core/docs/System/Ansi.md +40 -0
  57. package/core/docs/System/Array.md +16 -0
  58. package/core/docs/System/BigInt.md +30 -0
  59. package/core/docs/System/Buffer.md +31 -0
  60. package/core/docs/System/Channel.md +10 -0
  61. package/core/docs/System/ClassBuffer.md +15 -0
  62. package/core/docs/System/Console.md +13 -0
  63. package/core/docs/System/Controls/Button.md +12 -0
  64. package/core/docs/System/Controls/CheckBox.md +15 -0
  65. package/core/docs/System/Controls/Container.md +82 -0
  66. package/core/docs/System/Controls/Control.md +5 -0
  67. package/core/docs/System/Controls/Geometry.md +26 -0
  68. package/core/docs/System/Controls/Layout.md +37 -0
  69. package/core/docs/System/Controls/LayoutParams.md +13 -0
  70. package/core/docs/System/Controls/Text.md +12 -0
  71. package/core/docs/System/Controls/TextBox.md +13 -0
  72. package/core/docs/System/Controls/Window.md +20 -0
  73. package/core/docs/System/Disposable.md +5 -0
  74. package/core/docs/System/Enumerable.md +5 -0
  75. package/core/docs/System/Graph.md +17 -0
  76. package/core/docs/System/Init.md +9 -0
  77. package/core/docs/System/LinkedList.md +16 -0
  78. package/core/docs/System/List.md +13 -0
  79. package/core/docs/System/Map.md +14 -0
  80. package/core/docs/System/Math.md +11 -0
  81. package/core/docs/System/Mutex.md +10 -0
  82. package/core/docs/System/Nursery.md +5 -0
  83. package/core/docs/System/Sendable.md +5 -0
  84. package/core/docs/System/Set.md +14 -0
  85. package/core/docs/System/Stream/Directory.md +12 -0
  86. package/core/docs/System/Stream/File.md +21 -0
  87. package/core/docs/System/String.md +14 -0
  88. package/core/docs/System/StringBuilder.md +12 -0
  89. package/core/docs/System/Stringable.md +5 -0
  90. package/core/docs/System/Task.md +15 -0
  91. package/core/docs/System/Text/Json.md +12 -0
  92. package/core/docs/System/Text/JsonTree.md +21 -0
  93. package/core/docs/System/Text/Regex.md +12 -0
  94. package/core/docs/System/Time.md +11 -0
  95. package/core/docs/System/Tree.md +18 -0
  96. package/core/docs/System/Viewable.md +5 -0
  97. package/core/docs/System/bool.md +9 -0
  98. package/core/docs/System/char.md +9 -0
  99. package/core/docs/System/float.md +9 -0
  100. package/core/docs/System/int.md +10 -0
  101. package/core/docs/System/int64.md +9 -0
  102. package/core/docs/System/int8.md +9 -0
  103. package/core/docs/System/uint.md +9 -0
  104. package/core/docs/System/uint64.md +9 -0
  105. package/core/docs/System/uint8.md +9 -0
  106. package/core/package.jsonc +4 -0
  107. package/dist/index.mjs +548 -5489
  108. package/package.json +33 -30
  109. package/src/args.ts +171 -0
  110. package/src/index.ts +55 -106
  111. package/src/init.ts +128 -0
  112. package/src/test.ts +20 -8
  113. package/test/fixtures/build/calc.test +0 -0
  114. package/test/fixtures/build/calc.test.c +0 -969
  115. package/test/fixtures/build/main.h +0 -170
  116. package/test/fixtures/calc.test.nm +0 -32
  117. package/tsconfig.json +0 -21
  118. package/vite.config.ts +0 -7
@@ -0,0 +1,235 @@
1
+ # AGENTS.md
2
+
3
+ This is a [Nomen](https://github.com/andrewjk/nomen) project. This file orients
4
+ coding agents working in this codebase.
5
+
6
+ ## Commands
7
+
8
+ ```bash
9
+ nomen run # build + run src/main.nm
10
+ nomen build # build only (no run); emits build/
11
+ nomen check # parse + type-check only (fastest verification)
12
+ nomen test # discover and run every *.test.nm
13
+ nomen format # reformat every .nm file in place
14
+ nomen docs # generate markdown docs into docs/
15
+ ```
16
+
17
+ Flags worth knowing:
18
+
19
+ - `--in <path>` override the entry file/folder
20
+ - `--arch c` emit C instead of AArch64 assembly
21
+ - `--platform macos|ios|linux|android|windows|web` target platform
22
+ - `--watch` rebuild on change
23
+ - `-f <regex>` filter which test files run
24
+
25
+ ## Review Checklist
26
+
27
+ - [ ] `nomen check` passes (fast; catches parse + type errors)
28
+ - [ ] `nomen test` passes
29
+ - [ ] `nomen format` produces no diffs (run it, then re-`check`)
30
+
31
+ ## Language Directives
32
+
33
+ The rules below trip up newcomers and LLMs. Follow them.
34
+
35
+ ### Prefer implicit types
36
+
37
+ Nomen infers types from initializers and return values. Don't spell them out
38
+ unless the inference would be wrong or the annotation materially aids a public
39
+ API.
40
+
41
+ ```nomen
42
+ const x = 5 // good — inferred int
43
+ const int x = 5 // avoid
44
+ const msg = "hi" // good
45
+ var items = [1, 2, 3] // good — int[]
46
+ ```
47
+
48
+ Annotate when you need a wider type (`int64` rather than `int`), when there is
49
+ no initializer, or on a `pub` API where the type is the contract.
50
+
51
+ ### No `else if` — use `switch` or separate `if`s
52
+
53
+ Nomen forbids `else if` and `else { if { … } }` chains. Use a `switch` for
54
+ related conditions, or pull each condition into its own top-level `if`.
55
+
56
+ ### Constraints are compile-time assertions
57
+
58
+ `name: <bool expr>` after a parameter, field, or variable. Only evaluated when
59
+ the value is a compile-time constant; constraints on fields propagate to the
60
+ auto-generated `#init` parameters.
61
+
62
+ ```nomen
63
+ func div = (int a, int b: b != 0, out int) => a / b
64
+ func safe = (string[] s, int i: i >= 0 && i < s.length, out string) {
65
+ return s.at(i)
66
+ }
67
+ ```
68
+
69
+ ### Memory modifiers
70
+
71
+ | Modifier | Meaning |
72
+ | -------- | ---------------------------------------------- |
73
+ | `ref T` | mutable borrow; caller must also write `ref` |
74
+ | `view T` | read-only borrow |
75
+ | `mov T` | transfer ownership; caller writes `mov` |
76
+ | `out T` | output parameter, assigned inside the function |
77
+
78
+ `const` values cannot be passed to `ref` — rebind the caller as `var` first.
79
+
80
+ ### Return types are `out` at the end
81
+
82
+ A function's return type is written as a final, unnamed `out T` parameter:
83
+
84
+ ```nomen
85
+ func add = (int a, int b, out int) => a + b
86
+ func greet = (string name, out void) { Console.write("hi \{name}\n") }
87
+ ```
88
+
89
+ `out void` may be omitted.
90
+
91
+ ### Nullable tracking is static
92
+
93
+ `T?` is nullable. The compiler tracks nullness flow; using a variable that is
94
+ currently `null` is a **compile error**, not a runtime one.
95
+
96
+ ```nomen
97
+ var int? x = null
98
+ const y = x + 1 // Error: 'x' is null
99
+ ```
100
+
101
+ ### Visibility
102
+
103
+ `pub` exports; everything else is module-private. There is no `private` keyword.
104
+
105
+ ### Imports
106
+
107
+ ```nomen
108
+ import System // standard library
109
+ import System/Test // submodule
110
+ import System/Collections/List // specific module
111
+ ```
112
+
113
+ ### No exceptions
114
+
115
+ Failures are signalled via return values — nullable results, status structs,
116
+ or boolean + out-parameter pairs. There is no `throw`/`try`/`catch`.
117
+
118
+ ## Tests
119
+
120
+ A test is any `pub func <name> = (ref Tester t)` in a `*.test.nm` file.
121
+ Use `t.expect(cond, "msg")` for assertions and `t.bench("label", fn)` for
122
+ benchmarks.
123
+
124
+ ```nomen
125
+ import System
126
+ import System/Test
127
+
128
+ func add = (int a, int b, out int) => a + b
129
+
130
+ func add_once = () {
131
+ const int r = add(1, 1)
132
+ }
133
+
134
+ pub func test_add = (ref Tester t) {
135
+ t.expect(add(1, 1) == 2, "1 + 1 should be 2")
136
+ }
137
+
138
+ pub func bench_add = (ref Tester t) {
139
+ t.bench("add", add_once)
140
+ }
141
+ ```
142
+
143
+ ## Quick Syntax Reference
144
+
145
+ ### Declarations
146
+
147
+ ```nomen
148
+ const x = 5 // immutable
149
+ var int y = 10 // mutable, explicit type
150
+ const int[] nums = [1, 2, 3]
151
+ const int[10] buf = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] // fixed-length
152
+ var int? maybe = null // nullable
153
+ ref int ptr // reference to an int
154
+ ```
155
+
156
+ ### Functions
157
+
158
+ ```nomen
159
+ func add = (int a, int b, out int) => a + b // expression body
160
+ func greet = (string name) { // block body; out void omitted
161
+ Console.write("hi \{name}\n")
162
+ }
163
+ pub func main = (Init init) { ... } // program entry point
164
+ ```
165
+
166
+ Special function names: `#init` (constructor), `#destroy` (auto-raii destructor).
167
+
168
+ ### Control flow
169
+
170
+ ```nomen
171
+ if cond { ... }
172
+ switch x {
173
+ 0 { ... }
174
+ 1 { ... }
175
+ else { ... }
176
+ }
177
+ for i of 0 .. 10 { ... } // exclusive range
178
+ for item of array { ... }
179
+ while cond { ... }
180
+ ```
181
+
182
+ ### Structs and classes
183
+
184
+ ```nomen
185
+ pub struct Point {
186
+ pub var int x
187
+ pub var int y
188
+ pub func add = (self, Point other, out Point) {
189
+ Point(self.x + other.x, self.y + other.y)
190
+ }
191
+ }
192
+
193
+ class Node { // class = heap-allocated, reference semantics
194
+ var int value
195
+ }
196
+ ```
197
+
198
+ Construct by calling the type name as a function: `Point(1, 2)`.
199
+
200
+ ### Strings
201
+
202
+ ```nomen
203
+ const name = "world"
204
+ Console.write("hello \{name}\n") // interpolation with \{...}
205
+ Console.write_line("with newline")
206
+ ```
207
+
208
+ ### Traits
209
+
210
+ ```nomen
211
+ trait Drawable {
212
+ pub func draw = (ref self)
213
+ }
214
+
215
+ pub struct Circle {
216
+ pub var int radius
217
+ pub func draw = (ref self) { /* ... */ }
218
+ }
219
+ ```
220
+
221
+ ### Arrays
222
+
223
+ ```nomen
224
+ const nums = [1, 2, 3]
225
+ nums.length // 3
226
+ nums.at(0) // 1
227
+ nums.set(0, 99)
228
+ const typed = Array<int>(1, 2, 3)
229
+ for n of nums { Console.write("\{n}\n") }
230
+ ```
231
+
232
+ ## Reference
233
+
234
+ - Full language spec: [SPEC.md](https://github.com/andrewjk/nomen/blob/main/SPEC.md)
235
+ - Memory model: [MEMORY.md](https://github.com/andrewjk/nomen/blob/main/MEMORY.md)
@@ -0,0 +1,150 @@
1
+ // ANSI escape code helpers for styling terminal output. Each function wraps a
2
+ // string with the relevant SGR (Select Graphic Rendition) sequence and a
3
+ // trailing reset, so styles never leak past the wrapped text.
4
+ //
5
+ // Usage:
6
+ // Console.write("\{Ansi.bg_red("ERROR")}: it didn't work")
7
+ // Console.write_line(Ansi.bold(Ansi.green("success")))
8
+ //
9
+ // The escape sequences ("\x1b[...m") are interpreted by the C compiler and the
10
+ // assembler when the string literals are emitted, so the resulting strings
11
+ // carry real ESC (0x1b) bytes. Modern terminals (macOS Terminal, iTerm, Linux
12
+ // xterm, Windows Terminal/PowerShell 7, etc.) render them. On the web platform
13
+ // you would typically render to the DOM rather than use Ansi.
14
+
15
+ /**
16
+ * Helpers for styling terminal output with ANSI escape codes
17
+ **/
18
+ pub struct Ansi {
19
+ // Styles
20
+ pub func bold = (string s, out string) {
21
+ return "\x1b[1m" + s + "\x1b[0m"
22
+ }
23
+
24
+ pub func dim = (string s, out string) {
25
+ return "\x1b[2m" + s + "\x1b[0m"
26
+ }
27
+
28
+ pub func italic = (string s, out string) {
29
+ return "\x1b[3m" + s + "\x1b[0m"
30
+ }
31
+
32
+ pub func underline = (string s, out string) {
33
+ return "\x1b[4m" + s + "\x1b[0m"
34
+ }
35
+
36
+ pub func blink = (string s, out string) {
37
+ return "\x1b[5m" + s + "\x1b[0m"
38
+ }
39
+
40
+ pub func reverse = (string s, out string) {
41
+ return "\x1b[7m" + s + "\x1b[0m"
42
+ }
43
+
44
+ pub func hidden = (string s, out string) {
45
+ return "\x1b[8m" + s + "\x1b[0m"
46
+ }
47
+
48
+ pub func strikethrough = (string s, out string) {
49
+ return "\x1b[9m" + s + "\x1b[0m"
50
+ }
51
+
52
+ // Foreground colors
53
+ pub func black = (string s, out string) {
54
+ return "\x1b[30m" + s + "\x1b[0m"
55
+ }
56
+
57
+ pub func red = (string s, out string) {
58
+ return "\x1b[31m" + s + "\x1b[0m"
59
+ }
60
+
61
+ pub func green = (string s, out string) {
62
+ return "\x1b[32m" + s + "\x1b[0m"
63
+ }
64
+
65
+ pub func yellow = (string s, out string) {
66
+ return "\x1b[33m" + s + "\x1b[0m"
67
+ }
68
+
69
+ pub func blue = (string s, out string) {
70
+ return "\x1b[34m" + s + "\x1b[0m"
71
+ }
72
+
73
+ pub func magenta = (string s, out string) {
74
+ return "\x1b[35m" + s + "\x1b[0m"
75
+ }
76
+
77
+ pub func cyan = (string s, out string) {
78
+ return "\x1b[36m" + s + "\x1b[0m"
79
+ }
80
+
81
+ pub func white = (string s, out string) {
82
+ return "\x1b[37m" + s + "\x1b[0m"
83
+ }
84
+
85
+ // Bright foreground colors
86
+ pub func bright_black = (string s, out string) {
87
+ return "\x1b[90m" + s + "\x1b[0m"
88
+ }
89
+
90
+ pub func bright_red = (string s, out string) {
91
+ return "\x1b[91m" + s + "\x1b[0m"
92
+ }
93
+
94
+ pub func bright_green = (string s, out string) {
95
+ return "\x1b[92m" + s + "\x1b[0m"
96
+ }
97
+
98
+ pub func bright_yellow = (string s, out string) {
99
+ return "\x1b[93m" + s + "\x1b[0m"
100
+ }
101
+
102
+ pub func bright_blue = (string s, out string) {
103
+ return "\x1b[94m" + s + "\x1b[0m"
104
+ }
105
+
106
+ pub func bright_magenta = (string s, out string) {
107
+ return "\x1b[95m" + s + "\x1b[0m"
108
+ }
109
+
110
+ pub func bright_cyan = (string s, out string) {
111
+ return "\x1b[96m" + s + "\x1b[0m"
112
+ }
113
+
114
+ pub func bright_white = (string s, out string) {
115
+ return "\x1b[97m" + s + "\x1b[0m"
116
+ }
117
+
118
+ // Background colors
119
+ pub func bg_black = (string s, out string) {
120
+ return "\x1b[40m" + s + "\x1b[0m"
121
+ }
122
+
123
+ pub func bg_red = (string s, out string) {
124
+ return "\x1b[41m" + s + "\x1b[0m"
125
+ }
126
+
127
+ pub func bg_green = (string s, out string) {
128
+ return "\x1b[42m" + s + "\x1b[0m"
129
+ }
130
+
131
+ pub func bg_yellow = (string s, out string) {
132
+ return "\x1b[43m" + s + "\x1b[0m"
133
+ }
134
+
135
+ pub func bg_blue = (string s, out string) {
136
+ return "\x1b[44m" + s + "\x1b[0m"
137
+ }
138
+
139
+ pub func bg_magenta = (string s, out string) {
140
+ return "\x1b[45m" + s + "\x1b[0m"
141
+ }
142
+
143
+ pub func bg_cyan = (string s, out string) {
144
+ return "\x1b[46m" + s + "\x1b[0m"
145
+ }
146
+
147
+ pub func bg_white = (string s, out string) {
148
+ return "\x1b[47m" + s + "\x1b[0m"
149
+ }
150
+ }