Implemented logic for loops and if statements
This commit is contained in:
@@ -44,6 +44,12 @@ impl<'s> ShErr {
|
||||
let span = span.into();
|
||||
Self::Full { kind, msg, span }
|
||||
}
|
||||
pub fn kind(&self) -> &ShErrKind {
|
||||
match self {
|
||||
ShErr::Simple { kind, msg: _ } |
|
||||
ShErr::Full { kind, msg: _, span: _ } => kind
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for ShErr {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user