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, serde::Serialize, serde::Deserialize)]
5pub struct Command {
6 pub name: String,
7 pub args: Vec<Arg>,
8 /// Char offset of the verb token in the whole source (for LSP diagnostics).
9 pub pos: usize,
10}
11
12#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
13pub enum Arg {
14 Word(String),
15 Str(String),
16 Block(Vec<Command>),
17}
18
19impl Arg {
20 /// The textual value of a word/string arg, or `None` for a block.
21 pub fn as_str(&self) -> Option<&str> {
22 match self {
23 Arg::Word(s) | Arg::Str(s) => Some(s),
24 Arg::Block(_) => None,
25 }
26 }
27}