diff --git a/src/ast/mod.rs b/src/ast/mod.rs index 1b725d6..1ffd725 100644 --- a/src/ast/mod.rs +++ b/src/ast/mod.rs @@ -578,7 +578,12 @@ impl ModuleDef { let rewrite_import = |e: &mut Expression| { let main_separator = format!("{}", std::path::MAIN_SEPARATOR); if let Expression::Include(ref mut def) = e { - let path = PathBuf::from(&def.path.fragment.replace("/", &main_separator).replace("\\", &main_separator)); + let path = PathBuf::from( + &def.path + .fragment + .replace("/", &main_separator) + .replace("\\", &main_separator), + ); if path.is_relative() { def.path.fragment = base .join(path) @@ -589,7 +594,12 @@ impl ModuleDef { } } if let Expression::Import(ref mut def) = e { - let path = PathBuf::from(&def.path.fragment.replace("/", &main_separator).replace("\\", &main_separator)); + let path = PathBuf::from( + &def.path + .fragment + .replace("/", &main_separator) + .replace("\\", &main_separator), + ); // std/ paths are special and do not get made into absolute paths. if path.starts_with(format!("std{}", main_separator)) { return; diff --git a/src/build/compile_test.rs b/src/build/compile_test.rs index 2cbfc25..c71d09d 100644 --- a/src/build/compile_test.rs +++ b/src/build/compile_test.rs @@ -575,4 +575,4 @@ fn test_bad_import_path_compile_failure() { Regex::new(r"line: 1 column: 18").unwrap(), ], ) -} \ No newline at end of file +} diff --git a/src/build/mod.rs b/src/build/mod.rs index afbe0d5..c95cbda 100644 --- a/src/build/mod.rs +++ b/src/build/mod.rs @@ -23,19 +23,19 @@ use std::io::Read; use std::path::PathBuf; use std::rc::Rc; -use simple_error; use rustyline; +use simple_error; use crate::ast::*; use crate::error; use crate::iter::OffsetStrIter; use crate::parse::parse; +use crate::build::opcode::pointer::OpPointer; use crate::build::opcode::translate; +use crate::build::opcode::translate::PositionMap; use crate::build::opcode::Environment; use crate::build::opcode::VM; -use crate::build::opcode::pointer::OpPointer; -use crate::build::opcode::translate::PositionMap; pub mod assets; pub mod format; @@ -207,7 +207,11 @@ where println!("Type '#help' for help."); println!(""); // Initialize VM with an empty OpPointer - let mut vm = VM::new(Rc::new(PositionMap::new()), self.environment.clone(), &self.working_dir); + let mut vm = VM::new( + Rc::new(PositionMap::new()), + self.environment.clone(), + &self.working_dir, + ); loop { // print prompt let line = editor.readline(&format!("{}> ", lines.next_line()))?; @@ -255,8 +259,7 @@ where println!("{}", val); vm.last = None; } - None => { - } + None => {} } editor.history_mut().add(stmt); editor.save_history(&config_home)?; diff --git a/src/build/opcode/cache.rs b/src/build/opcode/cache.rs index 267a74c..fdfcd59 100644 --- a/src/build/opcode/cache.rs +++ b/src/build/opcode/cache.rs @@ -46,9 +46,7 @@ impl<'a> Entry<'a> { path: P, ) -> Result { let cached = match self.0 { - btree_map::Entry::Occupied(e) => { - e.get().clone() - } + btree_map::Entry::Occupied(e) => e.get().clone(), btree_map::Entry::Vacant(e) => { let v = Rc::new(f()?); e.insert(v.clone()); diff --git a/src/build/opcode/error.rs b/src/build/opcode/error.rs index 8122f6a..8eb4b19 100644 --- a/src/build/opcode/error.rs +++ b/src/build/opcode/error.rs @@ -78,7 +78,9 @@ impl From for Error { impl From for Error { fn from(e: std::io::Error) -> Self { let msg = match dbg!(e.kind()) { - io::ErrorKind::NotFound | io::ErrorKind::Other => format!("OSError: Path not found: {}", e), + io::ErrorKind::NotFound | io::ErrorKind::Other => { + format!("OSError: Path not found: {}", e) + } _ => format!("{}", e), }; Error { diff --git a/src/build/opcode/mod.rs b/src/build/opcode/mod.rs index eb666a1..a9ac0b3 100644 --- a/src/build/opcode/mod.rs +++ b/src/build/opcode/mod.rs @@ -367,4 +367,4 @@ impl From<&Val> for Value { } } } -} \ No newline at end of file +} diff --git a/src/build/opcode/runtime.rs b/src/build/opcode/runtime.rs index 8ae844d..1523bcb 100644 --- a/src/build/opcode/runtime.rs +++ b/src/build/opcode/runtime.rs @@ -12,11 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. use std::cell::RefCell; +use std::fmt::Debug; use std::fs::File; use std::io::Read; use std::path::{Path, PathBuf}; use std::rc::Rc; -use std::fmt::Debug; use regex::Regex; @@ -123,11 +123,11 @@ impl Builtins { // The canonicalize method on windows is not what we want so we'll // do something a little different on windows that we would do on // other Operating Systems. - #[cfg(target_os="windows")] + #[cfg(target_os = "windows")] { Ok(dbg!(normalized)) } - #[cfg(not(target_os="windows"))] + #[cfg(not(target_os = "windows"))] { Ok(dbg!(normalized.canonicalize()?)) } @@ -156,7 +156,12 @@ impl Builtins { } } - fn get_file_as_string>(&self, base_path: P, path: &str, pos: Position) -> Result { + fn get_file_as_string>( + &self, + base_path: P, + path: &str, + pos: Position, + ) -> Result { let sep = format!("{}", std::path::MAIN_SEPARATOR); let raw_path = path.replace("/", &sep); // FIXME(jwall): import paths? @@ -180,40 +185,37 @@ impl Builtins { where O: std::io::Write + Clone, E: std::io::Write + Clone, - P: Into + Clone + Debug, + P: Into + Clone + Debug, { let path = stack.pop(); if let Some((val, path_pos)) = path { if let &Value::P(Str(ref path)) = val.as_ref() { // TODO(jwall): A bit hacky we should probably change import stacks to be pathbufs. - let normalized = decorate_error!(path_pos => self.normalize_path(base_path, false, dbg!(path)))?; + let normalized = + decorate_error!(path_pos => self.normalize_path(base_path, false, dbg!(path)))?; // first we chack the cache let path = dbg!(normalized.to_string_lossy().to_string()); if let Some(val) = env.borrow().get_cached_path_val(&path) { stack.push((val, path_pos)); return Ok(()); } - if import_stack - .iter() - .find(|p| *p == &path) - .is_some() { - return Err(Error::new( - format!("Import cycle detected: {} in {:?}", path, import_stack), - pos)); + if import_stack.iter().find(|p| *p == &path).is_some() { + return Err(Error::new( + format!("Import cycle detected: {} in {:?}", path, import_stack), + pos, + )); } - let val = { - env.borrow_mut().get_cached_path_val(&path) - }; + let val = { env.borrow_mut().get_cached_path_val(&path) }; match val { Some(v) => { stack.push((v, path_pos)); } None => { - let op_pointer = - decorate_error!(path_pos => env.borrow_mut().get_ops_for_path(&normalized))?; + let op_pointer = decorate_error!(path_pos => env.borrow_mut().get_ops_for_path(&normalized))?; // TODO(jwall): What if we don't have a base path? - let mut vm = VM::with_pointer(op_pointer, env.clone(), normalized.parent().unwrap()) - .with_import_stack(import_stack.clone()); + let mut vm = + VM::with_pointer(op_pointer, env.clone(), normalized.parent().unwrap()) + .with_import_stack(import_stack.clone()); vm.run()?; let result = Rc::new(vm.symbols_to_tuple(true)); env.borrow_mut().update_path_val(&path, result.clone()); @@ -265,7 +267,11 @@ impl Builtins { }; if typ == "str" { stack.push(( - Rc::new(P(Str(self.get_file_as_string(base_path, &path, pos.clone())?))), + Rc::new(P(Str(self.get_file_as_string( + base_path, + &path, + pos.clone(), + )?))), pos.clone(), )); } else { @@ -368,7 +374,8 @@ impl Builtins { if env.borrow().get_out_lock_for_path(&path) { return Err(Error::new( format!("You can only have one output per file"), - pos)); + pos, + )); } env.borrow_mut().set_out_lock_for_path(path.as_ref()); Some(write_path) @@ -376,7 +383,8 @@ impl Builtins { if env.borrow().get_out_lock_for_path("/dev/stdout") { return Err(Error::new( format!("You can only have one output per file"), - pos)); + pos, + )); } env.borrow_mut().set_out_lock_for_path("/dev/stdout"); None @@ -393,7 +401,7 @@ impl Builtins { Some(p) => { let p = p.with_extension(c.file_ext()); Box::new(File::create(&p)?) - }, + } None => Box::new(stdout), }; if let Err(e) = c.convert(Rc::new(val), &mut writer) { @@ -625,7 +633,7 @@ impl Builtins { _ => { result_elems.push(e.clone()); pos_elems.push(e_pos); - }, + } } } stack.push((Rc::new(C(List(result_elems, pos_elems))), pos)); @@ -651,7 +659,7 @@ impl Builtins { _ => { new_fields.push((name.clone(), val.clone())); new_flds_pos_list.push((name_pos, val_pos)); - }, + } } } stack.push((Rc::new(C(Tuple(new_fields, new_flds_pos_list))), pos)); diff --git a/src/build/opcode/vm.rs b/src/build/opcode/vm.rs index 4115cc0..4920cb0 100644 --- a/src/build/opcode/vm.rs +++ b/src/build/opcode/vm.rs @@ -140,7 +140,7 @@ where } return C(Tuple(flds, pos_list)); } - + pub fn remove_symbol(&mut self, sym: &str) -> Option<(Rc, Position)> { self.symbols.remove_symbol(sym) } diff --git a/src/build/scope.rs b/src/build/scope.rs index f439097..9f9ca26 100644 --- a/src/build/scope.rs +++ b/src/build/scope.rs @@ -165,11 +165,7 @@ impl Scope { } } } - Val::Boolean(_) - | Val::Empty - | Val::Float(_) - | Val::Int(_) - | Val::Str(_) => { + Val::Boolean(_) | Val::Empty | Val::Float(_) | Val::Int(_) | Val::Str(_) => { // noop } }; diff --git a/src/main.rs b/src/main.rs index c0c795b..f5639d0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,7 +28,7 @@ use std::process; use std::rc::Rc; use ucglib::build; -use ucglib::build::assets::{MemoryCache}; +use ucglib::build::assets::MemoryCache; use ucglib::convert::{ConverterRegistry, ImporterRegistry}; use ucglib::iter::OffsetStrIter; use ucglib::parse::parse; diff --git a/src/parse/mod.rs b/src/parse/mod.rs index 18751e6..6fc8585 100644 --- a/src/parse/mod.rs +++ b/src/parse/mod.rs @@ -472,50 +472,50 @@ make_fn!( ); //fn select_expression(input: SliceIter) -> Result, Expression> { - //let parsed = do_each!(input, - //_ => word!("select"), - //val => do_each!( - //expr => wrap_err!( - //trace_parse!(must!(expression)), - //"Did you forget a comma after your selector value?"), - //_ => must!(punct!(",")), - //(expr) - //), - //default_and_map => either!( - //do_each!( - //default => do_each!( - //expr => trace_parse!(expression), - //_ => punct!(","), - //(expr) - //), - //map => trace_parse!(must!(tuple)), - //(Some(default), map) - //), - //do_each!( - //map => wrap_err!( - //trace_parse!(must!(tuple)), - //"Did you forget a comma after your default value?" - //), - //(None, map) - //) - //), - //(val, default_and_map.0, default_and_map.1) - //); - //match parsed { - //Result::Abort(e) => Result::Abort(e), - //Result::Fail(e) => Result::Fail(e), - //Result::Incomplete(offset) => Result::Incomplete(offset), - //Result::Complete(rest, (val, default, map)) => { - //match tuple_to_select(input.clone(), val, default, map) { - //Ok(expr) => Result::Complete(rest, expr), - //Err(e) => Result::Fail(Error::caused_by( - //"Invalid Select Expression", - //Box::new(e), - //Box::new(rest.clone()), - //)), - //} - //} - //} +//let parsed = do_each!(input, +//_ => word!("select"), +//val => do_each!( +//expr => wrap_err!( +//trace_parse!(must!(expression)), +//"Did you forget a comma after your selector value?"), +//_ => must!(punct!(",")), +//(expr) +//), +//default_and_map => either!( +//do_each!( +//default => do_each!( +//expr => trace_parse!(expression), +//_ => punct!(","), +//(expr) +//), +//map => trace_parse!(must!(tuple)), +//(Some(default), map) +//), +//do_each!( +//map => wrap_err!( +//trace_parse!(must!(tuple)), +//"Did you forget a comma after your default value?" +//), +//(None, map) +//) +//), +//(val, default_and_map.0, default_and_map.1) +//); +//match parsed { +//Result::Abort(e) => Result::Abort(e), +//Result::Fail(e) => Result::Fail(e), +//Result::Incomplete(offset) => Result::Incomplete(offset), +//Result::Complete(rest, (val, default, map)) => { +//match tuple_to_select(input.clone(), val, default, map) { +//Ok(expr) => Result::Complete(rest, expr), +//Err(e) => Result::Fail(Error::caused_by( +//"Invalid Select Expression", +//Box::new(e), +//Box::new(rest.clone()), +//)), +//} +//} +//} //} make_fn!(