Implemented loops and redirection for shell structures
This commit is contained in:
@@ -5,6 +5,7 @@ use shellenv::jobs::{ChildProc, JobBldr};
|
||||
use crate::{builtin::export::export, libsh::{error::Blame, sys::{execvpe, get_bin_path}, utils::{ArgVec, StrOps}}, parse::{lex::Token, parse::{CmdGuard, NdFlag, Node, NdRule, SynTree}}, prelude::*};
|
||||
|
||||
pub mod ifthen;
|
||||
pub mod loops;
|
||||
|
||||
pub fn exec_input<S: Into<String>>(input: S, shenv: &mut ShEnv) -> ShResult<()> {
|
||||
let input = input.into();
|
||||
@@ -41,6 +42,7 @@ impl<'a> Executor<'a> {
|
||||
Self { ast, shenv }
|
||||
}
|
||||
pub fn walk(&mut self) -> ShResult<()> {
|
||||
self.shenv.ctx_mut().descend()?;
|
||||
log!(DEBUG, "Starting walk");
|
||||
while let Some(node) = self.ast.next_node() {
|
||||
if let NdRule::CmdList { cmds } = node.clone().into_rule() {
|
||||
@@ -48,6 +50,7 @@ impl<'a> Executor<'a> {
|
||||
exec_list(cmds, self.shenv).try_blame(node.as_raw(self.shenv),node.span())?
|
||||
} else { unreachable!() }
|
||||
}
|
||||
self.shenv.ctx_mut().ascend();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -77,6 +80,7 @@ fn exec_list(list: Vec<(Option<CmdGuard>, Node)>, shenv: &mut ShEnv) -> ShResult
|
||||
NdRule::Command {..} => dispatch_command(cmd, shenv).try_blame(cmd_raw, span)?,
|
||||
NdRule::Subshell {..} => exec_subshell(cmd,shenv).try_blame(cmd_raw, span)?,
|
||||
NdRule::IfThen {..} => ifthen::exec_if(cmd, shenv).try_blame(cmd_raw, span)?,
|
||||
NdRule::Loop {..} => loops::exec_loop(cmd, shenv).try_blame(cmd_raw, span)?,
|
||||
NdRule::FuncDef {..} => exec_funcdef(cmd,shenv).try_blame(cmd_raw, span)?,
|
||||
NdRule::Assignment {..} => exec_assignment(cmd,shenv).try_blame(cmd_raw, span)?,
|
||||
NdRule::Pipeline {..} => exec_pipeline(cmd, shenv).try_blame(cmd_raw, span)?,
|
||||
@@ -244,6 +248,8 @@ fn exec_builtin(node: Node, shenv: &mut ShEnv) -> ShResult<()> {
|
||||
"alias" => alias(node, shenv)?,
|
||||
"exit" => sh_flow(node, shenv, ShErrKind::CleanExit)?,
|
||||
"return" => sh_flow(node, shenv, ShErrKind::FuncReturn)?,
|
||||
"break" => sh_flow(node, shenv, ShErrKind::LoopBreak)?,
|
||||
"continue" => sh_flow(node, shenv, ShErrKind::LoopContinue)?,
|
||||
_ => unimplemented!("Have not yet implemented support for builtin `{}'",command)
|
||||
}
|
||||
log!(TRACE, "done");
|
||||
|
||||
Reference in New Issue
Block a user