refmt
This commit is contained in:
parent
f805290a4b
commit
be73b0b828
17 changed files with 588 additions and 675 deletions
|
|
@ -15,15 +15,15 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use dirs::home_dir;
|
||||
use relish::ast::{ast_to_string, eval, func_call, lex, new_ast, Ctr, FTable, VTable};
|
||||
use relish::aux::configure;
|
||||
use relish::stdlib::get_stdlib;
|
||||
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, new_ast, func_call};
|
||||
use relish::aux::configure;
|
||||
use relish::stdlib::{get_stdlib};
|
||||
use std::env;
|
||||
use std::rc::Rc;
|
||||
|
||||
fn main() {
|
||||
let mut rl = Editor::<()>::new();
|
||||
|
|
@ -52,12 +52,12 @@ fn main() {
|
|||
|
||||
match env::var("RELISH_CFG_FILE") {
|
||||
Ok(s) => configure(s, vt.clone(), ft.clone()),
|
||||
Err(_) => configure(cfg, vt.clone(), ft.clone())
|
||||
Err(_) => configure(cfg, vt.clone(), ft.clone()),
|
||||
}
|
||||
|
||||
match get_stdlib(vt.clone()) {
|
||||
Ok(f) => ft = f,
|
||||
Err(s) => println!("{}", s)
|
||||
Err(s) => println!("{}", s),
|
||||
}
|
||||
|
||||
loop {
|
||||
|
|
@ -68,23 +68,26 @@ fn main() {
|
|||
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()) {
|
||||
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("")
|
||||
}
|
||||
}
|
||||
|
||||
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("");
|
||||
|
|
@ -103,40 +106,32 @@ fn main() {
|
|||
}
|
||||
|
||||
match lex(l) {
|
||||
Ok(a) => {
|
||||
match eval(a.clone(), vt.clone(), ft.clone(), false) {
|
||||
Ok(a) => {
|
||||
match a {
|
||||
Ctr::Symbol(s) => println!("{}", s),
|
||||
Ctr::String(s) => println!("{}", s),
|
||||
Ctr::Integer(i) => println!("{}", i),
|
||||
Ctr::Float(f) => println!("{}", f),
|
||||
Ctr::Bool(b) => println!("{}", b),
|
||||
Ctr::Seg(c) => println!("{}", ast_to_string(c.clone())),
|
||||
Ctr::None => ()
|
||||
}
|
||||
},
|
||||
Err(s) => {
|
||||
println!("{}", s);
|
||||
}
|
||||
Ok(a) => match eval(a.clone(), vt.clone(), ft.clone(), false) {
|
||||
Ok(a) => match a {
|
||||
Ctr::Symbol(s) => println!("{}", s),
|
||||
Ctr::String(s) => println!("{}", s),
|
||||
Ctr::Integer(i) => println!("{}", i),
|
||||
Ctr::Float(f) => println!("{}", f),
|
||||
Ctr::Bool(b) => println!("{}", b),
|
||||
Ctr::Seg(c) => println!("{}", ast_to_string(c.clone())),
|
||||
Ctr::None => (),
|
||||
},
|
||||
Err(s) => {
|
||||
println!("{}", s);
|
||||
}
|
||||
},
|
||||
Err(s) => {
|
||||
println!("{}", s);
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
Err(ReadlineError::Interrupted) => {
|
||||
break
|
||||
},
|
||||
Err(ReadlineError::Interrupted) => break,
|
||||
|
||||
Err(ReadlineError::Eof) => {
|
||||
return
|
||||
},
|
||||
Err(ReadlineError::Eof) => return,
|
||||
Err(err) => {
|
||||
eprintln!("Prompt error: {:?}", err);
|
||||
break
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue