Implemented logic for loops and if statements

This commit is contained in:
2025-03-16 14:28:49 -04:00
parent 51d735073f
commit da51be27a7
24 changed files with 811 additions and 299 deletions

View File

@@ -1,6 +1,7 @@
use std::collections::VecDeque;
use crate::parse::lex::{Span, Tk};
use crate::parse::{Redir, RedirType};
use crate::prelude::*;
pub trait VecDequeExt<T> {
@@ -12,6 +13,13 @@ pub trait TkVecUtils<Tk> {
fn debug_tokens(&self);
}
pub trait RedirVecUtils<Redir> {
/// Splits the vector of redirections into two vectors
///
/// One vector contains input redirs, the other contains output redirs
fn split_by_channel(self) -> (Vec<Redir>,Vec<Redir>);
}
impl<T> VecDequeExt<T> for VecDeque<T> {
fn to_vec(self) -> Vec<T> {
self.into_iter().collect::<Vec<T>>()
@@ -41,3 +49,25 @@ impl<'t> TkVecUtils<Tk<'t>> for Vec<Tk<'t>> {
}
}
}
impl RedirVecUtils<Redir> for Vec<Redir> {
fn split_by_channel(self) -> (Vec<Redir>,Vec<Redir>) {
let mut input = vec![];
let mut output = vec![];
for redir in self {
match redir.class {
RedirType::Input => input.push(redir),
RedirType::Pipe => {
match redir.io_mode.tgt_fd() {
STDIN_FILENO => input.push(redir),
STDOUT_FILENO |
STDERR_FILENO => output.push(redir),
_ => unreachable!()
}
}
_ => output.push(redir)
}
}
(input,output)
}
}