4
4
//! placeholders, which start with `$`. For replacement templates, this is the final form. For
5
5
//! search patterns, we go further and parse the pattern as each kind of thing that we can match.
6
6
//! e.g. expressions, type references etc.
7
+ use rustc_hash:: { FxHashMap , FxHashSet } ;
8
+ use std:: { fmt:: Display , str:: FromStr } ;
9
+ use syntax:: { SmolStr , SyntaxKind , SyntaxNode , T } ;
7
10
8
11
use crate :: errors:: bail;
9
12
use crate :: { fragments, SsrError , SsrPattern , SsrRule } ;
10
- use rustc_hash:: { FxHashMap , FxHashSet } ;
11
- use std:: { fmt:: Display , str:: FromStr } ;
12
- use syntax:: { ast, AstNode , SmolStr , SyntaxKind , SyntaxNode , T } ;
13
13
14
14
#[ derive( Debug ) ]
15
15
pub ( crate ) struct ParsedRule {
@@ -75,14 +75,14 @@ impl ParsedRule {
75
75
76
76
let raw_template_stmt = raw_template. map ( fragments:: stmt) ;
77
77
if let raw_template_expr @ Some ( Ok ( _) ) = raw_template. map ( fragments:: expr) {
78
- builder. try_add2 ( fragments:: expr ( & raw_pattern) , raw_template_expr) ;
78
+ builder. try_add ( fragments:: expr ( & raw_pattern) , raw_template_expr) ;
79
79
} else {
80
- builder. try_add2 ( fragments:: expr ( & raw_pattern) , raw_template_stmt. clone ( ) ) ;
80
+ builder. try_add ( fragments:: expr ( & raw_pattern) , raw_template_stmt. clone ( ) ) ;
81
81
}
82
- builder. try_add2 ( fragments:: ty ( & raw_pattern) , raw_template. map ( fragments:: ty) ) ;
83
- builder. try_add2 ( fragments:: item ( & raw_pattern) , raw_template. map ( fragments:: item) ) ;
84
- builder. try_add ( ast :: Pat :: parse ( & raw_pattern) , raw_template. map ( ast :: Pat :: parse ) ) ;
85
- builder. try_add2 ( fragments:: stmt ( & raw_pattern) , raw_template_stmt) ;
82
+ builder. try_add ( fragments:: ty ( & raw_pattern) , raw_template. map ( fragments:: ty) ) ;
83
+ builder. try_add ( fragments:: item ( & raw_pattern) , raw_template. map ( fragments:: item) ) ;
84
+ builder. try_add ( fragments :: pat ( & raw_pattern) , raw_template. map ( fragments :: pat ) ) ;
85
+ builder. try_add ( fragments:: stmt ( & raw_pattern) , raw_template_stmt) ;
86
86
builder. build ( )
87
87
}
88
88
}
@@ -93,27 +93,7 @@ struct RuleBuilder {
93
93
}
94
94
95
95
impl RuleBuilder {
96
- fn try_add < T : AstNode , T2 : AstNode > (
97
- & mut self ,
98
- pattern : Result < T , ( ) > ,
99
- template : Option < Result < T2 , ( ) > > ,
100
- ) {
101
- match ( pattern, template) {
102
- ( Ok ( pattern) , Some ( Ok ( template) ) ) => self . rules . push ( ParsedRule {
103
- placeholders_by_stand_in : self . placeholders_by_stand_in . clone ( ) ,
104
- pattern : pattern. syntax ( ) . clone ( ) ,
105
- template : Some ( template. syntax ( ) . clone ( ) ) ,
106
- } ) ,
107
- ( Ok ( pattern) , None ) => self . rules . push ( ParsedRule {
108
- placeholders_by_stand_in : self . placeholders_by_stand_in . clone ( ) ,
109
- pattern : pattern. syntax ( ) . clone ( ) ,
110
- template : None ,
111
- } ) ,
112
- _ => { }
113
- }
114
- }
115
-
116
- fn try_add2 (
96
+ fn try_add (
117
97
& mut self ,
118
98
pattern : Result < SyntaxNode , ( ) > ,
119
99
template : Option < Result < SyntaxNode , ( ) > > ,
0 commit comments