REFACTOR: More consistent naming for Builder methods.

This commit is contained in:
Jeremy Wall 2018-11-28 20:15:04 -06:00
parent 960dbef591
commit 163420ff55
2 changed files with 13 additions and 13 deletions

View File

@ -245,9 +245,9 @@ impl Builder {
} }
/// Builds a list of parsed UCG Statements. /// Builds a list of parsed UCG Statements.
pub fn build(&mut self, ast: &Vec<Statement>) -> BuildResult { pub fn eval_stmts(&mut self, ast: &Vec<Statement>) -> BuildResult {
for stmt in ast.iter() { for stmt in ast.iter() {
try!(self.build_stmt(stmt)); try!(self.eval_stmt(stmt));
} }
Ok(()) Ok(())
} }
@ -258,7 +258,7 @@ impl Builder {
//panic!("Successfully parsed {}", input); //panic!("Successfully parsed {}", input);
let mut out: Option<Rc<Val>> = None; let mut out: Option<Rc<Val>> = None;
for stmt in stmts.iter() { for stmt in stmts.iter() {
out = Some(try!(self.build_stmt(stmt))); out = Some(try!(self.eval_stmt(stmt)));
} }
match out { match out {
None => return Ok(Rc::new(Val::Empty)), None => return Ok(Rc::new(Val::Empty)),
@ -279,7 +279,7 @@ impl Builder {
} }
/// Builds a ucg file at the named path. /// Builds a ucg file at the named path.
pub fn build_file(&mut self) -> BuildResult { pub fn build(&mut self) -> BuildResult {
let mut f = try!(File::open(&self.file)); let mut f = try!(File::open(&self.file));
let mut s = String::new(); let mut s = String::new();
try!(f.read_to_string(&mut s)); try!(f.read_to_string(&mut s));
@ -310,7 +310,7 @@ impl Builder {
} }
} }
fn build_import(&mut self, def: &ImportDef) -> Result<Rc<Val>, Box<Error>> { fn eval_import(&mut self, def: &ImportDef) -> Result<Rc<Val>, Box<Error>> {
let sym = &def.name; let sym = &def.name;
// TODO(jwall): Enforce reserved word restriction here. // TODO(jwall): Enforce reserved word restriction here.
if Self::check_reserved_word(&sym.fragment) { if Self::check_reserved_word(&sym.fragment) {
@ -340,7 +340,7 @@ impl Builder {
Some(v) => v.clone(), Some(v) => v.clone(),
None => { None => {
let mut b = Self::new(normalized.clone(), self.assets.clone()); let mut b = Self::new(normalized.clone(), self.assets.clone());
try!(b.build_file()); try!(b.build());
b.get_outputs_as_val() b.get_outputs_as_val()
} }
}; };
@ -358,7 +358,7 @@ impl Builder {
return Ok(result); return Ok(result);
} }
fn build_let(&mut self, def: &LetDef) -> Result<Rc<Val>, Box<Error>> { fn eval_let(&mut self, def: &LetDef) -> Result<Rc<Val>, Box<Error>> {
let val = try!(self.eval_expr(&def.value)); let val = try!(self.eval_expr(&def.value));
let name = &def.name; let name = &def.name;
// TODO(jwall): Enforce the reserved words list here. // TODO(jwall): Enforce the reserved words list here.
@ -390,11 +390,11 @@ impl Builder {
Ok(val) Ok(val)
} }
fn build_stmt(&mut self, stmt: &Statement) -> Result<Rc<Val>, Box<Error>> { fn eval_stmt(&mut self, stmt: &Statement) -> Result<Rc<Val>, Box<Error>> {
match stmt { match stmt {
&Statement::Assert(ref expr) => self.build_assert(&expr), &Statement::Assert(ref expr) => self.build_assert(&expr),
&Statement::Let(ref def) => self.build_let(def), &Statement::Let(ref def) => self.eval_let(def),
&Statement::Import(ref def) => self.build_import(def), &Statement::Import(ref def) => self.eval_import(def),
&Statement::Expression(ref expr) => self.eval_expr(expr), &Statement::Expression(ref expr) => self.eval_expr(expr),
// Only one output can be used per file. Right now we enforce this by // Only one output can be used per file. Right now we enforce this by
// having a single builder per file. // having a single builder per file.
@ -1015,7 +1015,7 @@ impl Builder {
} }
} }
// 4. Evaluate all the statements using the builder. // 4. Evaluate all the statements using the builder.
try!(b.build(&mod_def.statements)); try!(b.eval_stmts(&mod_def.statements));
// 5. Take all of the bindings in the module and construct a new // 5. Take all of the bindings in the module and construct a new
// tuple using them. // tuple using them.
return Ok(b.get_outputs_as_val()); return Ok(b.get_outputs_as_val());

View File

@ -87,7 +87,7 @@ fn build_file(
if validate { if validate {
builder.enable_validate_mode(); builder.enable_validate_mode();
} }
try!(builder.build_file()); try!(builder.build());
if validate { if validate {
println!("{}", builder.assert_collector.summary); println!("{}", builder.assert_collector.summary);
} }
@ -231,7 +231,7 @@ fn inspect_command(
match registry.get_converter(target) { match registry.get_converter(target) {
Some(converter) => { Some(converter) => {
// TODO(jwall): We should warn if this is a test file. // TODO(jwall): We should warn if this is a test file.
let result = builder.build_file(); let result = builder.build();
if !result.is_ok() { if !result.is_ok() {
eprintln!("{:?}", result.err().unwrap()); eprintln!("{:?}", result.err().unwrap());
process::exit(1); process::exit(1);