got all the load script stuff done.

added script args to main shell
also added userlib tests to ci
This commit is contained in:
Ava Apples Affine 2023-03-20 19:00:30 -07:00
parent 381852b3bd
commit 3f75157fac
Signed by: affine
GPG key ID: 3A4645B8CF806069
7 changed files with 122 additions and 49 deletions

View file

@ -1,88 +0,0 @@
/* relish: versatile lisp shell
* Copyright (C) 2021 Aidan Hahn
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
use crate::eval::eval;
use crate::lex::lex;
use crate::segment::{Ctr, Seg};
use crate::sym::{Args, SymTable, Symbol, ValueType};
use std::fs;
use std::io;
use std::rc::Rc;
fn prompt_default_callback(_: &Seg, _: &mut SymTable) -> Result<Ctr, String> {
Ok(Ctr::Symbol("λ".to_string()))
}
/* loads defaults, evaluates config script */
pub fn configure(filename: String, syms: &mut SymTable) -> Result<(), String> {
syms.insert(
"CFG_RELISH_POSIX".to_string(),
Symbol {
name: String::from("CFG_RELISH_POSIX"),
args: Args::None,
conditional_branches: false,
docs: "variable holding whether or not POSIX job control functions are to be loaded.
checked at shell startup by configuration daemon. not used afterwards.
default value: false".to_string(),
value: ValueType::VarForm(Box::new(Ctr::Bool(false))),
..Default::default()
},
);
syms.insert(
"CFG_RELISH_ENV".to_string(),
Symbol {
name: String::from("CFG_RELISH_ENV"),
args: Args::None,
conditional_branches: false,
docs: "variable holding whether or not vars and other symbols should be linked to process environment variables.
If set/defined all calls to def will result in additions or subtractions from user environment variables.
checked at shell startup by configuration daemon. not used afterwards.
default value: 1 (set)
".to_string(),
value: ValueType::VarForm(Box::new(Ctr::Bool(true))),
..Default::default()
},
);
syms.insert(
"CFG_RELISH_PROMPT".to_string(),
Symbol {
name: String::from("default relish prompt"),
args: Args::None,
conditional_branches: false,
docs: "function called to output prompt. this function is called with no arguments.
default value (<lambda>)"
.to_string(),
value: ValueType::Internal(Rc::new(prompt_default_callback)),
..Default::default()
},
);
let mut config_document = fs::read_to_string(filename).unwrap_or_else(|err: io::Error| {
eprintln!("{}", err);
"".to_string()
}) + ")";
config_document = "(".to_string() + &config_document;
let config_tree = lex(&config_document)?;
eval(&config_tree, syms)?;
Ok(())
}