mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-22 18:19:54 -04:00
REFACTOR: More consistent naming for Builder methods.
This commit is contained in:
parent
960dbef591
commit
163420ff55
@ -245,9 +245,9 @@ impl Builder {
|
||||
}
|
||||
|
||||
/// 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() {
|
||||
try!(self.build_stmt(stmt));
|
||||
try!(self.eval_stmt(stmt));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@ -258,7 +258,7 @@ impl Builder {
|
||||
//panic!("Successfully parsed {}", input);
|
||||
let mut out: Option<Rc<Val>> = None;
|
||||
for stmt in stmts.iter() {
|
||||
out = Some(try!(self.build_stmt(stmt)));
|
||||
out = Some(try!(self.eval_stmt(stmt)));
|
||||
}
|
||||
match out {
|
||||
None => return Ok(Rc::new(Val::Empty)),
|
||||
@ -279,7 +279,7 @@ impl Builder {
|
||||
}
|
||||
|
||||
/// 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 s = String::new();
|
||||
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;
|
||||
// TODO(jwall): Enforce reserved word restriction here.
|
||||
if Self::check_reserved_word(&sym.fragment) {
|
||||
@ -340,7 +340,7 @@ impl Builder {
|
||||
Some(v) => v.clone(),
|
||||
None => {
|
||||
let mut b = Self::new(normalized.clone(), self.assets.clone());
|
||||
try!(b.build_file());
|
||||
try!(b.build());
|
||||
b.get_outputs_as_val()
|
||||
}
|
||||
};
|
||||
@ -358,7 +358,7 @@ impl Builder {
|
||||
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 name = &def.name;
|
||||
// TODO(jwall): Enforce the reserved words list here.
|
||||
@ -390,11 +390,11 @@ impl Builder {
|
||||
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 {
|
||||
&Statement::Assert(ref expr) => self.build_assert(&expr),
|
||||
&Statement::Let(ref def) => self.build_let(def),
|
||||
&Statement::Import(ref def) => self.build_import(def),
|
||||
&Statement::Let(ref def) => self.eval_let(def),
|
||||
&Statement::Import(ref def) => self.eval_import(def),
|
||||
&Statement::Expression(ref expr) => self.eval_expr(expr),
|
||||
// Only one output can be used per file. Right now we enforce this by
|
||||
// having a single builder per file.
|
||||
@ -1015,7 +1015,7 @@ impl 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
|
||||
// tuple using them.
|
||||
return Ok(b.get_outputs_as_val());
|
||||
|
@ -87,7 +87,7 @@ fn build_file(
|
||||
if validate {
|
||||
builder.enable_validate_mode();
|
||||
}
|
||||
try!(builder.build_file());
|
||||
try!(builder.build());
|
||||
if validate {
|
||||
println!("{}", builder.assert_collector.summary);
|
||||
}
|
||||
@ -231,7 +231,7 @@ fn inspect_command(
|
||||
match registry.get_converter(target) {
|
||||
Some(converter) => {
|
||||
// TODO(jwall): We should warn if this is a test file.
|
||||
let result = builder.build_file();
|
||||
let result = builder.build();
|
||||
if !result.is_ok() {
|
||||
eprintln!("{:?}", result.err().unwrap());
|
||||
process::exit(1);
|
||||
|
Loading…
x
Reference in New Issue
Block a user