trebol 0.1.0 → 0.1.2

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 (160) hide show
  1. package/README.md +18 -3
  2. package/dist/cli.js +13790 -11417
  3. package/dist/fonts/OFL.txt +93 -0
  4. package/dist/fonts/inter-cyrillic-ext.woff2 +0 -0
  5. package/dist/fonts/inter-cyrillic.woff2 +0 -0
  6. package/dist/fonts/inter-greek-ext.woff2 +0 -0
  7. package/dist/fonts/inter-greek.woff2 +0 -0
  8. package/dist/fonts/inter-latin-ext.woff2 +0 -0
  9. package/dist/fonts/inter-latin.woff2 +0 -0
  10. package/dist/fonts/inter-vietnamese.woff2 +0 -0
  11. package/dist/lib/core/access.d.ts +10 -0
  12. package/dist/lib/core/access.js +210 -0
  13. package/dist/lib/core/base.d.ts +4 -0
  14. package/dist/lib/core/base.js +50 -0
  15. package/dist/lib/core/bitset.d.ts +9 -0
  16. package/dist/lib/core/bitset.js +75 -0
  17. package/dist/lib/core/boot.d.ts +18 -0
  18. package/dist/lib/core/boot.js +73 -0
  19. package/dist/lib/core/compare.d.ts +9 -0
  20. package/dist/lib/core/compare.js +156 -0
  21. package/dist/lib/core/ctx.d.ts +36 -0
  22. package/dist/lib/core/ctx.js +251 -0
  23. package/dist/lib/core/dec.d.ts +28 -0
  24. package/dist/lib/core/dec.js +158 -0
  25. package/dist/lib/core/errors.d.ts +15 -0
  26. package/dist/lib/core/errors.js +44 -0
  27. package/dist/lib/core/escapes.d.ts +14 -0
  28. package/dist/lib/core/escapes.js +80 -0
  29. package/dist/lib/core/eval.d.ts +220 -0
  30. package/dist/lib/core/eval.js +666 -0
  31. package/dist/lib/core/func.d.ts +68 -0
  32. package/dist/lib/core/func.js +129 -0
  33. package/dist/lib/core/hash.d.ts +5 -0
  34. package/dist/lib/core/hash.js +155 -0
  35. package/dist/lib/core/index.d.ts +18 -0
  36. package/dist/lib/core/index.js +20 -0
  37. package/dist/lib/core/int64.d.ts +22 -0
  38. package/dist/lib/core/int64.js +113 -0
  39. package/dist/lib/core/kinds.d.ts +67 -0
  40. package/dist/lib/core/kinds.js +134 -0
  41. package/dist/lib/core/lexer.d.ts +13 -0
  42. package/dist/lib/core/lexer.js +702 -0
  43. package/dist/lib/core/mezz.d.ts +1 -0
  44. package/dist/lib/core/mezz.js +360 -0
  45. package/dist/lib/core/mold.d.ts +20 -0
  46. package/dist/lib/core/mold.js +434 -0
  47. package/dist/lib/core/natives/control.d.ts +1 -0
  48. package/dist/lib/core/natives/control.js +374 -0
  49. package/dist/lib/core/natives/csv.d.ts +15 -0
  50. package/dist/lib/core/natives/csv.js +315 -0
  51. package/dist/lib/core/natives/data.d.ts +11 -0
  52. package/dist/lib/core/natives/data.js +367 -0
  53. package/dist/lib/core/natives/define.d.ts +17 -0
  54. package/dist/lib/core/natives/define.js +47 -0
  55. package/dist/lib/core/natives/encode.d.ts +3 -0
  56. package/dist/lib/core/natives/encode.js +187 -0
  57. package/dist/lib/core/natives/json.d.ts +5 -0
  58. package/dist/lib/core/natives/json.js +273 -0
  59. package/dist/lib/core/natives/math.d.ts +3 -0
  60. package/dist/lib/core/natives/math.js +500 -0
  61. package/dist/lib/core/natives/parse.d.ts +1 -0
  62. package/dist/lib/core/natives/parse.js +600 -0
  63. package/dist/lib/core/natives/series.d.ts +4 -0
  64. package/dist/lib/core/natives/series.js +519 -0
  65. package/dist/lib/core/natives/text.d.ts +1 -0
  66. package/dist/lib/core/natives/text.js +487 -0
  67. package/dist/lib/core/natives/xml.d.ts +9 -0
  68. package/dist/lib/core/natives/xml.js +242 -0
  69. package/dist/lib/core/series.d.ts +26 -0
  70. package/dist/lib/core/series.js +73 -0
  71. package/dist/lib/core/symbols.d.ts +9 -0
  72. package/dist/lib/core/symbols.js +44 -0
  73. package/dist/lib/core/values.d.ts +206 -0
  74. package/dist/lib/core/values.js +223 -0
  75. package/dist/lib/host/browser.d.ts +4 -0
  76. package/dist/lib/host/browser.js +4974 -0
  77. package/dist/lib/host/chart.d.ts +26 -0
  78. package/dist/lib/host/chart.js +158 -0
  79. package/dist/lib/host/compress.d.ts +1 -0
  80. package/dist/lib/host/compress.js +37 -0
  81. package/dist/lib/host/devlog.d.ts +11 -0
  82. package/dist/lib/host/devlog.js +13 -0
  83. package/dist/lib/host/devtools.d.ts +23 -0
  84. package/dist/lib/host/devtools.js +626 -0
  85. package/dist/lib/host/draw.d.ts +31 -0
  86. package/dist/lib/host/draw.js +348 -0
  87. package/dist/lib/host/fonts/OFL.txt +93 -0
  88. package/dist/lib/host/fonts/inter-cyrillic-ext.woff2 +0 -0
  89. package/dist/lib/host/fonts/inter-cyrillic.woff2 +0 -0
  90. package/dist/lib/host/fonts/inter-greek-ext.woff2 +0 -0
  91. package/dist/lib/host/fonts/inter-greek.woff2 +0 -0
  92. package/dist/lib/host/fonts/inter-latin-ext.woff2 +0 -0
  93. package/dist/lib/host/fonts/inter-latin.woff2 +0 -0
  94. package/dist/lib/host/fonts/inter-vietnamese.woff2 +0 -0
  95. package/dist/lib/host/fonts.d.ts +11 -0
  96. package/dist/lib/host/fonts.js +29 -0
  97. package/dist/lib/host/icons.d.ts +3 -0
  98. package/dist/lib/host/icons.js +97 -0
  99. package/dist/lib/host/index.d.ts +40 -0
  100. package/dist/lib/host/index.js +192 -0
  101. package/dist/lib/host/js.d.ts +5 -0
  102. package/dist/lib/host/js.js +130 -0
  103. package/dist/lib/host/locale.d.ts +40 -0
  104. package/dist/lib/host/locale.js +241 -0
  105. package/dist/lib/host/markdown.d.ts +30 -0
  106. package/dist/lib/host/markdown.js +161 -0
  107. package/dist/lib/host/modules.d.ts +14 -0
  108. package/dist/lib/host/modules.js +300 -0
  109. package/dist/lib/host/natives.d.ts +6 -0
  110. package/dist/lib/host/natives.js +98 -0
  111. package/dist/lib/host/net.d.ts +12 -0
  112. package/dist/lib/host/net.js +549 -0
  113. package/dist/lib/host/orbit.d.ts +121 -0
  114. package/dist/lib/host/orbit.js +374 -0
  115. package/dist/lib/host/page.d.ts +9 -0
  116. package/dist/lib/host/page.js +55 -0
  117. package/dist/lib/host/rows.d.ts +29 -0
  118. package/dist/lib/host/rows.js +109 -0
  119. package/dist/lib/host/scheduler.d.ts +51 -0
  120. package/dist/lib/host/scheduler.js +197 -0
  121. package/dist/lib/host/theme.d.ts +58 -0
  122. package/dist/lib/host/theme.js +1667 -0
  123. package/dist/lib/ui/i18n.trb +117 -0
  124. package/dist/lib/ui/test.trb +565 -0
  125. package/dist/lib/ui/ui.trb +1678 -0
  126. package/dist/trebol.js +1427 -138
  127. package/editors/vscode/README.md +15 -0
  128. package/editors/vscode/language-configuration.json +28 -0
  129. package/editors/vscode/package.json +42 -0
  130. package/editors/vscode/syntaxes/trebol.tmLanguage.json +237 -0
  131. package/package.json +23 -7
  132. package/src/core/boot.ts +1 -1
  133. package/src/core/func.ts +4 -0
  134. package/src/core/natives/control.ts +1 -1
  135. package/src/core/natives/series.ts +9 -1
  136. package/src/core/natives/text.ts +2 -0
  137. package/src/host/browser.ts +1235 -83
  138. package/src/host/devlog.ts +16 -0
  139. package/src/host/devtools.ts +641 -0
  140. package/src/host/fonts/OFL.txt +93 -0
  141. package/src/host/fonts/inter-cyrillic-ext.woff2 +0 -0
  142. package/src/host/fonts/inter-cyrillic.woff2 +0 -0
  143. package/src/host/fonts/inter-greek-ext.woff2 +0 -0
  144. package/src/host/fonts/inter-greek.woff2 +0 -0
  145. package/src/host/fonts/inter-latin-ext.woff2 +0 -0
  146. package/src/host/fonts/inter-latin.woff2 +0 -0
  147. package/src/host/fonts/inter-vietnamese.woff2 +0 -0
  148. package/src/host/fonts.ts +39 -0
  149. package/src/host/index.ts +5 -3
  150. package/src/host/js.ts +127 -0
  151. package/src/host/markdown.ts +9 -0
  152. package/src/host/modules.ts +41 -2
  153. package/src/host/net.ts +9 -1
  154. package/src/host/orbit.ts +432 -0
  155. package/src/host/rows.ts +30 -0
  156. package/src/host/scheduler.ts +62 -36
  157. package/src/host/theme.ts +270 -6
  158. package/src/ui/i18n.trb +10 -0
  159. package/src/ui/test.trb +565 -0
  160. package/src/ui/ui.trb +564 -90
