Updated api bootstrap
This commit is contained in:
@@ -11,11 +11,11 @@ use mist_parser::rev_mapper;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct MistDiagnosticMessage {
|
||||
pub String message,
|
||||
pub PathBuf file_path,
|
||||
pub String file_name,
|
||||
pub usize line,
|
||||
pub usize column,
|
||||
pub message String,
|
||||
pub file_path PathBuf,
|
||||
pub file_name String ,
|
||||
pub line usize,
|
||||
pub column usize,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -25,7 +25,7 @@ pub enum MistDiagnostic {
|
||||
Rust[CompilerMessage],
|
||||
}
|
||||
|
||||
pub bool build(Vec<String> mut args, PathBuf root) {
|
||||
pub fn build(mut args Vec<String>, root PathBuf) bool {
|
||||
args.remove(0);
|
||||
args.insert(1, "--message-format=json".to_string());
|
||||
|
||||
@@ -68,7 +68,7 @@ pub bool build(Vec<String> mut args, PathBuf root) {
|
||||
break;
|
||||
}
|
||||
|
||||
let map = mapping.entry(rust_path.clone()).or_insert_with(|| {
|
||||
let map = mapping.entry(rust_path.clone()).or_insert_with(fn() {
|
||||
rev_mapper::get_mapping(
|
||||
&fs::read_to_string(rust_path)
|
||||
.expect("Failed to read file for mapping")
|
||||
@@ -117,7 +117,7 @@ pub bool build(Vec<String> mut args, PathBuf root) {
|
||||
let mut stdout = std::io::stdout();
|
||||
|
||||
std::io::copy(&mut raw_reader, &mut stdout)
|
||||
.map_err(|let v| v.to_string())
|
||||
.map_err(fn(v) -> v.to_string())
|
||||
.expect("(Mist) Failed to copy IO");
|
||||
|
||||
command.wait().unwrap();
|
||||
@@ -133,7 +133,7 @@ pub bool build(Vec<String> mut args, PathBuf root) {
|
||||
false
|
||||
}
|
||||
|
||||
pub void print_diagnostics(Vec<MistDiagnostic>* diagnostics) {
|
||||
pub fn print_diagnostics(diagnostics *Vec<MistDiagnostic>) {
|
||||
let mut files = HashMap::new();
|
||||
|
||||
for (diag : diagnostics) {
|
||||
@@ -169,13 +169,13 @@ pub void print_diagnostics(Vec<MistDiagnostic>* diagnostics) {
|
||||
}
|
||||
}
|
||||
|
||||
pub Option<String> get_line(
|
||||
HashMap<PathBuf, Vec<String>> mut* files,
|
||||
MistDiagnosticMessage* msg,
|
||||
) {
|
||||
pub fn get_line(
|
||||
files *mut HashMap<PathBuf, Vec<String>>,
|
||||
msg *MistDiagnosticMessage,
|
||||
) Option<String> {
|
||||
let src_path = msg.file_path.clone();
|
||||
|
||||
let lines = files.entry(src_path.clone()).or_insert_with(|| {
|
||||
let lines = files.entry(src_path.clone()).or_insert_with(fn() {
|
||||
fs::read_to_string(src_path)
|
||||
.expect("Unable to read mist file")
|
||||
.lines()
|
||||
@@ -184,5 +184,5 @@ pub Option<String> get_line(
|
||||
.collect()
|
||||
});
|
||||
|
||||
lines.get(msg.line - 1).map(|let v| v.trim().to_string())
|
||||
lines.get(msg.line - 1).map(fn(v) -> v.trim().to_string())
|
||||
}
|
||||
|
||||
@@ -2,4 +2,4 @@ pub mod builder;
|
||||
pub mod transpiler;
|
||||
pub mod modules;
|
||||
|
||||
void main() {}
|
||||
fn main() {}
|
||||
@@ -5,22 +5,22 @@ use std::process;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub class Module {
|
||||
pub String name;
|
||||
pub PathBuf path;
|
||||
pub Vec<Self> children;
|
||||
pub name String;
|
||||
pub path PathBuf;
|
||||
pub children Vec<Self>;
|
||||
|
||||
pub constructor(PathBuf mist_path) {
|
||||
pub constructor(mist_path PathBuf) {
|
||||
self.children = Vec::new();
|
||||
self.name = mist_path.file_stem()
|
||||
.and_then(|let s| s.to_str())
|
||||
.and_then(fn(s) -> s.to_str())
|
||||
.expect("Failed to get module name")
|
||||
.to_string();
|
||||
self.path = mist_path;
|
||||
|
||||
if (self.path.is_dir()) {
|
||||
PathBuf dir = self.path.clone();
|
||||
let dir = self.path.clone();
|
||||
|
||||
PathBuf pkg_gate = self.path.join("package.mist");
|
||||
let pkg_gate = self.path.join("package.mist");
|
||||
if (pkg_gate.exists()) {
|
||||
self.path = pkg_gate;
|
||||
}
|
||||
@@ -29,7 +29,7 @@ pub class Module {
|
||||
}
|
||||
}
|
||||
|
||||
void scan_directory(self mut*, Path* search_dir) {
|
||||
fn scan_directory(*mut self, search_dir *Path) {
|
||||
let entries = match (fs::read_dir(search_dir)) {
|
||||
Ok[entries] => entries;
|
||||
Err[e] => {
|
||||
@@ -47,7 +47,7 @@ pub class Module {
|
||||
}
|
||||
};
|
||||
|
||||
PathBuf child_path = entry.path();
|
||||
let child_path = entry.path();
|
||||
|
||||
if (child_path == self.path) {
|
||||
continue;
|
||||
@@ -57,7 +57,7 @@ pub class Module {
|
||||
}
|
||||
}
|
||||
|
||||
pub PathBuf output_dir(self*, PathBuf* parent_dir) {
|
||||
pub fn output_dir(*self, parent_dir *PathBuf) PathBuf {
|
||||
if (self.path.is_dir() || Some("package.mist") == self.path.file_name().unwrap().to_str()) {
|
||||
parent_dir.join(&self.name)
|
||||
} else {
|
||||
@@ -65,7 +65,7 @@ pub class Module {
|
||||
}
|
||||
}
|
||||
|
||||
pub PathBuf output_path(self*, PathBuf* parent_dir) {
|
||||
pub fn output_path(*self, parent_dir *PathBuf) PathBuf {
|
||||
if (self.path.is_dir() || Some("package.mist") == self.path.file_name().unwrap().to_str()) {
|
||||
parent_dir.join(&self.name).join("mod.rs")
|
||||
} else {
|
||||
@@ -74,10 +74,10 @@ pub class Module {
|
||||
}
|
||||
}
|
||||
|
||||
pub Module master_package(PathBuf mist_path) {
|
||||
pub fn master_package(mist_path PathBuf) Module {
|
||||
let mut root_mod = Module::new(mist_path.clone());
|
||||
|
||||
Path* parent_dir = mist_path.parent()
|
||||
let parent_dir = mist_path.parent()
|
||||
.expect("Failed to get parent directory of root file");
|
||||
|
||||
root_mod.scan_directory(parent_dir);
|
||||
|
||||
@@ -7,13 +7,13 @@ use std::env;
|
||||
use mist_parser::error;
|
||||
use crate::modules;
|
||||
|
||||
pub PathBuf transpile() {
|
||||
pub fn transpile() PathBuf {
|
||||
let start = time::Instant::now();
|
||||
|
||||
let root = env::current_dir().expect("Unable to find project root");
|
||||
|
||||
PathBuf src = root.join("src");
|
||||
PathBuf out = root.join(".mist/src");
|
||||
let src = root.join("src");
|
||||
let out = root.join(".mist/src");
|
||||
|
||||
let master = modules::master_package(src.join("main.mist"));
|
||||
|
||||
@@ -30,10 +30,10 @@ pub PathBuf transpile() {
|
||||
}
|
||||
|
||||
impl modules::Module {
|
||||
String transpile(self*, PathBuf* parent_dir) {
|
||||
if (!self.path.is_dir() && self.path.extension().and_then(|let v| v.to_str()) != Some("mist")) {
|
||||
fn transpile(*self, parent_dir *PathBuf) 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(|let s| s.to_str())
|
||||
.and_then(fn(s) -> s.to_str())
|
||||
.expect("Failed to get file name");
|
||||
|
||||
fs::copy(&self.path, parent_dir.join(&file_name)).expect("Failed to copy SideFile");
|
||||
@@ -41,12 +41,12 @@ impl modules::Module {
|
||||
return String::new();
|
||||
}
|
||||
|
||||
PathBuf dir = self.output_dir(&parent_dir);
|
||||
PathBuf output_file = self.output_path(&parent_dir);
|
||||
let dir = self.output_dir(&parent_dir);
|
||||
let output_file = self.output_path(&parent_dir);
|
||||
|
||||
let _ = fs::create_dir_all(&dir);
|
||||
|
||||
String mut output = String::new();
|
||||
let mut output = String::new();
|
||||
|
||||
for (child : &self.children) {
|
||||
output.push_str(&child.transpile(&dir));
|
||||
@@ -76,8 +76,8 @@ impl modules::Module {
|
||||
}
|
||||
}
|
||||
|
||||
void transpile_file(PathBuf* path, PathBuf* output_file, str* mod_decl) {
|
||||
String source = match (fs::read_to_string(path)) {
|
||||
fn transpile_file(path *PathBuf, output_file *PathBuf, mod_decl *str) {
|
||||
let source = match (fs::read_to_string(path)) {
|
||||
Ok[s] => s;
|
||||
Err[e] => {
|
||||
eprintln!("error: failed to read file {}\n {}", path.display(), e);
|
||||
@@ -88,7 +88,7 @@ void transpile_file(PathBuf* path, PathBuf* output_file, str* mod_decl) {
|
||||
|
||||
let mut gc = mist_codegen::RustCodegen::new();
|
||||
|
||||
String output = gc.generate(match (mist_parser::parse(&source)) {
|
||||
let output = gc.generate(match (mist_parser::parse(&source)) {
|
||||
Ok[ast] => ast;
|
||||
Err[e] => {
|
||||
match (e) {
|
||||
|
||||
Reference in New Issue
Block a user