flesh out todo list, better configure code

Signed-off-by: Ava Hahn <ava@aidanis.online>
This commit is contained in:
Ava Hahn 2023-01-21 16:12:21 -08:00
parent d296eb4510
commit e7dd0caa4a
Signed by untrusted user who does not match committer: affine
GPG key ID: 3A4645B8CF806069
4 changed files with 64 additions and 26 deletions

View file

@ -47,12 +47,24 @@ fn main() {
}
let vt = Rc::new(RefCell::new(VTable::new()));
// if we fail to get stdlib we can just use this one
let mut ft = Rc::new(RefCell::new(FTable::new()));
let conf_file;
let mut ft;
match env::var("RELISH_CFG_FILE") {
Ok(s) => configure(s, vt.clone(), ft.clone()),
Err(_) => configure(cfg, vt.clone(), ft.clone()),
Ok(s) => {
conf_file = s
},
Err(e) => {
eprintln!("{}", e);
conf_file = cfg;
},
}
match configure(conf_file, vt.clone()) {
Ok(f) => ft = f,
Err(e) => {
ft = Rc::new(RefCell::new(FTable::new()));
eprintln!("{}", e);
},
}
match get_stdlib(vt.clone()) {

View file

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

View file

@ -27,6 +27,7 @@ pub type FTable = HashMap<String, Rc<RefCell<Function>>>;
// Standardized function signature for stdlib functions
//pub type InternalOperation = impl Fn(Ast, Rc<RefCell<VTable>>, Rc<RefCell<FTable>>) -> Ctr;
#[derive(Debug)]
pub struct ExternalOperation {
// Un-evaluated abstract syntax tree
// TODO: Intermediate evaluation to simplify branches with no argument in them