@@ -0,0 +1,134 @@
1
+ // Datatype identifiers.
2
+ //
3
+ // A plain const object instead of a TS `enum`: enums are not erasable syntax,
4
+ // so Node cannot run them with type stripping. The numeric values are stable
5
+ // and meant to be mirrored 1:1 by a `enum(u8)` in a future Zig core.
6
+ export const K = {
7
+ Unset: 0,
8
+ None: 1,
9
+ Logic: 2,
10
+ Integer: 3,
11
+ Decimal: 4,
12
+ Percent: 5,
13
+ Money: 6,
14
+ Char: 7,
15
+ Pair: 8,
16
+ Tuple: 9,
17
+ Date: 10,
18
+ Time: 11,
19
+ // string-like series (code points or bytes)
20
+ String: 12,
21
+ File: 13,
22
+ Email: 14,
23
+ Url: 15,
24
+ Tag: 16,
25
+ Binary: 17,
26
+ Bitset: 18,
27
+ // word-like (carry a symbol and a binding)
28
+ Word: 19,
29
+ SetWord: 20,
30
+ GetWord: 21,
31
+ LitWord: 22,
32
+ Refinement: 23,
33
+ Issue: 24,
34
+ // block-like (series of cells)
35
+ Block: 25,
36
+ Paren: 26,
37
+ Path: 27,
38
+ SetPath: 28,
39
+ GetPath: 29,
40
+ LitPath: 30,
41
+ // contexts and the rest
42
+ Map: 31,
43
+ Object: 32,
44
+ Error: 33,
45
+ Function: 34,
46
+ Native: 35,
47
+ Op: 36,
48
+ Datatype: 37,
49
+ Typeset: 38,
50
+ Handle: 39,
51
+ };
52
+ /** Datatype names, indexed by Kind. */
53
+ export const KIND_NAMES = [
54
+ 'unset!', 'none!', 'logic!', 'integer!', 'decimal!', 'percent!', 'money!',
55
+ 'char!', 'pair!', 'tuple!', 'date!', 'time!',
56
+ 'string!', 'file!', 'email!', 'url!', 'tag!', 'binary!', 'bitset!',
57
+ 'word!', 'set-word!', 'get-word!', 'lit-word!', 'refinement!', 'issue!',
58
+ 'block!', 'paren!', 'path!', 'set-path!', 'get-path!', 'lit-path!',
59
+ 'map!', 'object!', 'error!', 'function!', 'native!', 'op!',
60
+ 'datatype!', 'typeset!', 'handle!',
61
+ ];
62
+ export const KIND_COUNT = KIND_NAMES.length;
63
+ const byName = new Map();
64
+ KIND_NAMES.forEach((n, i) => byName.set(n, i));
65
+ /** Looks up a datatype by its name, e.g. "integer!". Case-insensitive. */
66
+ export function kindByName(name) {
67
+ return byName.get(name.toLowerCase());
68
+ }
69
+ export function kindName(k) {
70
+ return KIND_NAMES[k] ?? '?!';
71
+ }
72
+ /** The kind's name with its article: "a block!", "an email!". */
73
+ export function aKindName(k) {
74
+ const n = kindName(k);
75
+ return ('aeiou'.includes(n[0]) ? 'an ' : 'a ') + n;
76
+ }
77
+ // --- classification helpers ------------------------------------------------
78
+ export function isAnyString(k) {
79
+ return k >= K.String && k <= K.Tag;
80
+ }
81
+ export function isAnyWord(k) {
82
+ return k >= K.Word && k <= K.Issue;
83
+ }
84
+ export function isAnyBlock(k) {
85
+ return k >= K.Block && k <= K.LitPath;
86
+ }
87
+ export function isAnyPath(k) {
88
+ return k >= K.Path && k <= K.LitPath;
89
+ }
90
+ export function isSeries(k) {
91
+ return (k >= K.String && k <= K.Binary) || isAnyBlock(k);
92
+ }
93
+ // --- typesets ------------------------------------------------------------------
94
+ /**
95
+ * A typeset as a table indexed by kind, for checks on the hot path: testing
96
+ * a bigint mask allocates, reading an array does not.
97
+ */
98
+ export function kindTable(bits) {
99
+ const out = [];
100
+ for (let k = 0; k < KIND_COUNT; k++)
101
+ out.push((bits & (1n << BigInt(k))) !== 0n);
102
+ return out;
103
+ }
104
+ /** A set of kinds as a bitmask: bit `k` is set when kind `k` belongs to it. */
105
+ export function kindBit(k) {
106
+ return 1n << BigInt(k);
107
+ }
108
+ function range(from, to) {
109
+ let bits = 0n;
110
+ for (let k = from; k <= to; k++)
111
+ bits |= 1n << BigInt(k);
112
+ return bits;
113
+ }
114
+ const ALL_KINDS = range(K.Unset, (KIND_COUNT - 1));
115
+ /** Built-in typesets, usable wherever a datatype is expected (function specs, `make typeset!`). */
116
+ export const TYPESETS = {
117
+ 'any-type!': ALL_KINDS,
118
+ 'any-value!': ALL_KINDS & ~kindBit(K.Unset),
119
+ 'number!': kindBit(K.Integer) | kindBit(K.Decimal) | kindBit(K.Percent),
120
+ 'scalar!': range(K.Logic, K.Time) & ~kindBit(K.Logic),
121
+ 'any-string!': range(K.String, K.Tag),
122
+ 'series!': range(K.String, K.Binary) | range(K.Block, K.LitPath),
123
+ 'any-word!': range(K.Word, K.Issue),
124
+ 'any-block!': range(K.Block, K.LitPath),
125
+ 'any-path!': range(K.Path, K.LitPath),
126
+ 'any-object!': kindBit(K.Object) | kindBit(K.Error),
127
+ 'any-function!': kindBit(K.Function) | kindBit(K.Native) | kindBit(K.Op),
128
+ };
129
+ /** Bits for a datatype or typeset name ("integer!", "series!"), or undefined. */
130
+ export function typeBitsByName(name) {
131
+ const lower = name.toLowerCase();
132
+ const k = byName.get(lower);
133
+ return k !== undefined ? kindBit(k) : TYPESETS[lower];
134
+ }
@@ -0,0 +1,13 @@
1
+ import { type BlockCell } from './values.ts';
2
+ export declare class LoadError extends Error {
3
+ readonly line: number;
4
+ readonly col: number;
5
+ readonly file: string | undefined;
6
+ constructor(message: string, line: number, col: number, file?: string);
7
+ }
8
+ export interface LoadOptions {
9
+ /** File name used in error messages and kept on the loaded series. */
10
+ file?: string;
11
+ }
12
+ /** Loads source text into a block. Throws LoadError on malformed input. */
13
+ export declare function load(src: string, opts?: LoadOptions): BlockCell;