aboutsummaryrefslogtreecommitdiff
path: root/src/makefile/token.rs
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2024-12-17 20:27:44 -0700
committerMelody Horn <melody@boringcactus.com>2024-12-17 20:27:44 -0700
commit5947cb97b51b5bbd78ec4213bff8541e3167e737 (patch)
tree18bbfb0055fd8b544b7733643cd13d356abd6e74 /src/makefile/token.rs
parent5411a125821c67db5cff29142ff39b207a2637f7 (diff)
downloadmakers-5947cb97b51b5bbd78ec4213bff8541e3167e737.tar.gz
makers-5947cb97b51b5bbd78ec4213bff8541e3167e737.zip
allow commas within balanced parentheses in function args
i am miserable
Diffstat (limited to 'src/makefile/token.rs')
-rw-r--r--src/makefile/token.rs36
1 files changed, 33 insertions, 3 deletions
diff --git a/src/makefile/token.rs b/src/makefile/token.rs
index 7b88823..8507a3a 100644
--- a/src/makefile/token.rs
+++ b/src/makefile/token.rs
@@ -255,6 +255,13 @@ impl Delimiter {
Self::Braces => "}",
}
}
+
+ const fn end_char(&self) -> char {
+ match self {
+ Delimiter::Parens => ')',
+ Delimiter::Braces => '}',
+ }
+ }
}
fn macro_function_name<'a, E: Err<'a>>(
@@ -365,13 +372,12 @@ fn text_but_not<'a, E: Err<'a>>(
}
fn nested_delimiters<'a, E: Err<'a>>(
- ends: Vec<char>,
context: Delimiter,
) -> impl FnMut(&'a str) -> IResult<&'a str, TokenString, E> {
map(
tuple((
tag(context.start()),
- move |x| tokens_but_not(ends.clone(), context)(x),
+ move |x| tokens_but_not(vec![context.end_char()], context)(x),
tag(context.end()),
)),
|(left, center, right)| {
@@ -392,7 +398,7 @@ fn single_token_but_not<'a, E: Err<'a>>(
alt((
text_but_not(tbn_ends),
macro_expansion,
- nested_delimiters(ends, context),
+ nested_delimiters(context),
))
}
@@ -638,4 +644,28 @@ mod test {
);
Ok(())
}
+
+ #[cfg(feature = "full")]
+ #[test]
+ fn quoted_function_call_comma() -> R {
+ let text = "$(egg $$(bug a, b/c))";
+ let tokens = tokenize(text)?;
+
+ assert_eq!(
+ tokens,
+ TokenString::just(Token::FunctionCall {
+ name: TokenString::text("egg"),
+ args: vec![TokenString::text("$(bug a, b/c)")],
+ })
+ );
+ Ok(())
+ }
+
+ #[cfg(feature = "full")]
+ #[test]
+ fn unbalanced_parentheses_rejected() -> R {
+ let text = "$(egg ()";
+ assert!(tokenize(text).is_err());
+ Ok(())
+ }
}