input function
This commit is contained in:
parent
df6b5b5f06
commit
1ce5fd3454
4 changed files with 35 additions and 5 deletions
|
|
@ -478,10 +478,6 @@ Note: this section only tracks the state of incomplete TODO items. Having everyt
|
||||||
|
|
||||||
** TODO Pre-alpha tasks
|
** TODO Pre-alpha tasks
|
||||||
- Shell prompt is fully configurable (History, L, R, and Delim)
|
- Shell prompt is fully configurable (History, L, R, and Delim)
|
||||||
- Input function
|
|
||||||
- Lex function
|
|
||||||
- Read function (Input + Lex)
|
|
||||||
- get type function
|
|
||||||
- Shell module
|
- Shell module
|
||||||
- Only loadable via POSIX config var
|
- Only loadable via POSIX config var
|
||||||
- Overload Load function to hook into this lib
|
- Overload Load function to hook into this lib
|
||||||
|
|
@ -499,6 +495,9 @@ Note: this section only tracks the state of incomplete TODO items. Having everyt
|
||||||
- Rename to Flesh
|
- Rename to Flesh
|
||||||
- master branch -> main branch
|
- master branch -> main branch
|
||||||
- Create a dedicated community channel on matrix.sunnypup.io
|
- Create a dedicated community channel on matrix.sunnypup.io
|
||||||
|
- get type function
|
||||||
|
- Lex function
|
||||||
|
- Read function (Input + Lex)
|
||||||
|
|
||||||
** TODO post-alpha tasks
|
** TODO post-alpha tasks
|
||||||
- Post to relevant channels
|
- Post to relevant channels
|
||||||
|
|
|
||||||
12
src/stl.rs
12
src/stl.rs
|
|
@ -595,6 +595,18 @@ pub fn static_stdlib(syms: &mut SymTable) -> Result<(), String> {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
syms.insert(
|
||||||
|
"input".to_string(),
|
||||||
|
Symbol {
|
||||||
|
name: String::from("input"),
|
||||||
|
args: Args::Strict(vec![Type::String]),
|
||||||
|
conditional_branches: false,
|
||||||
|
docs: strings::INPUT_DOCSTRING.to_string(),
|
||||||
|
value: ValueType::Internal(Rc::new(strings::input_callback)),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,8 @@
|
||||||
|
|
||||||
use crate::segment::{Ctr, Seg};
|
use crate::segment::{Ctr, Seg};
|
||||||
use crate::sym::SymTable;
|
use crate::sym::SymTable;
|
||||||
|
use std::io::Write;
|
||||||
|
use std::io;
|
||||||
|
|
||||||
pub const ECHO_DOCSTRING: &str =
|
pub const ECHO_DOCSTRING: &str =
|
||||||
"traverses any number of arguments. Prints their evaluated values on a new line for each.";
|
"traverses any number of arguments. Prints their evaluated values on a new line for each.";
|
||||||
|
|
@ -150,3 +152,19 @@ pub fn split_callback(ast: &Seg, _syms: &mut SymTable) -> Result<Ctr, String> {
|
||||||
|
|
||||||
Ok(Ctr::Seg(ret))
|
Ok(Ctr::Seg(ret))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub const INPUT_DOCSTRING: &str = "Takes one argument (string) and prints it.
|
||||||
|
Then prompts for user input.
|
||||||
|
User input is returned as a string";
|
||||||
|
|
||||||
|
pub fn input_callback(ast: &Seg, _syms: &mut SymTable) -> Result<Ctr, String> {
|
||||||
|
if let Ctr::String(ref s) = *ast.car {
|
||||||
|
print!("{}", s);
|
||||||
|
let _= io::stdout().flush();
|
||||||
|
let mut input = String::new();
|
||||||
|
io::stdin().read_line(&mut input).expect("couldnt read user input");
|
||||||
|
Ok(Ctr::String(input.trim().to_string()))
|
||||||
|
} else {
|
||||||
|
Err("impossible: arg not string".to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -101,10 +101,11 @@ impl SymTable {
|
||||||
* * sym is not in self
|
* * sym is not in self
|
||||||
* * sym has a newer generation than the entry in self
|
* * sym has a newer generation than the entry in self
|
||||||
*/
|
*/
|
||||||
|
let tmp = self.1;
|
||||||
for i in other.iter() {
|
for i in other.iter() {
|
||||||
self.0.entry(i.0.to_string())
|
self.0.entry(i.0.to_string())
|
||||||
.and_modify(|inner: &mut Symbol| {
|
.and_modify(|inner: &mut Symbol| {
|
||||||
if inner.__generation < i.1.__generation {
|
if tmp < i.1.__generation {
|
||||||
inner.__generation = i.1.__generation;
|
inner.__generation = i.1.__generation;
|
||||||
inner.value = i.1.value.clone();
|
inner.value = i.1.value.clone();
|
||||||
inner.args = i.1.args.clone();
|
inner.args = i.1.args.clone();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue