diff options
Diffstat (limited to 'src/makefile')
-rw-r--r-- | src/makefile/token.rs | 36 |
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(()) + } } |