Add simple string functions
This commit is contained in:
parent
8bf4b3c368
commit
d4121a734a
4 changed files with 366 additions and 190 deletions
63
src/stl.rs
63
src/stl.rs
|
|
@ -24,7 +24,7 @@ pub mod boolean;
|
|||
pub mod control;
|
||||
pub mod decl;
|
||||
pub mod math;
|
||||
//pub mod str;
|
||||
pub mod strings;
|
||||
|
||||
/// static_stdlib
|
||||
/// inserts all stdlib functions that can be inserted without
|
||||
|
|
@ -47,8 +47,52 @@ pub fn static_stdlib(syms: &mut SymTable) -> Result<(), String> {
|
|||
name: String::from("echo"),
|
||||
args: Args::Infinite,
|
||||
conditional_branches: false,
|
||||
docs: ECHO_DOCSTRING.to_string(),
|
||||
value: ValueType::Internal(Rc::new(_echo_callback)),
|
||||
docs: strings::ECHO_DOCSTRING.to_string(),
|
||||
value: ValueType::Internal(Rc::new(strings::echo_callback)),
|
||||
},
|
||||
);
|
||||
|
||||
syms.insert(
|
||||
"concat".to_string(),
|
||||
Symbol {
|
||||
name: String::from("concat"),
|
||||
args: Args::Infinite,
|
||||
conditional_branches: false,
|
||||
docs: strings::CONCAT_DOCSTRING.to_string(),
|
||||
value: ValueType::Internal(Rc::new(strings::concat_callback)),
|
||||
},
|
||||
);
|
||||
|
||||
syms.insert(
|
||||
"contains".to_string(),
|
||||
Symbol {
|
||||
name: String::from("contains"),
|
||||
args: Args::Strict(vec![Type::String, Type::String]),
|
||||
conditional_branches: false,
|
||||
docs: strings::CONTAINS_DOCSTRING.to_string(),
|
||||
value: ValueType::Internal(Rc::new(strings::contains_callback)),
|
||||
},
|
||||
);
|
||||
|
||||
syms.insert(
|
||||
"strlen".to_string(),
|
||||
Symbol {
|
||||
name: String::from("strlen"),
|
||||
args: Args::Lazy(1),
|
||||
conditional_branches: false,
|
||||
docs: strings::STRLEN_DOCSTRING.to_string(),
|
||||
value: ValueType::Internal(Rc::new(strings::strlen_callback)),
|
||||
},
|
||||
);
|
||||
|
||||
syms.insert(
|
||||
"string".to_string(),
|
||||
Symbol {
|
||||
name: String::from("string"),
|
||||
args: Args::Lazy(1),
|
||||
conditional_branches: false,
|
||||
docs: strings::STRCAST_DOCSTRING.to_string(),
|
||||
value: ValueType::Internal(Rc::new(strings::strcast_callback)),
|
||||
},
|
||||
);
|
||||
|
||||
|
|
@ -402,16 +446,3 @@ pub fn dynamic_stdlib(syms: &mut SymTable) -> Result<(), String> {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub const ECHO_DOCSTRING: &str =
|
||||
"traverses any number of arguments. Prints their evaluated values on a new line for each.";
|
||||
|
||||
fn _echo_callback(ast: &Seg, _syms: &mut SymTable) -> Result<Ctr, String> {
|
||||
if ast.len() == 1 {
|
||||
println!("{}", ast.car);
|
||||
} else {
|
||||
ast.circuit(&mut |arg: &Ctr| print!("{}", arg) == ());
|
||||
}
|
||||
|
||||
Ok(Ctr::None)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue