Skip to content

Commit b30e53e

Browse files
lu-zeroshssoichiro
authored andcommitted
Relax again the braced placeholder tokenizer
1 parent 5d91ad6 commit b30e53e

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,6 +1786,20 @@ mod tests {
17861786
expected
17871787
);
17881788
}
1789+
#[test]
1790+
fn it_formats_raw_sql_and_conditional_queries() {
1791+
let input = "SELECT {foo: &[T]}, {b.c()}, {d.e};";
1792+
let options = FormatOptions::default();
1793+
let expected = indoc!(
1794+
"
1795+
SELECT
1796+
{foo: &[T]},
1797+
{b.c()},
1798+
{d.e};"
1799+
);
1800+
1801+
assert_eq!(format(input, &QueryParams::None, &options), expected);
1802+
}
17891803

17901804
#[test]
17911805
fn it_formats_query_with_go_batch_separator() {

src/tokenizer.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -384,22 +384,18 @@ fn get_ident_named_placeholder_token<'i>(input: &mut &'i str) -> Result<Token<'i
384384
}
385385

386386
fn get_braced_named_placeholder_token<'i>(input: &mut &'i str) -> Result<Token<'i>> {
387-
delimited(
388-
'{',
389-
take_while(1.., |c: char| c.is_alphanumeric() || c == '_'),
390-
'}',
391-
)
392-
.with_taken()
393-
.parse_next(input)
394-
.map(|(index, token)| {
395-
let index = Cow::Borrowed(index);
396-
Token {
397-
kind: TokenKind::Placeholder,
398-
value: token,
399-
key: Some(PlaceholderKind::Named(index)),
400-
alias: token,
401-
}
402-
})
387+
delimited('{', take_until(1.., '}'), '}')
388+
.with_taken()
389+
.parse_next(input)
390+
.map(|(index, token)| {
391+
let index = Cow::Borrowed(index);
392+
Token {
393+
kind: TokenKind::Placeholder,
394+
value: token,
395+
key: Some(PlaceholderKind::Named(index)),
396+
alias: token,
397+
}
398+
})
403399
}
404400

405401
fn get_string_named_placeholder_token<'i>(

0 commit comments

Comments
 (0)