MAINT: cargo fmt

This commit is contained in:
Jeremy Wall 2019-11-03 14:20:25 -06:00
parent db9b7aef43
commit 34636a1743
11 changed files with 108 additions and 91 deletions

View File

@ -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;

View File

@ -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)?;

View File

@ -46,9 +46,7 @@ impl<'a> Entry<'a> {
path: P,
) -> Result<OpPointer, Error> {
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());

View File

@ -78,7 +78,9 @@ impl From<regex::Error> for Error {
impl From<std::io::Error> 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 {

View File

@ -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<P: Into<PathBuf>>(&self, base_path: P, path: &str, pos: Position) -> Result<String, Error> {
fn get_file_as_string<P: Into<PathBuf>>(
&self,
base_path: P,
path: &str,
pos: Position,
) -> Result<String, Error> {
let sep = format!("{}", std::path::MAIN_SEPARATOR);
let raw_path = path.replace("/", &sep);
// FIXME(jwall): import paths?
@ -186,34 +191,31 @@ impl Builtins {
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));

View File

@ -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
}
};

View File

@ -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;

View File

@ -472,50 +472,50 @@ make_fn!(
);
//fn select_expression(input: SliceIter<Token>) -> Result<SliceIter<Token>, 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!(