diff --git a/Cargo.lock b/Cargo.lock index 0803178..25fb60d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,14 +2,6 @@ # It is not intended for manual editing. version = 4 -[[package]] -name = "Ast" -version = "0.1.0" -dependencies = [ - "eframe", - "lazy_static", -] - [[package]] name = "ab_glyph" version = "0.2.32" @@ -171,6 +163,56 @@ dependencies = [ "libc", ] +[[package]] +name = "anstream" +version = "0.6.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43d5b281e737544384e969a5ccad3f1cdd24b48086a0fc1b2a5262a26b8f4f4a" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78" + +[[package]] +name = "anstyle-parse" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" +dependencies = [ + "anstyle", + "once_cell_polyfill", + "windows-sys 0.61.2", +] + [[package]] name = "anyhow" version = "1.0.101" @@ -600,6 +642,46 @@ dependencies = [ "libc", ] +[[package]] +name = "clap" +version = "4.5.59" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5caf74d17c3aec5495110c34cc3f78644bfa89af6c8993ed4de2790e49b6499" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.59" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "370daa45065b80218950227371916a1633217ae42b2715b2287b606dcd618e24" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.5.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a92793da1a46a5f2a02a6f4c46c6496b28c43638adea8306fcb0caa1634f24e5" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a822ea5bc7590f9d40f1ba12c0dc3c2760f3482c6984db1573ad11031420831" + [[package]] name = "clipboard-win" version = "5.4.1" @@ -620,6 +702,12 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "colorchoice" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" + [[package]] name = "combine" version = "4.6.7" @@ -1526,6 +1614,12 @@ dependencies = [ "serde_core", ] +[[package]] +name = "is_terminal_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" + [[package]] name = "itoa" version = "1.0.17" @@ -1743,6 +1837,15 @@ dependencies = [ "pxfm", ] +[[package]] +name = "myc" +version = "0.1.0" +dependencies = [ + "clap", + "eframe", + "lazy_static", +] + [[package]] name = "naga" version = "27.0.3" @@ -2123,6 +2226,12 @@ version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" +[[package]] +name = "once_cell_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" + [[package]] name = "orbclient" version = "0.3.50" @@ -2701,6 +2810,12 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6637bab7722d379c8b41ba849228d680cc12d0a45ba1fa2b48f2a30577a06731" +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + [[package]] name = "syn" version = "2.0.116" @@ -2964,6 +3079,12 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + [[package]] name = "uuid" version = "1.21.0" diff --git a/Cargo.toml b/Cargo.toml index e4a964c..85a9a4e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,9 @@ [package] -name = "Ast" +name = "myc" version = "0.1.0" edition = "2024" [dependencies] eframe = "0.33.3" lazy_static = "1.4.0" +clap = { version = "4.5", features = ["derive"] } diff --git a/src/bin/ast.rs b/src/bin/ast.rs new file mode 100644 index 0000000..f6d9c2e --- /dev/null +++ b/src/bin/ast.rs @@ -0,0 +1,45 @@ +use myc::ast::environment::Environment; +use clap::Parser; +use std::fs; +use std::path::PathBuf; + +#[derive(Parser)] +#[command(author, version, about = "MYC AST Compiler CLI", long_about = None)] +struct Cli { + /// The script file to run + #[arg(value_name = "FILE")] + file: Option, + + /// Run a script string directly + #[arg(short, long)] + eval: Option, +} + +fn main() { + let cli = Cli::parse(); + let env = Environment::new(); + + if let Some(script_str) = cli.eval { + execute(&env, &script_str); + } else if let Some(file_path) = cli.file { + match fs::read_to_string(&file_path) { + Ok(content) => execute(&env, &content), + Err(e) => { + eprintln!("Error reading file {:?}: {}", file_path, e); + std::process::exit(1); + } + } + } else { + println!("MYC AST Compiler CLI. Use --help for usage."); + } +} + +fn execute(env: &Environment, source: &str) { + match env.run_script(source) { + Ok(result) => println!("{}", result), + Err(e) => { + eprintln!("Error: {}", e); + std::process::exit(1); + } + } +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..a885174 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,4 @@ +pub mod ast; + +#[cfg(test)] +mod integration_test; diff --git a/src/main.rs b/src/main.rs index 96d9316..99e512f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,5 @@ use eframe::egui; -use crate::ast::environment::Environment; - -pub mod ast; -#[cfg(test)] -mod integration_test; +use myc::ast::environment::Environment; fn main() -> eframe::Result { let options = eframe::NativeOptions {