parser bugfix, started working on external libraries (libraries can register functions and react to function calls via stdout/stdin)

This commit is contained in:
Dummi26 2023-03-24 14:57:42 +01:00
parent 296163d5fe
commit 45186e3803
4 changed files with 44 additions and 2 deletions

36
src/libs/mod.rs Normal file
View File

@ -0,0 +1,36 @@
use std::{
io,
process::{Child, ChildStdin, ChildStdout, Command},
};
pub struct Lib {
process: Child,
stdin: ChildStdin,
stdout: ChildStdout,
}
impl Lib {
pub fn launch(mut exec: Command) -> Result<Self, LaunchError> {
let mut handle = match exec.spawn() {
Ok(v) => v,
Err(e) => return Err(LaunchError::CouldNotSpawnProcess(e)),
};
if let (Some(stdin), Some(stdout), stderr) = (
handle.stdin.take(),
handle.stdout.take(),
handle.stderr.take(),
) {
Ok(Self {
process: handle,
stdin,
stdout,
})
} else {
return Err(LaunchError::NoStdio);
}
}
}
pub enum LaunchError {
NoStdio,
CouldNotSpawnProcess(io::Error),
}

View File

@ -1,5 +1,6 @@
use std::time::Instant; use std::time::Instant;
pub(crate) mod libs;
pub(crate) mod parse; pub(crate) mod parse;
pub(crate) mod script; pub(crate) mod script;

View File

@ -93,9 +93,12 @@ fn parse_block_advanced(
_ => (), _ => (),
} }
statements.push(parse_statement(file)?); statements.push(parse_statement(file)?);
match file.get_char(file.get_char_index().saturating_sub(1)) { match file.peek() {
// Some('}') if treat_closed_block_bracket_as_closing_delimeter => break, // Some('}') if treat_closed_block_bracket_as_closing_delimeter => break,
Some(')') if treat_closed_normal_bracket_as_closing_delimeter => break, Some(')') if treat_closed_normal_bracket_as_closing_delimeter => {
file.next();
break;
}
_ => (), _ => (),
} }
if single_statement && !statements.is_empty() { if single_statement && !statements.is_empty() {

View File

@ -131,6 +131,8 @@ impl VSingleType {
types types
} }
Self::List(v) => v.types.clone(), Self::List(v) => v.types.clone(),
// NOTE: to make ints work in for loops
Self::Int => vec![Self::Int],
_ => vec![], _ => vec![],
} }
} }