aboutsummaryrefslogtreecommitdiff
path: root/src/makefile/conditional.rs
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2021-03-31 13:43:46 -0600
committerMelody Horn <melody@boringcactus.com>2021-03-31 13:43:46 -0600
commite1128fe55d91ca60086de45c911b4568d2eec9ee (patch)
tree14a31a8423ea848715de3ca672702104a5bc483a /src/makefile/conditional.rs
parent43d2639526aa0534ef7a051cce39043095aebbab (diff)
downloadmakers-e1128fe55d91ca60086de45c911b4568d2eec9ee.tar.gz
makers-e1128fe55d91ca60086de45c911b4568d2eec9ee.zip
awolnation voice BAIL
Diffstat (limited to 'src/makefile/conditional.rs')
-rw-r--r--src/makefile/conditional.rs14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/makefile/conditional.rs b/src/makefile/conditional.rs
index 6795051..0b4de01 100644
--- a/src/makefile/conditional.rs
+++ b/src/makefile/conditional.rs
@@ -1,3 +1,5 @@
+use anyhow::bail;
+
use super::token::TokenString;
pub enum Line {
@@ -47,12 +49,13 @@ pub enum StateAction {
}
impl StateAction {
+ #[allow(clippy::panic)]
pub fn apply_to(self, stack: &mut Vec<State>) {
match self {
Self::Push(state) => stack.push(state),
Self::Replace(state) => match stack.last_mut() {
Some(x) => *x = state,
- None => panic!("applying Replace on an empty condition stack"),
+ None => panic!("internal error: applying Replace on an empty condition stack"),
},
Self::Pop => {
stack.pop();
@@ -154,7 +157,7 @@ impl Line {
State::SkippingUntilEndIf
}
Some(State::SkippingUntilElseOrEndIf) => State::Executing,
- None => panic!("got an Else but not in a conditional"),
+ None => bail!("got an Else but not in a conditional"),
}),
Self::ElseIf(inner_condition) => match current_state {
Some(State::Executing) | Some(State::SkippingUntilEndIf) => {
@@ -163,9 +166,12 @@ impl Line {
Some(State::SkippingUntilElseOrEndIf) => {
inner_condition.action(current_state, is_macro_defined, expand_macro)?
}
- None => panic!("got an ElseIf but not in a conditional"),
+ None => bail!("got an ElseIf but not in a conditional"),
+ },
+ Self::EndIf => match current_state {
+ Some(_) => StateAction::Pop,
+ None => bail!("got an EndIf but not in a conditional"),
},
- Self::EndIf => StateAction::Pop,
})
}
}