Update api bootstrap
This commit is contained in:
@@ -20,8 +20,9 @@ pub struct MistConfig {
|
||||
pub packages Vec<PathBuf>,
|
||||
pub main_mods String
|
||||
}
|
||||
|
||||
impl MistConfig {
|
||||
pub fn should_ignore(*self, path *Path) bool {
|
||||
pub fn bool should_ignore(*self, path *Path) {
|
||||
if path == self.package {
|
||||
return true;
|
||||
}
|
||||
@@ -36,7 +37,7 @@ impl MistConfig {
|
||||
}
|
||||
}
|
||||
impl Default for MistConfig {
|
||||
fn default() Self {
|
||||
fn Self default() {
|
||||
Self {
|
||||
package: PathBuf::from("main.mist"),
|
||||
packages: Vec::new(),
|
||||
@@ -45,7 +46,7 @@ impl Default for MistConfig {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn transpile() PathBuf {
|
||||
pub fn PathBuf transpile() {
|
||||
let start = time::Instant::now();
|
||||
|
||||
let root = env::current_dir().expect("Unable to find project root");
|
||||
@@ -84,7 +85,7 @@ pub fn transpile() PathBuf {
|
||||
}
|
||||
|
||||
impl modules::Module {
|
||||
fn transpile(*self, parent_dir *PathBuf, config *mut MistConfig) [bool, String] {
|
||||
fn (bool, String) transpile(*self, parent_dir *PathBuf, config *mut MistConfig) {
|
||||
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())
|
||||
@@ -123,7 +124,7 @@ impl modules::Module {
|
||||
self.write_transpile(output, parent_dir, child_changed)
|
||||
}
|
||||
|
||||
fn write_transpile(*self, output String, parent_dir *PathBuf, child_changed bool) [bool, String] {
|
||||
fn (bool, String) write_transpile(*self, output String, parent_dir *PathBuf, child_changed bool) {
|
||||
if self.path.is_dir() {
|
||||
let output_file = self.output_path(parent_dir, &None);
|
||||
|
||||
@@ -146,8 +147,8 @@ impl modules::Module {
|
||||
(false, format!("pub mod {};\n", self.name))
|
||||
} else {
|
||||
let source = match fs::read_to_string(&self.path) {
|
||||
Ok[s] => s;
|
||||
Err[e] => {
|
||||
Ok(s) => s;
|
||||
Err(e) => {
|
||||
eprintln!("error: failed to read file {}\n {}", self.path.display(), e);
|
||||
|
||||
process::exit(1);
|
||||
@@ -173,7 +174,7 @@ impl modules::Module {
|
||||
}
|
||||
}
|
||||
|
||||
fn is_source_newer(source *Path, output *Path) std::io::Result<bool> {
|
||||
fn std::io::Result<bool> is_source_newer(source *Path, output *Path) {
|
||||
if !output.exists() {
|
||||
return Ok(true);
|
||||
}
|
||||
@@ -185,12 +186,12 @@ fn is_source_newer(source *Path, output *Path) std::io::Result<bool> {
|
||||
}
|
||||
|
||||
pub enum TranspileError<'a> {
|
||||
Parse[error::ParseError<'a, Vec<mist_parser::ast::TopLevel>>],
|
||||
Semantic[Vec<mist_parser::semantics::SemanticError>]
|
||||
Parse(error::ParseError<'a, Vec<mist_parser::ast::TopLevel>>),
|
||||
Semantic(Vec<mist_parser::semantics::SemanticError>)
|
||||
}
|
||||
|
||||
pub fn transpile_code<'a>(path *PathBuf, source *'a str, mut output_file PathBuf, mod_decl *str, curr_mod_decl *Option<[mist_parser::ast::Visibility, mist_parser::ast::Identifier]>)
|
||||
Result<[PathBuf, mist_codegen::RustCodegen, String], TranspileError<'a>> {
|
||||
pub fn Result<(PathBuf, mist_codegen::RustCodegen, String), TranspileError<'a>>
|
||||
transpile_code<'a>(path *PathBuf, source *'a str, mut output_file PathBuf, mod_decl *str, curr_mod_decl *Option<(mist_parser::ast::Visibility, mist_parser::ast::Identifier)>) {
|
||||
|
||||
if let Some[[_, name]] = &curr_mod_decl {
|
||||
if output_file.file_name().map(fn(v) -> v.to_str()).unwrap_or_default() != Some("mod.rs") {
|
||||
@@ -222,10 +223,10 @@ pub fn transpile_code<'a>(path *PathBuf, source *'a str, mut output_file PathBuf
|
||||
Ok((output_file, gc, output))
|
||||
}
|
||||
|
||||
pub fn transpile_file(path *PathBuf, source *str, output_file PathBuf, mod_decl *str, curr_mod_decl *Option<[mist_parser::ast::Visibility, mist_parser::ast::Identifier]>) {
|
||||
let [output_file, gc, output] = match transpile_code(path, source, output_file, mod_decl, curr_mod_decl) {
|
||||
Ok[output] => output;
|
||||
Err[e] => {
|
||||
pub fn void transpile_file(path *PathBuf, source *str, output_file PathBuf, mod_decl *str, curr_mod_decl *Option<(mist_parser::ast::Visibility, mist_parser::ast::Identifier)>) {
|
||||
let (output_file, gc, output) = match transpile_code(path, source, output_file, mod_decl, curr_mod_decl) {
|
||||
Ok(output) => output;
|
||||
Err(e) => {
|
||||
decode_err(&e, path);
|
||||
process::exit(1);
|
||||
}
|
||||
@@ -258,11 +259,11 @@ pub fn transpile_file(path *PathBuf, source *str, output_file PathBuf, mod_decl
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode_err<'a>(err *TranspileError<'a>, path *PathBuf) {
|
||||
pub fn void decode_err<'a>(err *TranspileError<'a>, path *PathBuf) {
|
||||
let curr_dir = std::env::current_dir().unwrap();
|
||||
|
||||
match err {
|
||||
TranspileError::Semantic[e_list] => {
|
||||
TranspileError::Semantic(e_list) => {
|
||||
for e in e_list {
|
||||
eprintln!(
|
||||
"\n{}:{}:{}\n \x1b[31mError\x1b[0m: {}",
|
||||
@@ -274,9 +275,9 @@ pub fn decode_err<'a>(err *TranspileError<'a>, path *PathBuf) {
|
||||
}
|
||||
}
|
||||
|
||||
TranspileError::Parse[e] => {
|
||||
TranspileError::Parse(e) => {
|
||||
match e {
|
||||
error::ParseError::Ast[e] => {
|
||||
error::ParseError::Ast(e) => {
|
||||
let start_pos = e.span.start_pos().line_col();
|
||||
|
||||
let span = e.span.as_str();
|
||||
@@ -293,7 +294,7 @@ pub fn decode_err<'a>(err *TranspileError<'a>, path *PathBuf) {
|
||||
);
|
||||
}
|
||||
|
||||
error::ParseError::PreAst[e] => {
|
||||
error::ParseError::PreAst(e) => {
|
||||
eprintln!("error: parse failed in {}\n{}", path.strip_prefix(curr_dir).unwrap_or_else(|_| path).display(), e);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user