aboutsummaryrefslogtreecommitdiff
path: root/src/makefile/token.rs
diff options
context:
space:
mode:
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)
}
}