diff --git a/src/parse.rs b/src/parse.rs index c1d84f8..fe9fb5f 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -10,6 +10,96 @@ pub fn parse(filename: Arc, src: &str) -> Result<()> { Ok(()) } +/* +Simplified conceptually: +COMMAND = PIPELINE +PIPELINE = LIST { "|" LIST } +LIST = COMPOUND { "&&" COMPOUND } +COMPOUND = ??? +SIMPLECOMMAND = word { word } +*/ + +pub struct SimpleCommand<'a> { + pub tokens: Vec>, +} + +pub enum CompoundCommand<'a> { + Simple(SimpleCommand<'a>), + Until { + test: Command<'a>, + do_: Vec>, + }, + While { + test: Command<'a>, + do_: Vec>, + }, + For { + name: Token<'a>, + words: Vec>, + do_: Vec>, + }, + ForArith, + If { + test: Command<'a>, + then: Vec>, + elif: Vec<(Command<'a>, Vec>)>, + else_: Vec>, + }, + Case, + Select, + /// `(( ))` + Arith, + /// `[[ ]]` + CondExpr, +} + +pub struct CommandList<'a> { + pub initial: SimpleCommand<'a>, + pub rest: Vec<(ListKind, SimpleCommand<'a>)>, +} + +pub struct Pipeline<'a> { + pub time: bool, + /// !!!! + pub exclamation: bool, + pub initial: CommandList<'a>, + pub rest: Vec<(PipelineKind, CommandList<'a>)>, + pub terminator: Option, +} + +pub enum Command<'a> { + Single(Pipeline<'a>), + /// `()` + Subshell(Vec>), + /// `{}` + Block(Vec>), +} + +pub enum ListKind { + /// `;` + Chain, + /// `&`` + Async, + /// `&&` + And, + /// `||` + Or, + Newline, +} + +pub enum ListTerminator { + Chain, + Async, + Newline, +} + +pub enum PipelineKind { + /// `|` + Simple, + /// `|&` + All, +} + #[derive(Debug)] pub struct Span { pub filename: Arc,