use crate::error::Span;
#[derive(Debug, Clone)]
pub struct Program {
pub commands: Vec<Command>,
}
#[derive(Debug, Clone)]
pub enum Command {
Simple {
assigns: Vec<Assignment>,
args: Vec<Word>,
redirs: Vec<Redir>,
span: Span,
},
Pipeline {
commands: Vec<Command>,
bang: bool,
span: Span,
},
And(Box<Command>, Box<Command>),
Or(Box<Command>, Box<Command>),
Sequence(Box<Command>, Box<Command>),
Subshell {
body: Box<Command>,
redirs: Vec<Redir>,
span: Span,
},
BraceGroup {
body: Box<Command>,
redirs: Vec<Redir>,
span: Span,
},
If {
cond: Box<Command>,
then_part: Box<Command>,
else_part: Option<Box<Command>>,
span: Span,
},
While {
cond: Box<Command>,
body: Box<Command>,
span: Span,
},
Until {
cond: Box<Command>,
body: Box<Command>,
span: Span,
},
For {
var: String,
words: Option<Vec<Word>>,
body: Box<Command>,
span: Span,
},
Case {
word: Word,
arms: Vec<CaseArm>,
span: Span,
},
FuncDef {
name: String,
body: Box<Command>,
span: Span,
},
Not(Box<Command>),
Background {
cmd: Box<Command>,
redirs: Vec<Redir>,
},
}
#[derive(Debug, Clone)]
pub struct CaseArm {
pub patterns: Vec<Word>,
pub body: Option<Command>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct Assignment {
pub name: String,
pub value: Word,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct Word {
pub parts: Vec<WordPart>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub enum WordPart {
Literal(String),
SingleQuoted(String),
DoubleQuoted(Vec<WordPart>),
Param(ParamExpr),
CmdSubst(Box<Command>),
Backtick(Box<Command>),
Arith(Vec<WordPart>),
Tilde(String),
}
#[derive(Debug, Clone)]
pub struct ParamExpr {
pub name: String,
pub op: ParamOp,
pub span: Span,
}
#[derive(Debug, Clone)]
pub enum ParamOp {
Normal,
Length,
Default { colon: bool, word: Vec<WordPart> },
Assign { colon: bool, word: Vec<WordPart> },
Error { colon: bool, word: Vec<WordPart> },
Alternative { colon: bool, word: Vec<WordPart> },
TrimSuffixSmall(Vec<WordPart>),
TrimSuffixLarge(Vec<WordPart>),
TrimPrefixSmall(Vec<WordPart>),
TrimPrefixLarge(Vec<WordPart>),
BadSubst,
}
#[derive(Debug, Clone)]
pub struct Redir {
pub fd: i32,
pub kind: RedirKind,
pub span: Span,
}
#[derive(Debug, Clone)]
pub enum HereDocBody {
Literal(String),
Parsed(Vec<WordPart>),
}
#[derive(Debug, Clone)]
pub enum RedirKind {
Input(Word),
Output(Word),
Clobber(Word),
Append(Word),
ReadWrite(Word),
DupInput(Word),
DupOutput(Word),
HereDoc(HereDocBody),
HereDocStrip(HereDocBody),
}