aboutsummaryrefslogtreecommitdiff
path: root/src/makefile/token.rs
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2021-03-31 12:51:11 -0600
committerMelody Horn <melody@boringcactus.com>2021-03-31 12:51:11 -0600
commite1a0584936b3aa5ce971e875dec750d2ae937d2e (patch)
treef1db896b9623e6480181df3ad4792107d9d87ecf /src/makefile/token.rs
parentd10ad4b37f726180e3da562a1fbb6cbbd106ef58 (diff)
downloadmakers-e1a0584936b3aa5ce971e875dec750d2ae937d2e.tar.gz
makers-e1a0584936b3aa5ce971e875dec750d2ae937d2e.zip
massively upgrade error handling
Diffstat (limited to 'src/makefile/token.rs')
-rw-r--r--src/makefile/token.rs16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/makefile/token.rs b/src/makefile/token.rs
index 8b21f06..22ef24a 100644
--- a/src/makefile/token.rs
+++ b/src/makefile/token.rs
@@ -1,6 +1,7 @@
use std::fmt;
use std::str::FromStr;
+use anyhow::Context;
use nom::{
branch::alt,
bytes::complete::{tag, take_till1, take_while1},
@@ -250,18 +251,19 @@ fn full_text_tokens(input: &str) -> IResult<&str, TokenString> {
all_consuming(tokens_but_not(vec![]))(input)
}
-pub(crate) fn tokenize(input: &str) -> TokenString {
- // TODO handle errors gracefully
- let (_, result) = full_text_tokens(input).expect("couldn't parse");
- result
+pub(crate) fn tokenize(input: &str) -> anyhow::Result<TokenString> {
+ let (_, result) = full_text_tokens(input)
+ .finish()
+ .map_err(|err| anyhow::anyhow!(err.to_string()))
+ .with_context(|| format!("couldn't parse {:?}", input))?;
+ Ok(result)
}
impl FromStr for TokenString {
- // TODO figure out how to get nom errors working (Error<&str> doesn't work because lifetimes)
- type Err = ();
+ type Err = anyhow::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
- full_text_tokens(s).finish().map(|(_, x)| x).map_err(|_| ())
+ tokenize(s)
}
}