rustfmt previous commit
This commit is contained in:
parent
dc6342bc74
commit
ca9f755d50
10 changed files with 144 additions and 123 deletions
|
|
@ -62,7 +62,7 @@ fn main() {
|
|||
match user_doc {
|
||||
Ok(line) => {
|
||||
rl.add_history_entry(line.as_str());
|
||||
let l = line.as_str().to_owned();
|
||||
let l = line.as_str().to_owned();
|
||||
|
||||
match lex(&l) {
|
||||
Ok(a) => match eval(&a, &mut syms) {
|
||||
|
|
|
|||
|
|
@ -30,18 +30,18 @@ fn prompt_default_callback(_: &Seg, _: &mut SymTable) -> Result<Ctr, 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.
|
||||
"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: not set".to_string(),
|
||||
value: ValueType::VarForm(Box::new(Ctr::String("0".to_string()))),
|
||||
},
|
||||
);*/
|
||||
default value: not set".to_string(),
|
||||
value: ValueType::VarForm(Box::new(Ctr::String("0".to_string()))),
|
||||
},
|
||||
);*/
|
||||
|
||||
syms.insert(
|
||||
"CFG_RELISH_ENV".to_string(),
|
||||
|
|
@ -66,7 +66,8 @@ default value: 1 (set)
|
|||
args: Args::None,
|
||||
conditional_branches: false,
|
||||
docs: "function called to output prompt. this function is called with no arguments.
|
||||
default value (<lambda>)".to_string(),
|
||||
default value (<lambda>)"
|
||||
.to_string(),
|
||||
value: ValueType::Internal(Rc::new(prompt_default_callback)),
|
||||
},
|
||||
);
|
||||
|
|
|
|||
58
src/stl.rs
58
src/stl.rs
|
|
@ -89,7 +89,8 @@ example: (let ((step1 'hello')
|
|||
In this example step1, step2, and step3 are created sequentially.
|
||||
Then, the echo form is evaluated, printing 'hello-world'.
|
||||
Finally, the some-func form is evaluated.
|
||||
Since the call to some-func is the final form, its value is returned.".to_string(),
|
||||
Since the call to some-func is the final form, its value is returned."
|
||||
.to_string(),
|
||||
value: ValueType::Internal(Rc::new(control::let_callback)),
|
||||
},
|
||||
);
|
||||
|
|
@ -126,7 +127,8 @@ example: (circuit (eq? (do-operation) myresult)
|
|||
false
|
||||
(do-another-operation))
|
||||
|
||||
in this example, do-another-operation will not be called".to_string(),
|
||||
in this example, do-another-operation will not be called"
|
||||
.to_string(),
|
||||
value: ValueType::Internal(Rc::new(control::circuit_callback)),
|
||||
},
|
||||
);
|
||||
|
|
@ -139,7 +141,8 @@ in this example, do-another-operation will not be called".to_string(),
|
|||
conditional_branches: false,
|
||||
docs: "traverses a list of N arguments, all of which are expected to be boolean.
|
||||
starts with arg1 AND arg2, and then calculates prev_result AND next_arg.
|
||||
returns final result.".to_string(),
|
||||
returns final result."
|
||||
.to_string(),
|
||||
value: ValueType::Internal(Rc::new(boolean::bool_and_callback)),
|
||||
},
|
||||
);
|
||||
|
|
@ -152,7 +155,8 @@ returns final result.".to_string(),
|
|||
conditional_branches: false,
|
||||
docs: "traverses a list of N arguments, all of which are expected to be boolean.
|
||||
starts with arg1 OR arg2, and then calculates prev_result OR next_arg.
|
||||
returns final result.".to_string(),
|
||||
returns final result."
|
||||
.to_string(),
|
||||
value: ValueType::Internal(Rc::new(boolean::bool_or_callback)),
|
||||
},
|
||||
);
|
||||
|
|
@ -164,7 +168,8 @@ returns final result.".to_string(),
|
|||
args: Args::Strict(vec![Type::Bool]),
|
||||
conditional_branches: false,
|
||||
docs: "takes a single argument (expects a boolean).
|
||||
returns false if arg is true or true if arg is false.".to_string(),
|
||||
returns false if arg is true or true if arg is false."
|
||||
.to_string(),
|
||||
value: ValueType::Internal(Rc::new(boolean::bool_not_callback)),
|
||||
},
|
||||
);
|
||||
|
|
@ -177,7 +182,8 @@ returns false if arg is true or true if arg is false.".to_string(),
|
|||
conditional_branches: false,
|
||||
docs: "traverses a list of N arguments.
|
||||
returns true if all arguments hold the same value.
|
||||
NOTE: 1 and 1.0 are the same, but '1' 'one' or one (symbol) aren't".to_string(),
|
||||
NOTE: 1 and 1.0 are the same, but '1' 'one' or one (symbol) aren't"
|
||||
.to_string(),
|
||||
value: ValueType::Internal(Rc::new(boolean::bool_iseq_callback)),
|
||||
},
|
||||
);
|
||||
|
|
@ -190,7 +196,8 @@ NOTE: 1 and 1.0 are the same, but '1' 'one' or one (symbol) aren't".to_string(),
|
|||
conditional_branches: true,
|
||||
docs: "switches a boolean symbol between true or false.
|
||||
Takes a single argument (a symbol). Looks it up in the variable table.
|
||||
Either sets the symbol to true if it is currently false, or vice versa.".to_string(),
|
||||
Either sets the symbol to true if it is currently false, or vice versa."
|
||||
.to_string(),
|
||||
value: ValueType::Internal(Rc::new(boolean::bool_toggle_callback)),
|
||||
},
|
||||
);
|
||||
|
|
@ -237,7 +244,8 @@ pub fn dynamic_stdlib(syms: &mut SymTable) -> Result<(), String> {
|
|||
(def myfunc 'does a thing' (myarg1 myarg2) (dothing myarg1 myarg2) (add myarg1 myarg2))
|
||||
3. symbol un-definition:
|
||||
Takes just a name. Removes variable from table.
|
||||
(def useless-var)".to_string(),
|
||||
(def useless-var)"
|
||||
.to_string(),
|
||||
value: ValueType::Internal(Rc::new(
|
||||
move |ast: &Seg, syms: &mut SymTable| -> Result<Ctr, String> {
|
||||
_store_callback(ast, syms, env_cfg_user_form)
|
||||
|
|
@ -261,7 +269,7 @@ fn _echo_callback(ast: &Seg, _syms: &mut SymTable) -> Result<Ctr, String> {
|
|||
|
||||
fn _help_callback(ast: &Seg, syms: &mut SymTable) -> Result<Ctr, String> {
|
||||
if ast.len() != 1 {
|
||||
return Err("help only takes a single argument".to_string())
|
||||
return Err("help only takes a single argument".to_string());
|
||||
}
|
||||
if let Ctr::Symbol(ref symbol) = *ast.car {
|
||||
if let Some(ref sym) = syms.get(symbol) {
|
||||
|
|
@ -271,17 +279,20 @@ fn _help_callback(ast: &Seg, syms: &mut SymTable) -> Result<Ctr, String> {
|
|||
} else {
|
||||
args_str = sym.args.to_string();
|
||||
}
|
||||
println!("NAME: {0}\n
|
||||
println!(
|
||||
"NAME: {0}\n
|
||||
ARGS: {1}\n
|
||||
DOCUMENTATION:\n
|
||||
{2}\n
|
||||
CURRENT VALUE AND/OR BODY:
|
||||
(TODO)", sym.name, args_str, sym.docs);
|
||||
(TODO)",
|
||||
sym.name, args_str, sym.docs
|
||||
);
|
||||
} else {
|
||||
return Err("undefined symbol".to_string())
|
||||
return Err("undefined symbol".to_string());
|
||||
}
|
||||
} else {
|
||||
return Err("help should only be called on a symbol".to_string())
|
||||
return Err("help should only be called on a symbol".to_string());
|
||||
}
|
||||
|
||||
Ok(Ctr::None)
|
||||
|
|
@ -293,7 +304,7 @@ fn _store_callback(ast: &Seg, syms: &mut SymTable, env_cfg: bool) -> Result<Ctr,
|
|||
match &*ast.cdr {
|
||||
// define a symbol
|
||||
Ctr::Seg(doc_tree) => {
|
||||
if let Ctr::String(ref doc) = *doc_tree.car {
|
||||
if let Ctr::String(ref doc) = *doc_tree.car {
|
||||
match &*doc_tree.cdr {
|
||||
// define a variable
|
||||
Ctr::Seg(data_tree) if is_var => match eval(&Box::new(data_tree), syms) {
|
||||
|
|
@ -336,7 +347,8 @@ fn _store_callback(ast: &Seg, syms: &mut SymTable, env_cfg: bool) -> Result<Ctr,
|
|||
}
|
||||
}) {
|
||||
return Err(
|
||||
"all arguments defined for function must be of type symbol".to_string()
|
||||
"all arguments defined for function must be of type symbol"
|
||||
.to_string(),
|
||||
);
|
||||
};
|
||||
|
||||
|
|
@ -361,17 +373,19 @@ fn _store_callback(ast: &Seg, syms: &mut SymTable, env_cfg: bool) -> Result<Ctr,
|
|||
);
|
||||
}
|
||||
} else {
|
||||
return Err("expected list of arguments in function definition".to_string());
|
||||
return Err(
|
||||
"expected list of arguments in function definition".to_string()
|
||||
);
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
// theres a name and a doc string but nothing else
|
||||
_ => return Err("have name and doc string, but no body.".to_string())
|
||||
_ => return Err("have name and doc string, but no body.".to_string()),
|
||||
}
|
||||
} else {
|
||||
return Err("doc string is a required argument".to_string())
|
||||
return Err("doc string is a required argument".to_string());
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
// undefine a symbol
|
||||
Ctr::None => {
|
||||
|
|
@ -379,12 +393,12 @@ fn _store_callback(ast: &Seg, syms: &mut SymTable, env_cfg: bool) -> Result<Ctr,
|
|||
if env_cfg {
|
||||
env::remove_var(identifier);
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
_ => return Err("arguments not in standard form".to_string()),
|
||||
}
|
||||
} else {
|
||||
return Err("first argument to export must be a symbol".to_string())
|
||||
return Err("first argument to export must be a symbol".to_string());
|
||||
}
|
||||
Ok(Ctr::None)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@
|
|||
use crate::eval::eval;
|
||||
use crate::segment::{Ctr, Seg, Type};
|
||||
use std::collections::HashMap;
|
||||
use std::rc::Rc;
|
||||
use std::fmt;
|
||||
use std::rc::Rc;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct SymTable(HashMap<String, Symbol>);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue