#[derive(Debug, Clone)]
#[allow(clippy::use_self)]
pub enum Node {
Word { value: String, parts: Vec<Node> },
Command {
words: Vec<Node>,
redirects: Vec<Node>,
},
Pipeline { commands: Vec<Node> },
List { parts: Vec<Node> },
Operator { op: String },
If {
condition: Box<Node>,
then_body: Box<Node>,
else_body: Option<Box<Node>>,
redirects: Vec<Node>,
},
While {
condition: Box<Node>,
body: Box<Node>,
redirects: Vec<Node>,
},
Until {
condition: Box<Node>,
body: Box<Node>,
redirects: Vec<Node>,
},
For {
var: String,
words: Option<Vec<Node>>,
body: Box<Node>,
redirects: Vec<Node>,
},
ForArith {
init: String,
cond: String,
incr: String,
body: Box<Node>,
redirects: Vec<Node>,
},
Select {
var: String,
words: Option<Vec<Node>>,
body: Box<Node>,
redirects: Vec<Node>,
},
Case {
word: Box<Node>,
patterns: Vec<CasePattern>,
redirects: Vec<Node>,
},
Function { name: String, body: Box<Node> },
Subshell {
body: Box<Node>,
redirects: Vec<Node>,
},
BraceGroup {
body: Box<Node>,
redirects: Vec<Node>,
},
Coproc {
name: Option<String>,
command: Box<Node>,
},
Redirect {
op: String,
target: Box<Node>,
fd: i32,
},
HereDoc {
delimiter: String,
content: String,
strip_tabs: bool,
quoted: bool,
fd: i32,
complete: bool,
},
ParamExpansion {
param: String,
op: Option<String>,
arg: Option<String>,
},
ParamLength { param: String },
ParamIndirect {
param: String,
op: Option<String>,
arg: Option<String>,
},
CommandSubstitution { command: Box<Node>, brace: bool },
ProcessSubstitution {
direction: String,
command: Box<Node>,
},
AnsiCQuote { content: String },
LocaleString { content: String },
ArithmeticExpansion { expression: Option<Box<Node>> },
ArithmeticCommand {
expression: Option<Box<Node>>,
redirects: Vec<Node>,
raw_content: String,
},
ArithNumber { value: String },
ArithVar { name: String },
ArithBinaryOp {
op: String,
left: Box<Node>,
right: Box<Node>,
},
ArithUnaryOp { op: String, operand: Box<Node> },
ArithPreIncr { operand: Box<Node> },
ArithPostIncr { operand: Box<Node> },
ArithPreDecr { operand: Box<Node> },
ArithPostDecr { operand: Box<Node> },
ArithAssign {
op: String,
target: Box<Node>,
value: Box<Node>,
},
ArithTernary {
condition: Box<Node>,
if_true: Option<Box<Node>>,
if_false: Option<Box<Node>>,
},
ArithComma { left: Box<Node>, right: Box<Node> },
ArithSubscript { array: String, index: Box<Node> },
ArithEmpty,
ArithEscape { ch: String },
ArithDeprecated { expression: String },
ArithConcat { parts: Vec<Node> },
ConditionalExpr {
body: Box<Node>,
redirects: Vec<Node>,
},
UnaryTest { op: String, operand: Box<Node> },
BinaryTest {
op: String,
left: Box<Node>,
right: Box<Node>,
},
CondAnd { left: Box<Node>, right: Box<Node> },
CondOr { left: Box<Node>, right: Box<Node> },
CondNot { operand: Box<Node> },
CondParen { inner: Box<Node> },
CondTerm { value: String },
Negation { pipeline: Box<Node> },
Time { pipeline: Box<Node>, posix: bool },
PipeBoth,
Array { elements: Vec<Node> },
Empty,
Comment { text: String },
}
#[derive(Debug, Clone)]
pub struct CasePattern {
pub patterns: Vec<Node>,
pub body: Option<Node>,
pub terminator: String,
}
impl CasePattern {
pub const fn new(patterns: Vec<Node>, body: Option<Node>, terminator: String) -> Self {
Self {
patterns,
body,
terminator,
}
}
}