use std::{
fs::read_to_string,
io::{stdin, stdout, Write},
thread,
time::Duration,
};
use serde::{Deserialize, Serialize};
use crate::{
context::Context,
error::{RuntimeError, ValidationError},
value::ValueInner,
Value,
};
use super::{AbstractNode, Evaluation, Expression, Type, TypeConstructor};
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
pub enum BuiltInFunctionCall {
JsonParse(TypeConstructor, Expression),
Length(Expression),
ReadFile(Expression),
ReadLine,
Sleep(Expression),
WriteLine(Expression),
}
impl AbstractNode for BuiltInFunctionCall {
fn define_types(&self, context: &Context) -> Result<(), ValidationError> {
Ok(())
}
fn validate(&self, _context: &Context, _manage_memory: bool) -> Result<(), ValidationError> {
match self {
BuiltInFunctionCall::JsonParse(_, expression) => {
expression.validate(_context, _manage_memory)
}
BuiltInFunctionCall::Length(expression) => {
expression.validate(_context, _manage_memory)
}
BuiltInFunctionCall::ReadFile(expression) => {
expression.validate(_context, _manage_memory)
}
BuiltInFunctionCall::ReadLine => Ok(()),
BuiltInFunctionCall::Sleep(expression) => expression.validate(_context, _manage_memory),
BuiltInFunctionCall::WriteLine(expression) => {
expression.validate(_context, _manage_memory)
}
}
}
fn evaluate(
self,
context: &Context,
_manage_memory: bool,
) -> Result