Mist.toml support

This commit is contained in:
2026-06-11 19:06:07 +02:00
parent c37392046a
commit 74d53fff97
5 changed files with 120 additions and 31 deletions
Generated
+79 -2
View File
@@ -122,7 +122,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856"
dependencies = [
"cfg-if",
"hashbrown",
"hashbrown 0.14.5",
"lock_api",
"once_cell",
"parking_lot_core",
@@ -136,7 +136,7 @@ checksum = "5041cc499144891f3790297212f32a74fb938e5136a14943f338ef9e0ae276cf"
dependencies = [
"cfg-if",
"crossbeam-utils",
"hashbrown",
"hashbrown 0.14.5",
"lock_api",
"once_cell",
"parking_lot_core",
@@ -163,6 +163,12 @@ dependencies = [
"syn",
]
[[package]]
name = "equivalent"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
[[package]]
name = "errno"
version = "0.3.14"
@@ -274,6 +280,12 @@ version = "0.14.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
[[package]]
name = "hashbrown"
version = "0.17.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a"
[[package]]
name = "httparse"
version = "1.10.1"
@@ -383,6 +395,16 @@ dependencies = [
"icu_properties",
]
[[package]]
name = "indexmap"
version = "2.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9"
dependencies = [
"equivalent",
"hashbrown 0.17.1",
]
[[package]]
name = "itoa"
version = "1.0.18"
@@ -464,6 +486,7 @@ dependencies = [
"mist-parser",
"serde",
"serde_json",
"toml",
]
[[package]]
@@ -711,6 +734,15 @@ dependencies = [
"syn",
]
[[package]]
name = "serde_spanned"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6662b5879511e06e8999a8a235d848113e942c9124f211511b16466ee2995f26"
dependencies = [
"serde_core",
]
[[package]]
name = "sha2"
version = "0.10.9"
@@ -859,6 +891,45 @@ dependencies = [
"tokio",
]
[[package]]
name = "toml"
version = "1.1.2+spec-1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81f3d15e84cbcd896376e6730314d59fb5a87f31e4b038454184435cd57defee"
dependencies = [
"indexmap",
"serde_core",
"serde_spanned",
"toml_datetime",
"toml_parser",
"toml_writer",
"winnow",
]
[[package]]
name = "toml_datetime"
version = "1.1.1+spec-1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3165f65f62e28e0115a00b2ebdd37eb6f3b641855f9d636d3cd4103767159ad7"
dependencies = [
"serde_core",
]
[[package]]
name = "toml_parser"
version = "1.1.2+spec-1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2abe9b86193656635d2411dc43050282ca48aa31c2451210f4202550afb7526"
dependencies = [
"winnow",
]
[[package]]
name = "toml_writer"
version = "1.1.1+spec-1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "756daf9b1013ebe47a8776667b466417e2d4c5679d441c26230efd9ef78692db"
[[package]]
name = "tower"
version = "0.4.13"
@@ -1014,6 +1085,12 @@ dependencies = [
"windows-link",
]
[[package]]
name = "winnow"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0592e1c9d151f854e6fd382574c3a0855250e1d9b2f99d9281c6e6391af352f1"
[[package]]
name = "writeable"
version = "0.6.3"
+1
View File
@@ -20,6 +20,7 @@ serde_json = "1.0.149"
cargo_metadata = "0.23.1"
mist-parser = { workspace = true }
mist-codegen = { workspace = true }
toml = "1.1.2"
[lib]
name = "mist_api"
+38 -4
View File
@@ -1,4 +1,5 @@
use std::fs;
use std::path::Path;
use std::path::PathBuf;
use std::process;
use std::time;
@@ -8,17 +9,50 @@ use mist_parser::error;
use crate::modules;
use mist_codegen::GetRust;
use serde::Deserialize;
#[derive(Debug, Deserialize)]
pub struct MistConfig {
packages Vec<PathBuf>,
}
impl MistConfig {
pub fn is_package(*self, path *Path) bool {
for (pkg : &self.packages) {
if (path.ends_with(pkg)) {
return true;
}
}
false
}
}
pub fn transpile() PathBuf {
let start = time::Instant::now();
let root = env::current_dir().expect("Unable to find project root");
let toml_path = root.join("Mist.toml");
let src = root.join("src");
let out = root.join(".mist/src");
let master = modules::master_package(src.join("main.mist"));
let toml_content = fs::read_to_string(&toml_path)
.unwrap_or_else(fn(_) -> panic!("Could not read file at {:?}", toml_path));
master.transpile(&out);
let mut config MistConfig = toml::from_str(&toml_content)
.unwrap_or_else(fn(_) -> panic!("Failed to parse Mist.toml from {:?}", toml_path));
for (pkg : &mut config.packages) {
*pkg = src.join(&*pkg);
}
let master = modules::master_package(
config.packages.get(0)
.unwrap_or_else(fn() -> panic!("Mist.toml packages must contain at least one element, eg, 'src/main.mist'"))
.to_path_buf()
);
master.transpile(&out, &config);
let elapsed = start.elapsed();
@@ -31,7 +65,7 @@ pub fn transpile() PathBuf {
}
impl modules::Module {
fn transpile(*self, parent_dir *PathBuf) String {
fn transpile(*self, parent_dir *PathBuf, config *MistConfig) String {
if (!self.path.is_dir() && self.path.extension().and_then(fn(v) -> v.to_str()) != Some("mist")) {
let file_name = self.path.file_name()
.and_then(fn(s) -> s.to_str())
@@ -50,7 +84,7 @@ impl modules::Module {
let mut output = String::new();
for (child : &self.children) {
output.push_str(&child.transpile(&dir));
output.push_str(&child.transpile(&dir, config));
}
if (self.path.is_dir()) {
+1 -1
View File
@@ -1 +1 @@
package = "main.mist"
packages = ["main.mist"]
-23
View File
@@ -1,23 +0,0 @@
pub module attribute_test;
#[derive(Debug)]
pub struct Debuggable {
value i32,
}
pub fn test_derive_attribute() {
let d = Debuggable { value: 42 };
assert_eq!(d.value, 42);
}
#[allow(unused_variables)]
pub fn test_allow_attribute() {
let x = 42;
let y = "unused";
assert_eq!(x, 42);
}
pub fn run_tests() {
test_derive_attribute();
test_allow_attribute();
}