| author | |
| committer | |
| log | bf7dedc48580545fcbcbb877d6f84087b96b4c62 |
| tree | 4c3e9f314c2647a517bba1d8f4c03eab5b5af113 |
| parent | b273a9fc6eaec7ed69a8c10b61d800e2b434f23f |
30 files changed, 1860 insertions(+), 426 deletions(-)
.gitignore+1-1| ... | @@ -1 +1 @@ | ... | @@ -1 +1 @@ |
| 1 | /target | 1 | target |
Cargo.lock+35-25| ... | @@ -95,15 +95,6 @@ version = "2.4.1" | ... | @@ -95,15 +95,6 @@ version = "2.4.1" |
| 95 | source = "registry+https://github.com/rust-lang/crates.io-index" | 95 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 96 | checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" | 96 | checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" |
| 97 | 97 | ||
| 98 | [[package]] | ||
| 99 | name = "blight" | ||
| 100 | version = "0.1.0" | ||
| 101 | dependencies = [ | ||
| 102 | "clap", | ||
| 103 | "miette", | ||
| 104 | "thiserror", | ||
| 105 | ] | ||
| 106 | |||
| 107 | [[package]] | 98 | [[package]] |
| 108 | name = "cc" | 99 | name = "cc" |
| 109 | version = "1.0.83" | 100 | version = "1.0.83" |
| ... | @@ -121,9 +112,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" | ... | @@ -121,9 +112,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" |
| 121 | 112 | ||
| 122 | [[package]] | 113 | [[package]] |
| 123 | name = "clap" | 114 | name = "clap" |
| 124 | version = "4.4.12" | 115 | version = "4.4.14" |
| 125 | source = "registry+https://github.com/rust-lang/crates.io-index" | 116 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 126 | checksum = "dcfab8ba68f3668e89f6ff60f5b205cea56aa7b769451a59f34b8682f51c056d" | 117 | checksum = "33e92c5c1a78c62968ec57dbc2440366a2d6e5a23faf829970ff1585dc6b18e2" |
| 127 | dependencies = [ | 118 | dependencies = [ |
| 128 | "clap_builder", | 119 | "clap_builder", |
| 129 | "clap_derive", | 120 | "clap_derive", |
| ... | @@ -131,9 +122,9 @@ dependencies = [ | ... | @@ -131,9 +122,9 @@ dependencies = [ |
| 131 | 122 | ||
| 132 | [[package]] | 123 | [[package]] |
| 133 | name = "clap_builder" | 124 | name = "clap_builder" |
| 134 | version = "4.4.12" | 125 | version = "4.4.14" |
| 135 | source = "registry+https://github.com/rust-lang/crates.io-index" | 126 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 136 | checksum = "fb7fb5e4e979aec3be7791562fcba452f94ad85e954da024396433e0e25a79e9" | 127 | checksum = "f4323769dc8a61e2c39ad7dc26f6f2800524691a44d74fe3d1071a5c24db6370" |
| 137 | dependencies = [ | 128 | dependencies = [ |
| 138 | "anstream", | 129 | "anstream", |
| 139 | "anstyle", | 130 | "anstyle", |
| ... | @@ -159,12 +150,31 @@ version = "0.6.0" | ... | @@ -159,12 +150,31 @@ version = "0.6.0" |
| 159 | source = "registry+https://github.com/rust-lang/crates.io-index" | 150 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 160 | checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" | 151 | checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" |
| 161 | 152 | ||
| 153 | [[package]] | ||
| 154 | name = "cli" | ||
| 155 | version = "0.1.0" | ||
| 156 | dependencies = [ | ||
| 157 | "clap", | ||
| 158 | "compiler", | ||
| 159 | "miette", | ||
| 160 | "thiserror", | ||
| 161 | ] | ||
| 162 | |||
| 162 | [[package]] | 163 | [[package]] |
| 163 | name = "colorchoice" | 164 | name = "colorchoice" |
| 164 | version = "1.0.0" | 165 | version = "1.0.0" |
| 165 | source = "registry+https://github.com/rust-lang/crates.io-index" | 166 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 166 | checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" | 167 | checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" |
| 167 | 168 | ||
| 169 | [[package]] | ||
| 170 | name = "compiler" | ||
| 171 | version = "0.1.0" | ||
| 172 | dependencies = [ | ||
| 173 | "clap", | ||
| 174 | "miette", | ||
| 175 | "thiserror", | ||
| 176 | ] | ||
| 177 | |||
| 168 | [[package]] | 178 | [[package]] |
| 169 | name = "errno" | 179 | name = "errno" |
| 170 | version = "0.3.8" | 180 | version = "0.3.8" |
| ... | @@ -212,9 +222,9 @@ checksum = "616cde7c720bb2bb5824a224687d8f77bfd38922027f01d825cd7453be5099fb" | ... | @@ -212,9 +222,9 @@ checksum = "616cde7c720bb2bb5824a224687d8f77bfd38922027f01d825cd7453be5099fb" |
| 212 | 222 | ||
| 213 | [[package]] | 223 | [[package]] |
| 214 | name = "libc" | 224 | name = "libc" |
| 215 | version = "0.2.151" | 225 | version = "0.2.152" |
| 216 | source = "registry+https://github.com/rust-lang/crates.io-index" | 226 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 217 | checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" | 227 | checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" |
| 218 | 228 | ||
| 219 | [[package]] | 229 | [[package]] |
| 220 | name = "linux-raw-sys" | 230 | name = "linux-raw-sys" |
| ... | @@ -292,18 +302,18 @@ checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" | ... | @@ -292,18 +302,18 @@ checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" |
| 292 | 302 | ||
| 293 | [[package]] | 303 | [[package]] |
| 294 | name = "proc-macro2" | 304 | name = "proc-macro2" |
| 295 | version = "1.0.73" | 305 | version = "1.0.76" |
| 296 | source = "registry+https://github.com/rust-lang/crates.io-index" | 306 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 297 | checksum = "2dd5e8a1f1029c43224ad5898e50140c2aebb1705f19e67c918ebf5b9e797fe1" | 307 | checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c" |
| 298 | dependencies = [ | 308 | dependencies = [ |
| 299 | "unicode-ident", | 309 | "unicode-ident", |
| 300 | ] | 310 | ] |
| 301 | 311 | ||
| 302 | [[package]] | 312 | [[package]] |
| 303 | name = "quote" | 313 | name = "quote" |
| 304 | version = "1.0.34" | 314 | version = "1.0.35" |
| 305 | source = "registry+https://github.com/rust-lang/crates.io-index" | 315 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 306 | checksum = "22a37c9326af5ed140c86a46655b5278de879853be5573c01df185b6f49a580a" | 316 | checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" |
| 307 | dependencies = [ | 317 | dependencies = [ |
| 308 | "proc-macro2", | 318 | "proc-macro2", |
| 309 | ] | 319 | ] |
| ... | @@ -369,9 +379,9 @@ dependencies = [ | ... | @@ -369,9 +379,9 @@ dependencies = [ |
| 369 | 379 | ||
| 370 | [[package]] | 380 | [[package]] |
| 371 | name = "syn" | 381 | name = "syn" |
| 372 | version = "2.0.44" | 382 | version = "2.0.48" |
| 373 | source = "registry+https://github.com/rust-lang/crates.io-index" | 383 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 374 | checksum = "92d27c2c202598d05175a6dd3af46824b7f747f8d8e9b14c623f19fa5069735d" | 384 | checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" |
| 375 | dependencies = [ | 385 | dependencies = [ |
| 376 | "proc-macro2", | 386 | "proc-macro2", |
| 377 | "quote", | 387 | "quote", |
| ... | @@ -401,18 +411,18 @@ dependencies = [ | ... | @@ -401,18 +411,18 @@ dependencies = [ |
| 401 | 411 | ||
| 402 | [[package]] | 412 | [[package]] |
| 403 | name = "thiserror" | 413 | name = "thiserror" |
| 404 | version = "1.0.53" | 414 | version = "1.0.56" |
| 405 | source = "registry+https://github.com/rust-lang/crates.io-index" | 415 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 406 | checksum = "b2cd5904763bad08ad5513ddbb12cf2ae273ca53fa9f68e843e236ec6dfccc09" | 416 | checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" |
| 407 | dependencies = [ | 417 | dependencies = [ |
| 408 | "thiserror-impl", | 418 | "thiserror-impl", |
| 409 | ] | 419 | ] |
| 410 | 420 | ||
| 411 | [[package]] | 421 | [[package]] |
| 412 | name = "thiserror-impl" | 422 | name = "thiserror-impl" |
| 413 | version = "1.0.53" | 423 | version = "1.0.56" |
| 414 | source = "registry+https://github.com/rust-lang/crates.io-index" | 424 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 415 | checksum = "3dcf4a824cce0aeacd6f38ae6f24234c8e80d68632338ebaa1443b5df9e29e19" | 425 | checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" |
| 416 | dependencies = [ | 426 | dependencies = [ |
| 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] |
| 2 | name = "blight" | ||
| 3 | version = "0.1.0" | 2 | version = "0.1.0" |
| 4 | edition = "2021" | 3 | name = "blight" |
| 4 | edition = "2023" | ||
| 5 | license = "MIT" | ||
| 6 | authors = ["Lino Le Van"] | ||
| 7 | repository = "https://github.com/lino-levan/blight" | ||
| 5 | 8 | ||
| 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | 9 | [workspace] |
| 10 | resolver = "2" | ||
| 11 | members = ["cli", "compiler"] | ||
| 7 | 12 | ||
| 8 | [dependencies] | 13 | [workspace.dependencies] |
| 9 | clap = { version = "4.4.12", features = ["derive"] } | 14 | clap = { version = "4.4.12", features = ["derive"] } |
| 10 | miette = { version = "5.10.0", features = ["fancy"] } | 15 | miette = { version = "5.10.0", features = ["fancy"] } |
| 11 | thiserror = "1.0.53" | 16 | thiserror = "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. | ||
| 3 | version = 3 | ||
| 4 | |||
| 5 | [[package]] | ||
| 6 | name = "addr2line" | ||
| 7 | version = "0.21.0" | ||
| 8 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 9 | checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" | ||
| 10 | dependencies = [ | ||
| 11 | "gimli", | ||
| 12 | ] | ||
| 13 | |||
| 14 | [[package]] | ||
| 15 | name = "adler" | ||
| 16 | version = "1.0.2" | ||
| 17 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 18 | checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" | ||
| 19 | |||
| 20 | [[package]] | ||
| 21 | name = "anstream" | ||
| 22 | version = "0.6.5" | ||
| 23 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 24 | checksum = "d664a92ecae85fd0a7392615844904654d1d5f5514837f471ddef4a057aba1b6" | ||
| 25 | dependencies = [ | ||
| 26 | "anstyle", | ||
| 27 | "anstyle-parse", | ||
| 28 | "anstyle-query", | ||
| 29 | "anstyle-wincon", | ||
| 30 | "colorchoice", | ||
| 31 | "utf8parse", | ||
| 32 | ] | ||
| 33 | |||
| 34 | [[package]] | ||
| 35 | name = "anstyle" | ||
| 36 | version = "1.0.4" | ||
| 37 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 38 | checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87" | ||
| 39 | |||
| 40 | [[package]] | ||
| 41 | name = "anstyle-parse" | ||
| 42 | version = "0.2.3" | ||
| 43 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 44 | checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" | ||
| 45 | dependencies = [ | ||
| 46 | "utf8parse", | ||
| 47 | ] | ||
| 48 | |||
| 49 | [[package]] | ||
| 50 | name = "anstyle-query" | ||
| 51 | version = "1.0.2" | ||
| 52 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 53 | checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" | ||
| 54 | dependencies = [ | ||
| 55 | "windows-sys", | ||
| 56 | ] | ||
| 57 | |||
| 58 | [[package]] | ||
| 59 | name = "anstyle-wincon" | ||
| 60 | version = "3.0.2" | ||
| 61 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 62 | checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" | ||
| 63 | dependencies = [ | ||
| 64 | "anstyle", | ||
| 65 | "windows-sys", | ||
| 66 | ] | ||
| 67 | |||
| 68 | [[package]] | ||
| 69 | name = "backtrace" | ||
| 70 | version = "0.3.69" | ||
| 71 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 72 | checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" | ||
| 73 | dependencies = [ | ||
| 74 | "addr2line", | ||
| 75 | "cc", | ||
| 76 | "cfg-if", | ||
| 77 | "libc", | ||
| 78 | "miniz_oxide", | ||
| 79 | "object", | ||
| 80 | "rustc-demangle", | ||
| 81 | ] | ||
| 82 | |||
| 83 | [[package]] | ||
| 84 | name = "backtrace-ext" | ||
| 85 | version = "0.2.1" | ||
| 86 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 87 | checksum = "537beee3be4a18fb023b570f80e3ae28003db9167a751266b259926e25539d50" | ||
| 88 | dependencies = [ | ||
| 89 | "backtrace", | ||
| 90 | ] | ||
| 91 | |||
| 92 | [[package]] | ||
| 93 | name = "bitflags" | ||
| 94 | version = "2.4.1" | ||
| 95 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 96 | checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" | ||
| 97 | |||
| 98 | [[package]] | ||
| 99 | name = "blight" | ||
| 100 | version = "0.1.0" | ||
| 101 | dependencies = [ | ||
| 102 | "clap", | ||
| 103 | "miette", | ||
| 104 | "thiserror", | ||
| 105 | ] | ||
| 106 | |||
| 107 | [[package]] | ||
| 108 | name = "cc" | ||
| 109 | version = "1.0.83" | ||
| 110 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 111 | checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" | ||
| 112 | dependencies = [ | ||
| 113 | "libc", | ||
| 114 | ] | ||
| 115 | |||
| 116 | [[package]] | ||
| 117 | name = "cfg-if" | ||
| 118 | version = "1.0.0" | ||
| 119 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 120 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" | ||
| 121 | |||
| 122 | [[package]] | ||
| 123 | name = "clap" | ||
| 124 | version = "4.4.12" | ||
| 125 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 126 | checksum = "dcfab8ba68f3668e89f6ff60f5b205cea56aa7b769451a59f34b8682f51c056d" | ||
| 127 | dependencies = [ | ||
| 128 | "clap_builder", | ||
| 129 | "clap_derive", | ||
| 130 | ] | ||
| 131 | |||
| 132 | [[package]] | ||
| 133 | name = "clap_builder" | ||
| 134 | version = "4.4.12" | ||
| 135 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 136 | checksum = "fb7fb5e4e979aec3be7791562fcba452f94ad85e954da024396433e0e25a79e9" | ||
| 137 | dependencies = [ | ||
| 138 | "anstream", | ||
| 139 | "anstyle", | ||
| 140 | "clap_lex", | ||
| 141 | "strsim", | ||
| 142 | ] | ||
| 143 | |||
| 144 | [[package]] | ||
| 145 | name = "clap_derive" | ||
| 146 | version = "4.4.7" | ||
| 147 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 148 | checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442" | ||
| 149 | dependencies = [ | ||
| 150 | "heck", | ||
| 151 | "proc-macro2", | ||
| 152 | "quote", | ||
| 153 | "syn", | ||
| 154 | ] | ||
| 155 | |||
| 156 | [[package]] | ||
| 157 | name = "clap_lex" | ||
| 158 | version = "0.6.0" | ||
| 159 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 160 | checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" | ||
| 161 | |||
| 162 | [[package]] | ||
| 163 | name = "colorchoice" | ||
| 164 | version = "1.0.0" | ||
| 165 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 166 | checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" | ||
| 167 | |||
| 168 | [[package]] | ||
| 169 | name = "errno" | ||
| 170 | version = "0.3.8" | ||
| 171 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 172 | checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" | ||
| 173 | dependencies = [ | ||
| 174 | "libc", | ||
| 175 | "windows-sys", | ||
| 176 | ] | ||
| 177 | |||
| 178 | [[package]] | ||
| 179 | name = "gimli" | ||
| 180 | version = "0.28.1" | ||
| 181 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 182 | checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" | ||
| 183 | |||
| 184 | [[package]] | ||
| 185 | name = "heck" | ||
| 186 | version = "0.4.1" | ||
| 187 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 188 | checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" | ||
| 189 | |||
| 190 | [[package]] | ||
| 191 | name = "hermit-abi" | ||
| 192 | version = "0.3.3" | ||
| 193 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 194 | checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" | ||
| 195 | |||
| 196 | [[package]] | ||
| 197 | name = "is-terminal" | ||
| 198 | version = "0.4.10" | ||
| 199 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 200 | checksum = "0bad00257d07be169d870ab665980b06cdb366d792ad690bf2e76876dc503455" | ||
| 201 | dependencies = [ | ||
| 202 | "hermit-abi", | ||
| 203 | "rustix", | ||
| 204 | "windows-sys", | ||
| 205 | ] | ||
| 206 | |||
| 207 | [[package]] | ||
| 208 | name = "is_ci" | ||
| 209 | version = "1.1.1" | ||
| 210 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 211 | checksum = "616cde7c720bb2bb5824a224687d8f77bfd38922027f01d825cd7453be5099fb" | ||
| 212 | |||
| 213 | [[package]] | ||
| 214 | name = "libc" | ||
| 215 | version = "0.2.151" | ||
| 216 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 217 | checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" | ||
| 218 | |||
| 219 | [[package]] | ||
| 220 | name = "linux-raw-sys" | ||
| 221 | version = "0.4.12" | ||
| 222 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 223 | checksum = "c4cd1a83af159aa67994778be9070f0ae1bd732942279cabb14f86f986a21456" | ||
| 224 | |||
| 225 | [[package]] | ||
| 226 | name = "memchr" | ||
| 227 | version = "2.7.1" | ||
| 228 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 229 | checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" | ||
| 230 | |||
| 231 | [[package]] | ||
| 232 | name = "miette" | ||
| 233 | version = "5.10.0" | ||
| 234 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 235 | checksum = "59bb584eaeeab6bd0226ccf3509a69d7936d148cf3d036ad350abe35e8c6856e" | ||
| 236 | dependencies = [ | ||
| 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]] | ||
| 253 | name = "miette-derive" | ||
| 254 | version = "5.10.0" | ||
| 255 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 256 | checksum = "49e7bc1560b95a3c4a25d03de42fe76ca718ab92d1a22a55b9b4cf67b3ae635c" | ||
| 257 | dependencies = [ | ||
| 258 | "proc-macro2", | ||
| 259 | "quote", | ||
| 260 | "syn", | ||
| 261 | ] | ||
| 262 | |||
| 263 | [[package]] | ||
| 264 | name = "miniz_oxide" | ||
| 265 | version = "0.7.1" | ||
| 266 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 267 | checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" | ||
| 268 | dependencies = [ | ||
| 269 | "adler", | ||
| 270 | ] | ||
| 271 | |||
| 272 | [[package]] | ||
| 273 | name = "object" | ||
| 274 | version = "0.32.2" | ||
| 275 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 276 | checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" | ||
| 277 | dependencies = [ | ||
| 278 | "memchr", | ||
| 279 | ] | ||
| 280 | |||
| 281 | [[package]] | ||
| 282 | name = "once_cell" | ||
| 283 | version = "1.19.0" | ||
| 284 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 285 | checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" | ||
| 286 | |||
| 287 | [[package]] | ||
| 288 | name = "owo-colors" | ||
| 289 | version = "3.5.0" | ||
| 290 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 291 | checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" | ||
| 292 | |||
| 293 | [[package]] | ||
| 294 | name = "proc-macro2" | ||
| 295 | version = "1.0.73" | ||
| 296 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 297 | checksum = "2dd5e8a1f1029c43224ad5898e50140c2aebb1705f19e67c918ebf5b9e797fe1" | ||
| 298 | dependencies = [ | ||
| 299 | "unicode-ident", | ||
| 300 | ] | ||
| 301 | |||
| 302 | [[package]] | ||
| 303 | name = "quote" | ||
| 304 | version = "1.0.34" | ||
| 305 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 306 | checksum = "22a37c9326af5ed140c86a46655b5278de879853be5573c01df185b6f49a580a" | ||
| 307 | dependencies = [ | ||
| 308 | "proc-macro2", | ||
| 309 | ] | ||
| 310 | |||
| 311 | [[package]] | ||
| 312 | name = "rustc-demangle" | ||
| 313 | version = "0.1.23" | ||
| 314 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 315 | checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" | ||
| 316 | |||
| 317 | [[package]] | ||
| 318 | name = "rustix" | ||
| 319 | version = "0.38.28" | ||
| 320 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 321 | checksum = "72e572a5e8ca657d7366229cdde4bd14c4eb5499a9573d4d366fe1b599daa316" | ||
| 322 | dependencies = [ | ||
| 323 | "bitflags", | ||
| 324 | "errno", | ||
| 325 | "libc", | ||
| 326 | "linux-raw-sys", | ||
| 327 | "windows-sys", | ||
| 328 | ] | ||
| 329 | |||
| 330 | [[package]] | ||
| 331 | name = "smawk" | ||
| 332 | version = "0.3.2" | ||
| 333 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 334 | checksum = "b7c388c1b5e93756d0c740965c41e8822f866621d41acbdf6336a6a168f8840c" | ||
| 335 | |||
| 336 | [[package]] | ||
| 337 | name = "strsim" | ||
| 338 | version = "0.10.0" | ||
| 339 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 340 | checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" | ||
| 341 | |||
| 342 | [[package]] | ||
| 343 | name = "supports-color" | ||
| 344 | version = "2.1.0" | ||
| 345 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 346 | checksum = "d6398cde53adc3c4557306a96ce67b302968513830a77a95b2b17305d9719a89" | ||
| 347 | dependencies = [ | ||
| 348 | "is-terminal", | ||
| 349 | "is_ci", | ||
| 350 | ] | ||
| 351 | |||
| 352 | [[package]] | ||
| 353 | name = "supports-hyperlinks" | ||
| 354 | version = "2.1.0" | ||
| 355 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 356 | checksum = "f84231692eb0d4d41e4cdd0cabfdd2e6cd9e255e65f80c9aa7c98dd502b4233d" | ||
| 357 | dependencies = [ | ||
| 358 | "is-terminal", | ||
| 359 | ] | ||
| 360 | |||
| 361 | [[package]] | ||
| 362 | name = "supports-unicode" | ||
| 363 | version = "2.0.0" | ||
| 364 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 365 | checksum = "4b6c2cb240ab5dd21ed4906895ee23fe5a48acdbd15a3ce388e7b62a9b66baf7" | ||
| 366 | dependencies = [ | ||
| 367 | "is-terminal", | ||
| 368 | ] | ||
| 369 | |||
| 370 | [[package]] | ||
| 371 | name = "syn" | ||
| 372 | version = "2.0.44" | ||
| 373 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 374 | checksum = "92d27c2c202598d05175a6dd3af46824b7f747f8d8e9b14c623f19fa5069735d" | ||
| 375 | dependencies = [ | ||
| 376 | "proc-macro2", | ||
| 377 | "quote", | ||
| 378 | "unicode-ident", | ||
| 379 | ] | ||
| 380 | |||
| 381 | [[package]] | ||
| 382 | name = "terminal_size" | ||
| 383 | version = "0.1.17" | ||
| 384 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 385 | checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df" | ||
| 386 | dependencies = [ | ||
| 387 | "libc", | ||
| 388 | "winapi", | ||
| 389 | ] | ||
| 390 | |||
| 391 | [[package]] | ||
| 392 | name = "textwrap" | ||
| 393 | version = "0.15.2" | ||
| 394 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 395 | checksum = "b7b3e525a49ec206798b40326a44121291b530c963cfb01018f63e135bac543d" | ||
| 396 | dependencies = [ | ||
| 397 | "smawk", | ||
| 398 | "unicode-linebreak", | ||
| 399 | "unicode-width", | ||
| 400 | ] | ||
| 401 | |||
| 402 | [[package]] | ||
| 403 | name = "thiserror" | ||
| 404 | version = "1.0.53" | ||
| 405 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 406 | checksum = "b2cd5904763bad08ad5513ddbb12cf2ae273ca53fa9f68e843e236ec6dfccc09" | ||
| 407 | dependencies = [ | ||
| 408 | "thiserror-impl", | ||
| 409 | ] | ||
| 410 | |||
| 411 | [[package]] | ||
| 412 | name = "thiserror-impl" | ||
| 413 | version = "1.0.53" | ||
| 414 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 415 | checksum = "3dcf4a824cce0aeacd6f38ae6f24234c8e80d68632338ebaa1443b5df9e29e19" | ||
| 416 | dependencies = [ | ||
| 417 | "proc-macro2", | ||
| 418 | "quote", | ||
| 419 | "syn", | ||
| 420 | ] | ||
| 421 | |||
| 422 | [[package]] | ||
| 423 | name = "unicode-ident" | ||
| 424 | version = "1.0.12" | ||
| 425 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 426 | checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" | ||
| 427 | |||
| 428 | [[package]] | ||
| 429 | name = "unicode-linebreak" | ||
| 430 | version = "0.1.5" | ||
| 431 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 432 | checksum = "3b09c83c3c29d37506a3e260c08c03743a6bb66a9cd432c6934ab501a190571f" | ||
| 433 | |||
| 434 | [[package]] | ||
| 435 | name = "unicode-width" | ||
| 436 | version = "0.1.11" | ||
| 437 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 438 | checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" | ||
| 439 | |||
| 440 | [[package]] | ||
| 441 | name = "utf8parse" | ||
| 442 | version = "0.2.1" | ||
| 443 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 444 | checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" | ||
| 445 | |||
| 446 | [[package]] | ||
| 447 | name = "winapi" | ||
| 448 | version = "0.3.9" | ||
| 449 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 450 | checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" | ||
| 451 | dependencies = [ | ||
| 452 | "winapi-i686-pc-windows-gnu", | ||
| 453 | "winapi-x86_64-pc-windows-gnu", | ||
| 454 | ] | ||
| 455 | |||
| 456 | [[package]] | ||
| 457 | name = "winapi-i686-pc-windows-gnu" | ||
| 458 | version = "0.4.0" | ||
| 459 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 460 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" | ||
| 461 | |||
| 462 | [[package]] | ||
| 463 | name = "winapi-x86_64-pc-windows-gnu" | ||
| 464 | version = "0.4.0" | ||
| 465 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 466 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" | ||
| 467 | |||
| 468 | [[package]] | ||
| 469 | name = "windows-sys" | ||
| 470 | version = "0.52.0" | ||
| 471 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 472 | checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" | ||
| 473 | dependencies = [ | ||
| 474 | "windows-targets", | ||
| 475 | ] | ||
| 476 | |||
| 477 | [[package]] | ||
| 478 | name = "windows-targets" | ||
| 479 | version = "0.52.0" | ||
| 480 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 481 | checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" | ||
| 482 | dependencies = [ | ||
| 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]] | ||
| 493 | name = "windows_aarch64_gnullvm" | ||
| 494 | version = "0.52.0" | ||
| 495 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 496 | checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" | ||
| 497 | |||
| 498 | [[package]] | ||
| 499 | name = "windows_aarch64_msvc" | ||
| 500 | version = "0.52.0" | ||
| 501 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 502 | checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" | ||
| 503 | |||
| 504 | [[package]] | ||
| 505 | name = "windows_i686_gnu" | ||
| 506 | version = "0.52.0" | ||
| 507 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 508 | checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" | ||
| 509 | |||
| 510 | [[package]] | ||
| 511 | name = "windows_i686_msvc" | ||
| 512 | version = "0.52.0" | ||
| 513 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 514 | checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" | ||
| 515 | |||
| 516 | [[package]] | ||
| 517 | name = "windows_x86_64_gnu" | ||
| 518 | version = "0.52.0" | ||
| 519 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 520 | checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" | ||
| 521 | |||
| 522 | [[package]] | ||
| 523 | name = "windows_x86_64_gnullvm" | ||
| 524 | version = "0.52.0" | ||
| 525 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 526 | checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" | ||
| 527 | |||
| 528 | [[package]] | ||
| 529 | name = "windows_x86_64_msvc" | ||
| 530 | version = "0.52.0" | ||
| 531 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 532 | checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" | ||
cli/Cargo.toml created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | [package] | ||
| 2 | name = "cli" | ||
| 3 | version = "0.1.0" | ||
| 4 | edition = "2021" | ||
| 5 | |||
| 6 | [[bin]] | ||
| 7 | name = "blight" | ||
| 8 | path = "./src/main.rs" | ||
| 9 | |||
| 10 | [dependencies] | ||
| 11 | clap.workspace = true | ||
| 12 | miette.workspace = true | ||
| 13 | thiserror.workspace = true | ||
| 14 | |||
| 15 | compiler = { path = "../compiler" } | ||
cli/src/main.rs created+40| ... | @@ -0,0 +1,40 @@ | ||
| 1 | use std::path::PathBuf; | ||
| 2 | |||
| 3 | use clap::{Parser, Subcommand}; | ||
| 4 | use miette::Result; | ||
| 5 | |||
| 6 | use compiler::transpile; | ||
| 7 | |||
| 8 | #[derive(Parser)] | ||
| 9 | #[command(author, version, about, long_about = None)] | ||
| 10 | struct 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)] | ||
| 20 | enum Commands { | ||
| 21 | /// Compiles a file into javascript | ||
| 22 | Compile { | ||
| 23 | /// lists test values | ||
| 24 | file: PathBuf, | ||
| 25 | }, | ||
| 26 | } | ||
| 27 | |||
| 28 | fn 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. | ||
| 3 | version = 3 | ||
| 4 | |||
| 5 | [[package]] | ||
| 6 | name = "addr2line" | ||
| 7 | version = "0.21.0" | ||
| 8 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 9 | checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" | ||
| 10 | dependencies = [ | ||
| 11 | "gimli", | ||
| 12 | ] | ||
| 13 | |||
| 14 | [[package]] | ||
| 15 | name = "adler" | ||
| 16 | version = "1.0.2" | ||
| 17 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 18 | checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" | ||
| 19 | |||
| 20 | [[package]] | ||
| 21 | name = "anstream" | ||
| 22 | version = "0.6.5" | ||
| 23 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 24 | checksum = "d664a92ecae85fd0a7392615844904654d1d5f5514837f471ddef4a057aba1b6" | ||
| 25 | dependencies = [ | ||
| 26 | "anstyle", | ||
| 27 | "anstyle-parse", | ||
| 28 | "anstyle-query", | ||
| 29 | "anstyle-wincon", | ||
| 30 | "colorchoice", | ||
| 31 | "utf8parse", | ||
| 32 | ] | ||
| 33 | |||
| 34 | [[package]] | ||
| 35 | name = "anstyle" | ||
| 36 | version = "1.0.4" | ||
| 37 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 38 | checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87" | ||
| 39 | |||
| 40 | [[package]] | ||
| 41 | name = "anstyle-parse" | ||
| 42 | version = "0.2.3" | ||
| 43 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 44 | checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" | ||
| 45 | dependencies = [ | ||
| 46 | "utf8parse", | ||
| 47 | ] | ||
| 48 | |||
| 49 | [[package]] | ||
| 50 | name = "anstyle-query" | ||
| 51 | version = "1.0.2" | ||
| 52 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 53 | checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" | ||
| 54 | dependencies = [ | ||
| 55 | "windows-sys", | ||
| 56 | ] | ||
| 57 | |||
| 58 | [[package]] | ||
| 59 | name = "anstyle-wincon" | ||
| 60 | version = "3.0.2" | ||
| 61 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 62 | checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" | ||
| 63 | dependencies = [ | ||
| 64 | "anstyle", | ||
| 65 | "windows-sys", | ||
| 66 | ] | ||
| 67 | |||
| 68 | [[package]] | ||
| 69 | name = "backtrace" | ||
| 70 | version = "0.3.69" | ||
| 71 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 72 | checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" | ||
| 73 | dependencies = [ | ||
| 74 | "addr2line", | ||
| 75 | "cc", | ||
| 76 | "cfg-if", | ||
| 77 | "libc", | ||
| 78 | "miniz_oxide", | ||
| 79 | "object", | ||
| 80 | "rustc-demangle", | ||
| 81 | ] | ||
| 82 | |||
| 83 | [[package]] | ||
| 84 | name = "backtrace-ext" | ||
| 85 | version = "0.2.1" | ||
| 86 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 87 | checksum = "537beee3be4a18fb023b570f80e3ae28003db9167a751266b259926e25539d50" | ||
| 88 | dependencies = [ | ||
| 89 | "backtrace", | ||
| 90 | ] | ||
| 91 | |||
| 92 | [[package]] | ||
| 93 | name = "bitflags" | ||
| 94 | version = "2.4.1" | ||
| 95 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 96 | checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" | ||
| 97 | |||
| 98 | [[package]] | ||
| 99 | name = "blight" | ||
| 100 | version = "0.1.0" | ||
| 101 | dependencies = [ | ||
| 102 | "clap", | ||
| 103 | "miette", | ||
| 104 | "thiserror", | ||
| 105 | ] | ||
| 106 | |||
| 107 | [[package]] | ||
| 108 | name = "cc" | ||
| 109 | version = "1.0.83" | ||
| 110 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 111 | checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" | ||
| 112 | dependencies = [ | ||
| 113 | "libc", | ||
| 114 | ] | ||
| 115 | |||
| 116 | [[package]] | ||
| 117 | name = "cfg-if" | ||
| 118 | version = "1.0.0" | ||
| 119 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 120 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" | ||
| 121 | |||
| 122 | [[package]] | ||
| 123 | name = "clap" | ||
| 124 | version = "4.4.12" | ||
| 125 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 126 | checksum = "dcfab8ba68f3668e89f6ff60f5b205cea56aa7b769451a59f34b8682f51c056d" | ||
| 127 | dependencies = [ | ||
| 128 | "clap_builder", | ||
| 129 | "clap_derive", | ||
| 130 | ] | ||
| 131 | |||
| 132 | [[package]] | ||
| 133 | name = "clap_builder" | ||
| 134 | version = "4.4.12" | ||
| 135 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 136 | checksum = "fb7fb5e4e979aec3be7791562fcba452f94ad85e954da024396433e0e25a79e9" | ||
| 137 | dependencies = [ | ||
| 138 | "anstream", | ||
| 139 | "anstyle", | ||
| 140 | "clap_lex", | ||
| 141 | "strsim", | ||
| 142 | ] | ||
| 143 | |||
| 144 | [[package]] | ||
| 145 | name = "clap_derive" | ||
| 146 | version = "4.4.7" | ||
| 147 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 148 | checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442" | ||
| 149 | dependencies = [ | ||
| 150 | "heck", | ||
| 151 | "proc-macro2", | ||
| 152 | "quote", | ||
| 153 | "syn", | ||
| 154 | ] | ||
| 155 | |||
| 156 | [[package]] | ||
| 157 | name = "clap_lex" | ||
| 158 | version = "0.6.0" | ||
| 159 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 160 | checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" | ||
| 161 | |||
| 162 | [[package]] | ||
| 163 | name = "colorchoice" | ||
| 164 | version = "1.0.0" | ||
| 165 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 166 | checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" | ||
| 167 | |||
| 168 | [[package]] | ||
| 169 | name = "errno" | ||
| 170 | version = "0.3.8" | ||
| 171 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 172 | checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" | ||
| 173 | dependencies = [ | ||
| 174 | "libc", | ||
| 175 | "windows-sys", | ||
| 176 | ] | ||
| 177 | |||
| 178 | [[package]] | ||
| 179 | name = "gimli" | ||
| 180 | version = "0.28.1" | ||
| 181 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 182 | checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" | ||
| 183 | |||
| 184 | [[package]] | ||
| 185 | name = "heck" | ||
| 186 | version = "0.4.1" | ||
| 187 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 188 | checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" | ||
| 189 | |||
| 190 | [[package]] | ||
| 191 | name = "hermit-abi" | ||
| 192 | version = "0.3.3" | ||
| 193 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 194 | checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" | ||
| 195 | |||
| 196 | [[package]] | ||
| 197 | name = "is-terminal" | ||
| 198 | version = "0.4.10" | ||
| 199 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 200 | checksum = "0bad00257d07be169d870ab665980b06cdb366d792ad690bf2e76876dc503455" | ||
| 201 | dependencies = [ | ||
| 202 | "hermit-abi", | ||
| 203 | "rustix", | ||
| 204 | "windows-sys", | ||
| 205 | ] | ||
| 206 | |||
| 207 | [[package]] | ||
| 208 | name = "is_ci" | ||
| 209 | version = "1.1.1" | ||
| 210 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 211 | checksum = "616cde7c720bb2bb5824a224687d8f77bfd38922027f01d825cd7453be5099fb" | ||
| 212 | |||
| 213 | [[package]] | ||
| 214 | name = "libc" | ||
| 215 | version = "0.2.151" | ||
| 216 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 217 | checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" | ||
| 218 | |||
| 219 | [[package]] | ||
| 220 | name = "linux-raw-sys" | ||
| 221 | version = "0.4.12" | ||
| 222 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 223 | checksum = "c4cd1a83af159aa67994778be9070f0ae1bd732942279cabb14f86f986a21456" | ||
| 224 | |||
| 225 | [[package]] | ||
| 226 | name = "memchr" | ||
| 227 | version = "2.7.1" | ||
| 228 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 229 | checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" | ||
| 230 | |||
| 231 | [[package]] | ||
| 232 | name = "miette" | ||
| 233 | version = "5.10.0" | ||
| 234 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 235 | checksum = "59bb584eaeeab6bd0226ccf3509a69d7936d148cf3d036ad350abe35e8c6856e" | ||
| 236 | dependencies = [ | ||
| 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]] | ||
| 253 | name = "miette-derive" | ||
| 254 | version = "5.10.0" | ||
| 255 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 256 | checksum = "49e7bc1560b95a3c4a25d03de42fe76ca718ab92d1a22a55b9b4cf67b3ae635c" | ||
| 257 | dependencies = [ | ||
| 258 | "proc-macro2", | ||
| 259 | "quote", | ||
| 260 | "syn", | ||
| 261 | ] | ||
| 262 | |||
| 263 | [[package]] | ||
| 264 | name = "miniz_oxide" | ||
| 265 | version = "0.7.1" | ||
| 266 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 267 | checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" | ||
| 268 | dependencies = [ | ||
| 269 | "adler", | ||
| 270 | ] | ||
| 271 | |||
| 272 | [[package]] | ||
| 273 | name = "object" | ||
| 274 | version = "0.32.2" | ||
| 275 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 276 | checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" | ||
| 277 | dependencies = [ | ||
| 278 | "memchr", | ||
| 279 | ] | ||
| 280 | |||
| 281 | [[package]] | ||
| 282 | name = "once_cell" | ||
| 283 | version = "1.19.0" | ||
| 284 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 285 | checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" | ||
| 286 | |||
| 287 | [[package]] | ||
| 288 | name = "owo-colors" | ||
| 289 | version = "3.5.0" | ||
| 290 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 291 | checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" | ||
| 292 | |||
| 293 | [[package]] | ||
| 294 | name = "proc-macro2" | ||
| 295 | version = "1.0.73" | ||
| 296 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 297 | checksum = "2dd5e8a1f1029c43224ad5898e50140c2aebb1705f19e67c918ebf5b9e797fe1" | ||
| 298 | dependencies = [ | ||
| 299 | "unicode-ident", | ||
| 300 | ] | ||
| 301 | |||
| 302 | [[package]] | ||
| 303 | name = "quote" | ||
| 304 | version = "1.0.34" | ||
| 305 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 306 | checksum = "22a37c9326af5ed140c86a46655b5278de879853be5573c01df185b6f49a580a" | ||
| 307 | dependencies = [ | ||
| 308 | "proc-macro2", | ||
| 309 | ] | ||
| 310 | |||
| 311 | [[package]] | ||
| 312 | name = "rustc-demangle" | ||
| 313 | version = "0.1.23" | ||
| 314 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 315 | checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" | ||
| 316 | |||
| 317 | [[package]] | ||
| 318 | name = "rustix" | ||
| 319 | version = "0.38.28" | ||
| 320 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 321 | checksum = "72e572a5e8ca657d7366229cdde4bd14c4eb5499a9573d4d366fe1b599daa316" | ||
| 322 | dependencies = [ | ||
| 323 | "bitflags", | ||
| 324 | "errno", | ||
| 325 | "libc", | ||
| 326 | "linux-raw-sys", | ||
| 327 | "windows-sys", | ||
| 328 | ] | ||
| 329 | |||
| 330 | [[package]] | ||
| 331 | name = "smawk" | ||
| 332 | version = "0.3.2" | ||
| 333 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 334 | checksum = "b7c388c1b5e93756d0c740965c41e8822f866621d41acbdf6336a6a168f8840c" | ||
| 335 | |||
| 336 | [[package]] | ||
| 337 | name = "strsim" | ||
| 338 | version = "0.10.0" | ||
| 339 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 340 | checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" | ||
| 341 | |||
| 342 | [[package]] | ||
| 343 | name = "supports-color" | ||
| 344 | version = "2.1.0" | ||
| 345 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 346 | checksum = "d6398cde53adc3c4557306a96ce67b302968513830a77a95b2b17305d9719a89" | ||
| 347 | dependencies = [ | ||
| 348 | "is-terminal", | ||
| 349 | "is_ci", | ||
| 350 | ] | ||
| 351 | |||
| 352 | [[package]] | ||
| 353 | name = "supports-hyperlinks" | ||
| 354 | version = "2.1.0" | ||
| 355 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 356 | checksum = "f84231692eb0d4d41e4cdd0cabfdd2e6cd9e255e65f80c9aa7c98dd502b4233d" | ||
| 357 | dependencies = [ | ||
| 358 | "is-terminal", | ||
| 359 | ] | ||
| 360 | |||
| 361 | [[package]] | ||
| 362 | name = "supports-unicode" | ||
| 363 | version = "2.0.0" | ||
| 364 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 365 | checksum = "4b6c2cb240ab5dd21ed4906895ee23fe5a48acdbd15a3ce388e7b62a9b66baf7" | ||
| 366 | dependencies = [ | ||
| 367 | "is-terminal", | ||
| 368 | ] | ||
| 369 | |||
| 370 | [[package]] | ||
| 371 | name = "syn" | ||
| 372 | version = "2.0.44" | ||
| 373 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 374 | checksum = "92d27c2c202598d05175a6dd3af46824b7f747f8d8e9b14c623f19fa5069735d" | ||
| 375 | dependencies = [ | ||
| 376 | "proc-macro2", | ||
| 377 | "quote", | ||
| 378 | "unicode-ident", | ||
| 379 | ] | ||
| 380 | |||
| 381 | [[package]] | ||
| 382 | name = "terminal_size" | ||
| 383 | version = "0.1.17" | ||
| 384 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 385 | checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df" | ||
| 386 | dependencies = [ | ||
| 387 | "libc", | ||
| 388 | "winapi", | ||
| 389 | ] | ||
| 390 | |||
| 391 | [[package]] | ||
| 392 | name = "textwrap" | ||
| 393 | version = "0.15.2" | ||
| 394 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 395 | checksum = "b7b3e525a49ec206798b40326a44121291b530c963cfb01018f63e135bac543d" | ||
| 396 | dependencies = [ | ||
| 397 | "smawk", | ||
| 398 | "unicode-linebreak", | ||
| 399 | "unicode-width", | ||
| 400 | ] | ||
| 401 | |||
| 402 | [[package]] | ||
| 403 | name = "thiserror" | ||
| 404 | version = "1.0.53" | ||
| 405 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 406 | checksum = "b2cd5904763bad08ad5513ddbb12cf2ae273ca53fa9f68e843e236ec6dfccc09" | ||
| 407 | dependencies = [ | ||
| 408 | "thiserror-impl", | ||
| 409 | ] | ||
| 410 | |||
| 411 | [[package]] | ||
| 412 | name = "thiserror-impl" | ||
| 413 | version = "1.0.53" | ||
| 414 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 415 | checksum = "3dcf4a824cce0aeacd6f38ae6f24234c8e80d68632338ebaa1443b5df9e29e19" | ||
| 416 | dependencies = [ | ||
| 417 | "proc-macro2", | ||
| 418 | "quote", | ||
| 419 | "syn", | ||
| 420 | ] | ||
| 421 | |||
| 422 | [[package]] | ||
| 423 | name = "unicode-ident" | ||
| 424 | version = "1.0.12" | ||
| 425 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 426 | checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" | ||
| 427 | |||
| 428 | [[package]] | ||
| 429 | name = "unicode-linebreak" | ||
| 430 | version = "0.1.5" | ||
| 431 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 432 | checksum = "3b09c83c3c29d37506a3e260c08c03743a6bb66a9cd432c6934ab501a190571f" | ||
| 433 | |||
| 434 | [[package]] | ||
| 435 | name = "unicode-width" | ||
| 436 | version = "0.1.11" | ||
| 437 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 438 | checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" | ||
| 439 | |||
| 440 | [[package]] | ||
| 441 | name = "utf8parse" | ||
| 442 | version = "0.2.1" | ||
| 443 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 444 | checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" | ||
| 445 | |||
| 446 | [[package]] | ||
| 447 | name = "winapi" | ||
| 448 | version = "0.3.9" | ||
| 449 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 450 | checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" | ||
| 451 | dependencies = [ | ||
| 452 | "winapi-i686-pc-windows-gnu", | ||
| 453 | "winapi-x86_64-pc-windows-gnu", | ||
| 454 | ] | ||
| 455 | |||
| 456 | [[package]] | ||
| 457 | name = "winapi-i686-pc-windows-gnu" | ||
| 458 | version = "0.4.0" | ||
| 459 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 460 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" | ||
| 461 | |||
| 462 | [[package]] | ||
| 463 | name = "winapi-x86_64-pc-windows-gnu" | ||
| 464 | version = "0.4.0" | ||
| 465 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 466 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" | ||
| 467 | |||
| 468 | [[package]] | ||
| 469 | name = "windows-sys" | ||
| 470 | version = "0.52.0" | ||
| 471 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 472 | checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" | ||
| 473 | dependencies = [ | ||
| 474 | "windows-targets", | ||
| 475 | ] | ||
| 476 | |||
| 477 | [[package]] | ||
| 478 | name = "windows-targets" | ||
| 479 | version = "0.52.0" | ||
| 480 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 481 | checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" | ||
| 482 | dependencies = [ | ||
| 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]] | ||
| 493 | name = "windows_aarch64_gnullvm" | ||
| 494 | version = "0.52.0" | ||
| 495 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 496 | checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" | ||
| 497 | |||
| 498 | [[package]] | ||
| 499 | name = "windows_aarch64_msvc" | ||
| 500 | version = "0.52.0" | ||
| 501 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 502 | checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" | ||
| 503 | |||
| 504 | [[package]] | ||
| 505 | name = "windows_i686_gnu" | ||
| 506 | version = "0.52.0" | ||
| 507 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 508 | checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" | ||
| 509 | |||
| 510 | [[package]] | ||
| 511 | name = "windows_i686_msvc" | ||
| 512 | version = "0.52.0" | ||
| 513 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 514 | checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" | ||
| 515 | |||
| 516 | [[package]] | ||
| 517 | name = "windows_x86_64_gnu" | ||
| 518 | version = "0.52.0" | ||
| 519 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 520 | checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" | ||
| 521 | |||
| 522 | [[package]] | ||
| 523 | name = "windows_x86_64_gnullvm" | ||
| 524 | version = "0.52.0" | ||
| 525 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 526 | checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" | ||
| 527 | |||
| 528 | [[package]] | ||
| 529 | name = "windows_x86_64_msvc" | ||
| 530 | version = "0.52.0" | ||
| 531 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 532 | checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" | ||
compiler/Cargo.toml created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | [package] | ||
| 2 | name = "compiler" | ||
| 3 | version = "0.1.0" | ||
| 4 | edition = "2021" | ||
| 5 | |||
| 6 | [lib] | ||
| 7 | |||
| 8 | [dependencies] | ||
| 9 | clap.workspace = true | ||
| 10 | miette.workspace = true | ||
| 11 | thiserror.workspace = true | ||
compiler/src/ast/error.rs created+17| ... | @@ -0,0 +1,17 @@ | ||
| 1 | use miette::Diagnostic; | ||
| 2 | use thiserror::Error; | ||
| 3 | |||
| 4 | #[derive(Error, Diagnostic, Debug)] | ||
| 5 | #[error("AstError")] | ||
| 6 | pub struct AstError { | ||
| 7 | #[help] | ||
| 8 | error: String, | ||
| 9 | } | ||
| 10 | |||
| 11 | impl 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 @@ | ||
| 1 | use miette::Result; | ||
| 2 | |||
| 3 | mod error; | ||
| 4 | mod types; | ||
| 5 | |||
| 6 | use super::tokenizer::Token; | ||
| 7 | |||
| 8 | use error::AstError; | ||
| 9 | use types::{ParserContext, Argument}; | ||
| 10 | |||
| 11 | pub use types::{Ast, Type}; | ||
| 12 | |||
| 13 | fn 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 | |||
| 69 | fn 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 | ||
| 82 | fn 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 | |||
| 251 | pub 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 @@ | ||
| 1 | use crate::util::Operator; | ||
| 2 | use crate::tokenizer::Token; | ||
| 3 | |||
| 4 | #[derive(Debug)] | ||
| 5 | pub struct ParserContext { | ||
| 6 | pub tokens: Vec<Token>, | ||
| 7 | pub cursor: usize | ||
| 8 | } | ||
| 9 | |||
| 10 | impl 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)] | ||
| 40 | pub enum Type { | ||
| 41 | Int, | ||
| 42 | Float, | ||
| 43 | Bigint, | ||
| 44 | } | ||
| 45 | |||
| 46 | #[derive(Debug)] | ||
| 47 | pub struct Argument { | ||
| 48 | pub name: String, | ||
| 49 | pub return_type: Type | ||
| 50 | } | ||
| 51 | |||
| 52 | #[derive(Debug)] | ||
| 53 | pub 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 @@ | ||
| 1 | use miette::Result; | ||
| 2 | |||
| 3 | pub mod ast; | ||
| 4 | pub mod tokenizer; | ||
| 5 | pub mod walker; | ||
| 6 | |||
| 7 | pub mod util; | ||
| 8 | |||
| 9 | pub 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 @@ | ||
| 1 | use miette::{Diagnostic, Result}; | ||
| 2 | use thiserror::Error; | ||
| 3 | |||
| 4 | use super::util::Operator; | ||
| 5 | |||
| 6 | #[derive(Error, Diagnostic, Debug)] | ||
| 7 | #[error("UnknownCharacter")] | ||
| 8 | struct UnknownCharacter { | ||
| 9 | #[help] | ||
| 10 | error: String, | ||
| 11 | } | ||
| 12 | |||
| 13 | #[derive(Debug, Clone)] | ||
| 14 | pub 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 | |||
| 40 | pub 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)] | ||
| 2 | pub enum Operator { | ||
| 3 | Add, | ||
| 4 | Substract, | ||
| 5 | Multiply, | ||
| 6 | Divide, | ||
| 7 | Power, | ||
| 8 | } | ||
| 9 | |||
| 10 | impl 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 @@ | ||
| 1 | use miette::Result; | ||
| 2 | |||
| 3 | use super::ast::{Ast, Type}; | ||
| 4 | |||
| 5 | fn 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 | |||
| 68 | pub 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 | ||
| 2 | let x: int = 0; | ||
| 3 | |||
| 4 | /// this is a doc comment | ||
| 5 | let 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. | ||
| 9 | let z: int = 0; | ||
examples/basics/control.blight created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | |||
examples/basics/functions.blight created+5| ... | @@ -0,0 +1,5 @@ | ||
| 1 | fn bingus(x: int, y: int) -> int { | ||
| 2 | return x * y; | ||
| 3 | } | ||
| 4 | |||
| 5 | let result: int = bingus(10, 25); | ||
examples/basics/operations.blight created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | let a: int = 10 - 2 / 4 * 15; | ||
examples/basics/variables.blight created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | var x: int = 0; | ||
| 2 | var y: float = 0; | ||
| 3 | var z: bigint = 0; | ||
| 4 | |||
| 5 | let a: int = 0; | ||
| 6 | let b: float = 0; | ||
| 7 | let c: bigint = 0; | ||
examples/interop/blight_in_js/add.blight created+5| ... | @@ -0,0 +1,5 @@ | ||
| 1 | pub fn add(x: int, y: int) -> int { | ||
| 2 | return x + y; | ||
| 3 | } | ||
| 4 | |||
| 5 | pub let TOP_LEVEL: int = 100; | ||
examples/interop/blight_in_js/main.js created+4| ... | @@ -0,0 +1,4 @@ | ||
| 1 | import { add, TOP_LEVEL } from "./add.js"; | ||
| 2 | |||
| 3 | console.log(add(1, 2)); | ||
| 4 | console.log(TOP_LEVEL) | ||
examples/operations.blight deleted-1| ... | @@ -1 +0,0 @@ | ||
| 1 | let a: int = 10 - 2 / 4 * 15; | ||
examples/variables.blight deleted-7| ... | @@ -1,7 +0,0 @@ | ||
| 1 | var x: int = 0; | ||
| 2 | var y: float = 0; | ||
| 3 | var z: bigint = 0; | ||
| 4 | |||
| 5 | let a: int = 0; | ||
| 6 | let b: float = 0; | ||
| 7 | let c: bigint = 0; | ||
src/main.rs deleted-40| ... | @@ -1,40 +0,0 @@ | ||
| 1 | use std::path::PathBuf; | ||
| 2 | |||
| 3 | use clap::{Parser, Subcommand}; | ||
| 4 | use miette::Result; | ||
| 5 | |||
| 6 | mod transpile; | ||
| 7 | |||
| 8 | #[derive(Parser)] | ||
| 9 | #[command(author, version, about, long_about = None)] | ||
| 10 | struct 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)] | ||
| 20 | enum Commands { | ||
| 21 | /// Compiles a file into javascript | ||
| 22 | Compile { | ||
| 23 | /// lists test values | ||
| 24 | file: PathBuf, | ||
| 25 | }, | ||
| 26 | } | ||
| 27 | |||
| 28 | fn 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 @@ | ||
| 1 | use miette::{Diagnostic, Result}; | ||
| 2 | use thiserror::Error; | ||
| 3 | |||
| 4 | use super::tokenizer::Token; | ||
| 5 | use super::util::{Operator, PeekableIterator}; | ||
| 6 | |||
| 7 | #[derive(Error, Diagnostic, Debug)] | ||
| 8 | #[error("AstError")] | ||
| 9 | struct AstError { | ||
| 10 | #[help] | ||
| 11 | error: String, | ||
| 12 | } | ||
| 13 | |||
| 14 | impl AstError { | ||
| 15 | fn new(error: &'static str) -> AstError { | ||
| 16 | AstError { | ||
| 17 | error: String::from(error), | ||
| 18 | } | ||
| 19 | } | ||
| 20 | } | ||
| 21 | |||
| 22 | #[derive(Debug)] | ||
| 23 | pub enum Type { | ||
| 24 | Int, | ||
| 25 | Float, | ||
| 26 | Bigint, | ||
| 27 | } | ||
| 28 | |||
| 29 | #[derive(Debug)] | ||
| 30 | pub 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 | |||
| 49 | fn 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 | ||
| 77 | fn 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 | |||
| 154 | pub 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 @@ | ||
| 1 | use miette::Result; | ||
| 2 | |||
| 3 | mod ast; | ||
| 4 | mod tokenizer; | ||
| 5 | mod walker; | ||
| 6 | |||
| 7 | mod util; | ||
| 8 | |||
| 9 | pub 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 @@ | ||
| 1 | use miette::{Diagnostic, Result}; | ||
| 2 | use thiserror::Error; | ||
| 3 | |||
| 4 | use super::util::Operator; | ||
| 5 | |||
| 6 | #[derive(Error, Diagnostic, Debug)] | ||
| 7 | #[error("UnknownCharacter")] | ||
| 8 | struct UnknownCharacter { | ||
| 9 | #[help] | ||
| 10 | error: String, | ||
| 11 | } | ||
| 12 | |||
| 13 | #[derive(Debug, Clone)] | ||
| 14 | pub 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 | |||
| 28 | pub 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 | ||
| 3 | pub trait PeekableIterator: std::iter::Iterator { | ||
| 4 | fn peek(&mut self) -> Option<&Self::Item>; | ||
| 5 | } | ||
| 6 | |||
| 7 | impl<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)] | ||
| 14 | pub enum Operator { | ||
| 15 | Add, | ||
| 16 | Substract, | ||
| 17 | Multiply, | ||
| 18 | Divide, | ||
| 19 | } | ||
| 20 | |||
| 21 | impl 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 @@ | ||
| 1 | use miette::Result; | ||
| 2 | |||
| 3 | use super::ast::{Ast, Type}; | ||
| 4 | |||
| 5 | fn 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 | |||
| 29 | pub 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 | } | ||