diff options
Diffstat (limited to 'crates/ra_tools')
-rw-r--r-- | crates/ra_tools/src/boilerplate_gen.rs | 44 |
1 files changed, 18 insertions, 26 deletions
diff --git a/crates/ra_tools/src/boilerplate_gen.rs b/crates/ra_tools/src/boilerplate_gen.rs index 578f13a3e..1d112c0af 100644 --- a/crates/ra_tools/src/boilerplate_gen.rs +++ b/crates/ra_tools/src/boilerplate_gen.rs | |||
@@ -160,31 +160,24 @@ fn generate_ast(grammar: &Grammar) -> Result<String> { | |||
160 | } | 160 | } |
161 | 161 | ||
162 | fn generate_syntax_kinds(grammar: &Grammar) -> Result<String> { | 162 | fn generate_syntax_kinds(grammar: &Grammar) -> Result<String> { |
163 | let single_byte_tokens_values = | 163 | let (single_byte_tokens_values, single_byte_tokens): (Vec<_>, Vec<_>) = grammar |
164 | grammar.single_byte_tokens.iter().map(|(token, _name)| token.chars().next().unwrap()); | 164 | .punct |
165 | let single_byte_tokens = grammar | ||
166 | .single_byte_tokens | ||
167 | .iter() | 165 | .iter() |
168 | .map(|(_token, name)| format_ident!("{}", name)) | 166 | .filter(|(token, _name)| token.len() == 1) |
169 | .collect::<Vec<_>>(); | 167 | .map(|(token, name)| (token.chars().next().unwrap(), format_ident!("{}", name))) |
170 | 168 | .unzip(); | |
171 | let punctuation_values = | 169 | |
172 | grammar.single_byte_tokens.iter().chain(grammar.multi_byte_tokens.iter()).map( | 170 | let punctuation_values = grammar.punct.iter().map(|(token, _name)| { |
173 | |(token, _name)| { | 171 | if "{}[]()".contains(token) { |
174 | if "{}[]()".contains(token) { | 172 | let c = token.chars().next().unwrap(); |
175 | let c = token.chars().next().unwrap(); | 173 | quote! { #c } |
176 | quote! { #c } | 174 | } else { |
177 | } else { | 175 | let cs = token.chars().map(|c| Punct::new(c, Spacing::Joint)); |
178 | let cs = token.chars().map(|c| Punct::new(c, Spacing::Joint)); | 176 | quote! { #(#cs)* } |
179 | quote! { #(#cs)* } | 177 | } |
180 | } | 178 | }); |
181 | }, | 179 | let punctuation = |
182 | ); | 180 | grammar.punct.iter().map(|(_token, name)| format_ident!("{}", name)).collect::<Vec<_>>(); |
183 | let punctuation = single_byte_tokens | ||
184 | .clone() | ||
185 | .into_iter() | ||
186 | .chain(grammar.multi_byte_tokens.iter().map(|(_token, name)| format_ident!("{}", name))) | ||
187 | .collect::<Vec<_>>(); | ||
188 | 181 | ||
189 | let full_keywords_values = &grammar.keywords; | 182 | let full_keywords_values = &grammar.keywords; |
190 | let full_keywords = | 183 | let full_keywords = |
@@ -294,8 +287,7 @@ fn reformat(text: impl std::fmt::Display) -> Result<String> { | |||
294 | 287 | ||
295 | #[derive(Deserialize, Debug)] | 288 | #[derive(Deserialize, Debug)] |
296 | struct Grammar { | 289 | struct Grammar { |
297 | single_byte_tokens: Vec<(String, String)>, | 290 | punct: Vec<(String, String)>, |
298 | multi_byte_tokens: Vec<(String, String)>, | ||
299 | keywords: Vec<String>, | 291 | keywords: Vec<String>, |
300 | contextual_keywords: Vec<String>, | 292 | contextual_keywords: Vec<String>, |
301 | literals: Vec<String>, | 293 | literals: Vec<String>, |