flesh out todo list, better configure code
Signed-off-by: Ava Hahn <ava@aidanis.online>
This commit is contained in:
parent
d296eb4510
commit
e7dd0caa4a
4 changed files with 64 additions and 26 deletions
|
|
@ -30,7 +30,9 @@ fn prompt_default_callback(_: Ast, _: Rc<RefCell<VTable>>, _: Rc<RefCell<FTable>
|
|||
return Ctr::None;
|
||||
}
|
||||
|
||||
pub fn configure(filename: String, vars: Rc<RefCell<VTable>>, mut funcs: Rc<RefCell<FTable>>) {
|
||||
pub fn configure(filename: String, vars: Rc<RefCell<VTable>>) -> Result<Rc<RefCell<FTable>>, String> {
|
||||
let funcs;
|
||||
|
||||
define(
|
||||
vars.clone(),
|
||||
String::from("CFG_RELISH_POSIX"),
|
||||
|
|
@ -44,10 +46,13 @@ pub fn configure(filename: String, vars: Rc<RefCell<VTable>>, mut funcs: Rc<RefC
|
|||
|
||||
match get_stdlib(vars.clone()) {
|
||||
Ok(f) => funcs = f,
|
||||
Err(s) => println!("{}", s),
|
||||
Err(s) => {
|
||||
funcs = Rc::new(RefCell::new(FTable::new()));
|
||||
println!("Couldnt get stdlib: {}", s)
|
||||
},
|
||||
}
|
||||
|
||||
func_declare(
|
||||
match func_declare(
|
||||
funcs.clone(),
|
||||
Rc::new(RefCell::new(Function {
|
||||
name: String::from("CFG_RELISH_PROMPT"),
|
||||
|
|
@ -56,31 +61,33 @@ pub fn configure(filename: String, vars: Rc<RefCell<VTable>>, mut funcs: Rc<RefC
|
|||
args: Args::Lazy(0),
|
||||
function: Operation::Internal(Box::new(prompt_default_callback)),
|
||||
})),
|
||||
);
|
||||
) {
|
||||
Some(e) => return Err(e),
|
||||
None => {},
|
||||
}
|
||||
|
||||
match fs::read_to_string(filename) {
|
||||
match fs::read_to_string(filename.clone()) {
|
||||
Err(s) => {
|
||||
eprintln!("Couldnt open configuration file: {}", s);
|
||||
return;
|
||||
return Err(format!("Couldnt open configuration file: {}", s));
|
||||
}
|
||||
|
||||
Ok(raw_config) => match lex(raw_config) {
|
||||
Err(s) => {
|
||||
println!("Error in configuration: {}", s);
|
||||
return;
|
||||
}
|
||||
Ok(raw_config) => {
|
||||
let mut l = raw_config;
|
||||
l = "(".to_owned() + &l + ")";
|
||||
|
||||
Ok(config) => match eval(config, vars, funcs, false) {
|
||||
match lex(l) {
|
||||
Err(s) => {
|
||||
println!("Error in applying configuration: {}", s);
|
||||
return;
|
||||
return Err(format!("Error in configuration: {}", s));
|
||||
}
|
||||
|
||||
Ok(ctr) => match ctr {
|
||||
Ctr::String(s) => println!("{}", s),
|
||||
_ => (),
|
||||
},
|
||||
},
|
||||
Ok(config) => {
|
||||
if let Err(errst) = eval(config, vars, funcs.clone(), false) {
|
||||
return Err(format!("Error loading {}: {}", filename.clone(), errst));
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
return Ok(funcs);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue