@@ -10,15 +10,18 @@ use nom::{AsChar, Err, IResult};
10
10
use std:: borrow:: Cow ;
11
11
use unicode_categories:: UnicodeCategories ;
12
12
13
- pub ( crate ) fn tokenize ( mut input : & str ) -> Vec < Token < ' _ > > {
13
+ pub ( crate ) fn tokenize ( mut input : & str , named_placeholders : bool ) -> Vec < Token < ' _ > > {
14
14
let mut tokens: Vec < Token > = Vec :: new ( ) ;
15
15
16
16
let mut last_reserved_token = None ;
17
17
18
18
// Keep processing the string until it is empty
19
- while let Ok ( result) =
20
- get_next_token ( input, tokens. last ( ) . cloned ( ) , last_reserved_token. clone ( ) )
21
- {
19
+ while let Ok ( result) = get_next_token (
20
+ input,
21
+ tokens. last ( ) . cloned ( ) ,
22
+ last_reserved_token. clone ( ) ,
23
+ named_placeholders,
24
+ ) {
22
25
if result. 1 . kind == TokenKind :: Reserved {
23
26
last_reserved_token = Some ( result. 1 . clone ( ) ) ;
24
27
}
@@ -83,15 +86,16 @@ fn get_next_token<'a>(
83
86
input : & ' a str ,
84
87
previous_token : Option < Token < ' a > > ,
85
88
last_reserved_token : Option < Token < ' a > > ,
89
+ named_placeholders : bool ,
86
90
) -> IResult < & ' a str , Token < ' a > > {
87
91
get_whitespace_token ( input)
88
92
. or_else ( |_| get_comment_token ( input) )
89
93
. or_else ( |_| get_string_token ( input) )
90
94
. or_else ( |_| get_open_paren_token ( input) )
91
95
. or_else ( |_| get_close_paren_token ( input) )
92
- . or_else ( |_| get_placeholder_token ( input) )
93
96
. or_else ( |_| get_number_token ( input) )
94
97
. or_else ( |_| get_reserved_word_token ( input, previous_token, last_reserved_token) )
98
+ . or_else ( |_| get_placeholder_token ( input, named_placeholders) )
95
99
. or_else ( |_| get_word_token ( input) )
96
100
. or_else ( |_| get_operator_token ( input) )
97
101
}
@@ -288,12 +292,23 @@ fn get_close_paren_token(input: &str) -> IResult<&str, Token<'_>> {
288
292
} )
289
293
}
290
294
291
- fn get_placeholder_token ( input : & str ) -> IResult < & str , Token < ' _ > > {
292
- alt ( (
293
- get_ident_named_placeholder_token,
294
- get_string_named_placeholder_token,
295
- get_indexed_placeholder_token,
296
- ) ) ( input)
295
+ fn get_placeholder_token ( input : & str , named_placeholders : bool ) -> IResult < & str , Token < ' _ > > {
296
+ // The precedence changes based on 'named_placeholders' but not the exhaustiveness.
297
+ // This is to ensure the formatting is the same even if parameters aren't used.
298
+
299
+ if named_placeholders {
300
+ alt ( (
301
+ get_ident_named_placeholder_token,
302
+ get_string_named_placeholder_token,
303
+ get_indexed_placeholder_token,
304
+ ) ) ( input)
305
+ } else {
306
+ alt ( (
307
+ get_indexed_placeholder_token,
308
+ get_ident_named_placeholder_token,
309
+ get_string_named_placeholder_token,
310
+ ) ) ( input)
311
+ }
297
312
}
298
313
299
314
fn get_indexed_placeholder_token ( input : & str ) -> IResult < & str , Token < ' _ > > {
@@ -327,7 +342,7 @@ fn get_indexed_placeholder_token(input: &str) -> IResult<&str, Token<'_>> {
327
342
328
343
fn get_ident_named_placeholder_token ( input : & str ) -> IResult < & str , Token < ' _ > > {
329
344
recognize ( tuple ( (
330
- alt ( ( char ( '@' ) , char ( ':' ) ) ) ,
345
+ alt ( ( char ( '@' ) , char ( ':' ) , char ( '$' ) ) ) ,
331
346
take_while1 ( |item : char | {
332
347
item. is_alphanumeric ( ) || item == '.' || item == '_' || item == '$'
333
348
} ) ,
0 commit comments