rooklang 0.0.0-stage → 0.3.0

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 (314) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +177 -2
  3. package/README.ru.md +178 -0
  4. package/dist/ast/declarations.d.ts +185 -0
  5. package/dist/ast/declarations.js +1 -0
  6. package/dist/ast/expressions.d.ts +201 -0
  7. package/dist/ast/expressions.js +1 -0
  8. package/dist/ast/markup.d.ts +141 -0
  9. package/dist/ast/markup.js +1 -0
  10. package/dist/ast/statements.d.ts +173 -0
  11. package/dist/ast/statements.js +1 -0
  12. package/dist/ast.d.ts +18 -0
  13. package/dist/ast.js +18 -0
  14. package/dist/attrs.d.ts +8 -0
  15. package/dist/attrs.js +23 -0
  16. package/dist/browser.d.ts +30 -0
  17. package/dist/browser.js +36 -0
  18. package/dist/build.d.ts +48 -0
  19. package/dist/build.js +112 -0
  20. package/dist/checker/assignments.d.ts +14 -0
  21. package/dist/checker/assignments.js +197 -0
  22. package/dist/checker/base.d.ts +124 -0
  23. package/dist/checker/base.js +180 -0
  24. package/dist/checker/bigint.d.ts +15 -0
  25. package/dist/checker/bigint.js +85 -0
  26. package/dist/checker/builtins.d.ts +9 -0
  27. package/dist/checker/builtins.js +307 -0
  28. package/dist/checker/bytes.d.ts +11 -0
  29. package/dist/checker/bytes.js +72 -0
  30. package/dist/checker/calls.d.ts +23 -0
  31. package/dist/checker/calls.js +210 -0
  32. package/dist/checker/channel.d.ts +14 -0
  33. package/dist/checker/channel.js +44 -0
  34. package/dist/checker/channels.d.ts +9 -0
  35. package/dist/checker/channels.js +95 -0
  36. package/dist/checker/checker.d.ts +4 -0
  37. package/dist/checker/checker.js +22 -0
  38. package/dist/checker/classes.d.ts +24 -0
  39. package/dist/checker/classes.js +223 -0
  40. package/dist/checker/completion-names.d.ts +11 -0
  41. package/dist/checker/completion-names.js +100 -0
  42. package/dist/checker/completion.d.ts +25 -0
  43. package/dist/checker/completion.js +222 -0
  44. package/dist/checker/component-values.d.ts +11 -0
  45. package/dist/checker/component-values.js +88 -0
  46. package/dist/checker/components.d.ts +37 -0
  47. package/dist/checker/components.js +287 -0
  48. package/dist/checker/context.d.ts +196 -0
  49. package/dist/checker/context.js +35 -0
  50. package/dist/checker/control-flow.d.ts +24 -0
  51. package/dist/checker/control-flow.js +237 -0
  52. package/dist/checker/declarations.d.ts +26 -0
  53. package/dist/checker/declarations.js +259 -0
  54. package/dist/checker/decorator-exports.d.ts +5 -0
  55. package/dist/checker/decorator-exports.js +40 -0
  56. package/dist/checker/decorator-members.d.ts +28 -0
  57. package/dist/checker/decorator-members.js +140 -0
  58. package/dist/checker/decorator-wrappers.d.ts +20 -0
  59. package/dist/checker/decorator-wrappers.js +132 -0
  60. package/dist/checker/decorators.d.ts +28 -0
  61. package/dist/checker/decorators.js +265 -0
  62. package/dist/checker/dom-svg.d.ts +7 -0
  63. package/dist/checker/dom-svg.js +19 -0
  64. package/dist/checker/dom.d.ts +22 -0
  65. package/dist/checker/dom.js +361 -0
  66. package/dist/checker/expressions.d.ts +32 -0
  67. package/dist/checker/expressions.js +244 -0
  68. package/dist/checker/flow.d.ts +18 -0
  69. package/dist/checker/flow.js +134 -0
  70. package/dist/checker/forwarding.d.ts +15 -0
  71. package/dist/checker/forwarding.js +78 -0
  72. package/dist/checker/functions.d.ts +24 -0
  73. package/dist/checker/functions.js +154 -0
  74. package/dist/checker/go-for.d.ts +12 -0
  75. package/dist/checker/go-for.js +93 -0
  76. package/dist/checker/goroutines.d.ts +19 -0
  77. package/dist/checker/goroutines.js +110 -0
  78. package/dist/checker/helpers.d.ts +35 -0
  79. package/dist/checker/helpers.js +162 -0
  80. package/dist/checker/imports.d.ts +7 -0
  81. package/dist/checker/imports.js +83 -0
  82. package/dist/checker/initializers.d.ts +22 -0
  83. package/dist/checker/initializers.js +104 -0
  84. package/dist/checker/iterables.d.ts +5 -0
  85. package/dist/checker/iterables.js +17 -0
  86. package/dist/checker/iterators.d.ts +13 -0
  87. package/dist/checker/iterators.js +95 -0
  88. package/dist/checker/loops.d.ts +10 -0
  89. package/dist/checker/loops.js +82 -0
  90. package/dist/checker/markup.d.ts +28 -0
  91. package/dist/checker/markup.js +220 -0
  92. package/dist/checker/members.d.ts +29 -0
  93. package/dist/checker/members.js +233 -0
  94. package/dist/checker/operators.d.ts +13 -0
  95. package/dist/checker/operators.js +177 -0
  96. package/dist/checker/promise.d.ts +17 -0
  97. package/dist/checker/promise.js +49 -0
  98. package/dist/checker/refs.d.ts +26 -0
  99. package/dist/checker/refs.js +136 -0
  100. package/dist/checker/resolution.d.ts +23 -0
  101. package/dist/checker/resolution.js +173 -0
  102. package/dist/checker/statements.d.ts +28 -0
  103. package/dist/checker/statements.js +212 -0
  104. package/dist/checker/styles.d.ts +14 -0
  105. package/dist/checker/styles.js +49 -0
  106. package/dist/checker/transfer.d.ts +5 -0
  107. package/dist/checker/transfer.js +83 -0
  108. package/dist/checker/types/bytes.d.ts +4 -0
  109. package/dist/checker/types/bytes.js +51 -0
  110. package/dist/checker/types/classes.d.ts +22 -0
  111. package/dist/checker/types/classes.js +93 -0
  112. package/dist/checker/types/constructors.d.ts +27 -0
  113. package/dist/checker/types/constructors.js +129 -0
  114. package/dist/checker/types/generics.d.ts +20 -0
  115. package/dist/checker/types/generics.js +75 -0
  116. package/dist/checker/types/lazy.d.ts +30 -0
  117. package/dist/checker/types/lazy.js +92 -0
  118. package/dist/checker/types/model.d.ts +149 -0
  119. package/dist/checker/types/model.js +15 -0
  120. package/dist/checker/types/params.d.ts +7 -0
  121. package/dist/checker/types/params.js +220 -0
  122. package/dist/checker/types/printing.d.ts +6 -0
  123. package/dist/checker/types/printing.js +109 -0
  124. package/dist/checker/types/relations.d.ts +16 -0
  125. package/dist/checker/types/relations.js +294 -0
  126. package/dist/checker/types.d.ts +9 -0
  127. package/dist/checker/types.js +10 -0
  128. package/dist/cli.d.ts +2 -0
  129. package/dist/cli.js +193 -0
  130. package/dist/codegen/analysis.d.ts +18 -0
  131. package/dist/codegen/analysis.js +144 -0
  132. package/dist/codegen/attributes.d.ts +40 -0
  133. package/dist/codegen/attributes.js +227 -0
  134. package/dist/codegen/calls.d.ts +22 -0
  135. package/dist/codegen/calls.js +106 -0
  136. package/dist/codegen/chan-helpers.d.ts +2 -0
  137. package/dist/codegen/chan-helpers.js +253 -0
  138. package/dist/codegen/component-helpers.d.ts +33 -0
  139. package/dist/codegen/component-helpers.js +18 -0
  140. package/dist/codegen/component-props.d.ts +42 -0
  141. package/dist/codegen/component-props.js +173 -0
  142. package/dist/codegen/component-values.d.ts +27 -0
  143. package/dist/codegen/component-values.js +146 -0
  144. package/dist/codegen/components.d.ts +53 -0
  145. package/dist/codegen/components.js +268 -0
  146. package/dist/codegen/control-flow.d.ts +25 -0
  147. package/dist/codegen/control-flow.js +152 -0
  148. package/dist/codegen/control-statements.d.ts +28 -0
  149. package/dist/codegen/control-statements.js +226 -0
  150. package/dist/codegen/creation.d.ts +31 -0
  151. package/dist/codegen/creation.js +113 -0
  152. package/dist/codegen/early-returns.d.ts +59 -0
  153. package/dist/codegen/early-returns.js +244 -0
  154. package/dist/codegen/element-helpers.d.ts +12 -0
  155. package/dist/codegen/element-helpers.js +54 -0
  156. package/dist/codegen/elements.d.ts +71 -0
  157. package/dist/codegen/elements.js +293 -0
  158. package/dist/codegen/emitter.d.ts +135 -0
  159. package/dist/codegen/emitter.js +296 -0
  160. package/dist/codegen/expressions.d.ts +49 -0
  161. package/dist/codegen/expressions.js +262 -0
  162. package/dist/codegen/functions.d.ts +28 -0
  163. package/dist/codegen/functions.js +170 -0
  164. package/dist/codegen/go-helpers.d.ts +9 -0
  165. package/dist/codegen/go-helpers.js +307 -0
  166. package/dist/codegen/helpers.d.ts +10 -0
  167. package/dist/codegen/helpers.js +356 -0
  168. package/dist/codegen/imported.d.ts +38 -0
  169. package/dist/codegen/imported.js +71 -0
  170. package/dist/codegen/js.d.ts +20 -0
  171. package/dist/codegen/js.js +113 -0
  172. package/dist/codegen/mutations.d.ts +10 -0
  173. package/dist/codegen/mutations.js +102 -0
  174. package/dist/codegen/parallel.d.ts +7 -0
  175. package/dist/codegen/parallel.js +63 -0
  176. package/dist/codegen/reactive.d.ts +95 -0
  177. package/dist/codegen/reactive.js +280 -0
  178. package/dist/codegen/refs.d.ts +62 -0
  179. package/dist/codegen/refs.js +160 -0
  180. package/dist/codegen/select-helpers.d.ts +2 -0
  181. package/dist/codegen/select-helpers.js +135 -0
  182. package/dist/codegen/simple-statements.d.ts +42 -0
  183. package/dist/codegen/simple-statements.js +253 -0
  184. package/dist/codegen/statements.d.ts +22 -0
  185. package/dist/codegen/statements.js +142 -0
  186. package/dist/codegen/styles.d.ts +54 -0
  187. package/dist/codegen/styles.js +157 -0
  188. package/dist/codegen/syntax.d.ts +18 -0
  189. package/dist/codegen/syntax.js +70 -0
  190. package/dist/codegen/thread-helpers.d.ts +2 -0
  191. package/dist/codegen/thread-helpers.js +198 -0
  192. package/dist/codegen/updates.d.ts +51 -0
  193. package/dist/codegen/updates.js +201 -0
  194. package/dist/codegen/web-components.d.ts +20 -0
  195. package/dist/codegen/web-components.js +149 -0
  196. package/dist/compile-file.d.ts +11 -0
  197. package/dist/compile-file.js +24 -0
  198. package/dist/compile.d.ts +53 -0
  199. package/dist/compile.js +187 -0
  200. package/dist/completion.d.ts +10 -0
  201. package/dist/completion.js +134 -0
  202. package/dist/config.d.ts +2 -0
  203. package/dist/config.js +44 -0
  204. package/dist/css/hash.d.ts +1 -0
  205. package/dist/css/hash.js +10 -0
  206. package/dist/css/parse.d.ts +42 -0
  207. package/dist/css/parse.js +138 -0
  208. package/dist/css/print.d.ts +9 -0
  209. package/dist/css/print.js +35 -0
  210. package/dist/css/selectors.d.ts +29 -0
  211. package/dist/css/selectors.js +168 -0
  212. package/dist/declarations.d.ts +3 -0
  213. package/dist/declarations.js +207 -0
  214. package/dist/decorator-copy.d.ts +18 -0
  215. package/dist/decorator-copy.js +158 -0
  216. package/dist/decorators.d.ts +61 -0
  217. package/dist/decorators.js +241 -0
  218. package/dist/diagnostics.d.ts +17 -0
  219. package/dist/diagnostics.js +22 -0
  220. package/dist/go-for.d.ts +26 -0
  221. package/dist/go-for.js +155 -0
  222. package/dist/goroutines.d.ts +37 -0
  223. package/dist/goroutines.js +253 -0
  224. package/dist/html-tag.d.ts +21 -0
  225. package/dist/html-tag.js +103 -0
  226. package/dist/index.d.ts +33 -0
  227. package/dist/index.js +55 -0
  228. package/dist/inline-packages.d.ts +32 -0
  229. package/dist/inline-packages.js +129 -0
  230. package/dist/iterators.d.ts +10 -0
  231. package/dist/iterators.js +33 -0
  232. package/dist/lexer/base.d.ts +24 -0
  233. package/dist/lexer/base.js +87 -0
  234. package/dist/lexer/lexer.d.ts +8 -0
  235. package/dist/lexer/lexer.js +134 -0
  236. package/dist/lexer/literals.d.ts +18 -0
  237. package/dist/lexer/literals.js +203 -0
  238. package/dist/lexer/markup.d.ts +10 -0
  239. package/dist/lexer/markup.js +93 -0
  240. package/dist/lexer/style.d.ts +17 -0
  241. package/dist/lexer/style.js +97 -0
  242. package/dist/lexer/tables.d.ts +53 -0
  243. package/dist/lexer/tables.js +101 -0
  244. package/dist/lexer/token.d.ts +42 -0
  245. package/dist/lexer/token.js +108 -0
  246. package/dist/loader.d.ts +1 -0
  247. package/dist/loader.js +50 -0
  248. package/dist/methods.d.ts +5 -0
  249. package/dist/methods.js +81 -0
  250. package/dist/modules.d.ts +3 -0
  251. package/dist/modules.js +49 -0
  252. package/dist/names.d.ts +23 -0
  253. package/dist/names.js +267 -0
  254. package/dist/parser/base.d.ts +96 -0
  255. package/dist/parser/base.js +202 -0
  256. package/dist/parser/classes.d.ts +8 -0
  257. package/dist/parser/classes.js +164 -0
  258. package/dist/parser/control-flow.d.ts +29 -0
  259. package/dist/parser/control-flow.js +232 -0
  260. package/dist/parser/declarations.d.ts +27 -0
  261. package/dist/parser/declarations.js +238 -0
  262. package/dist/parser/decorators.d.ts +30 -0
  263. package/dist/parser/decorators.js +176 -0
  264. package/dist/parser/expressions.d.ts +15 -0
  265. package/dist/parser/expressions.js +255 -0
  266. package/dist/parser/literals.d.ts +27 -0
  267. package/dist/parser/literals.js +206 -0
  268. package/dist/parser/markup.d.ts +22 -0
  269. package/dist/parser/markup.js +193 -0
  270. package/dist/parser/parser.d.ts +14 -0
  271. package/dist/parser/parser.js +22 -0
  272. package/dist/parser/simple-statements.d.ts +22 -0
  273. package/dist/parser/simple-statements.js +156 -0
  274. package/dist/parser/statements.d.ts +37 -0
  275. package/dist/parser/statements.js +267 -0
  276. package/dist/parser/syntax.d.ts +51 -0
  277. package/dist/parser/syntax.js +173 -0
  278. package/dist/parser/types.d.ts +23 -0
  279. package/dist/parser/types.js +218 -0
  280. package/dist/recursion.d.ts +25 -0
  281. package/dist/recursion.js +170 -0
  282. package/dist/refs.d.ts +49 -0
  283. package/dist/refs.js +210 -0
  284. package/dist/run.d.ts +1 -0
  285. package/dist/run.js +21 -0
  286. package/dist/source.d.ts +15 -0
  287. package/dist/source.js +34 -0
  288. package/dist/style-modules.d.ts +17 -0
  289. package/dist/style-modules.js +49 -0
  290. package/dist/styles.d.ts +36 -0
  291. package/dist/styles.js +160 -0
  292. package/dist/svg.d.ts +8 -0
  293. package/dist/svg.js +77 -0
  294. package/dist/ts-types.d.ts +11 -0
  295. package/dist/ts-types.js +133 -0
  296. package/dist/typed-arrays.d.ts +8 -0
  297. package/dist/typed-arrays.js +43 -0
  298. package/dist/typescript/convert-base.d.ts +42 -0
  299. package/dist/typescript/convert-base.js +135 -0
  300. package/dist/typescript/convert-objects.d.ts +28 -0
  301. package/dist/typescript/convert-objects.js +245 -0
  302. package/dist/typescript/convert.d.ts +14 -0
  303. package/dist/typescript/convert.js +67 -0
  304. package/dist/typescript/importer.d.ts +37 -0
  305. package/dist/typescript/importer.js +152 -0
  306. package/dist/typescript/library.d.ts +23 -0
  307. package/dist/typescript/library.js +81 -0
  308. package/dist/vite.d.ts +11 -0
  309. package/dist/vite.js +86 -0
  310. package/dist/walk-types.d.ts +4 -0
  311. package/dist/walk-types.js +56 -0
  312. package/dist/walk.d.ts +5 -0
  313. package/dist/walk.js +315 -0
  314. package/package.json +104 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Qwern9876r
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,178 @@
1
- # Temporary Holding Version
1
+ # Rook
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ **English** · [Русский](README.ru.md)
4
+
5
+ A language with the semantics of JavaScript, Go-style syntax, goroutines on real threads and static
6
+ types. It compiles to readable JavaScript without a runtime (WebAssembly is planned).
7
+
8
+ ```go
9
+ async func square(jobs <-chan number, results chan<- number) {
10
+ for n in jobs {
11
+ results <- n * n
12
+ }
13
+ }
14
+
15
+ const jobs = chan<number>(10)
16
+ const results = chan<number>()
17
+ go square(jobs, results) // another thread, at once with the rest
18
+ go square(jobs, results)
19
+
20
+ for let n = 1; n <= 4; n++ {
21
+ jobs <- n
22
+ }
23
+ close(jobs)
24
+ for let i = 0; i < 4; i++ {
25
+ console.log(<-results)
26
+ }
27
+ ```
28
+
29
+ - **Goroutines and channels.** `go f(x)` runs a function as a goroutine, on another processor, and
30
+ channels, `select`, `after`, `tick` and `cancel` work as in Go; `go for i, v in pixels { ... }`
31
+ splits an array among the processors. The compiler checks that what goes to another thread can be
32
+ copied there.
33
+ - **Go syntax.** `func`, the type after the name, several results, errors as a second value,
34
+ `defer`, a single `for` loop:
35
+
36
+ ```go
37
+ func divide(a, b number) (number, error) {
38
+ if b == 0 {
39
+ return 0, error("division by zero")
40
+ }
41
+ return a / b, null
42
+ }
43
+ ```
44
+
45
+ - **Static types with null safety.** A `?User` cannot be used without a check.
46
+ - **JavaScript inside.** The same values, classes and modules, any JS library; markup creates real
47
+ DOM elements, and components are compiled away.
48
+
49
+ The guide with examples and a playground: <https://qwern-9876r.github.io/RookLang/>.
50
+ Specification: [docs/spec.md](docs/spec.md), design of components:
51
+ [docs/components.md](docs/components.md), an example: [examples/hello.rk](examples/hello.rk).
52
+
53
+ ## Installation
54
+
55
+ Rook needs Node.js ≥ 24.
56
+
57
+ ```sh
58
+ npm install --save-dev rooklang
59
+ npx rook build app.rk # app.js next to the source
60
+ npx rook build src --out-dir dist # every module of a folder
61
+ npx rook run app.rk # compile and run
62
+ ```
63
+
64
+ From code, the compiler is `import { compile } from 'rooklang'`. The package also has the
65
+ [Vite](#vite) plugin, `rooklang/vite`, and `rooklang/browser`, the compiler without the
66
+ TypeScript compiler for running in a browser, as in the site's playground: there imports are not
67
+ type checked.
68
+
69
+ ## Development
70
+
71
+ Node.js ≥ 24 (`nvm use`). The compiler is written in TypeScript, and Node runs the `.ts` files
72
+ directly, so development needs no build step: the commands below run the compiler from `src/`.
73
+ `dist/` is built only for the npm package.
74
+
75
+ `npm install` also installs a pre-commit hook that formats the staged files: ESLint adds the blank
76
+ lines between statements that Prettier keeps but never adds, then Prettier formats. Only the
77
+ staged version is formatted, so edits that are not staged stay out of the commit.
78
+
79
+ ## Commands
80
+
81
+ | Command | What it does |
82
+ | --------------------------------- | ------------------------------------------------------- |
83
+ | `npm run rook -- build file.rk` | Compile to `file.js`, with the `.rk` modules it imports |
84
+ | `npm run rook -- run file.rk` | Compile and run |
85
+ | `npm run rook -- tokens file.rk` | Show the lexer's tokens |
86
+ | `npm run rook -- ast file.rk` | Show the syntax tree |
87
+ | `npm test` / `npm run test:watch` | Tests (Vitest) |
88
+ | `npm run typecheck` | Type check |
89
+ | `npm run lint` / `npm run format` | ESLint / Prettier with the blank lines from ESLint |
90
+ | `npm run check` | All at once: types, lint, format, tests |
91
+ | `npm run build` | Build the npm package to `dist/` |
92
+ | `npm run vscode:install` | Build and install the VS Code extension |
93
+
94
+ Options of `build`: `--out-dir dir` writes the `.js` files to a separate folder, `--stdout` prints
95
+ the JS of one file, `--no-check` skips type checking. `--markup` and `--no-markup` turn markup and
96
+ components on or off for all files (with `run` too); by default they are off, and a package turns
97
+ them on in its `package.json`: `"rook": { "markup": true }`.
98
+
99
+ ## Releases
100
+
101
+ A release is a new version in `package.json` on `main`: `npm version minor --no-git-tag-version`
102
+ (or `patch`) changes it, and the push to `main` releases it. The workflow
103
+ [.github/workflows/publish.yml](.github/workflows/publish.yml) sees that npm does not have this
104
+ version yet, runs `npm run check`, builds `dist/`, publishes the package to npm and tags the commit
105
+ `v0.2.0`. A push that keeps the version publishes nothing.
106
+
107
+ ## VS Code
108
+
109
+ [editors/vscode/](editors/vscode/) has an extension for `.rk` files: highlighting of code, types
110
+ and markup, errors as you type and completion of names, members, types, tags and attributes, from a
111
+ language server with the compiler. `npm run vscode:install` builds it and installs it with `code`;
112
+ see [editors/vscode/README.md](editors/vscode/README.md).
113
+
114
+ ## Documentation site
115
+
116
+ [site/](site/) holds the site of Rook in English and Russian (in `ru/`), three pages in each: the
117
+ home page (`index.html`), the guide (`docs/`) and the playground (`playground/`). The pages and
118
+ their server are written in Rook, and the compiler runs right in the browser: every example of
119
+ the guide has a tab with the JavaScript it compiles to and a run button, and the playground is a
120
+ small IDE.
121
+
122
+ - [site/src/en/](site/src/en/) and [site/src/ru/](site/src/ru/): the entry module of each page
123
+ (`home.rk`, `docs.rk`, `playground.rk`), the texts (`strings.rk`, `home-strings.rk`) and the
124
+ sections of the guide, listed in `guide.rk`;
125
+ - [site/src/home/](site/src/home/), [site/src/docs/](site/src/docs/) and
126
+ [site/src/playground/](site/src/playground/): the three pages; the guide shows one section at a
127
+ time, chosen by the hash of the address, and has a search; [site/src/layout/](site/src/layout/):
128
+ the bar at the top and the footer;
129
+ - [site/ui/](site/ui/): RookUI, the kit of components and the dark theme that the pages use;
130
+ - [site/examples/](site/examples/) and [site/examples/ru/](site/examples/ru/): the examples; tests
131
+ check that they all compile and that each has a translation;
132
+ - [site/src/i18n.rk](site/src/i18n.rk): the language of the page and the texts around the
133
+ guide;
134
+ - [site/src/example.rk](site/src/example.rk) and [site/src/sandbox.rk](site/src/sandbox.rk): the
135
+ example with tabs, and compiling and running code in the page;
136
+ - [site/src/highlight.rk](site/src/highlight.rk): code highlighting with the compiler's lexer;
137
+ - [site/src/editor/](site/src/editor/): the editor of the playground, the one of VS Code (Monaco)
138
+ with the grammar of the VS Code extension, the compiler's errors under the code and its
139
+ completion; TypeScript for the browser, checked with [site/tsconfig.json](site/tsconfig.json);
140
+ - [site/server.rk](site/server.rk): a static server on `node:http` with a log through `defer`.
141
+
142
+ Vite builds the site ([vite.config.ts](vite.config.ts)): the plugin [src/vite.ts](src/vite.ts)
143
+ compiles `.rk` modules with type checking, the playground's compiler comes straight from
144
+ [src/browser.ts](src/browser.ts), and the code of the examples gets into the bundle from the
145
+ `virtual:examples/en` and `virtual:examples/ru` modules. The compiler is a chunk of its own,
146
+ loaded by [site/src/compiler.ts](site/src/compiler.ts) on the first run, when a JavaScript tab is
147
+ opened and in the playground: the pages themselves need only the lexer, for highlighting. The
148
+ editor of the playground, some 3.5 MB, is loaded by the playground only; until it is, and on touch
149
+ screens, the playground has a text area of its own. The fonts, Geist and Geist Mono, come with the
150
+ site from npm ([site/src/fonts.css](site/src/fonts.css)).
151
+
152
+ ```sh
153
+ npm run site:dev # the Vite dev server: changes show up right away
154
+ npm run site # builds the site to site/dist and runs site/server.rk at http://localhost:3000
155
+ ```
156
+
157
+ ## Vite
158
+
159
+ The plugin `rooklang/vite` ([src/vite.ts](src/vite.ts)) adds Rook to any Vite project:
160
+
161
+ ```ts
162
+ import { defineConfig } from 'vite';
163
+ import { rook } from 'rooklang/vite';
164
+
165
+ export default defineConfig({ plugins: [rook()] });
166
+ ```
167
+
168
+ Then `.rk` files can be imported from JS, TS and other `.rk` modules. Type errors stop the
169
+ build, and in development they show up over the page. Markup and components are off by default,
170
+ so `.rk` modules fit a React, Svelte or Vue app as they are; turn them on with
171
+ `"rook": { "markup": true }` in `package.json`, or `rook({ markup: true })`.
172
+
173
+ ## Conventions
174
+
175
+ - Imports are written with the `.ts` extension (`import { x } from './lexer.ts'`).
176
+ - Only erasable TS syntax: instead of `enum`, unions of strings or `as const` objects.
177
+ - Text for people is written in English first (README, docs, the site, examples, comments); the
178
+ Russian versions are next to it: `README.ru.md`, `docs/*.ru.md`, `site/examples/ru/`.
package/README.ru.md ADDED
@@ -0,0 +1,178 @@
1
+ # Rook
2
+
3
+ [English](README.md) · **Русский**
4
+
5
+ Язык с семантикой JavaScript, синтаксисом в духе Go, горутинами на настоящих потоках и статической
6
+ типизацией. Компилируется в читаемый JavaScript без рантайма (в планах — WebAssembly).
7
+
8
+ ```go
9
+ async func square(jobs <-chan number, results chan<- number) {
10
+ for n in jobs {
11
+ results <- n * n
12
+ }
13
+ }
14
+
15
+ const jobs = chan<number>(10)
16
+ const results = chan<number>()
17
+ go square(jobs, results) // другой поток, одновременно с остальной программой
18
+ go square(jobs, results)
19
+
20
+ for let n = 1; n <= 4; n++ {
21
+ jobs <- n
22
+ }
23
+ close(jobs)
24
+ for let i = 0; i < 4; i++ {
25
+ console.log(<-results)
26
+ }
27
+ ```
28
+
29
+ - **Горутины и каналы.** `go f(x)` запускает функцию горутиной, на другом процессоре, а каналы,
30
+ `select`, `after`, `tick` и `cancel` работают как в Go; `go for i, v in pixels { ... }` делит
31
+ массив между процессорами. Компилятор проверяет, что уходящее в другой поток можно туда
32
+ скопировать.
33
+ - **Синтаксис Go.** `func`, тип после имени, несколько результатов, ошибки вторым значением,
34
+ `defer`, один цикл `for`:
35
+
36
+ ```go
37
+ func divide(a, b number) (number, error) {
38
+ if b == 0 {
39
+ return 0, error("division by zero")
40
+ }
41
+ return a / b, null
42
+ }
43
+ ```
44
+
45
+ - **Статическая типизация с null-safety.** Значение типа `?User` нельзя использовать без проверки.
46
+ - **Внутри — JavaScript.** Те же значения, классы и модули, любые JS-библиотеки; разметка создаёт
47
+ настоящие DOM-элементы, а компоненты исчезают при компиляции.
48
+
49
+ Руководство с примерами и песочницей: <https://qwern-9876r.github.io/RookLang/ru/>.
50
+ Спецификация: [docs/spec.ru.md](docs/spec.ru.md), концепция компонентов:
51
+ [docs/components.ru.md](docs/components.ru.md), пример: [examples/hello.rk](examples/hello.rk).
52
+
53
+ ## Установка
54
+
55
+ Нужен Node.js ≥ 24.
56
+
57
+ ```sh
58
+ npm install --save-dev rooklang
59
+ npx rook build app.rk # app.js рядом с исходником
60
+ npx rook build src --out-dir dist # все модули папки
61
+ npx rook run app.rk # скомпилировать и запустить
62
+ ```
63
+
64
+ Из кода компилятор подключается как `import { compile } from 'rooklang'`. Ещё в пакете есть
65
+ плагин для [Vite](#vite) — `rooklang/vite` — и `rooklang/browser`: компилятор без
66
+ компилятора TypeScript, для работы в браузере, как в песочнице сайта; импорты там не проверяются
67
+ по типам.
68
+
69
+ ## Разработка
70
+
71
+ Node.js ≥ 24 (`nvm use`). Компилятор написан на TypeScript, Node запускает `.ts`-файлы напрямую,
72
+ поэтому отдельная сборка для разработки не нужна: команды ниже запускают компилятор из `src/`.
73
+ `dist/` собирается только для npm-пакета.
74
+
75
+ `npm install` ставит и pre-commit хук, который форматирует застейдженные файлы: ESLint добавляет
76
+ пустые строки между операторами, которые Prettier сохраняет, но сам не добавляет, затем
77
+ форматирует Prettier. Форматируется только застейдженная версия, так что незастейдженные правки
78
+ в коммит не попадают.
79
+
80
+ ## Команды
81
+
82
+ | Команда | Что делает |
83
+ | --------------------------------- | -------------------------------------------------------- |
84
+ | `npm run rook -- build file.rk` | Скомпилировать в `file.js` вместе с импортируемыми `.rk` |
85
+ | `npm run rook -- run file.rk` | Скомпилировать и запустить |
86
+ | `npm run rook -- tokens file.rk` | Показать токены лексера |
87
+ | `npm run rook -- ast file.rk` | Показать синтаксическое дерево |
88
+ | `npm test` / `npm run test:watch` | Тесты (Vitest) |
89
+ | `npm run typecheck` | Проверка типов |
90
+ | `npm run lint` / `npm run format` | ESLint / Prettier с пустыми строками от ESLint |
91
+ | `npm run check` | Всё сразу — типы, линт, формат, тесты |
92
+ | `npm run build` | Собрать npm-пакет в `dist/` |
93
+ | `npm run vscode:install` | Собрать и установить расширение для VS Code |
94
+
95
+ Опции `build`: `--out-dir dir` — писать `.js` в отдельную папку, `--stdout` — вывести JS одного
96
+ файла в консоль, `--no-check` — без проверки типов. `--markup` и `--no-markup` включают или
97
+ выключают разметку и компоненты для всех файлов (и в `run`); по умолчанию они выключены, а пакет
98
+ включает их в своём `package.json`: `"rook": { "markup": true }`.
99
+
100
+ ## Релизы
101
+
102
+ Релиз — это новая версия в `package.json` в `main`: `npm version minor --no-git-tag-version` (или
103
+ `patch`) меняет её, а пуш в `main` выпускает релиз. Workflow
104
+ [.github/workflows/publish.yml](.github/workflows/publish.yml) видит, что такой версии в npm ещё
105
+ нет, запускает `npm run check`, собирает `dist/`, публикует пакет в npm и ставит на коммит тег
106
+ `v0.2.0`. Пуш без новой версии ничего не публикует.
107
+
108
+ ## VS Code
109
+
110
+ В [editors/vscode/](editors/vscode/) лежит расширение для файлов `.rk`: подсветка кода, типов и
111
+ разметки, ошибки прямо при наборе и автодополнение имён, членов, типов, тегов и атрибутов — от
112
+ языкового сервера с компилятором. `npm run vscode:install` собирает его и устанавливает через
113
+ `code`; подробности — в [editors/vscode/README.ru.md](editors/vscode/README.ru.md).
114
+
115
+ ## Сайт с документацией
116
+
117
+ В [site/](site/) лежит сайт Rook на английском и русском (в `ru/`), в каждом по три страницы:
118
+ главная (`index.html`), руководство (`docs/`) и песочница (`playground/`). И страницы, и сервер
119
+ написаны на Rook, а компилятор работает прямо в браузере: у каждого примера руководства есть
120
+ вкладка с JavaScript, который из него получается, и кнопка запуска, а песочница — маленькая IDE.
121
+
122
+ - [site/src/en/](site/src/en/) и [site/src/ru/](site/src/ru/) — входной модуль каждой страницы
123
+ (`home.rk`, `docs.rk`, `playground.rk`), тексты (`strings.rk`, `home-strings.rk`) и разделы
124
+ руководства, перечисленные в `guide.rk`;
125
+ - [site/src/home/](site/src/home/), [site/src/docs/](site/src/docs/) и
126
+ [site/src/playground/](site/src/playground/) — три страницы; руководство показывает по одному
127
+ разделу, выбранному хешем адреса, и умеет искать; [site/src/layout/](site/src/layout/) — шапка
128
+ и подвал;
129
+ - [site/ui/](site/ui/) — RookUI, набор компонентов и тёмная тема, на которых построены страницы;
130
+ - [site/examples/](site/examples/) и [site/examples/ru/](site/examples/ru/) — примеры кода; тесты
131
+ проверяют, что все они компилируются и что у каждого есть перевод;
132
+ - [site/src/i18n.rk](site/src/i18n.rk) — язык страницы и тексты вокруг руководства;
133
+ - [site/src/example.rk](site/src/example.rk) и [site/src/sandbox.rk](site/src/sandbox.rk) — пример
134
+ с вкладками, компиляция и запуск кода на странице;
135
+ - [site/src/highlight.rk](site/src/highlight.rk) — подсветка кода лексером компилятора;
136
+ - [site/src/editor/](site/src/editor/) — редактор песочницы, тот же, что в VS Code (Monaco), с
137
+ грамматикой расширения VS Code, ошибками компилятора прямо в коде и его автодополнением;
138
+ TypeScript для браузера, проверяется по [site/tsconfig.json](site/tsconfig.json);
139
+ - [site/server.rk](site/server.rk) — статический сервер на `node:http` с логом через `defer`.
140
+
141
+ Сайт собирает Vite ([vite.config.ts](vite.config.ts)): `.rk`-модули компилирует плагин
142
+ [src/vite.ts](src/vite.ts) с проверкой типов, компилятор для песочницы берётся прямо из
143
+ [src/browser.ts](src/browser.ts), а код примеров попадает в бандл из модулей
144
+ `virtual:examples/en` и `virtual:examples/ru`. Компилятор вынесен в отдельный чанк, его загружает
145
+ [site/src/compiler.ts](site/src/compiler.ts) при первом запуске, при открытии вкладки JavaScript и
146
+ в песочнице: самим страницам нужен только лексер для подсветки. Редактор песочницы, около 3,5 МБ,
147
+ загружает только песочница; до этого и на сенсорных экранах у неё свой textarea. Шрифты Geist и
148
+ Geist Mono идут вместе с сайтом из npm ([site/src/fonts.css](site/src/fonts.css)).
149
+
150
+ ```sh
151
+ npm run site:dev # сервер разработки Vite: изменения видны сразу
152
+ npm run site # собирает сайт в site/dist и запускает site/server.rk на http://localhost:3000
153
+ ```
154
+
155
+ ## Vite
156
+
157
+ Плагин `rooklang/vite` ([src/vite.ts](src/vite.ts)) подключает Rook к любому проекту на
158
+ Vite:
159
+
160
+ ```ts
161
+ import { defineConfig } from 'vite';
162
+ import { rook } from 'rooklang/vite';
163
+
164
+ export default defineConfig({ plugins: [rook()] });
165
+ ```
166
+
167
+ После этого `.rk`-файлы можно импортировать из JS, TS и других `.rk`-модулей. Ошибки типов
168
+ останавливают сборку, а в режиме разработки показываются поверх страницы. Разметка и компоненты по
169
+ умолчанию выключены, поэтому `.rk`-модули подходят приложению на React, Svelte или Vue как
170
+ есть; включить их можно через `"rook": { "markup": true }` в `package.json` или
171
+ `rook({ markup: true })`.
172
+
173
+ ## Соглашения
174
+
175
+ - Импорты пишутся с расширением `.ts` (`import { x } from './lexer.ts'`).
176
+ - Только «стираемый» синтаксис TS: вместо `enum` — union-типы строк или `as const`-объекты.
177
+ - Тексты для людей — сначала на английском (README, документация, сайт, примеры, комментарии);
178
+ русские версии лежат рядом: `README.ru.md`, `docs/*.ru.md`, `site/examples/ru/`.
@@ -0,0 +1,185 @@
1
+ import type { Expression, Identifier, StringLiteral } from './expressions.ts';
2
+ import type { TypeMember, TypeNode, TypeReference } from './markup.ts';
3
+ import type { BlockStatement, Statement } from './statements.ts';
4
+ export interface NodeBase {
5
+ start: number;
6
+ end: number;
7
+ }
8
+ export interface Program extends NodeBase {
9
+ kind: 'Program';
10
+ body: Statement[];
11
+ }
12
+ /**
13
+ * `import x from "mod"`, `import * as ns from "mod"`, `import { a, b as c } from "mod"`,
14
+ * `import x, { a } from "mod"` and `import "mod"`.
15
+ */
16
+ export interface ImportDeclaration extends NodeBase {
17
+ kind: 'ImportDeclaration';
18
+ defaultImport: Identifier | null;
19
+ namespaceImport: Identifier | null;
20
+ namedImports: ImportSpecifier[];
21
+ source: StringLiteral;
22
+ }
23
+ /** `a` or `a as b` inside `import { ... }`. Without `as`, `imported` and `local` are the same node. */
24
+ export interface ImportSpecifier extends NodeBase {
25
+ kind: 'ImportSpecifier';
26
+ imported: Identifier;
27
+ local: Identifier;
28
+ }
29
+ /** `func divide(a, b number) (number, error) { ... }` */
30
+ export interface FuncDeclaration extends NodeBase {
31
+ kind: 'FuncDeclaration';
32
+ exported: boolean;
33
+ /** `public func` in a decorator: the component calls it as `@name.f()`. */
34
+ isPublic: boolean;
35
+ /**
36
+ * `async func load() User`: the results are those of the Promise it returns, so its type is
37
+ * `func() Promise<User>`.
38
+ */
39
+ async?: true;
40
+ name: Identifier;
41
+ /** `[T any, U Shape]` after the name; empty for ordinary functions. */
42
+ typeParams: TypeParameter[];
43
+ params: Parameter[];
44
+ /** Result types: `[]` for no result, `[T]` for one, `[T1, T2]` for `(T1, T2)`. */
45
+ results: TypeNode[];
46
+ body: BlockStatement;
47
+ }
48
+ /** `name number`. The type is `null` only for arrow function parameters inferred from context. */
49
+ export interface Parameter extends NodeBase {
50
+ kind: 'Parameter';
51
+ name: Identifier;
52
+ type: TypeNode | null;
53
+ /** `kind string = "info"`: only properties of components and decorators have default values. */
54
+ defaultValue: Expression | null;
55
+ /**
56
+ * `...attrs`, the last property of a component: the attributes of a use that are not its
57
+ * properties, which `{...attrs}` puts on one of its elements.
58
+ */
59
+ rest?: true;
60
+ }
61
+ /**
62
+ * `comp Card(title string, children Content) { ...; return <section>...</section> }`. Components
63
+ * exist only at compile time: each use is replaced by the component's code.
64
+ */
65
+ export interface ComponentDeclaration extends NodeBase {
66
+ kind: 'ComponentDeclaration';
67
+ exported: boolean;
68
+ name: Identifier;
69
+ params: Parameter[];
70
+ body: BlockStatement;
71
+ /** `@html-tag` before `comp`: the component is also a web component. */
72
+ htmlTag: HtmlTag | null;
73
+ /** `@visible("300px")` before `comp`, in the order they are written. */
74
+ decorators: DecoratorUse[];
75
+ }
76
+ /** `@html-tag` or `@html-tag("app-page")`; without a name the tag comes from the component's name. */
77
+ export interface HtmlTag extends NodeBase {
78
+ kind: 'HtmlTag';
79
+ name: StringLiteral | null;
80
+ }
81
+ /**
82
+ * `dec visible(margin string = "0px") { ... }`: logic added to the components it is applied to.
83
+ * Like a component, it exists only at compile time: its code is inlined into each of them.
84
+ */
85
+ export interface DecoratorDeclaration extends NodeBase {
86
+ kind: 'DecoratorDeclaration';
87
+ exported: boolean;
88
+ name: Identifier;
89
+ params: Parameter[];
90
+ /** `needs cart, auth`: the decorators whose public members it uses; they are applied above it. */
91
+ needs: Identifier[];
92
+ body: BlockStatement;
93
+ }
94
+ /** `@visible("300px")` or `@visible` before `comp`; the arguments are positional. */
95
+ export interface DecoratorUse extends NodeBase {
96
+ kind: 'DecoratorUse';
97
+ name: Identifier;
98
+ arguments: Expression[];
99
+ }
100
+ /**
101
+ * `let x number`, `const PI = 3.14`, `let a, b = 1, 2`, `const q, err = divide(10, 2)`; inside a
102
+ * component also `state count = 0` and `ref input`, which has no value: the markup gives it with
103
+ * `<input ref={input} />`.
104
+ *
105
+ * `values` is empty (every name gets its zero value), has one value per name, or holds a single
106
+ * call that returns several values.
107
+ */
108
+ export interface VariableDeclaration extends NodeBase {
109
+ kind: 'VariableDeclaration';
110
+ exported: boolean;
111
+ keyword: 'let' | 'const' | 'state' | 'derived' | 'ref';
112
+ /**
113
+ * `public state`, `public derived` or `public const` in a decorator: the component reads it with
114
+ * `get(@name.x)`.
115
+ */
116
+ isPublic: boolean;
117
+ /** `_` is an ordinary identifier here; the checker treats it as "skip this value". */
118
+ names: Identifier[];
119
+ type: TypeNode | null;
120
+ values: Expression[];
121
+ }
122
+ /** `class Admin extends User implements Shape { ... }` */
123
+ export interface ClassDeclaration extends NodeBase {
124
+ kind: 'ClassDeclaration';
125
+ exported: boolean;
126
+ name: Identifier;
127
+ typeParams: TypeParameter[];
128
+ /** An expression, as in JS, so that classes from JS modules can be extended. */
129
+ superClass: Expression | null;
130
+ implements: TypeReference[];
131
+ members: ClassMember[];
132
+ }
133
+ export type ClassMember = FieldDeclaration | ConstructorDeclaration | MethodDeclaration;
134
+ export type Visibility = 'public' | 'protected' | 'private';
135
+ /** `private age number`, `static count = 0`, `name = "circle"`. */
136
+ export interface FieldDeclaration extends NodeBase {
137
+ kind: 'FieldDeclaration';
138
+ /** `public` when no modifier is written. */
139
+ visibility: Visibility;
140
+ isStatic: boolean;
141
+ name: Identifier;
142
+ type: TypeNode | null;
143
+ value: Expression | null;
144
+ }
145
+ /** `constructor(name string, age number) { ... }` */
146
+ export interface ConstructorDeclaration extends NodeBase {
147
+ kind: 'ConstructorDeclaration';
148
+ visibility: Visibility;
149
+ params: Parameter[];
150
+ body: BlockStatement;
151
+ }
152
+ /** `greet() string { ... }`. Methods are written without `func`, as in JS classes. */
153
+ export interface MethodDeclaration extends NodeBase {
154
+ kind: 'MethodDeclaration';
155
+ visibility: Visibility;
156
+ isStatic: boolean;
157
+ /** `async load() User`, like `async func`. */
158
+ async?: true;
159
+ name: Identifier;
160
+ params: Parameter[];
161
+ results: TypeNode[];
162
+ body: BlockStatement;
163
+ }
164
+ /** `interface Shape { name string; area() number }` */
165
+ export interface InterfaceDeclaration extends NodeBase {
166
+ kind: 'InterfaceDeclaration';
167
+ exported: boolean;
168
+ name: Identifier;
169
+ typeParams: TypeParameter[];
170
+ members: TypeMember[];
171
+ }
172
+ /** `type ID string`, `type Handler func(string) bool`, `type Pair<A, B any> { ... }`. */
173
+ export interface TypeAliasDeclaration extends NodeBase {
174
+ kind: 'TypeAliasDeclaration';
175
+ exported: boolean;
176
+ name: Identifier;
177
+ typeParams: TypeParameter[];
178
+ type: TypeNode;
179
+ }
180
+ /** `T any` or `T Shape` in `[T any, U Shape]`; the constraint is `null` when it is left out. */
181
+ export interface TypeParameter extends NodeBase {
182
+ kind: 'TypeParameter';
183
+ name: Identifier;
184
+ constraint: TypeNode | null;
185
+ }
@@ -0,0 +1 @@
1
+ export {};