66//! e.g. expressions, type references etc.
77
88use crate :: { SsrError , SsrPattern , SsrRule } ;
9- use ra_syntax:: { ast, AstNode , SmolStr , SyntaxKind } ;
9+ use ra_syntax:: { ast, AstNode , SmolStr , SyntaxKind , T } ;
1010use rustc_hash:: { FxHashMap , FxHashSet } ;
1111use std:: str:: FromStr ;
1212
@@ -161,7 +161,7 @@ fn parse_pattern(pattern_str: &str) -> Result<Vec<PatternElement>, SsrError> {
161161 let mut placeholder_names = FxHashSet :: default ( ) ;
162162 let mut tokens = tokenize ( pattern_str) ?. into_iter ( ) ;
163163 while let Some ( token) = tokens. next ( ) {
164- if token. kind == SyntaxKind :: DOLLAR {
164+ if token. kind == T ! [ $ ] {
165165 let placeholder = parse_placeholder ( & mut tokens) ?;
166166 if !placeholder_names. insert ( placeholder. ident . clone ( ) ) {
167167 bail ! ( "Name `{}` repeats more than once" , placeholder. ident) ;
@@ -226,7 +226,7 @@ fn parse_placeholder(tokens: &mut std::vec::IntoIter<Token>) -> Result<Placehold
226226 SyntaxKind :: IDENT => {
227227 name = Some ( token. text ) ;
228228 }
229- SyntaxKind :: L_CURLY => {
229+ T ! [ '{' ] => {
230230 let token =
231231 tokens. next ( ) . ok_or_else ( || SsrError :: new ( "Unexpected end of placeholder" ) ) ?;
232232 if token. kind == SyntaxKind :: IDENT {
@@ -237,10 +237,10 @@ fn parse_placeholder(tokens: &mut std::vec::IntoIter<Token>) -> Result<Placehold
237237 . next ( )
238238 . ok_or_else ( || SsrError :: new ( "Placeholder is missing closing brace '}'" ) ) ?;
239239 match token. kind {
240- SyntaxKind :: COLON => {
240+ T ! [ : ] => {
241241 constraints. push ( parse_constraint ( tokens) ?) ;
242242 }
243- SyntaxKind :: R_CURLY => break ,
243+ T ! [ '}' ] => break ,
244244 _ => bail ! ( "Unexpected token while parsing placeholder: '{}'" , token. text) ,
245245 }
246246 }
@@ -330,24 +330,24 @@ mod tests {
330330 result. pattern. raw. tokens,
331331 vec![
332332 token( SyntaxKind :: IDENT , "foo" ) ,
333- token( SyntaxKind :: L_PAREN , "(" ) ,
333+ token( T ! [ '(' ] , "(" ) ,
334334 placeholder( "a" ) ,
335- token( SyntaxKind :: COMMA , "," ) ,
335+ token( T ! [ , ] , "," ) ,
336336 token( SyntaxKind :: WHITESPACE , " " ) ,
337337 placeholder( "b" ) ,
338- token( SyntaxKind :: R_PAREN , ")" ) ,
338+ token( T ! [ ')' ] , ")" ) ,
339339 ]
340340 ) ;
341341 assert_eq ! (
342342 result. template. tokens,
343343 vec![
344344 token( SyntaxKind :: IDENT , "bar" ) ,
345- token( SyntaxKind :: L_PAREN , "(" ) ,
345+ token( T ! [ '(' ] , "(" ) ,
346346 placeholder( "b" ) ,
347- token( SyntaxKind :: COMMA , "," ) ,
347+ token( T ! [ , ] , "," ) ,
348348 token( SyntaxKind :: WHITESPACE , " " ) ,
349349 placeholder( "a" ) ,
350- token( SyntaxKind :: R_PAREN , ")" ) ,
350+ token( T ! [ ')' ] , ")" ) ,
351351 ]
352352 ) ;
353353 }
0 commit comments