Skip to content

Commit

Permalink
refactor line checks
Browse files Browse the repository at this point in the history
  • Loading branch information
casey committed Oct 5, 2022
1 parent e445cfb commit d27b720
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions src/line.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use super::*;

// TODO
// - don't evaluate comments

/// A single line in a recipe body, consisting of any number of `Fragment`s.
#[derive(Debug, Clone, PartialEq, Serialize)]
#[serde(transparent)]
Expand All @@ -13,41 +16,39 @@ impl<'src> Line<'src> {
}

pub(crate) fn is_comment(&self) -> bool {
match self.fragments.first() {
Some(Fragment::Text { token }) => token.lexeme().starts_with('#'),
_ => false,
}
matches!(
self.fragments.first(),
Some(Fragment::Text { token }) if token.lexeme().starts_with('#'),
)
}

pub(crate) fn is_continuation(&self) -> bool {
match self.fragments.last() {
Some(Fragment::Text { token }) => token.lexeme().ends_with('\\'),
_ => false,
}
matches!(
self.fragments.last(),
Some(Fragment::Text { token }) if token.lexeme().ends_with('\\'),
)
}

pub(crate) fn is_shebang(&self) -> bool {
match self.fragments.first() {
Some(Fragment::Text { token }) => token.lexeme().starts_with("#!"),
_ => false,
}
matches!(
self.fragments.first(),
Some(Fragment::Text { token }) if token.lexeme().starts_with("#!"),
)
}

pub(crate) fn is_quiet(&self) -> bool {
match self.fragments.first() {
Some(Fragment::Text { token }) => {
token.lexeme().starts_with('@') || token.lexeme().starts_with("-@")
}
_ => false,
}
matches!(
self.fragments.first(),
Some(Fragment::Text { token })
if token.lexeme().starts_with('@') || token.lexeme().starts_with("-@"),
)
}

pub(crate) fn is_infallible(&self) -> bool {
match self.fragments.first() {
Some(Fragment::Text { token }) => {
token.lexeme().starts_with('-') || token.lexeme().starts_with("@-")
}
_ => false,
}
matches!(
self.fragments.first(),
Some(Fragment::Text { token })
if token.lexeme().starts_with('-') || token.lexeme().starts_with("@-"),
)
}
}

0 comments on commit d27b720

Please sign in to comment.