From 05aa57ae7fe9234099abd40c532c8b1619ab7da6 Mon Sep 17 00:00:00 2001 From: Jeremy Wall Date: Mon, 31 Dec 2018 10:10:19 -0600 Subject: [PATCH] REFACTOR: Builder => FileBuilder --- src/build/compile_test.rs | 4 ++-- src/build/mod.rs | 10 +++++----- src/build/test.rs | 24 ++++++++++++------------ src/convert/exec.rs | 8 ++++---- src/lib.rs | 2 +- src/main.rs | 6 +++--- 6 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/build/compile_test.rs b/src/build/compile_test.rs index 468110e..3bf24bf 100644 --- a/src/build/compile_test.rs +++ b/src/build/compile_test.rs @@ -16,12 +16,12 @@ use std::cell::RefCell; use std::rc::Rc; use super::assets::MemoryCache; -use super::Builder; +use super::FileBuilder; fn assert_build(input: &str) { let i_paths = Vec::new(); let cache = MemoryCache::new(); - let mut b = Builder::new("", &i_paths, Rc::new(RefCell::new(cache))); + let mut b = FileBuilder::new("", &i_paths, Rc::new(RefCell::new(cache))); b.enable_validate_mode(); b.eval_string(input).unwrap(); if !b.assert_collector.success { diff --git a/src/build/mod.rs b/src/build/mod.rs index 2440808..cba694e 100644 --- a/src/build/mod.rs +++ b/src/build/mod.rs @@ -43,7 +43,7 @@ impl MacroDef { pub fn eval( &self, root: PathBuf, - parent_builder: &Builder, + parent_builder: &FileBuilder, mut args: Vec>, ) -> Result, Rc)>, Box> { // Error conditions. If the args don't match the length and types of the argdefs then this is @@ -93,7 +93,7 @@ pub struct AssertCollector { } /// Builder handles building ucg code for a single file. -pub struct Builder<'a> { +pub struct FileBuilder<'a> { file: PathBuf, import_path: &'a Vec, validate_mode: bool, @@ -139,7 +139,7 @@ macro_rules! eval_binary_expr { }; } -impl<'a> Builder<'a> { +impl<'a> FileBuilder<'a> { /// Constructs a new Builder. pub fn new>( file: P, @@ -174,7 +174,7 @@ impl<'a> Builder<'a> { env: Rc, ) -> Self { let file = file.into(); - Builder { + FileBuilder { // Our import stack is initialized with ourself. import_stack: vec![file.to_string_lossy().to_string()], file: file, @@ -197,7 +197,7 @@ impl<'a> Builder<'a> { } pub fn clone_builder>(&self, file: P) -> Self { - Builder { + FileBuilder { // Our import stack is initialized with ourself. import_stack: self.import_stack.clone(), file: file.into(), diff --git a/src/build/test.rs b/src/build/test.rs index d1b61ad..9aabfd4 100644 --- a/src/build/test.rs +++ b/src/build/test.rs @@ -12,14 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. use super::assets::MemoryCache; -use super::{Builder, CallDef, MacroDef, SelectDef, Val}; +use super::{CallDef, FileBuilder, MacroDef, SelectDef, Val}; use crate::ast::*; use std; use std::cell::RefCell; use std::rc::Rc; -fn test_expr_to_val(mut cases: Vec<(Expression, Val)>, mut b: Builder) { +fn test_expr_to_val(mut cases: Vec<(Expression, Val)>, mut b: FileBuilder) { for tpl in cases.drain(0..) { assert_eq!(b.eval_expr(&tpl.0).unwrap(), Rc::new(tpl.1)); } @@ -30,7 +30,7 @@ fn test_expr_to_val(mut cases: Vec<(Expression, Val)>, mut b: Builder) { fn test_eval_div_expr_fail() { let i_paths = Vec::new(); let cache = Rc::new(RefCell::new(MemoryCache::new())); - let b = Builder::new(std::env::current_dir().unwrap(), &i_paths, cache); + let b = FileBuilder::new(std::env::current_dir().unwrap(), &i_paths, cache); test_expr_to_val( vec![( Expression::Binary(BinaryOpDef { @@ -56,7 +56,7 @@ fn test_eval_div_expr_fail() { fn test_eval_mul_expr_fail() { let i_paths = Vec::new(); let cache = Rc::new(RefCell::new(MemoryCache::new())); - let b = Builder::new(std::env::current_dir().unwrap(), &i_paths, cache); + let b = FileBuilder::new(std::env::current_dir().unwrap(), &i_paths, cache); test_expr_to_val( vec![( Expression::Binary(BinaryOpDef { @@ -82,7 +82,7 @@ fn test_eval_mul_expr_fail() { fn test_eval_subtract_expr_fail() { let i_paths = Vec::new(); let cache = Rc::new(RefCell::new(MemoryCache::new())); - let b = Builder::new(std::env::current_dir().unwrap(), &i_paths, cache); + let b = FileBuilder::new(std::env::current_dir().unwrap(), &i_paths, cache); test_expr_to_val( vec![( Expression::Binary(BinaryOpDef { @@ -107,7 +107,7 @@ fn test_eval_subtract_expr_fail() { fn test_eval_add_expr_fail() { let i_paths = Vec::new(); let cache = Rc::new(RefCell::new(MemoryCache::new())); - let b = Builder::new(std::env::current_dir().unwrap(), &i_paths, cache); + let b = FileBuilder::new(std::env::current_dir().unwrap(), &i_paths, cache); test_expr_to_val( vec![( Expression::Binary(BinaryOpDef { @@ -132,7 +132,7 @@ fn test_eval_add_expr_fail() { fn test_eval_simple_lookup_error() { let i_paths = Vec::new(); let cache = Rc::new(RefCell::new(MemoryCache::new())); - let mut b = Builder::new(std::env::current_dir().unwrap(), &i_paths, cache); + let mut b = FileBuilder::new(std::env::current_dir().unwrap(), &i_paths, cache); b.build_output .entry(value_node!("var1".to_string(), Position::new(1, 0, 0))) .or_insert(Rc::new(Val::Int(1))); @@ -149,7 +149,7 @@ fn test_eval_simple_lookup_error() { fn test_expr_copy_no_such_tuple() { let i_paths = Vec::new(); let cache = Rc::new(RefCell::new(MemoryCache::new())); - let b = Builder::new(std::env::current_dir().unwrap(), &i_paths, cache); + let b = FileBuilder::new(std::env::current_dir().unwrap(), &i_paths, cache); test_expr_to_val( vec![( Expression::Copy(CopyDef { @@ -171,7 +171,7 @@ fn test_expr_copy_no_such_tuple() { fn test_expr_copy_not_a_tuple() { let i_paths = Vec::new(); let cache = Rc::new(RefCell::new(MemoryCache::new())); - let mut b = Builder::new(std::env::current_dir().unwrap(), &i_paths, cache); + let mut b = FileBuilder::new(std::env::current_dir().unwrap(), &i_paths, cache); b.build_output .entry(value_node!("tpl1".to_string(), Position::new(1, 0, 0))) .or_insert(Rc::new(Val::Int(1))); @@ -196,7 +196,7 @@ fn test_expr_copy_not_a_tuple() { fn test_expr_copy_field_type_error() { let i_paths = Vec::new(); let cache = Rc::new(RefCell::new(MemoryCache::new())); - let mut b = Builder::new(std::env::current_dir().unwrap(), &i_paths, cache); + let mut b = FileBuilder::new(std::env::current_dir().unwrap(), &i_paths, cache); b.build_output .entry(value_node!("tpl1".to_string(), Position::new(1, 0, 0))) .or_insert(Rc::new(Val::Tuple(vec![( @@ -233,7 +233,7 @@ fn test_expr_copy_field_type_error() { fn test_macro_hermetic() { let i_paths = Vec::new(); let cache = Rc::new(RefCell::new(MemoryCache::new())); - let mut b = Builder::new(std::env::current_dir().unwrap(), &i_paths, cache); + let mut b = FileBuilder::new(std::env::current_dir().unwrap(), &i_paths, cache); b.build_output .entry(value_node!("arg1".to_string(), Position::new(1, 0, 0))) .or_insert(Rc::new(Val::Str("bar".to_string()))); @@ -277,7 +277,7 @@ fn test_macro_hermetic() { fn test_select_expr_not_a_string() { let i_paths = Vec::new(); let cache = Rc::new(RefCell::new(MemoryCache::new())); - let mut b = Builder::new(std::env::current_dir().unwrap(), &i_paths, cache); + let mut b = FileBuilder::new(std::env::current_dir().unwrap(), &i_paths, cache); b.build_output .entry(value_node!("foo".to_string(), Position::new(1, 0, 0))) .or_insert(Rc::new(Val::Int(4))); diff --git a/src/convert/exec.rs b/src/convert/exec.rs index 547a167..b251713 100644 --- a/src/convert/exec.rs +++ b/src/convert/exec.rs @@ -196,7 +196,7 @@ impl Converter for ExecConverter { mod exec_test { use super::*; use crate::build::assets::MemoryCache; - use crate::build::Builder; + use crate::build::FileBuilder; use crate::convert::traits::Converter; use std; @@ -207,7 +207,7 @@ mod exec_test { fn convert_just_command_test() { let i_paths = Vec::new(); let cache = Rc::new(RefCell::new(MemoryCache::new())); - let mut b = Builder::new(std::env::current_dir().unwrap(), &i_paths, cache); + let mut b = FileBuilder::new(std::env::current_dir().unwrap(), &i_paths, cache); let conv = ExecConverter::new(); b.eval_string( "let script = { @@ -229,7 +229,7 @@ mod exec_test { fn convert_command_with_env_test() { let i_paths = Vec::new(); let cache = Rc::new(RefCell::new(MemoryCache::new())); - let mut b = Builder::new(std::env::current_dir().unwrap(), &i_paths, cache); + let mut b = FileBuilder::new(std::env::current_dir().unwrap(), &i_paths, cache); let conv = ExecConverter::new(); b.eval_string( "let script = { @@ -258,7 +258,7 @@ mod exec_test { fn convert_command_with_arg_test() { let i_paths = Vec::new(); let cache = Rc::new(RefCell::new(MemoryCache::new())); - let mut b = Builder::new(std::env::current_dir().unwrap(), &i_paths, cache); + let mut b = FileBuilder::new(std::env::current_dir().unwrap(), &i_paths, cache); let conv = ExecConverter::new(); b.eval_string( "let script = { diff --git a/src/lib.rs b/src/lib.rs index 2aad197..58ab485 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -44,6 +44,6 @@ pub use crate::ast::Expression; pub use crate::ast::Statement; pub use crate::ast::Value; -pub use crate::build::Builder; +pub use crate::build::FileBuilder; pub use crate::build::Val; pub use crate::parse::parse; diff --git a/src/main.rs b/src/main.rs index 6d6eb00..241a066 100644 --- a/src/main.rs +++ b/src/main.rs @@ -80,12 +80,12 @@ fn build_file<'a>( strict: bool, import_paths: &'a Vec, cache: Rc>, -) -> Result, Box> { +) -> Result, Box> { let mut file_path_buf = PathBuf::from(file); if file_path_buf.is_relative() { file_path_buf = std::env::current_dir().unwrap().join(file_path_buf); } - let mut builder = build::Builder::new(file_path_buf, import_paths, cache); + let mut builder = build::FileBuilder::new(file_path_buf, import_paths, cache); builder.set_strict(strict); if validate { builder.enable_validate_mode(); @@ -243,7 +243,7 @@ fn inspect_command( let file = matches.value_of("INPUT").unwrap(); let sym = matches.value_of("sym"); let target = matches.value_of("target").unwrap(); - let mut builder = build::Builder::new(file, import_paths, cache); + let mut builder = build::FileBuilder::new(file, import_paths, cache); builder.set_strict(strict); match registry.get_converter(target) { Some(converter) => {