|
1 | 1 | use std::borrow::Cow; |
2 | 2 | use unicode_categories::UnicodeCategories; |
3 | 3 | use winnow::ascii::{digit0, digit1, till_line_ending, Caseless}; |
4 | | -use winnow::combinator::{alt, dispatch, eof, fail, opt, peek, terminated}; |
| 4 | +use winnow::combinator::{alt, delimited, dispatch, eof, fail, opt, peek, terminated}; |
5 | 5 | use winnow::error::ContextError; |
6 | 6 | use winnow::error::ParserError; |
7 | 7 | use winnow::prelude::*; |
@@ -326,13 +326,15 @@ fn get_placeholder_token<'i>( |
326 | 326 | get_ident_named_placeholder_token, |
327 | 327 | |input: &mut _| get_string_named_placeholder_token(input, dialect), |
328 | 328 | get_indexed_placeholder_token, |
| 329 | + get_braced_named_placeholder_token, |
329 | 330 | )) |
330 | 331 | .parse_next(input) |
331 | 332 | } else { |
332 | 333 | alt(( |
333 | 334 | get_indexed_placeholder_token, |
334 | 335 | get_ident_named_placeholder_token, |
335 | 336 | |input: &mut _| get_string_named_placeholder_token(input, dialect), |
| 337 | + get_braced_named_placeholder_token, |
336 | 338 | )) |
337 | 339 | .parse_next(input) |
338 | 340 | } |
@@ -381,6 +383,25 @@ fn get_ident_named_placeholder_token<'i>(input: &mut &'i str) -> Result<Token<'i |
381 | 383 | }) |
382 | 384 | } |
383 | 385 |
|
| 386 | +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 | + }) |
| 403 | +} |
| 404 | + |
384 | 405 | fn get_string_named_placeholder_token<'i>( |
385 | 406 | input: &mut &'i str, |
386 | 407 | dialect: Dialect, |
|
0 commit comments