Fix io.read_line function

This commit is contained in:
Jeff 2024-06-24 02:58:19 -04:00
parent 49dfdc4e10
commit 37d59f562d
3 changed files with 14 additions and 8 deletions

View File

@ -100,6 +100,12 @@ impl AbstractNode for Assignment {
let statement_type = self.statement.expected_type(context)?;
if statement_type.is_none() {
return Err(ValidationError::CannotAssignToNone(
self.statement.last_evaluated_statement().position(),
));
}
if let (Some(expected_type_constructor), Some(actual_type)) =
(&self.constructor, statement_type)
{

View File

@ -1,8 +1,4 @@
use std::{
array,
fs::read_to_string,
io::{self, stdin},
};
use std::{array, fs::read_to_string, io::stdin};
use serde::{Deserialize, Serialize};
use serde_json::from_str;
@ -308,9 +304,13 @@ impl FunctionLogic for ReadLine {
}
fn call(self, _: &Context, _: bool) -> Result<Option<Evaluation>, RuntimeError> {
let user_input = io::read_to_string(stdin())?;
let mut user_input = String::new();
Ok(Some(Evaluation::Return(Value::string(user_input))))
stdin().read_line(&mut user_input)?;
Ok(Some(Evaluation::Return(Value::string(
user_input.trim_end_matches('\n'),
))))
}
}

View File

@ -549,7 +549,7 @@ pub fn parser<'src>(
),
infix(
left(1),
just(Token::Symbol(Symbol::Slash)),
just(Token::Symbol(Symbol::Percent)),
|left, _, right, span| {
Expression::Math(Box::new(Math::Modulo(left, right)).with_position(span))
},