Skip to main content

arb/
ast.rs

1//! Parsed command tree: a spec is a list of commands, each a verb plus args;
2//! an arg may itself be a nested block of commands (e.g. a `source { … }` body).
3
4#[derive(Debug, Clone)]
5pub struct Command {
6    pub name: String,
7    pub args: Vec<Arg>,
8}
9
10#[derive(Debug, Clone)]
11pub enum Arg {
12    Word(String),
13    Str(String),
14    Block(Vec<Command>),
15}
16
17impl Arg {
18    /// The textual value of a word/string arg, or `None` for a block.
19    pub fn as_str(&self) -> Option<&str> {
20        match self {
21            Arg::Word(s) | Arg::Str(s) => Some(s),
22            Arg::Block(_) => None,
23        }
24    }
25}