From b84811539c50d19b6bdce3386270d2918c361750 Mon Sep 17 00:00:00 2001 From: Klesti Selimaj Date: Mon, 13 Apr 2026 16:39:06 +0200 Subject: [PATCH] .json instead of toml --- Cargo.lock | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 2 ++ src/compiler.rs | 33 +++++++++++----------------- test/mist.json | 4 ++++ test/mist.toml | 7 ------ 5 files changed, 75 insertions(+), 28 deletions(-) create mode 100644 test/mist.json delete mode 100644 test/mist.toml diff --git a/Cargo.lock b/Cargo.lock index f0dd88e..d08efc2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -56,6 +56,12 @@ dependencies = [ "version_check", ] +[[package]] +name = "itoa" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" + [[package]] name = "libc" version = "0.2.185" @@ -74,6 +80,8 @@ version = "0.1.0" dependencies = [ "pest", "pest_derive", + "serde", + "serde_json", ] [[package]] @@ -137,6 +145,49 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "serde" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.149" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + [[package]] name = "sha2" version = "0.10.9" @@ -182,3 +233,9 @@ name = "version_check" version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "zmij" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" diff --git a/Cargo.toml b/Cargo.toml index 6c7bdce..3f1f1f9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,3 +6,5 @@ edition = "2024" [dependencies] pest = "2.8.6" pest_derive = "2.8.6" +serde = { version = "1.0.228", features = ["serde_derive"] } +serde_json = "1.0.149" diff --git a/src/compiler.rs b/src/compiler.rs index c74ab7a..7091a9a 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -2,12 +2,20 @@ use std::{fs, path::PathBuf, process, time::Instant}; use crate::{gogen, parser}; +use serde::Deserialize; + +#[derive(Deserialize)] +struct Config { + entry: String, + out_dir: String, +} + pub fn build() { let start = Instant::now(); // 1. find project root let root = find_project_root().unwrap_or_else(|| { - panic!("error: could not find project root (mist.toml)"); + panic!("error: could not find project root (mist.json)"); }); println!("mistc build ({})", root.display()); @@ -69,7 +77,7 @@ pub fn find_project_root() -> Option { let mut dir = std::env::current_dir().ok()?; loop { - if dir.join("mist.toml").exists() { + if dir.join("mist.json").exists() { return Some(dir); } @@ -79,26 +87,9 @@ pub fn find_project_root() -> Option { } } -struct Config { - entry: String, - out_dir: String, -} - fn load_config(root: &std::path::Path) -> Config { let content = - std::fs::read_to_string(root.join("mist.toml")).expect("failed to read mist.toml"); + std::fs::read_to_string(root.join("mist.json")).expect("failed to read mist.json"); - // super minimal parsing (replace later with toml crate) - let entry = extract(&content, "entry").unwrap_or("src/main.ms".into()); - let out_dir = extract(&content, "out_dir").unwrap_or("build".into()); - - Config { entry, out_dir } -} - -fn extract(content: &str, key: &str) -> Option { - content - .lines() - .find(|l| l.trim().starts_with(key)) - .and_then(|l| l.split('=').nth(1)) - .map(|v| v.trim().trim_matches('"').to_string()) + serde_json::from_str(&content).expect("invalid mist.json format") } diff --git a/test/mist.json b/test/mist.json new file mode 100644 index 0000000..c639516 --- /dev/null +++ b/test/mist.json @@ -0,0 +1,4 @@ +{ + "entry": "src/main.ms", + "out_dir": "build" +} \ No newline at end of file diff --git a/test/mist.toml b/test/mist.toml deleted file mode 100644 index 071051b..0000000 --- a/test/mist.toml +++ /dev/null @@ -1,7 +0,0 @@ -[package] -name = "myapp" -version = "0.1.0" - -[build] -entry = "src/main.ms" -out_dir = "build"