pub_just/
line.rs

1use super::*;
2
3/// A single line in a recipe body, consisting of any number of `Fragment`s.
4#[derive(Debug, Clone, PartialEq, Serialize)]
5#[serde(transparent)]
6pub struct Line<'src> {
7  pub fragments: Vec<Fragment<'src>>,
8  #[serde(skip)]
9  pub number: usize,
10}
11
12impl<'src> Line<'src> {
13  pub fn is_empty(&self) -> bool {
14    self.fragments.is_empty()
15  }
16
17  pub fn is_comment(&self) -> bool {
18    matches!(
19      self.fragments.first(),
20      Some(Fragment::Text { token }) if token.lexeme().starts_with('#'),
21    )
22  }
23
24  pub fn is_continuation(&self) -> bool {
25    matches!(
26      self.fragments.last(),
27      Some(Fragment::Text { token }) if token.lexeme().ends_with('\\'),
28    )
29  }
30
31  pub fn is_shebang(&self) -> bool {
32    matches!(
33      self.fragments.first(),
34      Some(Fragment::Text { token }) if token.lexeme().starts_with("#!"),
35    )
36  }
37
38  pub fn is_quiet(&self) -> bool {
39    matches!(
40      self.fragments.first(),
41      Some(Fragment::Text { token })
42        if token.lexeme().starts_with('@') || token.lexeme().starts_with("-@"),
43    )
44  }
45
46  pub fn is_infallible(&self) -> bool {
47    matches!(
48      self.fragments.first(),
49      Some(Fragment::Text { token })
50        if token.lexeme().starts_with('-') || token.lexeme().starts_with("@-"),
51    )
52  }
53}