variable export and entire config system
This commit is contained in:
parent
0931fbdcf0
commit
307101327c
10 changed files with 184 additions and 21 deletions
|
|
@ -19,15 +19,17 @@ use rustyline::error::ReadlineError;
|
|||
use rustyline::Editor;
|
||||
use dirs::home_dir;
|
||||
use std::rc::Rc;
|
||||
use std::env;
|
||||
use std::cell::RefCell;
|
||||
use relish::ast::{VTable, FTable, Ctr, lex, eval, ast_to_string};
|
||||
use relish::ast::{VTable, FTable, Ctr, lex, eval, ast_to_string, new_ast, func_call};
|
||||
use relish::aux::configure;
|
||||
use relish::stdlib::{get_stdlib};
|
||||
|
||||
fn main() {
|
||||
let mut rl = Editor::<()>::new();
|
||||
|
||||
const HIST_FILE: &str = ".relish_hist";
|
||||
//const CONFIG_FILE: &str = ".relishrc";
|
||||
const CONFIG_FILE_DEFAULT: &str = ".relishrc";
|
||||
|
||||
let mut hist: String = "".to_owned();
|
||||
|
||||
|
|
@ -45,14 +47,47 @@ 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()));
|
||||
match get_stdlib() {
|
||||
|
||||
match env::var("RELISH_CFG_FILE") {
|
||||
Ok(s) => configure(s, vt.clone(), ft.clone()),
|
||||
Err(_) => configure(String::from(CONFIG_FILE_DEFAULT), vt.clone(), ft.clone())
|
||||
}
|
||||
|
||||
match get_stdlib(vt.clone()) {
|
||||
Ok(f) => ft = f,
|
||||
Err(s) => println!("{}", s)
|
||||
}
|
||||
|
||||
loop {
|
||||
// TODO: configurable prompt
|
||||
let readline = rl.readline("λ ");
|
||||
let readline: Result<String, ReadlineError>;
|
||||
// Rust is pain
|
||||
let tmp_ft_clone = ft.clone();
|
||||
// this is not okay
|
||||
let t_ft_c_b = tmp_ft_clone.borrow();
|
||||
let pfunc = t_ft_c_b.get("CFG_RELISH_PROMPT");
|
||||
if let Some(fnc) = pfunc {
|
||||
match func_call(fnc.clone(), new_ast(Ctr::None, Ctr::None), vt.clone(), ft.clone()) {
|
||||
Err(s) => {
|
||||
eprintln!("Couldnt generate prompt: {}", s);
|
||||
readline = rl.readline("");
|
||||
},
|
||||
|
||||
Ok(c) => {
|
||||
match c {
|
||||
Ctr::Symbol(s) => readline = rl.readline(&s.to_owned()),
|
||||
Ctr::String(s) => readline = rl.readline(&s),
|
||||
Ctr::Integer(i) => readline = rl.readline(&format!("{}", i)),
|
||||
Ctr::Float(f) => readline = rl.readline(&format!("{}", f)),
|
||||
Ctr::Bool(b) => readline = rl.readline(&format!("{}", b)),
|
||||
Ctr::Seg(c) => readline = rl.readline(&ast_to_string(c.clone())),
|
||||
Ctr::None => readline = rl.readline("")
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
readline = rl.readline("");
|
||||
}
|
||||
|
||||
match readline {
|
||||
Ok(line) => {
|
||||
rl.add_history_entry(line.as_str());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue