pub_just/
ast.rs

1use super::*;
2
3/// The top-level type produced by the parser. Not all successful parses result
4/// in valid justfiles, so additional consistency checks and name resolution
5/// are performed by the `Analyzer`, which produces a `Justfile` from an `Ast`.
6#[derive(Debug, Clone)]
7pub struct Ast<'src> {
8  pub items: Vec<Item<'src>>,
9  pub unstable_features: BTreeSet<UnstableFeature>,
10  pub warnings: Vec<Warning>,
11  pub working_directory: PathBuf,
12}
13
14impl<'src> Display for Ast<'src> {
15  fn fmt(&self, f: &mut Formatter) -> fmt::Result {
16    let mut iter = self.items.iter().peekable();
17
18    while let Some(item) = iter.next() {
19      writeln!(f, "{item}")?;
20
21      if let Some(next_item) = iter.peek() {
22        if matches!(item, Item::Recipe(_))
23          || mem::discriminant(item) != mem::discriminant(next_item)
24        {
25          writeln!(f)?;
26        }
27      }
28    }
29
30    Ok(())
31  }
32}