2019-11-07 10:55:15 -08:00
|
|
|
use crate::common::*;
|
|
|
|
|
2020-02-14 04:49:25 -08:00
|
|
|
/// A module, the top-level type produced by the parser. So-named because
|
|
|
|
/// although at present, all justfiles consist of a single module, in the future
|
|
|
|
/// we will likely have multi-module and multi-file justfiles.
|
2019-11-07 10:55:15 -08:00
|
|
|
///
|
|
|
|
/// Not all successful parses result in valid justfiles, so additional
|
2020-02-14 04:49:25 -08:00
|
|
|
/// consistency checks and name resolution are performed by the `Analyzer`,
|
|
|
|
/// which produces a `Justfile` from a `Module`.
|
2021-06-08 01:01:27 -07:00
|
|
|
#[derive(Debug, Clone)]
|
2019-11-07 10:55:15 -08:00
|
|
|
pub(crate) struct Module<'src> {
|
|
|
|
/// Items in the justfile
|
2020-02-10 20:07:06 -08:00
|
|
|
pub(crate) items: Vec<Item<'src>>,
|
2019-11-07 10:55:15 -08:00
|
|
|
/// Non-fatal warnings encountered during parsing
|
2021-03-28 23:39:23 -07:00
|
|
|
pub(crate) warnings: Vec<Warning>,
|
2019-11-07 10:55:15 -08:00
|
|
|
}
|
2021-06-08 01:01:27 -07:00
|
|
|
|
|
|
|
impl<'src> Display for Module<'src> {
|
|
|
|
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
|
|
|
|
let mut iter = self.items.iter().peekable();
|
|
|
|
|
|
|
|
while let Some(item) = iter.next() {
|
|
|
|
writeln!(f, "{}", item)?;
|
|
|
|
|
|
|
|
if let Some(next_item) = iter.peek() {
|
|
|
|
if matches!(item, Item::Recipe(_))
|
|
|
|
|| mem::discriminant(item) != mem::discriminant(next_item)
|
|
|
|
{
|
|
|
|
writeln!(f)?;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|