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

@ -11,6 +11,7 @@ https://gitlab.com/whom/shs
** To be as portable as possible
** To provide code and framework that can be embedded in other applications needing a user facing interpreter
** To be well tested code
** No unsafe code without extreme consideration and rigorous containment
* Current Status
*** DONE Core interpreter stuffs
@ -19,19 +20,36 @@ https://gitlab.com/whom/shs
**** DONE Evaluation
**** DONE Function table
**** DONE Variable table
*** DONE Echo function
In string lib
*** TODO Rudimentary Control Flow
**** TODO if clause
**** TODO loop clause
**** TODO while clause
**** TODO circuit clause
*** TODO Configuration
**** DONE Function to load configuration into Variable and Function tables
**** DONE Configure in main shell
**** DONE manual verification of config settings
**** FAILING manual verification of config defaults
Cannot get default CFG_RELISH_PROMPT. Unclear if this is a bug in FTable or config
*** TODO Help function
*** TODO Env function
*** TODO User variable declaration
*** TODO User function declaration
*** TODO Load (load a script) function
Pull/Refactor the logic out of the configure functions.
Optionally return a list of new variables and/or functions?
Will need a concatenate function for func tables
*** TODO Main shell calls Load function on arg and exits
*** TODO Shell module
**** TODO Process launching with environment variables
**** TODO Foreground process TTY
**** TODO Background processes
*** TODO Custom error printing
*** TODO Custom ast pretty print
*** TODO Implement Ctr, Ast to_string / Display trait
*** TODO get_stdlibphase1 -> configuration -> get_stdlibphase2
*** TODO STDLIB
**** DONE append
**** TODO string operations
@ -64,7 +82,7 @@ By default Relish will read from ~/.relishrc for configuration, but the default
*** The configuration file
The configuration file is a script containing arbitrary Relish code.
On start, any shell which leverages the configuration code in [the config module](src/config.rs) will create a clean seperate context, including default configuration values, within which the standard library will be initialized.
On start, any shell which leverages the configuration code in the config module (file:src/config.rs) will create a clean seperate context, including default configuration values, within which the standard library will be initialized.
The configuration file is evaluated and run as a standalone script and may include arbitrary executable code. Afterwards, configuration values found in the variable map will be used to configure the standard library function mappings that the shell will use.
Errors during configuration are non-terminal and will result in default values being returned.

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)),
})),
);
match fs::read_to_string(filename) {
Err(s) => {
eprintln!("Couldnt open configuration file: {}", s);
return;
) {
Some(e) => return Err(e),
None => {},
}
Ok(raw_config) => match lex(raw_config) {
match fs::read_to_string(filename.clone()) {
Err(s) => {
println!("Error in configuration: {}", s);
return;
return Err(format!("Couldnt open configuration file: {}", s));
}
Ok(config) => match eval(config, vars, funcs, false) {
Ok(raw_config) => {
let mut l = raw_config;
l = "(".to_owned() + &l + ")";
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