authorgravatar for 11367844+lino-levan@users.noreply.github.comLino Le Van <11367844+lino-levan@users.noreply.github.com> 2024-01-09 18:25:23-08:00
committergravatar for 11367844+lino-levan@users.noreply.github.comLino Le Van <11367844+lino-levan@users.noreply.github.com> 2024-01-09 18:25:23-08:00
logbf7dedc48580545fcbcbb877d6f84087b96b4c62
tree4c3e9f314c2647a517bba1d8f4c03eab5b5af113
parentb273a9fc6eaec7ed69a8c10b61d800e2b434f23f

feat: major refactor, lots of broken things


30 files changed, 1860 insertions(+), 426 deletions(-)

.gitignore+1-1
...@@ -1 +1 @@...@@ -1 +1 @@
1/target1target
Cargo.lock+35-25
...@@ -95,15 +95,6 @@ version = "2.4.1"...@@ -95,15 +95,6 @@ version = "2.4.1"
95source = "registry+https://github.com/rust-lang/crates.io-index"95source = "registry+https://github.com/rust-lang/crates.io-index"
96checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07"96checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07"
9797
98[[package]]
99name = "blight"
100version = "0.1.0"
101dependencies = [
102 "clap",
103 "miette",
104 "thiserror",
105]
106
107[[package]]98[[package]]
108name = "cc"99name = "cc"
109version = "1.0.83"100version = "1.0.83"
...@@ -121,9 +112,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"...@@ -121,9 +112,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
121112
122[[package]]113[[package]]
123name = "clap"114name = "clap"
124version = "4.4.12"115version = "4.4.14"
125source = "registry+https://github.com/rust-lang/crates.io-index"116source = "registry+https://github.com/rust-lang/crates.io-index"
126checksum = "dcfab8ba68f3668e89f6ff60f5b205cea56aa7b769451a59f34b8682f51c056d"117checksum = "33e92c5c1a78c62968ec57dbc2440366a2d6e5a23faf829970ff1585dc6b18e2"
127dependencies = [118dependencies = [
128 "clap_builder",119 "clap_builder",
129 "clap_derive",120 "clap_derive",
...@@ -131,9 +122,9 @@ dependencies = [...@@ -131,9 +122,9 @@ dependencies = [
131122
132[[package]]123[[package]]
133name = "clap_builder"124name = "clap_builder"
134version = "4.4.12"125version = "4.4.14"
135source = "registry+https://github.com/rust-lang/crates.io-index"126source = "registry+https://github.com/rust-lang/crates.io-index"
136checksum = "fb7fb5e4e979aec3be7791562fcba452f94ad85e954da024396433e0e25a79e9"127checksum = "f4323769dc8a61e2c39ad7dc26f6f2800524691a44d74fe3d1071a5c24db6370"
137dependencies = [128dependencies = [
138 "anstream",129 "anstream",
139 "anstyle",130 "anstyle",
...@@ -159,12 +150,31 @@ version = "0.6.0"...@@ -159,12 +150,31 @@ version = "0.6.0"
159source = "registry+https://github.com/rust-lang/crates.io-index"150source = "registry+https://github.com/rust-lang/crates.io-index"
160checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1"151checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1"
161152
153[[package]]
154name = "cli"
155version = "0.1.0"
156dependencies = [
157 "clap",
158 "compiler",
159 "miette",
160 "thiserror",
161]
162
162[[package]]163[[package]]
163name = "colorchoice"164name = "colorchoice"
164version = "1.0.0"165version = "1.0.0"
165source = "registry+https://github.com/rust-lang/crates.io-index"166source = "registry+https://github.com/rust-lang/crates.io-index"
166checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"167checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
167168
169[[package]]
170name = "compiler"
171version = "0.1.0"
172dependencies = [
173 "clap",
174 "miette",
175 "thiserror",
176]
177
168[[package]]178[[package]]
169name = "errno"179name = "errno"
170version = "0.3.8"180version = "0.3.8"
...@@ -212,9 +222,9 @@ checksum = "616cde7c720bb2bb5824a224687d8f77bfd38922027f01d825cd7453be5099fb"...@@ -212,9 +222,9 @@ checksum = "616cde7c720bb2bb5824a224687d8f77bfd38922027f01d825cd7453be5099fb"
212222
213[[package]]223[[package]]
214name = "libc"224name = "libc"
215version = "0.2.151"225version = "0.2.152"
216source = "registry+https://github.com/rust-lang/crates.io-index"226source = "registry+https://github.com/rust-lang/crates.io-index"
217checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4"227checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7"
218228
219[[package]]229[[package]]
220name = "linux-raw-sys"230name = "linux-raw-sys"
...@@ -292,18 +302,18 @@ checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f"...@@ -292,18 +302,18 @@ checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f"
292302
293[[package]]303[[package]]
294name = "proc-macro2"304name = "proc-macro2"
295version = "1.0.73"305version = "1.0.76"
296source = "registry+https://github.com/rust-lang/crates.io-index"306source = "registry+https://github.com/rust-lang/crates.io-index"
297checksum = "2dd5e8a1f1029c43224ad5898e50140c2aebb1705f19e67c918ebf5b9e797fe1"307checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c"
298dependencies = [308dependencies = [
299 "unicode-ident",309 "unicode-ident",
300]310]
301311
302[[package]]312[[package]]
303name = "quote"313name = "quote"
304version = "1.0.34"314version = "1.0.35"
305source = "registry+https://github.com/rust-lang/crates.io-index"315source = "registry+https://github.com/rust-lang/crates.io-index"
306checksum = "22a37c9326af5ed140c86a46655b5278de879853be5573c01df185b6f49a580a"316checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef"
307dependencies = [317dependencies = [
308 "proc-macro2",318 "proc-macro2",
309]319]
...@@ -369,9 +379,9 @@ dependencies = [...@@ -369,9 +379,9 @@ dependencies = [
369379
370[[package]]380[[package]]
371name = "syn"381name = "syn"
372version = "2.0.44"382version = "2.0.48"
373source = "registry+https://github.com/rust-lang/crates.io-index"383source = "registry+https://github.com/rust-lang/crates.io-index"
374checksum = "92d27c2c202598d05175a6dd3af46824b7f747f8d8e9b14c623f19fa5069735d"384checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f"
375dependencies = [385dependencies = [
376 "proc-macro2",386 "proc-macro2",
377 "quote",387 "quote",
...@@ -401,18 +411,18 @@ dependencies = [...@@ -401,18 +411,18 @@ dependencies = [
401411
402[[package]]412[[package]]
403name = "thiserror"413name = "thiserror"
404version = "1.0.53"414version = "1.0.56"
405source = "registry+https://github.com/rust-lang/crates.io-index"415source = "registry+https://github.com/rust-lang/crates.io-index"
406checksum = "b2cd5904763bad08ad5513ddbb12cf2ae273ca53fa9f68e843e236ec6dfccc09"416checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad"
407dependencies = [417dependencies = [
408 "thiserror-impl",418 "thiserror-impl",
409]419]
410420
411[[package]]421[[package]]
412name = "thiserror-impl"422name = "thiserror-impl"
413version = "1.0.53"423version = "1.0.56"
414source = "registry+https://github.com/rust-lang/crates.io-index"424source = "registry+https://github.com/rust-lang/crates.io-index"
415checksum = "3dcf4a824cce0aeacd6f38ae6f24234c8e80d68632338ebaa1443b5df9e29e19"425checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471"
416dependencies = [426dependencies = [
417 "proc-macro2",427 "proc-macro2",
418 "quote",428 "quote",
Cargo.toml+10-5
...@@ -1,11 +1,16 @@...@@ -1,11 +1,16 @@
1[package]1[workspace.package]
2name = "blight"
3version = "0.1.0"2version = "0.1.0"
4edition = "2021"3name = "blight"
4edition = "2023"
5license = "MIT"
6authors = ["Lino Le Van"]
7repository = "https://github.com/lino-levan/blight"
58
6# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html9[workspace]
10resolver = "2"
11members = ["cli", "compiler"]
712
8[dependencies]13[workspace.dependencies]
9clap = { version = "4.4.12", features = ["derive"] }14clap = { version = "4.4.12", features = ["derive"] }
10miette = { version = "5.10.0", features = ["fancy"] }15miette = { version = "5.10.0", features = ["fancy"] }
11thiserror = "1.0.53"16thiserror = "1.0.53"
cli/Cargo.lock created+532
...@@ -0,0 +1,532 @@
1# This file is automatically @generated by Cargo.
2# It is not intended for manual editing.
3version = 3
4
5[[package]]
6name = "addr2line"
7version = "0.21.0"
8source = "registry+https://github.com/rust-lang/crates.io-index"
9checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb"
10dependencies = [
11 "gimli",
12]
13
14[[package]]
15name = "adler"
16version = "1.0.2"
17source = "registry+https://github.com/rust-lang/crates.io-index"
18checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
19
20[[package]]
21name = "anstream"
22version = "0.6.5"
23source = "registry+https://github.com/rust-lang/crates.io-index"
24checksum = "d664a92ecae85fd0a7392615844904654d1d5f5514837f471ddef4a057aba1b6"
25dependencies = [
26 "anstyle",
27 "anstyle-parse",
28 "anstyle-query",
29 "anstyle-wincon",
30 "colorchoice",
31 "utf8parse",
32]
33
34[[package]]
35name = "anstyle"
36version = "1.0.4"
37source = "registry+https://github.com/rust-lang/crates.io-index"
38checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87"
39
40[[package]]
41name = "anstyle-parse"
42version = "0.2.3"
43source = "registry+https://github.com/rust-lang/crates.io-index"
44checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c"
45dependencies = [
46 "utf8parse",
47]
48
49[[package]]
50name = "anstyle-query"
51version = "1.0.2"
52source = "registry+https://github.com/rust-lang/crates.io-index"
53checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648"
54dependencies = [
55 "windows-sys",
56]
57
58[[package]]
59name = "anstyle-wincon"
60version = "3.0.2"
61source = "registry+https://github.com/rust-lang/crates.io-index"
62checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7"
63dependencies = [
64 "anstyle",
65 "windows-sys",
66]
67
68[[package]]
69name = "backtrace"
70version = "0.3.69"
71source = "registry+https://github.com/rust-lang/crates.io-index"
72checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837"
73dependencies = [
74 "addr2line",
75 "cc",
76 "cfg-if",
77 "libc",
78 "miniz_oxide",
79 "object",
80 "rustc-demangle",
81]
82
83[[package]]
84name = "backtrace-ext"
85version = "0.2.1"
86source = "registry+https://github.com/rust-lang/crates.io-index"
87checksum = "537beee3be4a18fb023b570f80e3ae28003db9167a751266b259926e25539d50"
88dependencies = [
89 "backtrace",
90]
91
92[[package]]
93name = "bitflags"
94version = "2.4.1"
95source = "registry+https://github.com/rust-lang/crates.io-index"
96checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07"
97
98[[package]]
99name = "blight"
100version = "0.1.0"
101dependencies = [
102 "clap",
103 "miette",
104 "thiserror",
105]
106
107[[package]]
108name = "cc"
109version = "1.0.83"
110source = "registry+https://github.com/rust-lang/crates.io-index"
111checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0"
112dependencies = [
113 "libc",
114]
115
116[[package]]
117name = "cfg-if"
118version = "1.0.0"
119source = "registry+https://github.com/rust-lang/crates.io-index"
120checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
121
122[[package]]
123name = "clap"
124version = "4.4.12"
125source = "registry+https://github.com/rust-lang/crates.io-index"
126checksum = "dcfab8ba68f3668e89f6ff60f5b205cea56aa7b769451a59f34b8682f51c056d"
127dependencies = [
128 "clap_builder",
129 "clap_derive",
130]
131
132[[package]]
133name = "clap_builder"
134version = "4.4.12"
135source = "registry+https://github.com/rust-lang/crates.io-index"
136checksum = "fb7fb5e4e979aec3be7791562fcba452f94ad85e954da024396433e0e25a79e9"
137dependencies = [
138 "anstream",
139 "anstyle",
140 "clap_lex",
141 "strsim",
142]
143
144[[package]]
145name = "clap_derive"
146version = "4.4.7"
147source = "registry+https://github.com/rust-lang/crates.io-index"
148checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442"
149dependencies = [
150 "heck",
151 "proc-macro2",
152 "quote",
153 "syn",
154]
155
156[[package]]
157name = "clap_lex"
158version = "0.6.0"
159source = "registry+https://github.com/rust-lang/crates.io-index"
160checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1"
161
162[[package]]
163name = "colorchoice"
164version = "1.0.0"
165source = "registry+https://github.com/rust-lang/crates.io-index"
166checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
167
168[[package]]
169name = "errno"
170version = "0.3.8"
171source = "registry+https://github.com/rust-lang/crates.io-index"
172checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245"
173dependencies = [
174 "libc",
175 "windows-sys",
176]
177
178[[package]]
179name = "gimli"
180version = "0.28.1"
181source = "registry+https://github.com/rust-lang/crates.io-index"
182checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253"
183
184[[package]]
185name = "heck"
186version = "0.4.1"
187source = "registry+https://github.com/rust-lang/crates.io-index"
188checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
189
190[[package]]
191name = "hermit-abi"
192version = "0.3.3"
193source = "registry+https://github.com/rust-lang/crates.io-index"
194checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7"
195
196[[package]]
197name = "is-terminal"
198version = "0.4.10"
199source = "registry+https://github.com/rust-lang/crates.io-index"
200checksum = "0bad00257d07be169d870ab665980b06cdb366d792ad690bf2e76876dc503455"
201dependencies = [
202 "hermit-abi",
203 "rustix",
204 "windows-sys",
205]
206
207[[package]]
208name = "is_ci"
209version = "1.1.1"
210source = "registry+https://github.com/rust-lang/crates.io-index"
211checksum = "616cde7c720bb2bb5824a224687d8f77bfd38922027f01d825cd7453be5099fb"
212
213[[package]]
214name = "libc"
215version = "0.2.151"
216source = "registry+https://github.com/rust-lang/crates.io-index"
217checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4"
218
219[[package]]
220name = "linux-raw-sys"
221version = "0.4.12"
222source = "registry+https://github.com/rust-lang/crates.io-index"
223checksum = "c4cd1a83af159aa67994778be9070f0ae1bd732942279cabb14f86f986a21456"
224
225[[package]]
226name = "memchr"
227version = "2.7.1"
228source = "registry+https://github.com/rust-lang/crates.io-index"
229checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149"
230
231[[package]]
232name = "miette"
233version = "5.10.0"
234source = "registry+https://github.com/rust-lang/crates.io-index"
235checksum = "59bb584eaeeab6bd0226ccf3509a69d7936d148cf3d036ad350abe35e8c6856e"
236dependencies = [
237 "backtrace",
238 "backtrace-ext",
239 "is-terminal",
240 "miette-derive",
241 "once_cell",
242 "owo-colors",
243 "supports-color",
244 "supports-hyperlinks",
245 "supports-unicode",
246 "terminal_size",
247 "textwrap",
248 "thiserror",
249 "unicode-width",
250]
251
252[[package]]
253name = "miette-derive"
254version = "5.10.0"
255source = "registry+https://github.com/rust-lang/crates.io-index"
256checksum = "49e7bc1560b95a3c4a25d03de42fe76ca718ab92d1a22a55b9b4cf67b3ae635c"
257dependencies = [
258 "proc-macro2",
259 "quote",
260 "syn",
261]
262
263[[package]]
264name = "miniz_oxide"
265version = "0.7.1"
266source = "registry+https://github.com/rust-lang/crates.io-index"
267checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7"
268dependencies = [
269 "adler",
270]
271
272[[package]]
273name = "object"
274version = "0.32.2"
275source = "registry+https://github.com/rust-lang/crates.io-index"
276checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441"
277dependencies = [
278 "memchr",
279]
280
281[[package]]
282name = "once_cell"
283version = "1.19.0"
284source = "registry+https://github.com/rust-lang/crates.io-index"
285checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
286
287[[package]]
288name = "owo-colors"
289version = "3.5.0"
290source = "registry+https://github.com/rust-lang/crates.io-index"
291checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f"
292
293[[package]]
294name = "proc-macro2"
295version = "1.0.73"
296source = "registry+https://github.com/rust-lang/crates.io-index"
297checksum = "2dd5e8a1f1029c43224ad5898e50140c2aebb1705f19e67c918ebf5b9e797fe1"
298dependencies = [
299 "unicode-ident",
300]
301
302[[package]]
303name = "quote"
304version = "1.0.34"
305source = "registry+https://github.com/rust-lang/crates.io-index"
306checksum = "22a37c9326af5ed140c86a46655b5278de879853be5573c01df185b6f49a580a"
307dependencies = [
308 "proc-macro2",
309]
310
311[[package]]
312name = "rustc-demangle"
313version = "0.1.23"
314source = "registry+https://github.com/rust-lang/crates.io-index"
315checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76"
316
317[[package]]
318name = "rustix"
319version = "0.38.28"
320source = "registry+https://github.com/rust-lang/crates.io-index"
321checksum = "72e572a5e8ca657d7366229cdde4bd14c4eb5499a9573d4d366fe1b599daa316"
322dependencies = [
323 "bitflags",
324 "errno",
325 "libc",
326 "linux-raw-sys",
327 "windows-sys",
328]
329
330[[package]]
331name = "smawk"
332version = "0.3.2"
333source = "registry+https://github.com/rust-lang/crates.io-index"
334checksum = "b7c388c1b5e93756d0c740965c41e8822f866621d41acbdf6336a6a168f8840c"
335
336[[package]]
337name = "strsim"
338version = "0.10.0"
339source = "registry+https://github.com/rust-lang/crates.io-index"
340checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
341
342[[package]]
343name = "supports-color"
344version = "2.1.0"
345source = "registry+https://github.com/rust-lang/crates.io-index"
346checksum = "d6398cde53adc3c4557306a96ce67b302968513830a77a95b2b17305d9719a89"
347dependencies = [
348 "is-terminal",
349 "is_ci",
350]
351
352[[package]]
353name = "supports-hyperlinks"
354version = "2.1.0"
355source = "registry+https://github.com/rust-lang/crates.io-index"
356checksum = "f84231692eb0d4d41e4cdd0cabfdd2e6cd9e255e65f80c9aa7c98dd502b4233d"
357dependencies = [
358 "is-terminal",
359]
360
361[[package]]
362name = "supports-unicode"
363version = "2.0.0"
364source = "registry+https://github.com/rust-lang/crates.io-index"
365checksum = "4b6c2cb240ab5dd21ed4906895ee23fe5a48acdbd15a3ce388e7b62a9b66baf7"
366dependencies = [
367 "is-terminal",
368]
369
370[[package]]
371name = "syn"
372version = "2.0.44"
373source = "registry+https://github.com/rust-lang/crates.io-index"
374checksum = "92d27c2c202598d05175a6dd3af46824b7f747f8d8e9b14c623f19fa5069735d"
375dependencies = [
376 "proc-macro2",
377 "quote",
378 "unicode-ident",
379]
380
381[[package]]
382name = "terminal_size"
383version = "0.1.17"
384source = "registry+https://github.com/rust-lang/crates.io-index"
385checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df"
386dependencies = [
387 "libc",
388 "winapi",
389]
390
391[[package]]
392name = "textwrap"
393version = "0.15.2"
394source = "registry+https://github.com/rust-lang/crates.io-index"
395checksum = "b7b3e525a49ec206798b40326a44121291b530c963cfb01018f63e135bac543d"
396dependencies = [
397 "smawk",
398 "unicode-linebreak",
399 "unicode-width",
400]
401
402[[package]]
403name = "thiserror"
404version = "1.0.53"
405source = "registry+https://github.com/rust-lang/crates.io-index"
406checksum = "b2cd5904763bad08ad5513ddbb12cf2ae273ca53fa9f68e843e236ec6dfccc09"
407dependencies = [
408 "thiserror-impl",
409]
410
411[[package]]
412name = "thiserror-impl"
413version = "1.0.53"
414source = "registry+https://github.com/rust-lang/crates.io-index"
415checksum = "3dcf4a824cce0aeacd6f38ae6f24234c8e80d68632338ebaa1443b5df9e29e19"
416dependencies = [
417 "proc-macro2",
418 "quote",
419 "syn",
420]
421
422[[package]]
423name = "unicode-ident"
424version = "1.0.12"
425source = "registry+https://github.com/rust-lang/crates.io-index"
426checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
427
428[[package]]
429name = "unicode-linebreak"
430version = "0.1.5"
431source = "registry+https://github.com/rust-lang/crates.io-index"
432checksum = "3b09c83c3c29d37506a3e260c08c03743a6bb66a9cd432c6934ab501a190571f"
433
434[[package]]
435name = "unicode-width"
436version = "0.1.11"
437source = "registry+https://github.com/rust-lang/crates.io-index"
438checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85"
439
440[[package]]
441name = "utf8parse"
442version = "0.2.1"
443source = "registry+https://github.com/rust-lang/crates.io-index"
444checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
445
446[[package]]
447name = "winapi"
448version = "0.3.9"
449source = "registry+https://github.com/rust-lang/crates.io-index"
450checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
451dependencies = [
452 "winapi-i686-pc-windows-gnu",
453 "winapi-x86_64-pc-windows-gnu",
454]
455
456[[package]]
457name = "winapi-i686-pc-windows-gnu"
458version = "0.4.0"
459source = "registry+https://github.com/rust-lang/crates.io-index"
460checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
461
462[[package]]
463name = "winapi-x86_64-pc-windows-gnu"
464version = "0.4.0"
465source = "registry+https://github.com/rust-lang/crates.io-index"
466checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
467
468[[package]]
469name = "windows-sys"
470version = "0.52.0"
471source = "registry+https://github.com/rust-lang/crates.io-index"
472checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
473dependencies = [
474 "windows-targets",
475]
476
477[[package]]
478name = "windows-targets"
479version = "0.52.0"
480source = "registry+https://github.com/rust-lang/crates.io-index"
481checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd"
482dependencies = [
483 "windows_aarch64_gnullvm",
484 "windows_aarch64_msvc",
485 "windows_i686_gnu",
486 "windows_i686_msvc",
487 "windows_x86_64_gnu",
488 "windows_x86_64_gnullvm",
489 "windows_x86_64_msvc",
490]
491
492[[package]]
493name = "windows_aarch64_gnullvm"
494version = "0.52.0"
495source = "registry+https://github.com/rust-lang/crates.io-index"
496checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea"
497
498[[package]]
499name = "windows_aarch64_msvc"
500version = "0.52.0"
501source = "registry+https://github.com/rust-lang/crates.io-index"
502checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef"
503
504[[package]]
505name = "windows_i686_gnu"
506version = "0.52.0"
507source = "registry+https://github.com/rust-lang/crates.io-index"
508checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313"
509
510[[package]]
511name = "windows_i686_msvc"
512version = "0.52.0"
513source = "registry+https://github.com/rust-lang/crates.io-index"
514checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a"
515
516[[package]]
517name = "windows_x86_64_gnu"
518version = "0.52.0"
519source = "registry+https://github.com/rust-lang/crates.io-index"
520checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd"
521
522[[package]]
523name = "windows_x86_64_gnullvm"
524version = "0.52.0"
525source = "registry+https://github.com/rust-lang/crates.io-index"
526checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e"
527
528[[package]]
529name = "windows_x86_64_msvc"
530version = "0.52.0"
531source = "registry+https://github.com/rust-lang/crates.io-index"
532checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04"
cli/Cargo.toml created+15
...@@ -0,0 +1,15 @@
1[package]
2name = "cli"
3version = "0.1.0"
4edition = "2021"
5
6[[bin]]
7name = "blight"
8path = "./src/main.rs"
9
10[dependencies]
11clap.workspace = true
12miette.workspace = true
13thiserror.workspace = true
14
15compiler = { path = "../compiler" }
cli/src/main.rs created+40
...@@ -0,0 +1,40 @@
1use std::path::PathBuf;
2
3use clap::{Parser, Subcommand};
4use miette::Result;
5
6use compiler::transpile;
7
8#[derive(Parser)]
9#[command(author, version, about, long_about = None)]
10struct Cli {
11 /// Turn debugging information on
12 #[arg(short, long, action = clap::ArgAction::Count)]
13 debug: u8,
14
15 #[command(subcommand)]
16 command: Commands,
17}
18
19#[derive(Subcommand)]
20enum Commands {
21 /// Compiles a file into javascript
22 Compile {
23 /// lists test values
24 file: PathBuf,
25 },
26}
27
28fn main() -> Result<()> {
29 let cli = Cli::parse();
30
31 match cli.command {
32 Commands::Compile { file } => {
33 let contents = std::fs::read_to_string(file.clone()).unwrap();
34 let result = transpile(contents.clone())?;
35 std::fs::write(file.with_extension("js"), result).unwrap();
36 }
37 }
38
39 Ok(())
40}
compiler/Cargo.lock created+532
...@@ -0,0 +1,532 @@
1# This file is automatically @generated by Cargo.
2# It is not intended for manual editing.
3version = 3
4
5[[package]]
6name = "addr2line"
7version = "0.21.0"
8source = "registry+https://github.com/rust-lang/crates.io-index"
9checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb"
10dependencies = [
11 "gimli",
12]
13
14[[package]]
15name = "adler"
16version = "1.0.2"
17source = "registry+https://github.com/rust-lang/crates.io-index"
18checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
19
20[[package]]
21name = "anstream"
22version = "0.6.5"
23source = "registry+https://github.com/rust-lang/crates.io-index"
24checksum = "d664a92ecae85fd0a7392615844904654d1d5f5514837f471ddef4a057aba1b6"
25dependencies = [
26 "anstyle",
27 "anstyle-parse",
28 "anstyle-query",
29 "anstyle-wincon",
30 "colorchoice",
31 "utf8parse",
32]
33
34[[package]]
35name = "anstyle"
36version = "1.0.4"
37source = "registry+https://github.com/rust-lang/crates.io-index"
38checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87"
39
40[[package]]
41name = "anstyle-parse"
42version = "0.2.3"
43source = "registry+https://github.com/rust-lang/crates.io-index"
44checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c"
45dependencies = [
46 "utf8parse",
47]
48
49[[package]]
50name = "anstyle-query"
51version = "1.0.2"
52source = "registry+https://github.com/rust-lang/crates.io-index"
53checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648"
54dependencies = [
55 "windows-sys",
56]
57
58[[package]]
59name = "anstyle-wincon"
60version = "3.0.2"
61source = "registry+https://github.com/rust-lang/crates.io-index"
62checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7"
63dependencies = [
64 "anstyle",
65 "windows-sys",
66]
67
68[[package]]
69name = "backtrace"
70version = "0.3.69"
71source = "registry+https://github.com/rust-lang/crates.io-index"
72checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837"
73dependencies = [
74 "addr2line",
75 "cc",
76 "cfg-if",
77 "libc",
78 "miniz_oxide",
79 "object",
80 "rustc-demangle",
81]
82
83[[package]]
84name = "backtrace-ext"
85version = "0.2.1"
86source = "registry+https://github.com/rust-lang/crates.io-index"
87checksum = "537beee3be4a18fb023b570f80e3ae28003db9167a751266b259926e25539d50"
88dependencies = [
89 "backtrace",
90]
91
92[[package]]
93name = "bitflags"
94version = "2.4.1"
95source = "registry+https://github.com/rust-lang/crates.io-index"
96checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07"
97
98[[package]]
99name = "blight"
100version = "0.1.0"
101dependencies = [
102 "clap",
103 "miette",
104 "thiserror",
105]
106
107[[package]]
108name = "cc"
109version = "1.0.83"
110source = "registry+https://github.com/rust-lang/crates.io-index"
111checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0"
112dependencies = [
113 "libc",
114]
115
116[[package]]
117name = "cfg-if"
118version = "1.0.0"
119source = "registry+https://github.com/rust-lang/crates.io-index"
120checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
121
122[[package]]
123name = "clap"
124version = "4.4.12"
125source = "registry+https://github.com/rust-lang/crates.io-index"
126checksum = "dcfab8ba68f3668e89f6ff60f5b205cea56aa7b769451a59f34b8682f51c056d"
127dependencies = [
128 "clap_builder",
129 "clap_derive",
130]
131
132[[package]]
133name = "clap_builder"
134version = "4.4.12"
135source = "registry+https://github.com/rust-lang/crates.io-index"
136checksum = "fb7fb5e4e979aec3be7791562fcba452f94ad85e954da024396433e0e25a79e9"
137dependencies = [
138 "anstream",
139 "anstyle",
140 "clap_lex",
141 "strsim",
142]
143
144[[package]]
145name = "clap_derive"
146version = "4.4.7"
147source = "registry+https://github.com/rust-lang/crates.io-index"
148checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442"
149dependencies = [
150 "heck",
151 "proc-macro2",
152 "quote",
153 "syn",
154]
155
156[[package]]
157name = "clap_lex"
158version = "0.6.0"
159source = "registry+https://github.com/rust-lang/crates.io-index"
160checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1"
161
162[[package]]
163name = "colorchoice"
164version = "1.0.0"
165source = "registry+https://github.com/rust-lang/crates.io-index"
166checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
167
168[[package]]
169name = "errno"
170version = "0.3.8"
171source = "registry+https://github.com/rust-lang/crates.io-index"
172checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245"
173dependencies = [
174 "libc",
175 "windows-sys",
176]
177
178[[package]]
179name = "gimli"
180version = "0.28.1"
181source = "registry+https://github.com/rust-lang/crates.io-index"
182checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253"
183
184[[package]]
185name = "heck"
186version = "0.4.1"
187source = "registry+https://github.com/rust-lang/crates.io-index"
188checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
189
190[[package]]
191name = "hermit-abi"
192version = "0.3.3"
193source = "registry+https://github.com/rust-lang/crates.io-index"
194checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7"
195
196[[package]]
197name = "is-terminal"
198version = "0.4.10"
199source = "registry+https://github.com/rust-lang/crates.io-index"
200checksum = "0bad00257d07be169d870ab665980b06cdb366d792ad690bf2e76876dc503455"
201dependencies = [
202 "hermit-abi",
203 "rustix",
204 "windows-sys",
205]
206
207[[package]]
208name = "is_ci"
209version = "1.1.1"
210source = "registry+https://github.com/rust-lang/crates.io-index"
211checksum = "616cde7c720bb2bb5824a224687d8f77bfd38922027f01d825cd7453be5099fb"
212
213[[package]]
214name = "libc"
215version = "0.2.151"
216source = "registry+https://github.com/rust-lang/crates.io-index"
217checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4"
218
219[[package]]
220name = "linux-raw-sys"
221version = "0.4.12"
222source = "registry+https://github.com/rust-lang/crates.io-index"
223checksum = "c4cd1a83af159aa67994778be9070f0ae1bd732942279cabb14f86f986a21456"
224
225[[package]]
226name = "memchr"
227version = "2.7.1"
228source = "registry+https://github.com/rust-lang/crates.io-index"
229checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149"
230
231[[package]]
232name = "miette"
233version = "5.10.0"
234source = "registry+https://github.com/rust-lang/crates.io-index"
235checksum = "59bb584eaeeab6bd0226ccf3509a69d7936d148cf3d036ad350abe35e8c6856e"
236dependencies = [
237 "backtrace",
238 "backtrace-ext",
239 "is-terminal",
240 "miette-derive",
241 "once_cell",
242 "owo-colors",
243 "supports-color",
244 "supports-hyperlinks",
245 "supports-unicode",
246 "terminal_size",
247 "textwrap",
248 "thiserror",
249 "unicode-width",
250]
251
252[[package]]
253name = "miette-derive"
254version = "5.10.0"
255source = "registry+https://github.com/rust-lang/crates.io-index"
256checksum = "49e7bc1560b95a3c4a25d03de42fe76ca718ab92d1a22a55b9b4cf67b3ae635c"
257dependencies = [
258 "proc-macro2",
259 "quote",
260 "syn",
261]
262
263[[package]]
264name = "miniz_oxide"
265version = "0.7.1"
266source = "registry+https://github.com/rust-lang/crates.io-index"
267checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7"
268dependencies = [
269 "adler",
270]
271
272[[package]]
273name = "object"
274version = "0.32.2"
275source = "registry+https://github.com/rust-lang/crates.io-index"
276checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441"
277dependencies = [
278 "memchr",
279]
280
281[[package]]
282name = "once_cell"
283version = "1.19.0"
284source = "registry+https://github.com/rust-lang/crates.io-index"
285checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
286
287[[package]]
288name = "owo-colors"
289version = "3.5.0"
290source = "registry+https://github.com/rust-lang/crates.io-index"
291checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f"
292
293[[package]]
294name = "proc-macro2"
295version = "1.0.73"
296source = "registry+https://github.com/rust-lang/crates.io-index"
297checksum = "2dd5e8a1f1029c43224ad5898e50140c2aebb1705f19e67c918ebf5b9e797fe1"
298dependencies = [
299 "unicode-ident",
300]
301
302[[package]]
303name = "quote"
304version = "1.0.34"
305source = "registry+https://github.com/rust-lang/crates.io-index"
306checksum = "22a37c9326af5ed140c86a46655b5278de879853be5573c01df185b6f49a580a"
307dependencies = [
308 "proc-macro2",
309]
310
311[[package]]
312name = "rustc-demangle"
313version = "0.1.23"
314source = "registry+https://github.com/rust-lang/crates.io-index"
315checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76"
316
317[[package]]
318name = "rustix"
319version = "0.38.28"
320source = "registry+https://github.com/rust-lang/crates.io-index"
321checksum = "72e572a5e8ca657d7366229cdde4bd14c4eb5499a9573d4d366fe1b599daa316"
322dependencies = [
323 "bitflags",
324 "errno",
325 "libc",
326 "linux-raw-sys",
327 "windows-sys",
328]
329
330[[package]]
331name = "smawk"
332version = "0.3.2"
333source = "registry+https://github.com/rust-lang/crates.io-index"
334checksum = "b7c388c1b5e93756d0c740965c41e8822f866621d41acbdf6336a6a168f8840c"
335
336[[package]]
337name = "strsim"
338version = "0.10.0"
339source = "registry+https://github.com/rust-lang/crates.io-index"
340checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
341
342[[package]]
343name = "supports-color"
344version = "2.1.0"
345source = "registry+https://github.com/rust-lang/crates.io-index"
346checksum = "d6398cde53adc3c4557306a96ce67b302968513830a77a95b2b17305d9719a89"
347dependencies = [
348 "is-terminal",
349 "is_ci",
350]
351
352[[package]]
353name = "supports-hyperlinks"
354version = "2.1.0"
355source = "registry+https://github.com/rust-lang/crates.io-index"
356checksum = "f84231692eb0d4d41e4cdd0cabfdd2e6cd9e255e65f80c9aa7c98dd502b4233d"
357dependencies = [
358 "is-terminal",
359]
360
361[[package]]
362name = "supports-unicode"
363version = "2.0.0"
364source = "registry+https://github.com/rust-lang/crates.io-index"
365checksum = "4b6c2cb240ab5dd21ed4906895ee23fe5a48acdbd15a3ce388e7b62a9b66baf7"
366dependencies = [
367 "is-terminal",
368]
369
370[[package]]
371name = "syn"
372version = "2.0.44"
373source = "registry+https://github.com/rust-lang/crates.io-index"
374checksum = "92d27c2c202598d05175a6dd3af46824b7f747f8d8e9b14c623f19fa5069735d"
375dependencies = [
376 "proc-macro2",
377 "quote",
378 "unicode-ident",
379]
380
381[[package]]
382name = "terminal_size"
383version = "0.1.17"
384source = "registry+https://github.com/rust-lang/crates.io-index"
385checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df"
386dependencies = [
387 "libc",
388 "winapi",
389]
390
391[[package]]
392name = "textwrap"
393version = "0.15.2"
394source = "registry+https://github.com/rust-lang/crates.io-index"
395checksum = "b7b3e525a49ec206798b40326a44121291b530c963cfb01018f63e135bac543d"
396dependencies = [
397 "smawk",
398 "unicode-linebreak",
399 "unicode-width",
400]
401
402[[package]]
403name = "thiserror"
404version = "1.0.53"
405source = "registry+https://github.com/rust-lang/crates.io-index"
406checksum = "b2cd5904763bad08ad5513ddbb12cf2ae273ca53fa9f68e843e236ec6dfccc09"
407dependencies = [
408 "thiserror-impl",
409]
410
411[[package]]
412name = "thiserror-impl"
413version = "1.0.53"
414source = "registry+https://github.com/rust-lang/crates.io-index"
415checksum = "3dcf4a824cce0aeacd6f38ae6f24234c8e80d68632338ebaa1443b5df9e29e19"
416dependencies = [
417 "proc-macro2",
418 "quote",
419 "syn",
420]
421
422[[package]]
423name = "unicode-ident"
424version = "1.0.12"
425source = "registry+https://github.com/rust-lang/crates.io-index"
426checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
427
428[[package]]
429name = "unicode-linebreak"
430version = "0.1.5"
431source = "registry+https://github.com/rust-lang/crates.io-index"
432checksum = "3b09c83c3c29d37506a3e260c08c03743a6bb66a9cd432c6934ab501a190571f"
433
434[[package]]
435name = "unicode-width"
436version = "0.1.11"
437source = "registry+https://github.com/rust-lang/crates.io-index"
438checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85"
439
440[[package]]
441name = "utf8parse"
442version = "0.2.1"
443source = "registry+https://github.com/rust-lang/crates.io-index"
444checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
445
446[[package]]
447name = "winapi"
448version = "0.3.9"
449source = "registry+https://github.com/rust-lang/crates.io-index"
450checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
451dependencies = [
452 "winapi-i686-pc-windows-gnu",
453 "winapi-x86_64-pc-windows-gnu",
454]
455
456[[package]]
457name = "winapi-i686-pc-windows-gnu"
458version = "0.4.0"
459source = "registry+https://github.com/rust-lang/crates.io-index"
460checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
461
462[[package]]
463name = "winapi-x86_64-pc-windows-gnu"
464version = "0.4.0"
465source = "registry+https://github.com/rust-lang/crates.io-index"
466checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
467
468[[package]]
469name = "windows-sys"
470version = "0.52.0"
471source = "registry+https://github.com/rust-lang/crates.io-index"
472checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
473dependencies = [
474 "windows-targets",
475]
476
477[[package]]
478name = "windows-targets"
479version = "0.52.0"
480source = "registry+https://github.com/rust-lang/crates.io-index"
481checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd"
482dependencies = [
483 "windows_aarch64_gnullvm",
484 "windows_aarch64_msvc",
485 "windows_i686_gnu",
486 "windows_i686_msvc",
487 "windows_x86_64_gnu",
488 "windows_x86_64_gnullvm",
489 "windows_x86_64_msvc",
490]
491
492[[package]]
493name = "windows_aarch64_gnullvm"
494version = "0.52.0"
495source = "registry+https://github.com/rust-lang/crates.io-index"
496checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea"
497
498[[package]]
499name = "windows_aarch64_msvc"
500version = "0.52.0"
501source = "registry+https://github.com/rust-lang/crates.io-index"
502checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef"
503
504[[package]]
505name = "windows_i686_gnu"
506version = "0.52.0"
507source = "registry+https://github.com/rust-lang/crates.io-index"
508checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313"
509
510[[package]]
511name = "windows_i686_msvc"
512version = "0.52.0"
513source = "registry+https://github.com/rust-lang/crates.io-index"
514checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a"
515
516[[package]]
517name = "windows_x86_64_gnu"
518version = "0.52.0"
519source = "registry+https://github.com/rust-lang/crates.io-index"
520checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd"
521
522[[package]]
523name = "windows_x86_64_gnullvm"
524version = "0.52.0"
525source = "registry+https://github.com/rust-lang/crates.io-index"
526checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e"
527
528[[package]]
529name = "windows_x86_64_msvc"
530version = "0.52.0"
531source = "registry+https://github.com/rust-lang/crates.io-index"
532checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04"
compiler/Cargo.toml created+11
...@@ -0,0 +1,11 @@
1[package]
2name = "compiler"
3version = "0.1.0"
4edition = "2021"
5
6[lib]
7
8[dependencies]
9clap.workspace = true
10miette.workspace = true
11thiserror.workspace = true
compiler/src/ast/error.rs created+17
...@@ -0,0 +1,17 @@
1use miette::Diagnostic;
2use thiserror::Error;
3
4#[derive(Error, Diagnostic, Debug)]
5#[error("AstError")]
6pub struct AstError {
7 #[help]
8 error: String,
9}
10
11impl AstError {
12 pub fn new(error: &'static str) -> AstError {
13 AstError {
14 error: String::from(error),
15 }
16 }
17}
compiler/src/ast/mod.rs created+260
...@@ -0,0 +1,260 @@
1use miette::Result;
2
3mod error;
4mod types;
5
6use super::tokenizer::Token;
7
8use error::AstError;
9use types::{ParserContext, Argument};
10
11pub use types::{Ast, Type};
12
13fn parse_expression(tokens: &mut ParserContext) -> Result<Ast> {
14
15 let left = match tokens.next() {
16 Some(token) => match token {
17 Token::Number(number) => Ast::Number(number.clone()),
18 Token::Identifier(name) => {
19 match tokens.peek() {
20 Some(Token::OpenParanthesis) => {
21 tokens.next();
22
23 let mut arguments = Vec::new();
24
25 loop {
26 match tokens.peek() {
27 Some(Token::ClosedParanthesis) => break,
28 _ => ()
29 }
30 arguments.push(parse_expression(tokens)?);
31
32 match tokens.peek() {
33 Some(Token::Comma) => {
34 tokens.next();
35 }
36 Some(Token::ClosedParanthesis) => (),
37 _ => return Err(AstError::new("Expected ) or , but found something else instead.").into()),
38 }
39 }
40
41 Ast::FunctionCall { name: name.clone(), arguments }
42 }
43 _ => Ast::Identifier(name.clone())
44 }
45 },
46 _ => return Err(AstError::new("Expected expression, but did not get it").into()),
47 },
48 None => return Err(AstError::new("Expected expression, but got nothing instead").into()),
49 };
50
51 match tokens.peek() {
52 Some(token) => match token {
53 Token::Operator(operator) => {
54 tokens.next();
55 return Ok(Ast::Operation {
56 operator: operator.clone(),
57 left: Box::new(left),
58 right: Box::new(parse_expression(tokens)?),
59 });
60 }
61 _ => (),
62 },
63 _ => (),
64 }
65
66 Ok(left)
67}
68
69fn parse_type(tokens: &mut ParserContext) -> Result<Type> {
70 match tokens.next() {
71 Some(Token::Identifier(typ)) => match typ.as_str() {
72 "int" => Ok(Type::Int),
73 "float" => Ok(Type::Float),
74 "bigint" => Ok(Type::Bigint),
75 _ => return Err(AstError::new("Expected type").into()),
76 },
77 _ => return Err(AstError::new("Expected type").into()),
78 }
79}
80
81/// Precondition: There is at least one token in the iterator
82fn parse_statement(tokens: &mut ParserContext) -> Result<Ast> {
83 let token = tokens.next().unwrap();
84 match token {
85 Token::Pub => {
86 match tokens.peek() {
87 Some(Token::Let) | Some(Token::Var) | Some(Token::Function) => (),
88 _ => return Err(AstError::new("Expected let, var, or fn after pub").into()),
89 }
90
91 let inner = parse_statement(tokens)?;
92
93 return Ok(Ast::Public { value: Box::new(inner) })
94 }
95 Token::Let => {
96 let name = match tokens.next() {
97 Some(Token::Identifier(name)) => name,
98 _ => return Err(AstError::new("Expected identifier after var").into()),
99 };
100 let return_type = match tokens.next() {
101 Some(Token::Colon) => parse_type(tokens)?,
102 _ => return Err(AstError::new("Expected colon after identifier").into()),
103 };
104 let value = match tokens.next() {
105 Some(Token::Equals) => parse_expression(tokens)?,
106 _ => return Err(AstError::new("Expected equals after identifier").into()),
107 };
108 match tokens.next() {
109 Some(Token::Semicolon) => (),
110 _ => {
111 return Err(
112 AstError::new("Expected semicolon after variable declaration").into(),
113 )
114 }
115 };
116 Ok(Ast::ConstantDeclaration {
117 name: name.clone(),
118 return_type,
119 value: Box::new(value),
120 })
121 }
122 Token::Var => {
123 let name = match tokens.next() {
124 Some(Token::Identifier(name)) => name,
125 _ => return Err(AstError::new("Expected identifier after var").into()),
126 };
127 let return_type = match tokens.next() {
128 Some(Token::Colon) => parse_type(tokens)?,
129 _ => return Err(AstError::new("Expected colon after identifier").into()),
130 };
131 let value = match tokens.next() {
132 Some(Token::Equals) => parse_expression(tokens)?,
133 _ => return Err(AstError::new("Expected equals after identifier").into()),
134 };
135 match tokens.next() {
136 Some(Token::Semicolon) => (),
137 _ => {
138 return Err(
139 AstError::new("Expected semicolon after variable declaration").into(),
140 )
141 }
142 };
143 Ok(Ast::VariableDeclaration {
144 name: name.clone(),
145 return_type,
146 value: Box::new(value),
147 })
148 }
149 Token::Return => {
150 let expression = parse_expression(tokens)?;
151
152 match tokens.next() {
153 Some(Token::Semicolon) => (),
154 _ => {
155 return Err(
156 AstError::new("Expected semicolon after return statement").into(),
157 )
158 }
159 };
160
161 Ok(Ast::Return { return_value: Box::new(expression) })
162 }
163 Token::Function => {
164 let name = match tokens.next() {
165 Some(Token::Identifier(name)) => name.clone(),
166 _ => return Err(AstError::new("Expected identifier after fn").into()),
167 };
168
169 match tokens.next() {
170 Some(Token::OpenParanthesis) => (),
171 _ => return Err(AstError::new("Expected open paranthesis after identifier in function").into()),
172 };
173
174 let mut arguments = Vec::new();
175
176 loop {
177 match tokens.peek() {
178 Some(Token::ClosedParanthesis) => {
179 tokens.next();
180 break;
181 },
182 _ => ()
183 }
184
185 let argument_name = match tokens.next() {
186 Some(Token::Identifier(name)) => name,
187 _ => return Err(AstError::new("Expected identifier for argument name in function").into()),
188 };
189
190 let return_type = match tokens.next() {
191 Some(Token::Colon) => parse_type(tokens)?,
192 _ => return Err(AstError::new("Expected colon after identifier").into()),
193 };
194
195 match tokens.peek() {
196 Some(Token::Comma) => {
197 tokens.next();
198 },
199 _ => ()
200 }
201
202 arguments.push(Argument { name: argument_name.clone(), return_type})
203 }
204
205 let return_type = match tokens.next() {
206 Some(Token::RightArrow) => parse_type(tokens)?,
207 _ => return Err(AstError::new("Expected right arrow after argument list in function").into()),
208 };
209
210 match tokens.next() {
211 Some(Token::OpenBracket) => (),
212 _ => return Err(AstError::new("Expected open bracket after type in function declaration").into()),
213 };
214
215 let mut value = Vec::new();
216
217 loop {
218 match tokens.peek() {
219 Some(Token::ClosedBracket) => {
220 tokens.next();
221 break;
222 },
223 _ => ()
224 }
225
226 value.push(parse_statement(tokens)?);
227 }
228
229 return Ok(Ast::Function { name, arguments, return_type, value })
230 }
231 Token::Comment(comment) => Ok(Ast::Comment(comment.clone())),
232 Token::DocComment(comment) => {
233 let mut concatted_comments = comment.clone();
234 loop {
235 match tokens.peek() {
236 Some(Token::DocComment(comment)) => {
237 concatted_comments.push_str(format!("\n{}", comment).as_str());
238 tokens.next();
239 },
240 _ => break,
241 }
242 }
243 Ok(Ast::DocComment(concatted_comments))
244 },
245 _ => {
246 return Err(AstError::new("Unexpected token").into())
247 },
248 }
249}
250
251pub fn parse(tokens: Vec<Token>) -> Result<Vec<Ast>> {
252 let mut ctx = ParserContext::new(tokens);
253 let mut ast: Vec<Ast> = Vec::new();
254
255 while !ctx.empty() {
256 ast.push(parse_statement(&mut ctx)?);
257 }
258
259 Ok(ast)
260}
compiler/src/ast/types.rs created+89
...@@ -0,0 +1,89 @@
1use crate::util::Operator;
2use crate::tokenizer::Token;
3
4#[derive(Debug)]
5pub struct ParserContext {
6 pub tokens: Vec<Token>,
7 pub cursor: usize
8}
9
10impl ParserContext {
11 pub fn new(tokens: Vec<Token>) -> ParserContext {
12 ParserContext { tokens, cursor: 0 }
13 }
14
15 pub fn empty(&self) -> bool {
16 self.cursor == self.tokens.len()
17 }
18
19 pub fn next(&mut self) -> Option<Token> {
20 if self.cursor == self.tokens.len() {
21 return None;
22 }
23
24 let token = self.tokens[self.cursor].clone();
25 self.cursor += 1;
26 Some(token)
27 }
28
29 pub fn peek(&self) -> Option<Token> {
30 if self.cursor == self.tokens.len() {
31 return None;
32 }
33
34 Some(self.tokens[self.cursor].clone())
35 }
36}
37
38
39#[derive(Debug)]
40pub enum Type {
41 Int,
42 Float,
43 Bigint,
44}
45
46#[derive(Debug)]
47pub struct Argument {
48 pub name: String,
49 pub return_type: Type
50}
51
52#[derive(Debug)]
53pub enum Ast {
54 Public {
55 value: Box<Ast>
56 },
57 ConstantDeclaration {
58 name: String,
59 return_type: Type,
60 value: Box<Ast>,
61 },
62 VariableDeclaration {
63 name: String,
64 return_type: Type,
65 value: Box<Ast>,
66 },
67 Operation {
68 operator: Operator,
69 left: Box<Ast>,
70 right: Box<Ast>,
71 },
72 Return {
73 return_value: Box<Ast>
74 },
75 Function {
76 name: String,
77 arguments: Vec<Argument>,
78 return_type: Type,
79 value: Vec<Ast>
80 },
81 FunctionCall {
82 name: String,
83 arguments: Vec<Ast>,
84 },
85 Number(String),
86 Identifier(String),
87 Comment(String),
88 DocComment(String)
89}
compiler/src/lib.rs created+18
...@@ -0,0 +1,18 @@
1use miette::Result;
2
3pub mod ast;
4pub mod tokenizer;
5pub mod walker;
6
7pub mod util;
8
9pub fn transpile(content: String) -> Result<String> {
10 // // 1. Tokenize the input
11 let tokens = tokenizer::tokenize(content)?;
12 // // 2. Parse the tokens into an AST
13 let tree = ast::parse(tokens)?;
14 // // 3. Transpile the AST into javascript
15 let result = walker::transpile(tree)?;
16 // 4. Return the javascript
17 return Ok(result);
18}
compiler/src/tokenizer.rs created+172
...@@ -0,0 +1,172 @@
1use miette::{Diagnostic, Result};
2use thiserror::Error;
3
4use super::util::Operator;
5
6#[derive(Error, Diagnostic, Debug)]
7#[error("UnknownCharacter")]
8struct UnknownCharacter {
9 #[help]
10 error: String,
11}
12
13#[derive(Debug, Clone)]
14pub enum Token {
15 // Literals
16 Identifier(String),
17 Number(String),
18 // Comments
19 Comment(String),
20 DocComment(String),
21 // Keywords
22 Let,
23 Var,
24 Return,
25 Pub,
26 Function,
27 RightArrow,
28 Comma,
29 OpenParanthesis,
30 ClosedParanthesis,
31 OpenBracket,
32 ClosedBracket,
33 Colon,
34 Equals,
35 Semicolon,
36 // Operators
37 Operator(Operator),
38}
39
40pub fn tokenize(content: String) -> Result<Vec<Token>> {
41 let mut tokens: Vec<Token> = Vec::new();
42 let mut chars = content.chars().enumerate().peekable();
43
44 loop {
45 match chars.next() {
46 Some((_, c)) => match c {
47 'a'..='z' | 'A'..='Z' | '_' => {
48 let mut current_token = String::new();
49 current_token.push(c);
50 loop {
51 let c = chars.peek();
52 if c.is_none() {
53 break;
54 }
55 let (_, c) = c.unwrap();
56 match c {
57 'a'..='z' | 'A'..='Z' | '_' | '0'..='9' => {
58 current_token.push(*c);
59 chars.next();
60 }
61 _ => break,
62 }
63 }
64
65 match current_token.as_str() {
66 "var" => tokens.push(Token::Var),
67 "let" => tokens.push(Token::Let),
68 "pub" => tokens.push(Token::Pub),
69 "fn" => tokens.push(Token::Function),
70 "return" => tokens.push(Token::Return),
71 _ => tokens.push(Token::Identifier(current_token)),
72 }
73 }
74 '0'..='9' => {
75 let mut current_token = String::new();
76 current_token.push(c);
77 loop {
78 let c = chars.peek();
79 if c.is_none() {
80 break;
81 }
82 let (_, c) = c.unwrap();
83 match c {
84 '0'..='9' => {
85 current_token.push(*c);
86 chars.next();
87 }
88 _ => break,
89 }
90 }
91 tokens.push(Token::Number(current_token));
92 }
93 ':' => tokens.push(Token::Colon),
94 '=' => tokens.push(Token::Equals),
95 ';' => tokens.push(Token::Semicolon),
96 '+' => tokens.push(Token::Operator(Operator::Add)),
97 '-' => {
98 match chars.peek() {
99 Some((_, '>')) => {
100 chars.next();
101 tokens.push(Token::RightArrow);
102 }
103 _ => tokens.push(Token::Operator(Operator::Substract))
104 }
105 },
106 '*' => {
107 match chars.peek() {
108 Some((_, '*')) => {
109 chars.next();
110 tokens.push(Token::Operator(Operator::Power));
111 }
112 _ => tokens.push(Token::Operator(Operator::Multiply))
113 }
114 },
115 '/' => {
116 match chars.peek() {
117 Some((_, '/')) => {
118 chars.next(); // Consume the second slash
119
120 let is_doc_comment = match chars.peek() {
121 Some((_, '/')) => {
122 chars.next(); // Consume the third slash
123 true
124 },
125 _ => false,
126 };
127
128 let mut comment = String::new();
129 loop {
130 let c = chars.next();
131 if c.is_none() {
132 break;
133 }
134 let (_, c) = c.unwrap();
135 match c {
136 '\n' => break,
137 _ => {
138 comment.push(c.clone());
139 },
140 }
141 }
142
143 comment = comment.trim().to_string();
144
145 if is_doc_comment {
146 tokens.push(Token::DocComment(comment));
147 } else {
148 tokens.push(Token::Comment(comment));
149 }
150 }
151 _ => tokens.push(Token::Operator(Operator::Divide))
152 }
153 },
154 ',' => tokens.push(Token::Comma),
155 '(' => tokens.push(Token::OpenParanthesis),
156 ')' => tokens.push(Token::ClosedParanthesis),
157 '{' => tokens.push(Token::OpenBracket),
158 '}' => tokens.push(Token::ClosedBracket),
159 s if s.is_whitespace() => (),
160 _ => {
161 return Err(UnknownCharacter {
162 error: format!("Unsupported character: {}", c),
163 }
164 .into())
165 }
166 },
167 None => break,
168 }
169 }
170
171 Ok(tokens)
172}
compiler/src/util.rs created+20
...@@ -0,0 +1,20 @@
1#[derive(Debug, Clone)]
2pub enum Operator {
3 Add,
4 Substract,
5 Multiply,
6 Divide,
7 Power,
8}
9
10impl Operator {
11 pub fn to_string(self) -> String {
12 String::from(match self {
13 Self::Add => "+",
14 Self::Substract => "-",
15 Self::Divide => "/",
16 Self::Multiply => "*",
17 Self::Power => "**",
18 })
19 }
20}
compiler/src/walker.rs created+76
...@@ -0,0 +1,76 @@
1use miette::Result;
2
3use super::ast::{Ast, Type};
4
5fn transpile_helper(tree: &Ast) -> Result<String> {
6 Ok(match tree {
7 Ast::Number(number) => format!("{}", number),
8 Ast::Identifier(name) => format!("{}", name),
9 Ast::Comment(comment) => format!("// {}\n", comment),
10 Ast::DocComment(comment) => format!("/** {} */\n", comment),
11 Ast::Operation {
12 operator,
13 left,
14 right,
15 } => format!(
16 "{} {} {}",
17 transpile_helper(left)?,
18 operator.clone().to_string(),
19 transpile_helper(right)?
20 ),
21 Ast::Public { value } => format!("export {}", transpile_helper(value)?),
22 Ast::VariableDeclaration { name, return_type, value } => match return_type {
23 Type::Bigint => format!("let {} = BigInt({});\n", name, transpile_helper(value)?),
24 _ => format!("let {} = {};\n", name, transpile_helper(value)?),
25 },
26 Ast::ConstantDeclaration { name, return_type, value } => match return_type {
27 Type::Bigint => format!("const {} = BigInt({});\n", name, transpile_helper(value)?),
28 _ => format!("const {} = {};\n", name, transpile_helper(value)?),
29 },
30 Ast::Return { return_value } => format!("return {};\n", transpile_helper(return_value)?),
31 Ast::Function { name, arguments, return_type: _, value } => {
32 let mut result = format!("function {}(", name);
33
34 for (i, argument) in arguments.iter().enumerate() {
35 if i == 0 {
36 result += argument.name.as_str();
37 } else {
38 result += format!(", {}", argument.name).as_str();
39 }
40 }
41
42 result += ") {\n";
43
44 for statement in value {
45 result += transpile_helper(statement)?.as_str();
46 }
47
48 result += "}\n";
49
50 result
51 },
52 Ast::FunctionCall { name, arguments } => {
53 let mut result = format!("{}(", name);
54
55 for (i, argument) in arguments.iter().enumerate() {
56 if i == 0 {
57 result += transpile_helper(argument)?.as_str();
58 } else {
59 result += format!(", {}", transpile_helper(argument)?).as_str();
60 }
61 }
62
63 result
64 }
65 })
66}
67
68pub fn transpile(forest: Vec<Ast>) -> Result<String> {
69 let mut result = String::new();
70
71 for tree in forest {
72 result.push_str(&transpile_helper(&tree)?);
73 }
74
75 Ok(result)
76}
examples/basics/comments.blight created+9
...@@ -0,0 +1,9 @@
1// this is a regular comment
2let x: int = 0;
3
4/// this is a doc comment
5let y: int = 0;
6
7/// Doc comments can be multiple lines.
8/// This can be done by simply adding another triple-slash to the next line.
9let z: int = 0;
examples/basics/control.blight created+1
...@@ -0,0 +1 @@
1
examples/basics/functions.blight created+5
...@@ -0,0 +1,5 @@
1fn bingus(x: int, y: int) -> int {
2 return x * y;
3}
4
5let result: int = bingus(10, 25);
examples/basics/operations.blight created+1
...@@ -0,0 +1 @@
1let a: int = 10 - 2 / 4 * 15;
examples/basics/variables.blight created+7
...@@ -0,0 +1,7 @@
1var x: int = 0;
2var y: float = 0;
3var z: bigint = 0;
4
5let a: int = 0;
6let b: float = 0;
7let c: bigint = 0;
examples/interop/blight_in_js/add.blight created+5
...@@ -0,0 +1,5 @@
1pub fn add(x: int, y: int) -> int {
2 return x + y;
3}
4
5pub let TOP_LEVEL: int = 100;
examples/interop/blight_in_js/main.js created+4
...@@ -0,0 +1,4 @@
1import { add, TOP_LEVEL } from "./add.js";
2
3console.log(add(1, 2));
4console.log(TOP_LEVEL)
examples/operations.blight deleted-1
...@@ -1 +0,0 @@
1let a: int = 10 - 2 / 4 * 15;
examples/variables.blight deleted-7
...@@ -1,7 +0,0 @@
1var x: int = 0;
2var y: float = 0;
3var z: bigint = 0;
4
5let a: int = 0;
6let b: float = 0;
7let c: bigint = 0;
src/main.rs deleted-40
...@@ -1,40 +0,0 @@
1use std::path::PathBuf;
2
3use clap::{Parser, Subcommand};
4use miette::Result;
5
6mod transpile;
7
8#[derive(Parser)]
9#[command(author, version, about, long_about = None)]
10struct Cli {
11 /// Turn debugging information on
12 #[arg(short, long, action = clap::ArgAction::Count)]
13 debug: u8,
14
15 #[command(subcommand)]
16 command: Commands,
17}
18
19#[derive(Subcommand)]
20enum Commands {
21 /// Compiles a file into javascript
22 Compile {
23 /// lists test values
24 file: PathBuf,
25 },
26}
27
28fn main() -> Result<()> {
29 let cli = Cli::parse();
30
31 match cli.command {
32 Commands::Compile { file } => {
33 let contents = std::fs::read_to_string(file.clone()).unwrap();
34 let result = transpile::transpile(contents.clone())?;
35 std::fs::write(file.with_extension("js"), result).unwrap();
36 }
37 }
38
39 Ok(())
40}
src/transpile/ast.rs deleted-163
...@@ -1,163 +0,0 @@
1use miette::{Diagnostic, Result};
2use thiserror::Error;
3
4use super::tokenizer::Token;
5use super::util::{Operator, PeekableIterator};
6
7#[derive(Error, Diagnostic, Debug)]
8#[error("AstError")]
9struct AstError {
10 #[help]
11 error: String,
12}
13
14impl AstError {
15 fn new(error: &'static str) -> AstError {
16 AstError {
17 error: String::from(error),
18 }
19 }
20}
21
22#[derive(Debug)]
23pub enum Type {
24 Int,
25 Float,
26 Bigint,
27}
28
29#[derive(Debug)]
30pub enum Ast {
31 ConstantDeclaration {
32 name: String,
33 typ: Type,
34 value: Box<Ast>,
35 },
36 VariableDeclaration {
37 name: String,
38 typ: Type,
39 value: Box<Ast>,
40 },
41 Operation {
42 operator: Operator,
43 left: Box<Ast>,
44 right: Box<Ast>,
45 },
46 Number(String),
47}
48
49fn parse_expression(tokens: &mut dyn PeekableIterator<Item = &Token>) -> Result<Ast> {
50 let left = match tokens.next() {
51 Some(token) => match token {
52 Token::Number(number) => Ast::Number(number.clone()),
53 _ => return Err(AstError::new("Expected expression, but did not get it").into()),
54 },
55 None => return Err(AstError::new("Expected expression, but got nothing instead").into()),
56 };
57
58 match tokens.peek() {
59 Some(token) => match token {
60 Token::Operator(operator) => {
61 tokens.next();
62 return Ok(Ast::Operation {
63 operator: operator.clone(),
64 left: Box::new(left),
65 right: Box::new(parse_expression(tokens)?),
66 });
67 }
68 _ => (),
69 },
70 _ => (),
71 }
72
73 Ok(Ast::Number(String::from("10")))
74}
75
76/// Precondition: There is at least one token in the iterator
77fn parse_statement(tokens: &mut dyn PeekableIterator<Item = &Token>) -> Result<Ast> {
78 match tokens.next().unwrap() {
79 Token::Let => {
80 let name = match tokens.next() {
81 Some(Token::Identifier(name)) => name,
82 _ => return Err(AstError::new("Expected identifier after var").into()),
83 };
84 let typ = match tokens.next() {
85 Some(Token::Colon) => match tokens.next() {
86 Some(Token::Identifier(typ)) => match typ.as_str() {
87 "int" => Type::Int,
88 "float" => Type::Float,
89 "bigint" => Type::Bigint,
90 _ => return Err(AstError::new("Expected type after colon").into()),
91 },
92 _ => return Err(AstError::new("Expected type after colon").into()),
93 },
94 _ => return Err(AstError::new("Expected colon after identifier").into()),
95 };
96 let value = match tokens.next() {
97 Some(Token::Equals) => parse_expression(tokens)?,
98 _ => return Err(AstError::new("Expected equals after identifier").into()),
99 };
100 match tokens.next() {
101 Some(Token::Semicolon) => (),
102 _ => {
103 return Err(
104 AstError::new("Expected semicolon after variable declaration").into(),
105 )
106 }
107 };
108 Ok(Ast::ConstantDeclaration {
109 name: name.clone(),
110 typ,
111 value: Box::new(value),
112 })
113 }
114 Token::Var => {
115 let name = match tokens.next() {
116 Some(Token::Identifier(name)) => name,
117 _ => return Err(AstError::new("Expected identifier after var").into()),
118 };
119 let typ = match tokens.next() {
120 Some(Token::Colon) => match tokens.next() {
121 Some(Token::Identifier(typ)) => match typ.as_str() {
122 "int" => Type::Int,
123 "float" => Type::Float,
124 "bigint" => Type::Bigint,
125 _ => return Err(AstError::new("Expected type after colon").into()),
126 },
127 _ => return Err(AstError::new("Expected type after colon").into()),
128 },
129 _ => return Err(AstError::new("Expected colon after identifier").into()),
130 };
131 let value = match tokens.next() {
132 Some(Token::Equals) => parse_expression(tokens)?,
133 _ => return Err(AstError::new("Expected equals after identifier").into()),
134 };
135 match tokens.next() {
136 Some(Token::Semicolon) => (),
137 _ => {
138 return Err(
139 AstError::new("Expected semicolon after variable declaration").into(),
140 )
141 }
142 };
143 Ok(Ast::VariableDeclaration {
144 name: name.clone(),
145 typ,
146 value: Box::new(value),
147 })
148 }
149 Token::Number(number) => Ok(Ast::Number(number.clone())),
150 _ => return Err(AstError::new("Unexpected token").into()),
151 }
152}
153
154pub fn parse(tokens: Vec<Token>) -> Result<Vec<Ast>> {
155 let mut iter = tokens.iter().peekable();
156 let mut ast: Vec<Ast> = Vec::new();
157
158 while iter.peek().is_some() {
159 ast.push(parse_statement(&mut iter)?);
160 }
161
162 Ok(ast)
163}
src/transpile/mod.rs deleted-19
...@@ -1,19 +0,0 @@
1use miette::Result;
2
3mod ast;
4mod tokenizer;
5mod walker;
6
7mod util;
8
9pub fn transpile(content: String) -> Result<String> {
10 // 1. Tokenize the input
11 let tokens = tokenizer::tokenize(content)?;
12 // 2. Parse the tokens into an AST
13 let tree = ast::parse(tokens)?;
14 print!("{:?}", tree);
15 // 3. Transpile the AST into javascript
16 let result = walker::transpile(tree)?;
17 // 4. Return the javascript
18 return Ok(result);
19}
src/transpile/tokenizer.rs deleted-98
...@@ -1,98 +0,0 @@
1use miette::{Diagnostic, Result};
2use thiserror::Error;
3
4use super::util::Operator;
5
6#[derive(Error, Diagnostic, Debug)]
7#[error("UnknownCharacter")]
8struct UnknownCharacter {
9 #[help]
10 error: String,
11}
12
13#[derive(Debug, Clone)]
14pub enum Token {
15 // Literals
16 Identifier(String),
17 Number(String),
18 // Keywords
19 Let,
20 Var,
21 Colon,
22 Equals,
23 Semicolon,
24 // Operators
25 Operator(Operator),
26}
27
28pub fn tokenize(content: String) -> Result<Vec<Token>> {
29 let mut tokens: Vec<Token> = Vec::new();
30 let mut chars = content.chars().enumerate().peekable();
31
32 loop {
33 match chars.next() {
34 Some((_, c)) => match c {
35 'a'..='z' | 'A'..='Z' | '_' => {
36 let mut current_token = String::new();
37 current_token.push(c);
38 loop {
39 let c = chars.peek();
40 if c.is_none() {
41 break;
42 }
43 let (_, c) = c.unwrap();
44 match c {
45 'a'..='z' | 'A'..='Z' | '_' | '0'..='9' => {
46 current_token.push(*c);
47 chars.next();
48 }
49 _ => break,
50 }
51 }
52
53 match current_token.as_str() {
54 "var" => tokens.push(Token::Var),
55 "let" => tokens.push(Token::Let),
56 _ => tokens.push(Token::Identifier(current_token)),
57 }
58 }
59 '0'..='9' => {
60 let mut current_token = String::new();
61 current_token.push(c);
62 loop {
63 let c = chars.peek();
64 if c.is_none() {
65 break;
66 }
67 let (_, c) = c.unwrap();
68 match c {
69 '0'..='9' => {
70 current_token.push(*c);
71 chars.next();
72 }
73 _ => break,
74 }
75 }
76 tokens.push(Token::Number(current_token));
77 }
78 ':' => tokens.push(Token::Colon),
79 '=' => tokens.push(Token::Equals),
80 ';' => tokens.push(Token::Semicolon),
81 '+' => tokens.push(Token::Operator(Operator::Add)),
82 '-' => tokens.push(Token::Operator(Operator::Substract)),
83 '*' => tokens.push(Token::Operator(Operator::Multiply)),
84 '/' => tokens.push(Token::Operator(Operator::Divide)),
85 s if s.is_whitespace() => (),
86 _ => {
87 return Err(UnknownCharacter {
88 error: format!("Unsupported character: {}", c),
89 }
90 .into())
91 }
92 },
93 None => break,
94 }
95 }
96
97 Ok(tokens)
98}
src/transpile/util.rs deleted-30
...@@ -1,30 +0,0 @@
1// Rust why do you not have a peekable iterator in the standard library?
2// Stolen from https://users.rust-lang.org/t/peekable-argument-there-has-to-be-a-simpler-way/6959
3pub trait PeekableIterator: std::iter::Iterator {
4 fn peek(&mut self) -> Option<&Self::Item>;
5}
6
7impl<I: std::iter::Iterator> PeekableIterator for std::iter::Peekable<I> {
8 fn peek(&mut self) -> Option<&Self::Item> {
9 std::iter::Peekable::peek(self)
10 }
11}
12
13#[derive(Debug, Clone)]
14pub enum Operator {
15 Add,
16 Substract,
17 Multiply,
18 Divide,
19}
20
21impl Operator {
22 pub fn to_string(self) -> String {
23 String::from(match self {
24 Self::Add => "+",
25 Self::Substract => "-",
26 Self::Divide => "/",
27 Self::Multiply => "*",
28 })
29 }
30}
src/transpile/walker.rs deleted-37
...@@ -1,37 +0,0 @@
1use miette::Result;
2
3use super::ast::{Ast, Type};
4
5fn transpile_helper(tree: Ast) -> Result<String> {
6 Ok(match tree {
7 Ast::Number(number) => format!("{}", number),
8 Ast::Operation {
9 operator,
10 left,
11 right,
12 } => format!(
13 "{} {} {}",
14 transpile_helper(*left)?,
15 operator.to_string(),
16 transpile_helper(*right)?
17 ),
18 Ast::VariableDeclaration { name, typ, value } => match typ {
19 Type::Bigint => format!("let {} = BigInt({});\n", name, transpile_helper(*value)?),
20 _ => format!("let {} = {};\n", name, transpile_helper(*value)?),
21 },
22 Ast::ConstantDeclaration { name, typ, value } => match typ {
23 Type::Bigint => format!("const {} = BigInt({});\n", name, transpile_helper(*value)?),
24 _ => format!("const {} = {};\n", name, transpile_helper(*value)?),
25 },
26 })
27}
28
29pub fn transpile(forest: Vec<Ast>) -> Result<String> {
30 let mut result = String::new();
31
32 for tree in forest {
33 result.push_str(&transpile_helper(tree)?);
34 }
35
36 Ok(result)
37}