Merge pull request #56 from mist-go/future-proofed-modules
Future proofed module stucture
This commit is contained in:
Generated
+12
-5
@@ -455,6 +455,17 @@ dependencies = [
|
||||
"tower-lsp",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mist-api"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"cargo_metadata",
|
||||
"mist-codegen",
|
||||
"mist-parser",
|
||||
"serde",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mist-codegen"
|
||||
version = "0.1.2"
|
||||
@@ -466,12 +477,8 @@ dependencies = [
|
||||
name = "mist-lang"
|
||||
version = "0.0.5-alpha0"
|
||||
dependencies = [
|
||||
"cargo_metadata",
|
||||
"mist-analyzer",
|
||||
"mist-codegen",
|
||||
"mist-parser",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"mist-api",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
+3
-10
@@ -16,19 +16,15 @@ include = [
|
||||
]
|
||||
|
||||
[dependencies]
|
||||
mist-parser = { workspace = true }
|
||||
mist-analyzer = { workspace = true }
|
||||
mist-codegen = { workspace = true }
|
||||
|
||||
serde = { version = "1.0.228", features = ["serde_derive"] }
|
||||
serde_json = "1.0.149"
|
||||
cargo_metadata = "0.23.1"
|
||||
mist-api = { workspace = true }
|
||||
|
||||
[workspace]
|
||||
members = [
|
||||
"crates/parser",
|
||||
"crates/analyzer",
|
||||
"crates/codegen",
|
||||
"crates/mist-api",
|
||||
]
|
||||
|
||||
exclude = [
|
||||
@@ -39,6 +35,7 @@ exclude = [
|
||||
mist-parser = { path = "crates/parser", version = "0.1.6" }
|
||||
mist-analyzer = { path = "crates/analyzer", version = "0.0.3" }
|
||||
mist-codegen = { path = "crates/codegen", version = "0.1.2" }
|
||||
mist-api = { path = "crates/mist-api", version = "0.1.0" }
|
||||
|
||||
[[bin]]
|
||||
name = "mist"
|
||||
@@ -48,10 +45,6 @@ path = ".mist/src/main.rs"
|
||||
name = "mist-lsp"
|
||||
path = ".mist/lsp/main.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "mist-header"
|
||||
path = "src/_header.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "mist-analyzer"
|
||||
path = ".mist/src/analyzer.rs"
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
[package]
|
||||
name = "mist-api"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
serde = { version = "1.0.228", features = ["serde_derive"] }
|
||||
serde_json = "1.0.149"
|
||||
cargo_metadata = "0.23.1"
|
||||
mist-parser = { workspace = true }
|
||||
mist-codegen = { workspace = true }
|
||||
|
||||
[lib]
|
||||
name = "mist_api"
|
||||
path = ".mist/src/lib.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "mist_lsp"
|
||||
path = ".mist/lsp/main.rs"
|
||||
@@ -0,0 +1,3 @@
|
||||
pub mod builder;
|
||||
pub mod transpiler;
|
||||
pub mod modules;
|
||||
@@ -0,0 +1,5 @@
|
||||
pub mod builder;
|
||||
pub mod transpiler;
|
||||
pub mod modules;
|
||||
|
||||
void main() {}
|
||||
@@ -0,0 +1,80 @@
|
||||
use <std::path::Path>;
|
||||
use <std::path::PathBuf>;
|
||||
use <std::fs>;
|
||||
use <std::process>;
|
||||
|
||||
pub class Module {
|
||||
pub String name;
|
||||
pub PathBuf path;
|
||||
pub Vec<Self> children;
|
||||
|
||||
pub constructor(String name, PathBuf mist_path, PathBuf rust_path) {
|
||||
self.children = new Vec();
|
||||
self.name = name;
|
||||
self.path = mist_path;
|
||||
|
||||
if (self.path.is_dir()) {
|
||||
var entries = match (fs::read_dir(&self.path)) {
|
||||
Ok[entries] => entries;
|
||||
Err[e] => {
|
||||
eprintln!(
|
||||
"error: failed to read directory {}\n {}",
|
||||
self.path.display(),
|
||||
e
|
||||
);
|
||||
|
||||
process::exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
for (entry : entries) {
|
||||
var entry = match (entry) {
|
||||
Ok[entry] => entry;
|
||||
Err[e] => {
|
||||
eprintln!("error: failed to read directory entry\n {}", e);
|
||||
|
||||
process::exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
PathBuf child_path = entry.path();
|
||||
|
||||
String child_name = child_path.file_stem()
|
||||
.and_then(|var s| s.to_str())
|
||||
.expect("Failed to get module name")
|
||||
.to_string();
|
||||
|
||||
PathBuf child_output = rust_path.join(&child_name).with_extension("rs");
|
||||
|
||||
if (should_skip(&child_path, &child_output)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
self.children.push(new Module(child_name, child_path, child_output));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub Module new_package(PathBuf mist_path, PathBuf rust_path) {
|
||||
String name = mist_path.file_stem()
|
||||
.and_then(|var s| s.to_str())
|
||||
.expect("Failed to get module name")
|
||||
.to_string();
|
||||
|
||||
new Module(name, mist_path, rust_path)
|
||||
}
|
||||
|
||||
bool should_skip(Path* source, Path* output) {
|
||||
var src_time = fs::metadata(source)
|
||||
.ok()
|
||||
.and_then(|var v| v.modified().ok());
|
||||
|
||||
var out_time = fs::metadata(output)
|
||||
.ok()
|
||||
.and_then(|var v| v.modified().ok());
|
||||
|
||||
out_time
|
||||
.map(|var out_time| out_time >= src_time.unwrap())
|
||||
.unwrap_or_default()
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
package = "main.mist"
|
||||
@@ -1,3 +0,0 @@
|
||||
pub mod builder;
|
||||
|
||||
fn main() {}
|
||||
+2
-3
@@ -1,9 +1,8 @@
|
||||
use <std::process>;
|
||||
use <std::env>;
|
||||
use <std::fs>;
|
||||
|
||||
pub mod builder;
|
||||
pub mod transpiler;
|
||||
use <mist_api::builder>;
|
||||
use <mist_api::transpiler>;
|
||||
|
||||
void main() {
|
||||
Vec<String> args = env::args().collect();
|
||||
|
||||
Reference in New Issue
Block a user