mirror of
https://github.com/Dummi26/mers.git
synced 2025-03-10 05:43:53 +01:00
transform read_line to new func
This commit is contained in:
parent
a9e5f9209c
commit
25c605d801
@ -5,11 +5,13 @@ use std::{
|
||||
|
||||
use crate::{
|
||||
data::{self, Data, Type},
|
||||
errors::{CheckError, EColor},
|
||||
program::{self, run::CheckInfo},
|
||||
};
|
||||
|
||||
use super::Config;
|
||||
use super::{
|
||||
gen::{function::func, OneOrNone},
|
||||
Config,
|
||||
};
|
||||
|
||||
impl Config {
|
||||
/// `println: fn` prints to stdout and adds a newline to the end
|
||||
@ -19,33 +21,44 @@ impl Config {
|
||||
/// `debug: fn` debug-prints any value
|
||||
/// `read_line: fn` reads a line from stdin and returns it
|
||||
pub fn with_stdio(self) -> Self {
|
||||
self.add_var(
|
||||
self
|
||||
// .add_var(
|
||||
// "read_line",
|
||||
// data::function::Function {
|
||||
// info: program::run::Info::neverused(),
|
||||
// info_check: Arc::new(Mutex::new(CheckInfo::neverused())),
|
||||
// out: Ok(Arc::new(|a, _i| {
|
||||
// if a.is_zero_tuple() {
|
||||
// Ok(Type::newm(vec![
|
||||
// Arc::new(data::tuple::TupleT(vec![Type::new(data::string::StringT)])),
|
||||
// Arc::new(data::tuple::TupleT(vec![])),
|
||||
// ]))
|
||||
// } else {
|
||||
// Err(CheckError::new().msg(vec![
|
||||
// ("expected (), got ".to_owned(), None),
|
||||
// (a.to_string(), Some(EColor::FunctionArgument)),
|
||||
// ]))
|
||||
// }
|
||||
// })),
|
||||
// run: Arc::new(|_a, _i| {
|
||||
// Ok(if let Some(Ok(line)) = std::io::stdin().lines().next() {
|
||||
// Data::one_tuple(Data::new(data::string::String(line)))
|
||||
// } else {
|
||||
// Data::empty_tuple()
|
||||
// })
|
||||
// }),
|
||||
// inner_statements: None,
|
||||
// },
|
||||
// )
|
||||
.add_var(
|
||||
"read_line",
|
||||
data::function::Function {
|
||||
info: program::run::Info::neverused(),
|
||||
info_check: Arc::new(Mutex::new(CheckInfo::neverused())),
|
||||
out: Ok(Arc::new(|a, _i| {
|
||||
if a.is_zero_tuple() {
|
||||
Ok(Type::newm(vec![
|
||||
Arc::new(data::tuple::TupleT(vec![Type::new(data::string::StringT)])),
|
||||
Arc::new(data::tuple::TupleT(vec![])),
|
||||
]))
|
||||
} else {
|
||||
Err(CheckError::new().msg(vec![
|
||||
("expected (), got ".to_owned(), None),
|
||||
(a.to_string(), Some(EColor::FunctionArgument)),
|
||||
]))
|
||||
}
|
||||
})),
|
||||
run: Arc::new(|_a, _i| {
|
||||
func(|_: (), _| {
|
||||
Ok(if let Some(Ok(line)) = std::io::stdin().lines().next() {
|
||||
Data::one_tuple(Data::new(data::string::String(line)))
|
||||
OneOrNone(Some(line))
|
||||
} else {
|
||||
Data::empty_tuple()
|
||||
OneOrNone(None)
|
||||
})
|
||||
}),
|
||||
inner_statements: None,
|
||||
},
|
||||
)
|
||||
.add_var(
|
||||
"debug",
|
||||
|
Loading…
Reference in New Issue
Block a user