cluaupp 1.5.2 → 2.0.0-beta.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 (210) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +29 -41
  3. package/api/generated/bench-latest.json +43 -21
  4. package/api/generated/lsp-index.json +1 -1
  5. package/api/manifests/roblox-target.manifest.json +5 -5
  6. package/api/normalized/roblox-target.profile.json +8729 -267
  7. package/api/roblox/luau-builtins.d.luau +185 -0
  8. package/api/roblox/surface.json +1 -0
  9. package/api/roblox-api.lock.json +11 -2
  10. package/bin/cluaupp.js +38 -0
  11. package/editors/vscode/README.md +1 -1
  12. package/editors/vscode/package.json +50 -15
  13. package/editors/vscode/snippets/flare.json +1 -1
  14. package/editors/vscode/snippets/hive.json +1 -1
  15. package/editors/vscode/syntaxes/clpp.tmLanguage.json +211 -0
  16. package/examples/README.md +9 -9
  17. package/examples/game/cluaupp.config.json +2 -2
  18. package/examples/game/default.project.json +4 -15
  19. package/examples/game/out/ReplicatedStorage/Shared/GameInfo.luau +8 -0
  20. package/examples/game/out/ReplicatedStorage/Shared/GameInfo.luau.map.json +13 -0
  21. package/examples/game/out/ServerScriptService/Leaderstats.server.luau +26 -0
  22. package/examples/game/out/ServerScriptService/Leaderstats.server.luau.map.json +13 -0
  23. package/examples/game/out/ServerScriptService/Main.server.luau +15 -0
  24. package/examples/game/out/ServerScriptService/Main.server.luau.map.json +13 -0
  25. package/examples/game/out/StarterPlayer/StarterPlayerScripts/Main.client.luau +10 -0
  26. package/examples/game/out/StarterPlayer/StarterPlayerScripts/Main.client.luau.map.json +13 -0
  27. package/examples/game/src/ReplicatedStorage/Shared/GameInfo.clp +1 -0
  28. package/examples/game/src/ServerScriptService/Leaderstats.server.clp +18 -0
  29. package/examples/game/src/ServerScriptService/Main.server.clp +9 -0
  30. package/examples/game/src/StarterPlayer/StarterPlayerScripts/Main.client.clp +4 -0
  31. package/generated/api/build-profile.js +1 -1
  32. package/generated/api/loader.js +2 -2
  33. package/generated/api/surface/build.js +328 -0
  34. package/generated/api/surface/luau-defs.js +595 -0
  35. package/generated/api/surface/model.js +8 -0
  36. package/generated/api-cli.js +2 -2
  37. package/generated/cli.js +18 -17
  38. package/generated/clpp/contract.js +6 -3
  39. package/generated/clpp/handshake.js +36 -0
  40. package/generated/clpp/modules.js +20 -9
  41. package/generated/clpp/runner.js +62 -31
  42. package/generated/compile.js +18 -1
  43. package/generated/compiler/ast.js +3 -0
  44. package/generated/compiler/checker/calls.js +999 -0
  45. package/generated/compiler/checker/checker.js +1215 -0
  46. package/generated/compiler/checker/exprs.js +791 -0
  47. package/generated/compiler/checker/flow.js +168 -0
  48. package/generated/compiler/checker/members.js +763 -0
  49. package/generated/compiler/checker/statements.js +792 -0
  50. package/generated/compiler/checker/symbols.js +90 -0
  51. package/generated/compiler/checker/typeops.js +348 -0
  52. package/generated/compiler/checker/yields.js +115 -0
  53. package/generated/compiler/diagnostics.js +138 -0
  54. package/generated/compiler/emit/emitter.js +2356 -0
  55. package/generated/compiler/emit/luau-types.js +137 -0
  56. package/generated/compiler/emit/names.js +130 -0
  57. package/generated/compiler/emit/runtime.js +432 -0
  58. package/generated/compiler/lexer.js +403 -0
  59. package/generated/compiler/parser.js +1881 -0
  60. package/generated/compiler/project.js +332 -0
  61. package/generated/compiler/roblox/api.js +388 -0
  62. package/generated/compiler/roblox/context.js +100 -0
  63. package/generated/compiler/source.js +59 -0
  64. package/generated/compiler/stdlib.js +232 -0
  65. package/generated/compiler/types.js +250 -0
  66. package/generated/intellisense.js +1 -15
  67. package/generated/lsp.js +1 -1
  68. package/generated/target/build-cache.js +4 -4
  69. package/generated/target/datamodel-generate.js +12 -0
  70. package/generated/target/gen-rojo-tree.js +15 -0
  71. package/generated/target/source-map.js +61 -8
  72. package/generated/target/studio-bridge.js +1 -0
  73. package/generated/utils/project.js +104 -31
  74. package/include/README.md +5 -0
  75. package/native/bin/.gitkeep +1 -0
  76. package/package.json +17 -6
  77. package/plugins/CluauppNav/Plugin.luau +28 -4
  78. package/rust/cluaupp/Cargo.lock +795 -0
  79. package/rust/cluaupp/Cargo.toml +17 -0
  80. package/rust/cluaupp/src/main.rs +717 -0
  81. package/scripts/postinstall-native.js +56 -0
  82. package/skills/README.md +3 -3
  83. package/skills/clpp-hive-flare/SKILL.md +30 -26
  84. package/skills/clpp-language/SKILL.md +67 -74
  85. package/skills/clpp-language/compiler.md +24 -36
  86. package/skills/clpp-style/SKILL.md +31 -44
  87. package/src/api/build-profile.ts +1 -1
  88. package/src/api/loader.ts +2 -2
  89. package/src/api/surface/build.ts +374 -0
  90. package/src/api/surface/luau-defs.ts +635 -0
  91. package/src/api/surface/model.ts +96 -0
  92. package/src/api-cli.ts +2 -2
  93. package/src/cli.ts +19 -18
  94. package/src/clpp/contract.ts +20 -3
  95. package/src/clpp/handshake.ts +25 -0
  96. package/src/clpp/modules.ts +17 -10
  97. package/src/clpp/runner.ts +52 -34
  98. package/src/compile.ts +20 -2
  99. package/src/compiler/ast.ts +336 -0
  100. package/src/compiler/checker/calls.ts +1025 -0
  101. package/src/compiler/checker/checker.ts +1352 -0
  102. package/src/compiler/checker/exprs.ts +805 -0
  103. package/src/compiler/checker/flow.ts +174 -0
  104. package/src/compiler/checker/members.ts +793 -0
  105. package/src/compiler/checker/statements.ts +802 -0
  106. package/src/compiler/checker/symbols.ts +219 -0
  107. package/src/compiler/checker/typeops.ts +355 -0
  108. package/src/compiler/checker/yields.ts +120 -0
  109. package/src/compiler/diagnostics.ts +163 -0
  110. package/src/compiler/emit/emitter.ts +2486 -0
  111. package/src/compiler/emit/luau-types.ts +143 -0
  112. package/src/compiler/emit/names.ts +130 -0
  113. package/src/compiler/emit/runtime.ts +438 -0
  114. package/src/compiler/lexer.ts +444 -0
  115. package/src/compiler/parser.ts +1943 -0
  116. package/src/compiler/project.ts +354 -0
  117. package/src/compiler/roblox/api.ts +408 -0
  118. package/src/compiler/roblox/context.ts +108 -0
  119. package/src/compiler/source.ts +67 -0
  120. package/src/compiler/stdlib.ts +256 -0
  121. package/src/compiler/types.ts +313 -0
  122. package/src/intellisense.ts +1 -13
  123. package/src/lsp.ts +1 -1
  124. package/src/target/build-cache.ts +5 -8
  125. package/src/target/datamodel-generate.ts +12 -1
  126. package/src/target/gen-rojo-tree.ts +15 -0
  127. package/src/target/source-map.ts +65 -27
  128. package/src/target/studio-bridge.ts +3 -0
  129. package/src/types.ts +3 -0
  130. package/src/utils/project.ts +99 -37
  131. package/templates/README.md +7 -0
  132. package/templates/{game → game-modern}/cluaupp.config.json +2 -2
  133. package/templates/{game → game-modern}/package.json +1 -2
  134. package/templates/game-modern/rokit.toml +2 -0
  135. package/templates/game-modern/src/ReplicatedStorage/Shared/GameInfo.clp +1 -0
  136. package/templates/game-modern/src/ServerScriptService/Handlers/Guard.server.clp +4 -0
  137. package/templates/game-modern/src/ServerScriptService/Main.server.clp +8 -0
  138. package/templates/game-modern/src/StarterPlayer/StarterPlayerScripts/Main.client.clp +4 -0
  139. package/examples/game/out/ReplicatedStorage/Shared/Constants/Datas/TemplateData.luau +0 -29
  140. package/examples/game/out/ReplicatedStorage/Shared/Constants/Datas/TemplateData.luau.map.json +0 -13
  141. package/examples/game/out/ReplicatedStorage/Shared/Net/Net.luau +0 -83
  142. package/examples/game/out/ReplicatedStorage/Shared/Net/Net.luau.map.json +0 -13
  143. package/examples/game/out/ServerScriptService/Boot/DataBoot.server.luau +0 -18
  144. package/examples/game/out/ServerScriptService/Boot/DataBoot.server.luau.map.json +0 -13
  145. package/examples/game/out/ServerScriptService/Configuration/ServerConfig.luau +0 -14
  146. package/examples/game/out/ServerScriptService/Configuration/ServerConfig.luau.map.json +0 -13
  147. package/examples/game/out/ServerScriptService/Handlers/Guard.server.luau +0 -15
  148. package/examples/game/out/ServerScriptService/Handlers/Guard.server.luau.map.json +0 -13
  149. package/examples/game/out/ServerScriptService/Handlers/PlayerHandler.server.luau +0 -50
  150. package/examples/game/out/ServerScriptService/Handlers/PlayerHandler.server.luau.map.json +0 -13
  151. package/examples/game/out/StarterPlayer/StarterCharacterScripts/Character/CharacterReady.client.luau +0 -12
  152. package/examples/game/out/StarterPlayer/StarterCharacterScripts/Character/CharacterReady.client.luau.map.json +0 -13
  153. package/examples/game/out/StarterPlayer/StarterPlayerScripts/Controllers/DataController.client.luau +0 -16
  154. package/examples/game/out/StarterPlayer/StarterPlayerScripts/Controllers/DataController.client.luau.map.json +0 -13
  155. package/examples/game/src/Client/Controllers/DataController.client.clpp +0 -7
  156. package/examples/game/src/Client/Main.client.clpp +0 -4
  157. package/examples/game/src/Declarations/Net.flare +0 -5
  158. package/examples/game/src/Include/GameTypes.clh +0 -40
  159. package/examples/game/src/Modules/Core/Guard.server.clpp +0 -7
  160. package/examples/game/src/Modules/Core/PlayerHandler.server.clpp +0 -23
  161. package/examples/game/src/Server/Boot/DataBoot.server.clpp +0 -13
  162. package/examples/game/src/Server/Main.server.clpp +0 -4
  163. package/templates/game/.clangd +0 -25
  164. package/templates/game/.vscode/extensions.json +0 -8
  165. package/templates/game/.vscode/settings.json +0 -17
  166. package/templates/game/Packages/.gitkeep +0 -0
  167. package/templates/game/compile_flags.txt +0 -6
  168. package/templates/game/default.project.json +0 -41
  169. package/templates/game/include/clpp/datatypes.clh +0 -575
  170. package/templates/game/include/clpp/generated/enums.clh +0 -4920
  171. package/templates/game/include/clpp/generated/instances.clh +0 -87182
  172. package/templates/game/include/clpp/libs/arrayindexer.clh +0 -12
  173. package/templates/game/include/clpp/libs/axiom.clh +0 -154
  174. package/templates/game/include/clpp/libs/bloom.clh +0 -58
  175. package/templates/game/include/clpp/libs/coil.clh +0 -37
  176. package/templates/game/include/clpp/libs/crest.clh +0 -22
  177. package/templates/game/include/clpp/libs/echo.clh +0 -52
  178. package/templates/game/include/clpp/libs/ember.clh +0 -17
  179. package/templates/game/include/clpp/libs/flare.clh +0 -65
  180. package/templates/game/include/clpp/libs/gleam.clh +0 -111
  181. package/templates/game/include/clpp/libs/guide.clh +0 -42
  182. package/templates/game/include/clpp/libs/helm.clh +0 -31
  183. package/templates/game/include/clpp/libs/hive.clh +0 -20
  184. package/templates/game/include/clpp/libs/keep.clh +0 -158
  185. package/templates/game/include/clpp/libs/lens.clh +0 -24
  186. package/templates/game/include/clpp/libs/mint.clh +0 -28
  187. package/templates/game/include/clpp/libs/net.clh +0 -31
  188. package/templates/game/include/clpp/libs/occlude.clh +0 -15
  189. package/templates/game/include/clpp/libs/pin.clh +0 -28
  190. package/templates/game/include/clpp/libs/promise.clh +0 -24
  191. package/templates/game/include/clpp/libs/roster.clh +0 -123
  192. package/templates/game/include/clpp/libs/shift.clh +0 -22
  193. package/templates/game/include/clpp/libs/spark.clh +0 -28
  194. package/templates/game/include/clpp/libs/stage.clh +0 -23
  195. package/templates/game/include/clpp/libs/sweep.clh +0 -23
  196. package/templates/game/include/clpp/libs/trace.clh +0 -18
  197. package/templates/game/include/clpp/libs/ward.clh +0 -19
  198. package/templates/game/include/clpp/libs.clh +0 -31
  199. package/templates/game/include/clpp/roblox.clh +0 -41
  200. package/templates/game/rokit.toml +0 -5
  201. package/templates/game/src/Client/Controllers/DataController.client.clpp +0 -7
  202. package/templates/game/src/Client/Main.client.clpp +0 -4
  203. package/templates/game/src/Declarations/Net.flare +0 -5
  204. package/templates/game/src/Include/GameTypes.clh +0 -40
  205. package/templates/game/src/Modules/Core/Guard.server.clpp +0 -7
  206. package/templates/game/src/Modules/Core/PlayerHandler.server.clpp +0 -24
  207. package/templates/game/src/Server/Boot/DataBoot.server.clpp +0 -13
  208. package/templates/game/src/Server/Main.server.clpp +0 -4
  209. package/templates/game/stylua.toml +0 -9
  210. package/templates/game/wally.toml +0 -12
@@ -0,0 +1,403 @@
1
+ "use strict";
2
+ /**
3
+ * CL++ 0.9 lexer (mirrors KartzRbx/CLPP `src/core/lexer/lexer.cpp`).
4
+ * `<<` line comments, `<<[ … ]>>` blocks, `<<[[]] … >>` doc comments, `<<!strict` directives,
5
+ * `.:` concat, `~>` connect, `::` scope, templates with `${}`, numbers with `_`, hex and binary.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.Lexer = exports.VALUE_KEYWORDS = exports.KEYWORDS = void 0;
9
+ exports.tokenize = tokenize;
10
+ exports.KEYWORDS = new Set([
11
+ "Vector2", "Vector3", "Vector4", "abstract", "and", "as", "async", "atomic", "auto", "await", "bool", "break",
12
+ "buffer", "case", "catch", "const", "constexpr", "continue", "cout", "decltype", "default", "double", "else",
13
+ "endl", "enum", "extern", "false", "final", "float", "for", "from", "func", "guard", "if", "import", "in", "int",
14
+ "join", "let", "link", "match", "move", "mut", "namespace", "new", "not", "null", "observable", "operator", "or",
15
+ "override", "parallel", "pcall", "post", "private", "public", "report", "return", "shl", "shr", "signal", "spawn",
16
+ "static", "string", "struct", "switch", "task", "thread", "true", "try", "type", "using", "variant", "void",
17
+ "warn", "where", "while",
18
+ ]);
19
+ /** Keywords that also name a value in Roblox code (`task.wait`, `string.format`, `buffer.create`, `type(x)`). */
20
+ exports.VALUE_KEYWORDS = new Set(["task", "string", "buffer", "type", "Vector2", "Vector3", "warn", "thread"]);
21
+ const OPERATORS = [
22
+ "...", "<=", ">=", "==", "!=", "&&", "||", "++", "--", "+=", "-=", "*=", "/=", "%=", "->", "=>", "~>", "::", ".:",
23
+ "..", "+", "-", "*", "/", "%", "=", "<", ">", "!", "&", "|", "^", "~", "?", ":", ".", ",", ";", "(", ")", "{",
24
+ "}", "[", "]", "@", "#",
25
+ ];
26
+ function isIdentStart(c) {
27
+ return (c >= 65 && c <= 90) || (c >= 97 && c <= 122) || c === 95 || c >= 0x80;
28
+ }
29
+ function isIdentPart(c) {
30
+ return isIdentStart(c) || (c >= 48 && c <= 57);
31
+ }
32
+ function isDigit(c) {
33
+ return c >= 48 && c <= 57;
34
+ }
35
+ const ESCAPES = {
36
+ n: "\n",
37
+ t: "\t",
38
+ r: "\r",
39
+ "0": "\0",
40
+ "\\": "\\",
41
+ '"': '"',
42
+ "'": "'",
43
+ "`": "`",
44
+ $: "$",
45
+ "{": "{",
46
+ "}": "}",
47
+ };
48
+ class Lexer {
49
+ diagnostics;
50
+ base;
51
+ end;
52
+ pos = 0;
53
+ tokens = [];
54
+ newline = true;
55
+ text;
56
+ constructor(text, diagnostics, base = 0, end = text.length) {
57
+ this.diagnostics = diagnostics;
58
+ this.base = base;
59
+ this.end = end;
60
+ this.text = text;
61
+ this.pos = base;
62
+ if (base === 0 && text.charCodeAt(0) === 0xfeff) {
63
+ this.pos = 1;
64
+ }
65
+ }
66
+ tokenize() {
67
+ while (true) {
68
+ this.skipTrivia();
69
+ if (this.pos >= this.end) {
70
+ this.push("eof", this.pos, this.pos);
71
+ return this.tokens;
72
+ }
73
+ this.next();
74
+ }
75
+ }
76
+ push(kind, start, end, value, parts) {
77
+ const token = { kind, text: this.text.slice(start, end), start, end, newlineBefore: this.newline };
78
+ if (value !== undefined) {
79
+ token.value = value;
80
+ }
81
+ if (parts) {
82
+ token.parts = parts;
83
+ }
84
+ this.newline = false;
85
+ this.tokens.push(token);
86
+ return token;
87
+ }
88
+ span(start, end) {
89
+ return { start, end };
90
+ }
91
+ skipTrivia() {
92
+ const t = this.text;
93
+ while (this.pos < this.end) {
94
+ const c = t.charCodeAt(this.pos);
95
+ if (c === 10 || c === 13) {
96
+ this.newline = true;
97
+ this.pos++;
98
+ continue;
99
+ }
100
+ if (c === 32 || c === 9 || c === 11 || c === 12) {
101
+ this.pos++;
102
+ continue;
103
+ }
104
+ if (c === 60 && t.charCodeAt(this.pos + 1) === 60) {
105
+ // `<<` comment family
106
+ const start = this.pos;
107
+ const third = t[this.pos + 2];
108
+ if (third === "!") {
109
+ let p = this.pos + 3;
110
+ while (p < this.end && /[A-Za-z0-9_-]/.test(t[p])) {
111
+ p++;
112
+ }
113
+ const word = t.slice(this.pos + 3, p);
114
+ this.push("directive", start, p, word);
115
+ this.pos = p;
116
+ this.skipLine();
117
+ continue;
118
+ }
119
+ if (third === "[" && t[this.pos + 3] === "[" && t[this.pos + 4] === "]" && t[this.pos + 5] === "]") {
120
+ const close = t.indexOf(">>", this.pos + 6);
121
+ if (close < 0 || close >= this.end) {
122
+ this.diagnostics.error("CL1003", this.span(start, Math.min(this.end, start + 6)), "unterminated doc comment", ["close it with `>>`"]);
123
+ this.pos = this.end;
124
+ return;
125
+ }
126
+ this.push("doc", start, close + 2, t.slice(this.pos + 6, close).trim());
127
+ this.pos = close + 2;
128
+ continue;
129
+ }
130
+ if (third === "[") {
131
+ const close = t.indexOf("]>>", this.pos + 3);
132
+ if (close < 0 || close >= this.end) {
133
+ this.diagnostics.error("CL1002", this.span(start, Math.min(this.end, start + 3)), "unterminated block comment", ["close it with `]>>`"]);
134
+ this.pos = this.end;
135
+ return;
136
+ }
137
+ for (let i = this.pos; i < close; i++) {
138
+ const cc = t.charCodeAt(i);
139
+ if (cc === 10 || cc === 13) {
140
+ this.newline = true;
141
+ }
142
+ }
143
+ this.pos = close + 3;
144
+ continue;
145
+ }
146
+ this.skipLine();
147
+ continue;
148
+ }
149
+ break;
150
+ }
151
+ }
152
+ skipLine() {
153
+ while (this.pos < this.end) {
154
+ const c = this.text.charCodeAt(this.pos);
155
+ if (c === 10 || c === 13) {
156
+ return;
157
+ }
158
+ this.pos++;
159
+ }
160
+ }
161
+ next() {
162
+ const t = this.text;
163
+ const start = this.pos;
164
+ const c = t.charCodeAt(start);
165
+ if (isIdentStart(c)) {
166
+ let p = start + 1;
167
+ while (p < this.end && isIdentPart(t.charCodeAt(p))) {
168
+ p++;
169
+ }
170
+ this.pos = p;
171
+ const word = t.slice(start, p);
172
+ this.push(exports.KEYWORDS.has(word) ? "keyword" : "ident", start, p);
173
+ return;
174
+ }
175
+ if (isDigit(c)) {
176
+ this.number(start);
177
+ return;
178
+ }
179
+ if (c === 34 || c === 39) {
180
+ this.string(start, c);
181
+ return;
182
+ }
183
+ if (c === 96) {
184
+ this.template(start);
185
+ return;
186
+ }
187
+ for (const op of OPERATORS) {
188
+ if (t.startsWith(op, start)) {
189
+ this.pos = start + op.length;
190
+ this.push("op", start, this.pos);
191
+ return;
192
+ }
193
+ }
194
+ this.pos = start + 1;
195
+ this.diagnostics.error("CL1001", this.span(start, this.pos), `unexpected character '${t[start]}'`);
196
+ }
197
+ number(start) {
198
+ const t = this.text;
199
+ let p = start;
200
+ let isFloat = false;
201
+ let bad = false;
202
+ const digits = (accept) => {
203
+ let last = "";
204
+ let count = 0;
205
+ while (p < this.end) {
206
+ const ch = t[p];
207
+ if (ch === "_") {
208
+ if (!accept(last) || !accept(t[p + 1] ?? "")) {
209
+ bad = true;
210
+ }
211
+ last = ch;
212
+ p++;
213
+ continue;
214
+ }
215
+ if (!accept(ch)) {
216
+ break;
217
+ }
218
+ last = ch;
219
+ count++;
220
+ p++;
221
+ }
222
+ return count;
223
+ };
224
+ const dec = (ch) => ch >= "0" && ch <= "9";
225
+ if (t[p] === "0" && (t[p + 1] === "x" || t[p + 1] === "X")) {
226
+ p += 2;
227
+ const n = digits((ch) => /[0-9a-fA-F]/.test(ch));
228
+ if (n === 0) {
229
+ bad = true;
230
+ }
231
+ }
232
+ else if (t[p] === "0" && (t[p + 1] === "b" || t[p + 1] === "B")) {
233
+ p += 2;
234
+ const n = digits((ch) => ch === "0" || ch === "1");
235
+ if (n === 0) {
236
+ bad = true;
237
+ }
238
+ }
239
+ else {
240
+ digits(dec);
241
+ // `0..4` is a range, `3.5` a float, `3.` followed by a name is member access.
242
+ if (t[p] === "." && dec(t[p + 1] ?? "")) {
243
+ isFloat = true;
244
+ p++;
245
+ digits(dec);
246
+ }
247
+ if (t[p] === "e" || t[p] === "E") {
248
+ let q = p + 1;
249
+ if (t[q] === "+" || t[q] === "-") {
250
+ q++;
251
+ }
252
+ if (dec(t[q] ?? "")) {
253
+ isFloat = true;
254
+ p = q;
255
+ digits(dec);
256
+ }
257
+ }
258
+ }
259
+ this.pos = p;
260
+ const raw = t.slice(start, p);
261
+ const clean = raw.replace(/_/g, "");
262
+ let value;
263
+ if (/^0[xX]/.test(clean)) {
264
+ value = parseInt(clean.slice(2), 16);
265
+ }
266
+ else if (/^0[bB]/.test(clean)) {
267
+ value = parseInt(clean.slice(2), 2);
268
+ }
269
+ else {
270
+ value = Number(clean);
271
+ }
272
+ if (bad || !Number.isFinite(value)) {
273
+ this.diagnostics.error("CL1004", this.span(start, p), raw.includes("_") ? "invalid numeric separator" : "invalid numeric literal");
274
+ value = 0;
275
+ }
276
+ this.push(isFloat ? "float" : "int", start, p, value);
277
+ }
278
+ escape(p, out) {
279
+ const t = this.text;
280
+ const ch = t[p + 1];
281
+ if (ch === "u" && t[p + 2] === "{") {
282
+ const close = t.indexOf("}", p + 3);
283
+ const hex = close > 0 ? t.slice(p + 3, close) : "";
284
+ if (/^[0-9a-fA-F]{1,6}$/.test(hex)) {
285
+ out.push(String.fromCodePoint(parseInt(hex, 16)));
286
+ return close + 1;
287
+ }
288
+ }
289
+ const mapped = ch !== undefined ? ESCAPES[ch] : undefined;
290
+ if (mapped === undefined) {
291
+ this.diagnostics.error("CL1005", this.span(p, Math.min(this.end, p + 2)), `invalid escape '\\${ch ?? ""}'`, ["valid escapes: \\n \\t \\r \\0 \\\\ \\\" \\' \\` \\$ \\u{hex}"]);
292
+ out.push(ch ?? "");
293
+ return p + 2;
294
+ }
295
+ out.push(mapped);
296
+ return p + 2;
297
+ }
298
+ string(start, quote) {
299
+ const t = this.text;
300
+ let p = start + 1;
301
+ const out = [];
302
+ while (p < this.end) {
303
+ const c = t.charCodeAt(p);
304
+ if (c === quote) {
305
+ this.pos = p + 1;
306
+ this.push("string", start, this.pos, out.join(""));
307
+ return;
308
+ }
309
+ if (c === 10 || c === 13) {
310
+ break;
311
+ }
312
+ if (c === 92) {
313
+ p = this.escape(p, out);
314
+ continue;
315
+ }
316
+ out.push(t[p]);
317
+ p++;
318
+ }
319
+ this.pos = p;
320
+ this.diagnostics.error("CL1006", this.span(start, p), "unterminated string");
321
+ this.push("string", start, p, out.join(""));
322
+ }
323
+ template(start) {
324
+ const t = this.text;
325
+ let p = start + 1;
326
+ const parts = [];
327
+ let literal = [];
328
+ const flush = () => {
329
+ if (literal.length) {
330
+ parts.push({ text: literal.join("") });
331
+ literal = [];
332
+ }
333
+ };
334
+ while (p < this.end) {
335
+ const c = t.charCodeAt(p);
336
+ if (c === 96) {
337
+ flush();
338
+ this.pos = p + 1;
339
+ this.push("template", start, this.pos, undefined, parts);
340
+ return;
341
+ }
342
+ if (c === 10 || c === 13) {
343
+ break;
344
+ }
345
+ if (c === 92) {
346
+ p = this.escape(p, literal);
347
+ continue;
348
+ }
349
+ if (c === 36 && t[p + 1] === "{") {
350
+ flush();
351
+ let depth = 1;
352
+ let q = p + 2;
353
+ let quote = 0;
354
+ while (q < this.end && depth > 0) {
355
+ const d = t.charCodeAt(q);
356
+ if (quote) {
357
+ if (d === 92) {
358
+ q += 2;
359
+ continue;
360
+ }
361
+ if (d === quote) {
362
+ quote = 0;
363
+ }
364
+ }
365
+ else if (d === 34 || d === 39) {
366
+ quote = d;
367
+ }
368
+ else if (d === 123) {
369
+ depth++;
370
+ }
371
+ else if (d === 125) {
372
+ depth--;
373
+ if (depth === 0) {
374
+ break;
375
+ }
376
+ }
377
+ else if (d === 10 || d === 13 || d === 96) {
378
+ break;
379
+ }
380
+ q++;
381
+ }
382
+ if (depth !== 0 || q >= this.end || t.charCodeAt(q) !== 125) {
383
+ this.diagnostics.error("CL1007", this.span(p, Math.min(this.end, q)), "unterminated interpolation", ["close `${` with `}`"]);
384
+ p = q;
385
+ break;
386
+ }
387
+ parts.push({ hole: { start: p + 2, end: q } });
388
+ p = q + 1;
389
+ continue;
390
+ }
391
+ literal.push(t[p]);
392
+ p++;
393
+ }
394
+ flush();
395
+ this.pos = p;
396
+ this.diagnostics.error("CL1008", this.span(start, p), "unterminated template string");
397
+ this.push("template", start, p, undefined, parts);
398
+ }
399
+ }
400
+ exports.Lexer = Lexer;
401
+ function tokenize(text, diagnostics, base = 0, end = text.length) {
402
+ return new Lexer(text, diagnostics, base, end).tokenize();
403
+ }