mirror of
https://github.com/Dummi26/mers.git
synced 2025-03-10 14:13:52 +01:00
parser bugfix, started working on external libraries (libraries can register functions and react to function calls via stdout/stdin)
This commit is contained in:
parent
296163d5fe
commit
45186e3803
36
src/libs/mod.rs
Normal file
36
src/libs/mod.rs
Normal 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),
|
||||||
|
}
|
@ -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;
|
||||||
|
|
||||||
|
@ -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() {
|
||||||
|
@ -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![],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user