From 9b74023ade989b0a8f5da89de38dad4e169d6903 Mon Sep 17 00:00:00 2001 From: Jeff Date: Wed, 20 Mar 2024 04:42:13 -0400 Subject: [PATCH] Begin project restructure --- Cargo.lock | 921 +++++++++++++++++- Cargo.toml | 24 +- README.md | 0 dust-lang/Cargo.toml | 19 + .../src}/abstract_tree/assignment.rs | 0 {src => dust-lang/src}/abstract_tree/block.rs | 0 .../src}/abstract_tree/expression.rs | 0 .../src}/abstract_tree/function_call.rs | 0 .../src}/abstract_tree/identifier.rs | 0 .../src}/abstract_tree/if_else.rs | 0 .../src}/abstract_tree/list_index.rs | 0 {src => dust-lang/src}/abstract_tree/logic.rs | 0 {src => dust-lang/src}/abstract_tree/loop.rs | 0 .../src}/abstract_tree/map_index.rs | 0 {src => dust-lang/src}/abstract_tree/math.rs | 0 {src => dust-lang/src}/abstract_tree/mod.rs | 0 .../src}/abstract_tree/statement.rs | 0 .../abstract_tree/structure_definition.rs | 0 {src => dust-lang/src}/abstract_tree/type.rs | 0 .../src}/abstract_tree/value_node.rs | 2 +- {src => dust-lang/src}/abstract_tree/while.rs | 0 {src => dust-lang/src}/context.rs | 8 +- {src => dust-lang/src}/error.rs | 12 +- {src => dust-lang/src}/lexer.rs | 0 {src => dust-lang/src}/lib.rs | 2 + {src => dust-lang/src}/parser.rs | 0 {src => dust-lang/src}/value.rs | 0 dust-shell/Cargo.toml | 17 + dust-shell/src/cli.rs | 239 +++++ {src => dust-shell/src}/main.rs | 18 +- 30 files changed, 1231 insertions(+), 31 deletions(-) create mode 100644 README.md create mode 100644 dust-lang/Cargo.toml rename {src => dust-lang/src}/abstract_tree/assignment.rs (100%) rename {src => dust-lang/src}/abstract_tree/block.rs (100%) rename {src => dust-lang/src}/abstract_tree/expression.rs (100%) rename {src => dust-lang/src}/abstract_tree/function_call.rs (100%) rename {src => dust-lang/src}/abstract_tree/identifier.rs (100%) rename {src => dust-lang/src}/abstract_tree/if_else.rs (100%) rename {src => dust-lang/src}/abstract_tree/list_index.rs (100%) rename {src => dust-lang/src}/abstract_tree/logic.rs (100%) rename {src => dust-lang/src}/abstract_tree/loop.rs (100%) rename {src => dust-lang/src}/abstract_tree/map_index.rs (100%) rename {src => dust-lang/src}/abstract_tree/math.rs (100%) rename {src => dust-lang/src}/abstract_tree/mod.rs (100%) rename {src => dust-lang/src}/abstract_tree/statement.rs (100%) rename {src => dust-lang/src}/abstract_tree/structure_definition.rs (100%) rename {src => dust-lang/src}/abstract_tree/type.rs (100%) rename {src => dust-lang/src}/abstract_tree/value_node.rs (99%) rename {src => dust-lang/src}/abstract_tree/while.rs (100%) rename {src => dust-lang/src}/context.rs (95%) rename {src => dust-lang/src}/error.rs (97%) rename {src => dust-lang/src}/lexer.rs (100%) rename {src => dust-lang/src}/lib.rs (97%) rename {src => dust-lang/src}/parser.rs (100%) rename {src => dust-lang/src}/value.rs (100%) create mode 100644 dust-shell/Cargo.toml create mode 100644 dust-shell/src/cli.rs rename {src => dust-shell/src}/main.rs (83%) diff --git a/Cargo.lock b/Cargo.lock index 204c227..49038dc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -29,6 +29,21 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "anstream" version = "0.6.13" @@ -77,6 +92,23 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "arboard" +version = "3.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2041f1943049c7978768d84e6d0fd95de98b76d6c4727b09e78ec253d29fa58" +dependencies = [ + "clipboard-win", + "log", + "objc", + "objc-foundation", + "objc_id", + "parking_lot", + "thiserror", + "wl-clipboard-rs", + "x11rb", +] + [[package]] name = "ariadne" version = "0.4.0" @@ -88,12 +120,39 @@ dependencies = [ "yansi", ] +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + [[package]] name = "bitflags" version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" +dependencies = [ + "serde", +] + +[[package]] +name = "block" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" + +[[package]] +name = "bumpalo" +version = "3.15.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ff69b9dd49fd426c69a0db9fc04dd934cdb6645ff000864d98f7e2af8830eaa" + [[package]] name = "cc" version = "1.0.90" @@ -106,6 +165,25 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cfg_aliases" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" + +[[package]] +name = "chrono" +version = "0.4.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8eaf5903dcbc0a39312feb77df2ff4c76387d591b9fc7b04a238dcf8bb62639a" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "num-traits", + "serde", + "windows-targets 0.52.4", +] + [[package]] name = "chumsky" version = "1.0.0-alpha.6" @@ -147,7 +225,7 @@ version = "4.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90239a040c80f5e14809ca132ddc4176ab33d5e17e49691793296e3fcb34d72f" dependencies = [ - "heck", + "heck 0.5.0", "proc-macro2", "quote", "syn", @@ -159,6 +237,15 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" +[[package]] +name = "clipboard-win" +version = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d517d4b86184dbb111d3556a10f1c8a04da7428d2987bf1081602bf11c3aa9ee" +dependencies = [ + "error-code", +] + [[package]] name = "colorchoice" version = "1.0.0" @@ -181,7 +268,7 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b946244a988c390a94667ae0e3958411fa40cc46ea496a929b263d883f5f9c3" dependencies = [ - "bitflags", + "bitflags 1.3.2", "concolor-query", "is-terminal", ] @@ -195,6 +282,64 @@ dependencies = [ "windows-sys 0.45.0", ] +[[package]] +name = "core-foundation-sys" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" + +[[package]] +name = "crossterm" +version = "0.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f476fe445d41c9e991fd07515a6f463074b782242ccf4a5b7b1d1012e70824df" +dependencies = [ + "bitflags 2.5.0", + "crossterm_winapi", + "libc", + "mio", + "parking_lot", + "serde", + "signal-hook", + "signal-hook-mio", + "winapi", +] + +[[package]] +name = "crossterm_winapi" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acdd7c62a3665c7f6830a51635d9ac9b23ed385797f70a83bb8bafe9c572ab2b" +dependencies = [ + "winapi", +] + +[[package]] +name = "derive-new" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d150dea618e920167e5973d70ae6ece4385b7164e0d799fe7c122dd0a5d912ad" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dlib" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "330c60081dcc4c72131f8eb70510f1ac07223e5d4163db481a04a0befcffa412" +dependencies = [ + "libloading", +] + +[[package]] +name = "downcast-rs" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" + [[package]] name = "dust-lang" version = "0.5.0" @@ -209,6 +354,24 @@ dependencies = [ "stanza", ] +[[package]] +name = "dust-shell" +version = "0.1.0" +dependencies = [ + "clap", + "colored", + "dust-lang", + "env_logger", + "nu-ansi-term", + "reedline", +] + +[[package]] +name = "either" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" + [[package]] name = "env_filter" version = "0.1.0" @@ -232,6 +395,79 @@ dependencies = [ "log", ] +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "error-code" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0474425d51df81997e2f90a21591180b38eccf27292d755f3e30750225c175b" + +[[package]] +name = "fallible-iterator" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649" + +[[package]] +name = "fallible-streaming-iterator" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a" + +[[package]] +name = "fastrand" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" + +[[package]] +name = "fd-lock" +version = "3.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef033ed5e9bad94e55838ca0ca906db0e043f517adda0c8b79c7a8c66c93c1b5" +dependencies = [ + "cfg-if", + "rustix", + "windows-sys 0.48.0", +] + +[[package]] +name = "fixedbitset" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "gethostname" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0176e0459c2e4a1fe232f984bca6890e681076abb9934f6cea7c326f3fc47818" +dependencies = [ + "libc", + "windows-targets 0.48.5", +] + [[package]] name = "getrandom" version = "0.2.12" @@ -253,6 +489,21 @@ dependencies = [ "allocator-api2", ] +[[package]] +name = "hashlink" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "692eaaf7f7607518dd3cef090f1474b61edc5301d8012f09579920df68b725ee" +dependencies = [ + "hashbrown", +] + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + [[package]] name = "heck" version = "0.5.0" @@ -265,12 +516,54 @@ version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +[[package]] +name = "home" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +dependencies = [ + "windows-sys 0.52.0", +] + [[package]] name = "humantime" version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" +[[package]] +name = "iana-time-zone" +version = "0.1.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "indexmap" +version = "2.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b0b929d511467233429c45a44ac1dcaa21ba0f5ba11e4879e6ed28ddb4f9df4" +dependencies = [ + "equivalent", + "hashbrown", +] + [[package]] name = "is-terminal" version = "0.4.12" @@ -282,6 +575,30 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" + +[[package]] +name = "js-sys" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" +dependencies = [ + "wasm-bindgen", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -294,24 +611,206 @@ version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +[[package]] +name = "libloading" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19" +dependencies = [ + "cfg-if", + "windows-targets 0.52.4", +] + +[[package]] +name = "libsqlite3-sys" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c10584274047cb335c23d3e61bcef8e323adae7c5c8c760540f73610177fc3f" +dependencies = [ + "cc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "linux-raw-sys" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" + +[[package]] +name = "lock_api" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +dependencies = [ + "autocfg", + "scopeguard", +] + [[package]] name = "log" version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" +[[package]] +name = "malloc_buf" +version = "0.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb" +dependencies = [ + "libc", +] + [[package]] name = "memchr" version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "log", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "nix" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab2156c4fce2f8df6c499cc1c763e4394b7482525bf2a9701c9d79d215f519e4" +dependencies = [ + "bitflags 2.5.0", + "cfg-if", + "cfg_aliases", + "libc", +] + +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "nu-ansi-term" +version = "0.50.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd2800e1520bdc966782168a627aa5d1ad92e33b984bf7c7615d31280c83ff14" +dependencies = [ + "windows-sys 0.48.0", +] + +[[package]] +name = "num-traits" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" +dependencies = [ + "autocfg", +] + +[[package]] +name = "objc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1" +dependencies = [ + "malloc_buf", +] + +[[package]] +name = "objc-foundation" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9" +dependencies = [ + "block", + "objc", + "objc_id", +] + +[[package]] +name = "objc_id" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c92d4ddb4bd7b50d730c215ff871754d0da6b2178849f8a2a2ab69712d0c073b" +dependencies = [ + "objc", +] + [[package]] name = "once_cell" version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +[[package]] +name = "os_pipe" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57119c3b893986491ec9aa85056780d3a0f3cf4da7cc09dd3650dbd6c6738fb9" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "parking_lot" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.48.5", +] + +[[package]] +name = "petgraph" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1d3afd2628e69da2be385eb6f2fd57c8ac7977ceeff6dc166ff1657b0e386a9" +dependencies = [ + "fixedbitset", + "indexmap", +] + +[[package]] +name = "pkg-config" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" + [[package]] name = "ppv-lite86" version = "0.2.17" @@ -336,6 +835,15 @@ dependencies = [ "cc", ] +[[package]] +name = "quick-xml" +version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1004a344b30a54e2ee58d66a71b32d2db2feb0a31f9a2d302bf0536f15de2a33" +dependencies = [ + "memchr", +] + [[package]] name = "quote" version = "1.0.35" @@ -375,6 +883,38 @@ dependencies = [ "getrandom", ] +[[package]] +name = "redox_syscall" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +dependencies = [ + "bitflags 1.3.2", +] + +[[package]] +name = "reedline" +version = "0.30.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413a9fa6a5d8c937d3ae1e975bfb6a918bb0b6cdfae6a10416218c837a31b8fc" +dependencies = [ + "arboard", + "chrono", + "crossterm", + "fd-lock", + "itertools", + "nu-ansi-term", + "rusqlite", + "serde", + "serde_json", + "strip-ansi-escapes", + "strum", + "strum_macros", + "thiserror", + "unicode-segmentation", + "unicode-width", +] + [[package]] name = "regex" version = "1.10.3" @@ -421,6 +961,57 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" +[[package]] +name = "rusqlite" +version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b838eba278d213a8beaf485bd313fd580ca4505a00d5871caeb1457c55322cae" +dependencies = [ + "bitflags 2.5.0", + "fallible-iterator", + "fallible-streaming-iterator", + "hashlink", + "libsqlite3-sys", + "smallvec", +] + +[[package]] +name = "rustix" +version = "0.38.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65e04861e65f21776e67888bfbea442b3642beaa0138fdb1dd7a84a52dffdb89" +dependencies = [ + "bitflags 2.5.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustversion" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" + +[[package]] +name = "ryu" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" + +[[package]] +name = "scoped-tls" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + [[package]] name = "serde" version = "1.0.197" @@ -441,6 +1032,53 @@ dependencies = [ "syn", ] +[[package]] +name = "serde_json" +version = "1.0.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5f09b1bd632ef549eaa9f60a1f8de742bdbc698e6cee2095fc84dde5f549ae0" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "signal-hook" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8621587d4798caf8eb44879d42e56b9a93ea5dcd315a6487c357130095b62801" +dependencies = [ + "libc", + "signal-hook-registry", +] + +[[package]] +name = "signal-hook-mio" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29ad2e15f37ec9a6cc544097b78a1ec90001e9f71b81338ca39f430adaca99af" +dependencies = [ + "libc", + "mio", + "signal-hook", +] + +[[package]] +name = "signal-hook-registry" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" +dependencies = [ + "libc", +] + +[[package]] +name = "smallvec" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" + [[package]] name = "stacker" version = "0.1.15" @@ -460,12 +1098,40 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5d230b987a5b524a015ded47fed54c5177598a71c90508acee1c5d0b4c955f74" +[[package]] +name = "strip-ansi-escapes" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55ff8ef943b384c414f54aefa961dd2bd853add74ec75e7ac74cf91dba62bcfa" +dependencies = [ + "vte", +] + [[package]] name = "strsim" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5ee073c9e4cd00e28217186dbe12796d692868f432bf2e97ee73bed0c56dfa01" +[[package]] +name = "strum" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290d54ea6f91c969195bdbcd7442c8c2a2ba87da8bf60a7ee86a235d4bc1e125" + +[[package]] +name = "strum_macros" +version = "0.25.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23dc1fa9ac9c169a78ba62f0b841814b7abae11bdd047b9c58f893439e309ea0" +dependencies = [ + "heck 0.4.1", + "proc-macro2", + "quote", + "rustversion", + "syn", +] + [[package]] name = "syn" version = "2.0.53" @@ -477,12 +1143,64 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "tempfile" +version = "3.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" +dependencies = [ + "cfg-if", + "fastrand", + "rustix", + "windows-sys 0.52.0", +] + +[[package]] +name = "thiserror" +version = "1.0.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tree_magic_mini" +version = "3.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77ee137597cdb361b55a4746983e4ac1b35ab6024396a419944ad473bb915265" +dependencies = [ + "fnv", + "home", + "memchr", + "nom", + "once_cell", + "petgraph", +] + [[package]] name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unicode-segmentation" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" + [[package]] name = "unicode-width" version = "0.1.11" @@ -495,18 +1213,171 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + [[package]] name = "version_check" version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "vte" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5022b5fbf9407086c180e9557be968742d839e68346af7792b8592489732197" +dependencies = [ + "utf8parse", + "vte_generate_state_changes", +] + +[[package]] +name = "vte_generate_state_changes" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d257817081c7dffcdbab24b9e62d2def62e2ff7d00b1c20062551e6cccc145ff" +dependencies = [ + "proc-macro2", + "quote", +] + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasm-bindgen" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" + +[[package]] +name = "wayland-backend" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d50fa61ce90d76474c87f5fc002828d81b32677340112b4ef08079a9d459a40" +dependencies = [ + "cc", + "downcast-rs", + "rustix", + "scoped-tls", + "smallvec", + "wayland-sys", +] + +[[package]] +name = "wayland-client" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82fb96ee935c2cea6668ccb470fb7771f6215d1691746c2d896b447a00ad3f1f" +dependencies = [ + "bitflags 2.5.0", + "rustix", + "wayland-backend", + "wayland-scanner", +] + +[[package]] +name = "wayland-protocols" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f81f365b8b4a97f422ac0e8737c438024b5951734506b0e1d775c73030561f4" +dependencies = [ + "bitflags 2.5.0", + "wayland-backend", + "wayland-client", + "wayland-scanner", +] + +[[package]] +name = "wayland-protocols-wlr" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad1f61b76b6c2d8742e10f9ba5c3737f6530b4c243132c2a2ccc8aa96fe25cd6" +dependencies = [ + "bitflags 2.5.0", + "wayland-backend", + "wayland-client", + "wayland-protocols", + "wayland-scanner", +] + +[[package]] +name = "wayland-scanner" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63b3a62929287001986fb58c789dce9b67604a397c15c611ad9f747300b6c283" +dependencies = [ + "proc-macro2", + "quick-xml", + "quote", +] + +[[package]] +name = "wayland-sys" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15a0c8eaff5216d07f226cb7a549159267f3467b289d9a2e52fd3ef5aae2b7af" +dependencies = [ + "dlib", + "log", + "pkg-config", +] + [[package]] name = "winapi" version = "0.3.9" @@ -529,6 +1400,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets 0.52.4", +] + [[package]] name = "windows-sys" version = "0.45.0" @@ -727,6 +1607,43 @@ version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" +[[package]] +name = "wl-clipboard-rs" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12b41773911497b18ca8553c3daaf8ec9fe9819caf93d451d3055f69de028adb" +dependencies = [ + "derive-new", + "libc", + "log", + "nix", + "os_pipe", + "tempfile", + "thiserror", + "tree_magic_mini", + "wayland-backend", + "wayland-client", + "wayland-protocols", + "wayland-protocols-wlr", +] + +[[package]] +name = "x11rb" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8f25ead8c7e4cba123243a6367da5d3990e0d3affa708ea19dce96356bd9f1a" +dependencies = [ + "gethostname", + "rustix", + "x11rb-protocol", +] + +[[package]] +name = "x11rb-protocol" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e63e71c4b8bd9ffec2c963173a4dc4cbde9ee96961d4fcb4429db9929b606c34" + [[package]] name = "yansi" version = "0.5.1" diff --git a/Cargo.toml b/Cargo.toml index 99f2393..d7a0f95 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,23 +1,15 @@ -[package] -name = "dust-lang" -description = "General purpose programming language" -version = "0.5.0" -repository = "https://git.jeffa.io/jeff/dust.git" +[workspace] +members = ["dust-lang", "dust-shell"] +resolver = "2" + +[workspace.package] +authors = ["Jeff Anderson"] edition = "2021" license = "MIT" -authors = ["Jeff Anderson"] +readme = "README.md" +repository = "https://git.jeffa.io/jeff/dust.git" [profile.dev] opt-level = 1 [profile.dev.package."*"] opt-level = 3 - -[dependencies] -ariadne = { version = "0.4.0", features = ["auto-color"] } -chumsky = { version = "1.0.0-alpha.6", features = ["pratt", "label"] } -clap = { version = "4.5.2", features = ["derive"] } -colored = "2.1.0" -env_logger = "0.11.3" -log = "0.4.21" -rand = "0.8.5" -stanza = "0.5.1" diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/dust-lang/Cargo.toml b/dust-lang/Cargo.toml new file mode 100644 index 0000000..d58e075 --- /dev/null +++ b/dust-lang/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "dust-lang" +description = "Interpreter library for the Dust programming language" +version = "0.5.0" +authors.workspace = true +edition.workspace = true +license.workspace = true +readme.workspace = true +repository.workspace = true + +[dependencies] +ariadne = { version = "0.4.0", features = ["auto-color"] } +chumsky = { version = "1.0.0-alpha.6", features = ["pratt", "label"] } +clap = { version = "4.5.2", features = ["derive"] } +colored = "2.1.0" +env_logger = "0.11.3" +log = "0.4.21" +rand = "0.8.5" +stanza = "0.5.1" diff --git a/src/abstract_tree/assignment.rs b/dust-lang/src/abstract_tree/assignment.rs similarity index 100% rename from src/abstract_tree/assignment.rs rename to dust-lang/src/abstract_tree/assignment.rs diff --git a/src/abstract_tree/block.rs b/dust-lang/src/abstract_tree/block.rs similarity index 100% rename from src/abstract_tree/block.rs rename to dust-lang/src/abstract_tree/block.rs diff --git a/src/abstract_tree/expression.rs b/dust-lang/src/abstract_tree/expression.rs similarity index 100% rename from src/abstract_tree/expression.rs rename to dust-lang/src/abstract_tree/expression.rs diff --git a/src/abstract_tree/function_call.rs b/dust-lang/src/abstract_tree/function_call.rs similarity index 100% rename from src/abstract_tree/function_call.rs rename to dust-lang/src/abstract_tree/function_call.rs diff --git a/src/abstract_tree/identifier.rs b/dust-lang/src/abstract_tree/identifier.rs similarity index 100% rename from src/abstract_tree/identifier.rs rename to dust-lang/src/abstract_tree/identifier.rs diff --git a/src/abstract_tree/if_else.rs b/dust-lang/src/abstract_tree/if_else.rs similarity index 100% rename from src/abstract_tree/if_else.rs rename to dust-lang/src/abstract_tree/if_else.rs diff --git a/src/abstract_tree/list_index.rs b/dust-lang/src/abstract_tree/list_index.rs similarity index 100% rename from src/abstract_tree/list_index.rs rename to dust-lang/src/abstract_tree/list_index.rs diff --git a/src/abstract_tree/logic.rs b/dust-lang/src/abstract_tree/logic.rs similarity index 100% rename from src/abstract_tree/logic.rs rename to dust-lang/src/abstract_tree/logic.rs diff --git a/src/abstract_tree/loop.rs b/dust-lang/src/abstract_tree/loop.rs similarity index 100% rename from src/abstract_tree/loop.rs rename to dust-lang/src/abstract_tree/loop.rs diff --git a/src/abstract_tree/map_index.rs b/dust-lang/src/abstract_tree/map_index.rs similarity index 100% rename from src/abstract_tree/map_index.rs rename to dust-lang/src/abstract_tree/map_index.rs diff --git a/src/abstract_tree/math.rs b/dust-lang/src/abstract_tree/math.rs similarity index 100% rename from src/abstract_tree/math.rs rename to dust-lang/src/abstract_tree/math.rs diff --git a/src/abstract_tree/mod.rs b/dust-lang/src/abstract_tree/mod.rs similarity index 100% rename from src/abstract_tree/mod.rs rename to dust-lang/src/abstract_tree/mod.rs diff --git a/src/abstract_tree/statement.rs b/dust-lang/src/abstract_tree/statement.rs similarity index 100% rename from src/abstract_tree/statement.rs rename to dust-lang/src/abstract_tree/statement.rs diff --git a/src/abstract_tree/structure_definition.rs b/dust-lang/src/abstract_tree/structure_definition.rs similarity index 100% rename from src/abstract_tree/structure_definition.rs rename to dust-lang/src/abstract_tree/structure_definition.rs diff --git a/src/abstract_tree/type.rs b/dust-lang/src/abstract_tree/type.rs similarity index 100% rename from src/abstract_tree/type.rs rename to dust-lang/src/abstract_tree/type.rs diff --git a/src/abstract_tree/value_node.rs b/dust-lang/src/abstract_tree/value_node.rs similarity index 99% rename from src/abstract_tree/value_node.rs rename to dust-lang/src/abstract_tree/value_node.rs index fc93f3f..e7810a4 100644 --- a/src/abstract_tree/value_node.rs +++ b/dust-lang/src/abstract_tree/value_node.rs @@ -258,7 +258,7 @@ impl PartialOrd for ValueNode { impl Ord for ValueNode { fn cmp(&self, other: &Self) -> Ordering { - use ValueNode::*; + use self::ValueNode::*; match (self, other) { (Boolean(left), Boolean(right)) => left.cmp(right), diff --git a/src/abstract_tree/while.rs b/dust-lang/src/abstract_tree/while.rs similarity index 100% rename from src/abstract_tree/while.rs rename to dust-lang/src/abstract_tree/while.rs diff --git a/src/context.rs b/dust-lang/src/context.rs similarity index 95% rename from src/context.rs rename to dust-lang/src/context.rs index df9ccb3..06df97b 100644 --- a/src/context.rs +++ b/dust-lang/src/context.rs @@ -1,6 +1,6 @@ use std::{ collections::BTreeMap, - sync::{Arc, RwLock}, + sync::{Arc, RwLock, RwLockReadGuard}, }; use crate::{ @@ -28,6 +28,12 @@ impl Context { } } + pub fn inner( + &self, + ) -> Result>, RwLockPoisonError> { + Ok(self.inner.read()?) + } + pub fn inherit_types_from(&self, other: &Context) -> Result<(), RwLockPoisonError> { let mut self_data = self.inner.write()?; diff --git a/src/error.rs b/dust-lang/src/error.rs similarity index 97% rename from src/error.rs rename to dust-lang/src/error.rs index 1dcabe1..4517cb9 100644 --- a/src/error.rs +++ b/dust-lang/src/error.rs @@ -1,6 +1,6 @@ -use std::{io, ops::Range, sync::PoisonError}; +use std::{io, sync::PoisonError}; -use ariadne::{Color, Fmt, Label, Report, ReportBuilder, ReportKind}; +use ariadne::{sources, Color, Fmt, Label, Report, ReportKind}; use chumsky::{prelude::Rich, span::Span}; use crate::{ @@ -29,7 +29,7 @@ pub enum Error { } impl Error { - pub fn build_report<'a>(self) -> ReportBuilder<'a, (&'a str, Range)> { + pub fn build_report(self, source: &str) -> Vec { let (mut builder, validation_error, error_position) = match self { Error::Parse { expected, span } => { let message = if expected.is_empty() { @@ -184,7 +184,13 @@ impl Error { } } + let mut output = Vec::new(); + builder + .finish() + .write_for_stdout(sources([("input", source)]), &mut output); + + output } } diff --git a/src/lexer.rs b/dust-lang/src/lexer.rs similarity index 100% rename from src/lexer.rs rename to dust-lang/src/lexer.rs diff --git a/src/lib.rs b/dust-lang/src/lib.rs similarity index 97% rename from src/lib.rs rename to dust-lang/src/lib.rs index 01b346a..8349dd3 100644 --- a/src/lib.rs +++ b/dust-lang/src/lib.rs @@ -1,3 +1,5 @@ +extern crate chumsky; + pub mod abstract_tree; pub mod context; pub mod error; diff --git a/src/parser.rs b/dust-lang/src/parser.rs similarity index 100% rename from src/parser.rs rename to dust-lang/src/parser.rs diff --git a/src/value.rs b/dust-lang/src/value.rs similarity index 100% rename from src/value.rs rename to dust-lang/src/value.rs diff --git a/dust-shell/Cargo.toml b/dust-shell/Cargo.toml new file mode 100644 index 0000000..abd0fb5 --- /dev/null +++ b/dust-shell/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "dust-shell" +description = "Command line shell for the Dust programming language" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true +readme.workspace = true +repository.workspace = true + +[dependencies] +clap = { version = "4.5.3", features = ["derive"] } +colored = "2.1.0" +dust-lang = { path = "../dust-lang" } +env_logger = "0.11.3" +nu-ansi-term = "0.50.0" +reedline = { version = "0.30.0", features = ["sqlite", "system_clipboard"] } diff --git a/dust-shell/src/cli.rs b/dust-shell/src/cli.rs new file mode 100644 index 0000000..b9ac142 --- /dev/null +++ b/dust-shell/src/cli.rs @@ -0,0 +1,239 @@ +use std::{ + borrow::Cow, + io::{stderr, Write}, + path::PathBuf, + process::Command, +}; + +use dust_lang::{ + context::{Context, ValueData}, + *, +}; +use nu_ansi_term::{Color, Style}; +use reedline::{ + default_emacs_keybindings, ColumnarMenu, Completer, DefaultHinter, EditCommand, Emacs, KeyCode, + KeyModifiers, MenuBuilder, Prompt, Reedline, ReedlineEvent, ReedlineMenu, Signal, Span, + SqliteBackedHistory, Suggestion, +}; + +pub fn run_shell(context: Context) { + let mut interpreter = Interpreter::new(context.clone()); + let mut keybindings = default_emacs_keybindings(); + + keybindings.add_binding( + KeyModifiers::CONTROL, + KeyCode::Char(' '), + ReedlineEvent::Edit(vec![EditCommand::InsertNewline]), + ); + keybindings.add_binding( + KeyModifiers::NONE, + KeyCode::Enter, + ReedlineEvent::SubmitOrNewline, + ); + keybindings.add_binding( + KeyModifiers::NONE, + KeyCode::Tab, + ReedlineEvent::Edit(vec![EditCommand::InsertString(" ".to_string())]), + ); + keybindings.add_binding( + KeyModifiers::NONE, + KeyCode::Tab, + ReedlineEvent::Multiple(vec![ + ReedlineEvent::Menu("context menu".to_string()), + ReedlineEvent::MenuNext, + ]), + ); + + let edit_mode = Box::new(Emacs::new(keybindings)); + let history = Box::new( + SqliteBackedHistory::with_file(PathBuf::from("target/history"), None, None) + .expect("Error loading history."), + ); + let hinter = Box::new(DefaultHinter::default().with_style(Style::new().dimmed())); + let completer = DustCompleter::new(context.clone()); + + let mut line_editor = Reedline::create() + .with_edit_mode(edit_mode) + .with_history(history) + .with_hinter(hinter) + .use_kitty_keyboard_enhancement(true) + .with_completer(Box::new(completer)) + .with_menu(ReedlineMenu::EngineCompleter(Box::new( + ColumnarMenu::default() + .with_name("context menu") + .with_text_style(Style::default().fg(Color::White)) + .with_columns(1) + .with_column_padding(10), + ))); + let mut prompt = StarshipPrompt::new(); + + prompt.reload(); + + loop { + let sig = line_editor.read_line(&prompt); + + match sig { + Ok(Signal::Success(buffer)) => { + if buffer.trim().is_empty() { + continue; + } + + let run_result = interpreter.run(&buffer); + + match run_result { + Ok(Some(value)) => { + println!("{value}") + } + Ok(None) => {} + Err(errors) => { + for error in errors { + let report = error.build_report(&buffer); + + stderr().write_all(&report).unwrap(); + } + } + } + + prompt.reload(); + } + Ok(Signal::CtrlD) | Ok(Signal::CtrlC) => { + println!("\nLeaving the Dust shell."); + break; + } + x => { + println!("Unknown event: {:?}", x); + } + } + } +} + +struct StarshipPrompt { + left: String, + right: String, +} + +impl StarshipPrompt { + fn new() -> Self { + Self { + left: String::new(), + right: String::new(), + } + } + + fn reload(&mut self) { + let run_starship_left = Command::new("starship").arg("prompt").output(); + let run_starship_right = Command::new("starship") + .args(["prompt", "--right"]) + .output(); + let left_prompt = if let Ok(output) = &run_starship_left { + String::from_utf8_lossy(&output.stdout).trim().to_string() + } else { + ">".to_string() + }; + let right_prompt = if let Ok(output) = &run_starship_right { + String::from_utf8_lossy(&output.stdout).trim().to_string() + } else { + "".to_string() + }; + + self.left = left_prompt; + self.right = right_prompt; + } +} + +impl Prompt for StarshipPrompt { + fn render_prompt_left(&self) -> Cow { + Cow::Borrowed(&self.left) + } + + fn render_prompt_right(&self) -> Cow { + Cow::Borrowed(&self.right) + } + + fn render_prompt_indicator(&self, _prompt_mode: reedline::PromptEditMode) -> Cow { + Cow::Borrowed(" ") + } + + fn render_prompt_multiline_indicator(&self) -> Cow { + Cow::Borrowed("") + } + + fn render_prompt_history_search_indicator( + &self, + _history_search: reedline::PromptHistorySearch, + ) -> Cow { + Cow::Borrowed("") + } +} + +pub struct DustCompleter { + context: Context, +} + +impl DustCompleter { + fn new(context: Context) -> Self { + DustCompleter { context } + } +} + +impl Completer for DustCompleter { + fn complete(&mut self, line: &str, pos: usize) -> Vec { + let mut suggestions = Vec::new(); + let last_word = if let Some(word) = line.rsplit([' ', ':']).next() { + word + } else { + line + }; + + if let Ok(path) = PathBuf::try_from(last_word) { + if let Ok(read_dir) = path.read_dir() { + for entry in read_dir { + if let Ok(entry) = entry { + let description = if let Ok(file_type) = entry.file_type() { + if file_type.is_dir() { + "directory" + } else if file_type.is_file() { + "file" + } else if file_type.is_symlink() { + "symlink" + } else { + "unknown" + } + } else { + "unknown" + }; + + suggestions.push(Suggestion { + value: entry.path().to_string_lossy().to_string(), + description: Some(description.to_string()), + extra: None, + span: Span::new(pos - last_word.len(), pos), + append_whitespace: false, + style: None, + }); + } + } + } + } + + for (key, value_data) in self.context.inner().unwrap().iter() { + let description = match value_data { + ValueData::Value(value) => value.to_string(), + ValueData::Type(r#type) => r#type.to_string(), + }; + + if key.as_str().contains(last_word) { + suggestions.push(Suggestion { + value: key.to_string(), + description: Some(description), + extra: None, + span: Span::new(pos - last_word.len(), pos), + append_whitespace: false, + style: None, + }); + } + } + + suggestions + } +} diff --git a/src/main.rs b/dust-shell/src/main.rs similarity index 83% rename from src/main.rs rename to dust-shell/src/main.rs index 968413f..1a07c86 100644 --- a/src/main.rs +++ b/dust-shell/src/main.rs @@ -1,10 +1,14 @@ //! Command line interface for the dust programming language. +mod cli; -use ariadne::sources; use clap::Parser; +use cli::run_shell; use colored::Colorize; -use std::{fs::read_to_string, io::Write}; +use std::{ + fs::read_to_string, + io::{stderr, Write}, +}; use dust_lang::{context::Context, Interpreter}; @@ -39,7 +43,7 @@ fn main() { } else if let Some(command) = args.command { command } else { - String::with_capacity(0) + return run_shell(context); }; let mut interpreter = Interpreter::new(context); @@ -54,11 +58,9 @@ fn main() { } Err(errors) => { for error in errors { - error - .build_report() - .finish() - .eprint(sources([("input", &source)])) - .unwrap() + let report = error.build_report(&source); + + stderr().write_all(&report).unwrap(); } } }