2022-06-18 21:56:31 -07:00
|
|
|
use super::*;
|
2019-11-07 10:55:15 -08:00
|
|
|
|
2020-02-14 04:49:25 -08:00
|
|
|
/// A single line in a recipe body, consisting of any number of `Fragment`s.
|
2021-11-17 00:07:48 -08:00
|
|
|
#[derive(Debug, Clone, PartialEq, Serialize)]
|
|
|
|
#[serde(transparent)]
|
2019-11-07 10:55:15 -08:00
|
|
|
pub(crate) struct Line<'src> {
|
|
|
|
pub(crate) fragments: Vec<Fragment<'src>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'src> Line<'src> {
|
|
|
|
pub(crate) fn is_empty(&self) -> bool {
|
|
|
|
self.fragments.is_empty()
|
|
|
|
}
|
|
|
|
|
2022-10-04 17:32:30 -07:00
|
|
|
pub(crate) fn is_comment(&self) -> bool {
|
2022-10-04 22:33:19 -07:00
|
|
|
matches!(
|
|
|
|
self.fragments.first(),
|
|
|
|
Some(Fragment::Text { token }) if token.lexeme().starts_with('#'),
|
|
|
|
)
|
2022-10-04 17:32:30 -07:00
|
|
|
}
|
|
|
|
|
2019-11-07 10:55:15 -08:00
|
|
|
pub(crate) fn is_continuation(&self) -> bool {
|
2022-10-04 22:33:19 -07:00
|
|
|
matches!(
|
|
|
|
self.fragments.last(),
|
|
|
|
Some(Fragment::Text { token }) if token.lexeme().ends_with('\\'),
|
|
|
|
)
|
2019-11-07 10:55:15 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn is_shebang(&self) -> bool {
|
2022-10-04 22:33:19 -07:00
|
|
|
matches!(
|
|
|
|
self.fragments.first(),
|
|
|
|
Some(Fragment::Text { token }) if token.lexeme().starts_with("#!"),
|
|
|
|
)
|
2019-11-07 10:55:15 -08:00
|
|
|
}
|
2020-06-09 15:16:05 -07:00
|
|
|
|
|
|
|
pub(crate) fn is_quiet(&self) -> bool {
|
2022-10-04 22:33:19 -07:00
|
|
|
matches!(
|
|
|
|
self.fragments.first(),
|
|
|
|
Some(Fragment::Text { token })
|
|
|
|
if token.lexeme().starts_with('@') || token.lexeme().starts_with("-@"),
|
|
|
|
)
|
2020-06-09 15:16:05 -07:00
|
|
|
}
|
2020-10-03 13:54:19 -07:00
|
|
|
|
2022-01-02 16:51:22 -08:00
|
|
|
pub(crate) fn is_infallible(&self) -> bool {
|
2022-10-04 22:33:19 -07:00
|
|
|
matches!(
|
|
|
|
self.fragments.first(),
|
|
|
|
Some(Fragment::Text { token })
|
|
|
|
if token.lexeme().starts_with('-') || token.lexeme().starts_with("@-"),
|
|
|
|
)
|
2020-10-03 13:54:19 -07:00
|
|
|
}
|
2019-11-07 10:55:15 -08:00
|
|
|
}
|