use slash_lang::parser::{
ast::{Op, Redirection},
parse,
};
fn main() {
let inputs = [
"/lint | /format | /build",
"/compile |& /report",
"/test && /deploy",
"/primary || /fallback",
"/report > out.txt",
"/log >> audit.log",
"/check && /lint | /fix",
"/foo? | /bar? | /baz",
];
for input in &inputs {
println!("Input: {input}");
match parse(input) {
Ok(program) => {
for (pi, pipeline) in program.pipelines.iter().enumerate() {
let sep = match &pipeline.operator {
Some(Op::And) => " && …",
Some(Op::Or) => " || …",
_ => "",
};
println!(" Pipeline[{pi}]{sep}:");
for cmd in &pipeline.commands {
let pipe_sym = match &cmd.pipe {
Some(Op::Pipe) => " |",
Some(Op::PipeErr) => " |&",
_ => "",
};
let redir = match &cmd.redirect {
Some(Redirection::Truncate(f)) => format!(" > {f}"),
Some(Redirection::Append(f)) => format!(" >> {f}"),
None => String::new(),
};
println!(
" /{}{opt}{pipe}{redir}",
cmd.name,
opt = if cmd.optional { "?" } else { "" },
pipe = pipe_sym,
redir = redir,
);
}
}
}
Err(e) => println!(" ERROR: {:?}", e),
}
println!();
}
}