diff --git a/crates/mist-api/src/builder.mist b/crates/mist-api/src/builder.mist index 90a9bd9..8e69c47 100644 --- a/crates/mist-api/src/builder.mist +++ b/crates/mist-api/src/builder.mist @@ -29,9 +29,9 @@ pub bool build(Vec mut args, PathBuf root) { args.remove(0); args.insert(1, "--message-format=json".to_string()); - var is_root = root == env::current_dir().expect("Failed getting env"); + let is_root = root == env::current_dir().expect("Failed getting env"); - var mut command = Command::new("cargo") + let mut command = Command::new("cargo") .args(args) .stdout(Stdio::piped()) .stderr(Stdio::inherit()) @@ -39,47 +39,47 @@ pub bool build(Vec mut args, PathBuf root) { .spawn() .expect("Failed to run cargo"); - var mut reader = std::io::BufReader::new(command.stdout.take().expect("Failed to get reader")); + let mut reader = std::io::BufReader::new(command.stdout.take().expect("Failed to get reader")); - var mut diagnostics = Vec::new(); + let mut diagnostics = Vec::new(); - var mut mapping = HashMap::new(); + let mut mapping = HashMap::new(); - var mist_src = format!(".mist{MAIN_SEPARATOR}src"); + let mist_src = format!(".mist{MAIN_SEPARATOR}src"); for (message : cargo_metadata::Message::parse_stream(&mut reader)) { match (message) { Ok[Message::CompilerMessage[msg]] => { for (span : &msg.message.spans) { if (span.is_primary) { - var rust_path = root.join(&span.file_name); + let rust_path = root.join(&span.file_name); - var mist_file = span + let mist_file = span .file_name .replacen(&mist_src, "src", 1) .trim_end_matches(".rs") .to_string() + ".mist"; - var mist_path = root.join(&mist_file); + let mist_path = root.join(&mist_file); if (!fs::exists(&mist_path).expect("Unable to check if mist file exists")) { diagnostics.push(MistDiagnostic::Rust(msg)); break; } - var map = mapping.entry(rust_path.clone()).or_insert_with(|| { + let map = mapping.entry(rust_path.clone()).or_insert_with(|| { rev_mapper::get_mapping( &fs::read_to_string(rust_path) .expect("Failed to read file for mapping") ) }); - var [_, rev_mapper::MistMap[line, column]] = + let [_, rev_mapper::MistMap[line, column]] = rev_mapper::find_mapping(&map, &rev_mapper::RustMap(span.line_end, span.column_start)) .expect("Unable to find mapping"); - var mist_msg = MistDiagnosticMessage { + let mist_msg = MistDiagnosticMessage { message: format!( "{}: {}", msg.message.message, @@ -113,11 +113,11 @@ pub bool build(Vec mut args, PathBuf root) { Ok[Message::BuildFinished[finish]] => { print_diagnostics(&diagnostics); - var mut raw_reader = reader.into_inner(); - var mut stdout = std::io::stdout(); + let mut raw_reader = reader.into_inner(); + let mut stdout = std::io::stdout(); std::io::copy(&mut raw_reader, &mut stdout) - .map_err(|var v| v.to_string()) + .map_err(|let v| v.to_string()) .expect("(Mist) Failed to copy IO"); command.wait().unwrap(); @@ -134,12 +134,12 @@ pub bool build(Vec mut args, PathBuf root) { } pub void print_diagnostics(Vec* diagnostics) { - var mut files = HashMap::new(); + let mut files = HashMap::new(); for (diag : diagnostics) { match (diag) { MistDiagnostic::Error[msg] => { - var line = get_line(&mut files, &msg); + let line = get_line(&mut files, &msg); println!( "\n{}:{}:{}\n \x1b[31mError\x1b[0m: {}\n\t{}", @@ -152,7 +152,7 @@ pub void print_diagnostics(Vec* diagnostics) { } MistDiagnostic::Warning[msg] => { - var line = get_line(&mut files, &msg); + let line = get_line(&mut files, &msg); println!( "\n{}:{}:{}\n \x1b[33mWarning\x1b[0m: {}\n\t{}", @@ -173,9 +173,9 @@ pub Option get_line( HashMap> mut* files, MistDiagnosticMessage* msg, ) { - var src_path = msg.file_path.clone(); + let src_path = msg.file_path.clone(); - var lines = files.entry(src_path.clone()).or_insert_with(|| { + let lines = files.entry(src_path.clone()).or_insert_with(|| { fs::read_to_string(src_path) .expect("Unable to read mist file") .lines() @@ -184,5 +184,5 @@ pub Option get_line( .collect() }); - lines.get(msg.line - 1).map(|var v| v.trim().to_string()) + lines.get(msg.line - 1).map(|let v| v.trim().to_string()) } diff --git a/crates/mist-api/src/modules.mist b/crates/mist-api/src/modules.mist index d28df95..8e4ac89 100644 --- a/crates/mist-api/src/modules.mist +++ b/crates/mist-api/src/modules.mist @@ -10,9 +10,9 @@ pub class Module { pub Vec children; pub constructor(PathBuf mist_path) { - self.children = new Vec(); + self.children = Vec::new(); self.name = mist_path.file_stem() - .and_then(|var s| s.to_str()) + .and_then(|let s| s.to_str()) .expect("Failed to get module name") .to_string(); self.path = mist_path; @@ -30,7 +30,7 @@ pub class Module { } void scan_directory(self mut*, Path* search_dir) { - var entries = match (fs::read_dir(search_dir)) { + let entries = match (fs::read_dir(search_dir)) { Ok[entries] => entries; Err[e] => { eprintln!("error: failed to read directory {}\n {}", search_dir.display(), e); @@ -39,7 +39,7 @@ pub class Module { }; for (entry : entries) { - var entry = match (entry) { + let entry = match (entry) { Ok[entry] => entry; Err[e] => { eprintln!("error: failed to read directory entry\n {}", e); @@ -53,7 +53,7 @@ pub class Module { continue; } - self.children.push(new Module(child_path)); + self.children.push(Module::new(child_path)); } } @@ -75,7 +75,7 @@ pub class Module { } pub Module master_package(PathBuf mist_path) { - var mut root_mod = new Module(mist_path.clone()); + let mut root_mod = Module::new(mist_path.clone()); Path* parent_dir = mist_path.parent() .expect("Failed to get parent directory of root file"); diff --git a/crates/mist-api/src/transpiler.mist b/crates/mist-api/src/transpiler.mist index 789c422..1554d3e 100644 --- a/crates/mist-api/src/transpiler.mist +++ b/crates/mist-api/src/transpiler.mist @@ -8,18 +8,18 @@ use ; use ; pub PathBuf transpile() { - var start = time::Instant::now(); + let start = time::Instant::now(); - var root = env::current_dir().expect("Unable to find project root"); + let root = env::current_dir().expect("Unable to find project root"); PathBuf src = root.join("src"); PathBuf out = root.join(".mist/src"); - var master = modules::master_package(src.join("main.mist")); + let master = modules::master_package(src.join("main.mist")); master.transpile(&out); - var elapsed = start.elapsed(); + let elapsed = start.elapsed(); println!( "\x1b[32m\nTranspile successful\x1b[0m in \x1b[34m{:.2?}\x1b[0m", @@ -31,9 +31,9 @@ pub PathBuf transpile() { impl modules::Module { String transpile(self*, PathBuf* parent_dir) { - if (!self.path.is_dir() && self.path.extension().and_then(|var v| v.to_str()) != Some("mist")) { - var file_name = self.path.file_name() - .and_then(|var s| s.to_str()) + if (!self.path.is_dir() && self.path.extension().and_then(|let v| v.to_str()) != Some("mist")) { + let file_name = self.path.file_name() + .and_then(|let s| s.to_str()) .expect("Failed to get file name"); fs::copy(&self.path, parent_dir.join(&file_name)).expect("Failed to copy SideFile"); @@ -44,7 +44,7 @@ impl modules::Module { PathBuf dir = self.output_dir(&parent_dir); PathBuf output_file = self.output_path(&parent_dir); - var _ = fs::create_dir_all(&dir); + let _ = fs::create_dir_all(&dir); String mut output = String::new(); @@ -57,7 +57,7 @@ impl modules::Module { return String::new(); } - var res = fs::write(&output_file, output); + let res = fs::write(&output_file, output); if (res.is_err()) { eprintln!( @@ -86,16 +86,16 @@ void transpile_file(PathBuf* path, PathBuf* output_file, str* mod_decl) { } }; - var mut gc = mist_codegen::RustCodegen::new(); + let mut gc = mist_codegen::RustCodegen::new(); String output = gc.generate(match (mist_parser::parse(&source)) { Ok[ast] => ast; Err[e] => { match (e) { error::ParseError::Ast[e] => { - var start_pos = e.span.start_pos().line_col(); + let start_pos = e.span.start_pos().line_col(); - var span = e.span.as_str(); + let span = e.span.as_str(); eprintln!( "\n{}:{}:{}\n \x1b[31mError\x1b[0m: {}\n\t{}{}\t{}", @@ -120,7 +120,7 @@ void transpile_file(PathBuf* path, PathBuf* output_file, str* mod_decl) { } }); - var res = fs::write(&output_file, format!("{mod_decl}{output}")); + let res = fs::write(&output_file, format!("{mod_decl}{output}")); if (res.is_err()) { eprintln!(