refmt
This commit is contained in:
parent
f805290a4b
commit
be73b0b828
17 changed files with 588 additions and 675 deletions
|
|
@ -15,16 +15,15 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use crate::vars::{VTable, define};
|
||||
use crate::func::{FTable, Args, Function, Operation, func_declare};
|
||||
use crate::segment::{Ast, Ctr};
|
||||
use crate::lex::lex;
|
||||
use crate::eval::eval;
|
||||
use crate::func::{func_declare, Args, FTable, Function, Operation};
|
||||
use crate::lex::lex;
|
||||
use crate::segment::{Ast, Ctr};
|
||||
use crate::stl::get_stdlib;
|
||||
use std::rc::Rc;
|
||||
use crate::vars::{define, VTable};
|
||||
use std::cell::RefCell;
|
||||
use std::fs;
|
||||
|
||||
use std::rc::Rc;
|
||||
|
||||
fn prompt_default_callback(_: Ast, _: Rc<RefCell<VTable>>, _: Rc<RefCell<FTable>>) -> Ctr {
|
||||
print!("λ ");
|
||||
|
|
@ -32,52 +31,56 @@ fn prompt_default_callback(_: Ast, _: Rc<RefCell<VTable>>, _: Rc<RefCell<FTable>
|
|||
}
|
||||
|
||||
pub fn configure(filename: String, vars: Rc<RefCell<VTable>>, mut funcs: Rc<RefCell<FTable>>) {
|
||||
define(vars.clone(), String::from("CFG_RELISH_POSIX"), Rc::new(Ctr::String(String::from("0"))));
|
||||
define(vars.clone(), String::from("CFG_RELISH_ENV"), Rc::new(Ctr::String(String::from("1"))));
|
||||
define(
|
||||
vars.clone(),
|
||||
String::from("CFG_RELISH_POSIX"),
|
||||
Rc::new(Ctr::String(String::from("0"))),
|
||||
);
|
||||
define(
|
||||
vars.clone(),
|
||||
String::from("CFG_RELISH_ENV"),
|
||||
Rc::new(Ctr::String(String::from("1"))),
|
||||
);
|
||||
|
||||
match get_stdlib(vars.clone()) {
|
||||
Ok(f) => funcs = f,
|
||||
Err(s) => println!("{}", s)
|
||||
Err(s) => println!("{}", s),
|
||||
}
|
||||
|
||||
|
||||
func_declare(funcs.clone(), Rc::new(RefCell::new(Function{
|
||||
name: String::from("CFG_RELISH_PROMPT"),
|
||||
loose_syms: false,
|
||||
eval_lazy: false,
|
||||
args: Args::Lazy(0),
|
||||
function: Operation::Internal(Box::new(prompt_default_callback))
|
||||
})));
|
||||
func_declare(
|
||||
funcs.clone(),
|
||||
Rc::new(RefCell::new(Function {
|
||||
name: String::from("CFG_RELISH_PROMPT"),
|
||||
loose_syms: false,
|
||||
eval_lazy: false,
|
||||
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
|
||||
},
|
||||
|
||||
Ok(raw_config) => {
|
||||
match lex(raw_config) {
|
||||
Err(s) => {
|
||||
println!("Error in configuration: {}", s);
|
||||
return
|
||||
},
|
||||
|
||||
Ok(config) => {
|
||||
match eval(config, vars, funcs, false) {
|
||||
Err(s) => {
|
||||
println!("Error in applying configuration: {}", s);
|
||||
return
|
||||
},
|
||||
|
||||
Ok(ctr) => {
|
||||
match ctr {
|
||||
Ctr:: String(s) => println!("{}", s),
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
Ok(raw_config) => match lex(raw_config) {
|
||||
Err(s) => {
|
||||
println!("Error in configuration: {}", s);
|
||||
return;
|
||||
}
|
||||
|
||||
Ok(config) => match eval(config, vars, funcs, false) {
|
||||
Err(s) => {
|
||||
println!("Error in applying configuration: {}", s);
|
||||
return;
|
||||
}
|
||||
|
||||
Ok(ctr) => match ctr {
|
||||
Ctr::String(s) => println!("{}", s),
|
||||
_ => (),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue