2022-06-18 21:56:31 -07:00
|
|
|
use super::*;
|
2019-11-07 10:55:15 -08:00
|
|
|
|
|
|
|
/// A single top-level item
|
2021-06-08 01:01:27 -07:00
|
|
|
#[derive(Debug, Clone)]
|
2019-11-07 10:55:15 -08:00
|
|
|
pub(crate) enum Item<'src> {
|
2019-11-21 07:39:32 -08:00
|
|
|
Alias(Alias<'src, Name<'src>>),
|
2019-11-07 10:55:15 -08:00
|
|
|
Assignment(Assignment<'src>),
|
2021-06-08 01:01:27 -07:00
|
|
|
Comment(&'src str),
|
2023-12-19 20:31:51 -08:00
|
|
|
Import {
|
2023-11-21 11:28:59 -08:00
|
|
|
absolute: Option<PathBuf>,
|
2023-12-29 12:16:31 -08:00
|
|
|
optional: bool,
|
|
|
|
path: Token<'src>,
|
|
|
|
relative: StringLiteral<'src>,
|
2023-11-21 11:28:59 -08:00
|
|
|
},
|
2023-12-29 12:16:31 -08:00
|
|
|
Module {
|
2023-12-27 20:27:15 -08:00
|
|
|
absolute: Option<PathBuf>,
|
2023-12-29 12:16:31 -08:00
|
|
|
name: Name<'src>,
|
|
|
|
optional: bool,
|
|
|
|
relative: Option<StringLiteral<'src>>,
|
2023-12-27 20:27:15 -08:00
|
|
|
},
|
|
|
|
Recipe(UnresolvedRecipe<'src>),
|
|
|
|
Set(Set<'src>),
|
2019-11-07 10:55:15 -08:00
|
|
|
}
|
2021-06-08 01:01:27 -07:00
|
|
|
|
|
|
|
impl<'src> Display for Item<'src> {
|
|
|
|
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
|
|
|
match self {
|
2022-12-15 16:53:21 -08:00
|
|
|
Item::Alias(alias) => write!(f, "{alias}"),
|
|
|
|
Item::Assignment(assignment) => write!(f, "{assignment}"),
|
|
|
|
Item::Comment(comment) => write!(f, "{comment}"),
|
2023-12-29 12:16:31 -08:00
|
|
|
Item::Import {
|
|
|
|
relative, optional, ..
|
|
|
|
} => {
|
|
|
|
write!(f, "import")?;
|
|
|
|
|
|
|
|
if *optional {
|
|
|
|
write!(f, "?")?;
|
|
|
|
}
|
|
|
|
|
|
|
|
write!(f, " {relative}")
|
|
|
|
}
|
|
|
|
Item::Module {
|
|
|
|
name,
|
|
|
|
relative,
|
|
|
|
optional,
|
|
|
|
..
|
|
|
|
} => {
|
|
|
|
write!(f, "mod")?;
|
|
|
|
|
|
|
|
if *optional {
|
|
|
|
write!(f, "?")?;
|
|
|
|
}
|
|
|
|
|
|
|
|
write!(f, " {name}")?;
|
2023-12-28 04:23:58 -08:00
|
|
|
|
2023-12-29 12:16:31 -08:00
|
|
|
if let Some(path) = relative {
|
2023-12-28 04:23:58 -08:00
|
|
|
write!(f, " {path}")?;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
2021-07-28 18:06:57 -07:00
|
|
|
Item::Recipe(recipe) => write!(f, "{}", recipe.color_display(Color::never())),
|
2022-12-15 16:53:21 -08:00
|
|
|
Item::Set(set) => write!(f, "{set}"),
|
2021-06-08 01:01:27 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|