Skip to main content

xtask_todo_lib/devshell/script/
ast.rs

1//! Script AST: statements and parse error.
2
3/// One script statement.
4#[derive(Debug, Clone)]
5pub enum ScriptStmt {
6    Assign(String, String),
7    Command(String),
8    SetE,
9    If {
10        cond: String,
11        then_body: Vec<Self>,
12        else_body: Option<Vec<Self>>,
13    },
14    For {
15        var: String,
16        words: Vec<String>,
17        body: Vec<Self>,
18    },
19    While {
20        cond: String,
21        body: Vec<Self>,
22    },
23    Source(String),
24}
25
26/// Parse error with message.
27#[derive(Debug)]
28pub struct ParseError(pub String);
29
30impl std::fmt::Display for ParseError {
31    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32        write!(f, "{}", self.0)
33    }
34}
35
36impl std::error::Error for ParseError {}