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
20
Readme.org
20
Readme.org
|
|
@ -11,6 +11,7 @@ https://gitlab.com/whom/shs
|
||||||
** To be as portable as possible
|
** To be as portable as possible
|
||||||
** To provide code and framework that can be embedded in other applications needing a user facing interpreter
|
** To provide code and framework that can be embedded in other applications needing a user facing interpreter
|
||||||
** To be well tested code
|
** To be well tested code
|
||||||
|
** No unsafe code without extreme consideration and rigorous containment
|
||||||
|
|
||||||
* Current Status
|
* Current Status
|
||||||
*** DONE Core interpreter stuffs
|
*** DONE Core interpreter stuffs
|
||||||
|
|
@ -19,19 +20,36 @@ https://gitlab.com/whom/shs
|
||||||
**** DONE Evaluation
|
**** DONE Evaluation
|
||||||
**** DONE Function table
|
**** DONE Function table
|
||||||
**** DONE Variable table
|
**** DONE Variable table
|
||||||
|
*** DONE Echo function
|
||||||
|
In string lib
|
||||||
*** TODO Rudimentary Control Flow
|
*** TODO Rudimentary Control Flow
|
||||||
**** TODO if clause
|
**** TODO if clause
|
||||||
**** TODO loop clause
|
**** TODO loop clause
|
||||||
**** TODO while clause
|
**** TODO while clause
|
||||||
**** TODO circuit clause
|
**** TODO circuit clause
|
||||||
*** TODO Configuration
|
*** 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 variable declaration
|
||||||
*** TODO User function 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 Shell module
|
||||||
**** TODO Process launching with environment variables
|
**** TODO Process launching with environment variables
|
||||||
**** TODO Foreground process TTY
|
**** TODO Foreground process TTY
|
||||||
**** TODO Background processes
|
**** TODO Background processes
|
||||||
*** TODO Custom error printing
|
*** 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
|
*** TODO STDLIB
|
||||||
**** DONE append
|
**** DONE append
|
||||||
**** TODO string operations
|
**** 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
|
||||||
The configuration file is a script containing arbitrary Relish code.
|
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.
|
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.
|
Errors during configuration are non-terminal and will result in default values being returned.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -47,12 +47,24 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
let vt = Rc::new(RefCell::new(VTable::new()));
|
let vt = Rc::new(RefCell::new(VTable::new()));
|
||||||
// if we fail to get stdlib we can just use this one
|
let conf_file;
|
||||||
let mut ft = Rc::new(RefCell::new(FTable::new()));
|
let mut ft;
|
||||||
|
|
||||||
match env::var("RELISH_CFG_FILE") {
|
match env::var("RELISH_CFG_FILE") {
|
||||||
Ok(s) => configure(s, vt.clone(), ft.clone()),
|
Ok(s) => {
|
||||||
Err(_) => configure(cfg, vt.clone(), ft.clone()),
|
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()) {
|
match get_stdlib(vt.clone()) {
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,9 @@ fn prompt_default_callback(_: Ast, _: Rc<RefCell<VTable>>, _: Rc<RefCell<FTable>
|
||||||
return Ctr::None;
|
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(
|
define(
|
||||||
vars.clone(),
|
vars.clone(),
|
||||||
String::from("CFG_RELISH_POSIX"),
|
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()) {
|
match get_stdlib(vars.clone()) {
|
||||||
Ok(f) => funcs = f,
|
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(),
|
funcs.clone(),
|
||||||
Rc::new(RefCell::new(Function {
|
Rc::new(RefCell::new(Function {
|
||||||
name: String::from("CFG_RELISH_PROMPT"),
|
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),
|
args: Args::Lazy(0),
|
||||||
function: Operation::Internal(Box::new(prompt_default_callback)),
|
function: Operation::Internal(Box::new(prompt_default_callback)),
|
||||||
})),
|
})),
|
||||||
);
|
) {
|
||||||
|
Some(e) => return Err(e),
|
||||||
match fs::read_to_string(filename) {
|
None => {},
|
||||||
Err(s) => {
|
|
||||||
eprintln!("Couldnt open configuration file: {}", s);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(raw_config) => match lex(raw_config) {
|
match fs::read_to_string(filename.clone()) {
|
||||||
Err(s) => {
|
Err(s) => {
|
||||||
println!("Error in configuration: {}", s);
|
return Err(format!("Couldnt open configuration file: {}", s));
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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) => {
|
Err(s) => {
|
||||||
println!("Error in applying configuration: {}", s);
|
return Err(format!("Error in configuration: {}", s));
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(ctr) => match ctr {
|
Ok(config) => {
|
||||||
Ctr::String(s) => println!("{}", s),
|
if let Err(errst) = eval(config, vars, funcs.clone(), false) {
|
||||||
_ => (),
|
return Err(format!("Error loading {}: {}", filename.clone(), errst));
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Ok(funcs);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ pub type FTable = HashMap<String, Rc<RefCell<Function>>>;
|
||||||
|
|
||||||
// Standardized function signature for stdlib functions
|
// Standardized function signature for stdlib functions
|
||||||
//pub type InternalOperation = impl Fn(Ast, Rc<RefCell<VTable>>, Rc<RefCell<FTable>>) -> Ctr;
|
//pub type InternalOperation = impl Fn(Ast, Rc<RefCell<VTable>>, Rc<RefCell<FTable>>) -> Ctr;
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct ExternalOperation {
|
pub struct ExternalOperation {
|
||||||
// Un-evaluated abstract syntax tree
|
// Un-evaluated abstract syntax tree
|
||||||
// TODO: Intermediate evaluation to simplify branches with no argument in them
|
// TODO: Intermediate evaluation to simplify branches with no argument in them
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue