From 485832510ca8c8da1f128a0ea34b10b6f1dbf0bb Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Mon, 20 Oct 2025 04:16:50 +0200 Subject: [PATCH] Relax again the braced placeholder tokenizer --- src/lib.rs | 14 ++++++++++++++ src/tokenizer.rs | 28 ++++++++++++---------------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index e29617e..623e679 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1786,6 +1786,20 @@ mod tests { expected ); } + #[test] + fn it_formats_raw_sql_and_conditional_queries() { + let input = "SELECT {foo: &[T]}, {b.c()}, {d.e};"; + let options = FormatOptions::default(); + let expected = indoc!( + " + SELECT + {foo: &[T]}, + {b.c()}, + {d.e};" + ); + + assert_eq!(format(input, &QueryParams::None, &options), expected); + } #[test] fn it_formats_query_with_go_batch_separator() { diff --git a/src/tokenizer.rs b/src/tokenizer.rs index 6177a0a..efd938d 100644 --- a/src/tokenizer.rs +++ b/src/tokenizer.rs @@ -384,22 +384,18 @@ fn get_ident_named_placeholder_token<'i>(input: &mut &'i str) -> Result(input: &mut &'i str) -> Result> { - delimited( - '{', - take_while(1.., |c: char| c.is_alphanumeric() || c == '_'), - '}', - ) - .with_taken() - .parse_next(input) - .map(|(index, token)| { - let index = Cow::Borrowed(index); - Token { - kind: TokenKind::Placeholder, - value: token, - key: Some(PlaceholderKind::Named(index)), - alias: token, - } - }) + delimited('{', take_until(1.., '}'), '}') + .with_taken() + .parse_next(input) + .map(|(index, token)| { + let index = Cow::Borrowed(index); + Token { + kind: TokenKind::Placeholder, + value: token, + key: Some(PlaceholderKind::Named(index)), + alias: token, + } + }) } fn get_string_named_placeholder_token<'i>(