added another test for the parser

This commit is contained in:
2025-03-19 15:16:43 -04:00
parent b0dd101740
commit 255a4586b4
11 changed files with 20179 additions and 17 deletions

39
src/builtin/flowctl.rs Normal file
View File

@@ -0,0 +1,39 @@
use crate::{builtin::setup_builtin, jobs::JobBldr, libsh::error::{ShErr, ShErrKind, ShResult}, parse::{execute::prepare_argv, NdRule, Node}, prelude::*, procio::IoStack, state};
pub fn flowctl(node: Node, kind: ShErrKind) -> ShResult<()> {
use ShErrKind::*;
let NdRule::Command { assignments: _, argv } = node.class else {
unreachable!()
};
let mut code = 0;
let mut argv = prepare_argv(argv);
let cmd = argv.remove(0).0;
if !argv.is_empty() {
let (arg,span) = argv
.into_iter()
.next()
.unwrap();
let Ok(status) = arg.parse::<i32>() else {
return Err(
ShErr::full(ShErrKind::SyntaxErr, format!("{cmd}: Expected a number"), span)
)
};
code = status;
}
flog!(DEBUG,code);
let kind = match kind {
LoopContinue(_) => LoopContinue(code),
LoopBreak(_) => LoopBreak(code),
FuncReturn(_) => FuncReturn(code),
CleanExit(_) => CleanExit(code),
_ => unreachable!()
};
Err(ShErr::simple(kind, ""))
}

View File

@@ -10,8 +10,9 @@ pub mod source;
pub mod shift;
pub mod jobctl;
pub mod alias;
pub mod flowctl;
pub const BUILTINS: [&str;10] = [
pub const BUILTINS: [&str;14] = [
"echo",
"cd",
"export",
@@ -21,7 +22,11 @@ pub const BUILTINS: [&str;10] = [
"jobs",
"fg",
"bg",
"alias"
"alias",
"return",
"break",
"continue",
"exit"
];
/// Sets up a builtin command