latest pushes

This commit is contained in:
2024-10-03 00:14:47 -04:00
parent 257dcbb92e
commit d6828d5ca6
15 changed files with 925 additions and 369 deletions

View File

@@ -16,13 +16,15 @@
#[derive(Debug, Clone, PartialEq)]
pub enum Token {
Word(String),
String(String),
Assignment,
Pipe,
Redirect(String),
LeftParen,
RightParen,
Redirect(RedirectType),
Semicolon,
NewLine,
Ampersand,
LeftParen,
RightParen,
If,
Then,
Else,
@@ -33,7 +35,23 @@ pub enum Token {
For,
In,
Function,
Ampersand,
}
#[derive(Debug, Clone, PartialEq)]
pub enum RedirectType {
Out,
Append,
In,
}
impl RedirectType {
pub fn as_str(&self) -> &'static str {
match self {
RedirectType::Out => ">",
RedirectType::Append => ">>",
RedirectType::In => "<",
}
}
}
#[derive(Debug, Clone)]
@@ -49,7 +67,7 @@ pub enum ASTNode {
Pipeline(Vec<ASTNode>),
Redirect {
node: Box<ASTNode>,
direction: String,
direction: RedirectType,
target: String,
},
Block(Vec<ASTNode>),
@@ -73,3 +91,12 @@ pub enum ASTNode {
},
Background(Box<ASTNode>),
}
impl ASTNode {
pub fn is_empty_command(&self) -> bool {
match self {
ASTNode::Command { name, args } => name.is_empty() && args.is_empty(),
_ => false,
}
}
}