From 66101e931c641b7d96dcfdbb83838130eab588bc Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 22 Sep 2019 23:46:27 +0300 Subject: simplify --- crates/ra_tools/src/boilerplate_gen.rs | 44 ++++++++++++++-------------------- 1 file changed, 18 insertions(+), 26 deletions(-) (limited to 'crates/ra_tools') 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 { } fn generate_syntax_kinds(grammar: &Grammar) -> Result { - let single_byte_tokens_values = - grammar.single_byte_tokens.iter().map(|(token, _name)| token.chars().next().unwrap()); - let single_byte_tokens = grammar - .single_byte_tokens + let (single_byte_tokens_values, single_byte_tokens): (Vec<_>, Vec<_>) = grammar + .punct .iter() - .map(|(_token, name)| format_ident!("{}", name)) - .collect::>(); - - let punctuation_values = - grammar.single_byte_tokens.iter().chain(grammar.multi_byte_tokens.iter()).map( - |(token, _name)| { - if "{}[]()".contains(token) { - let c = token.chars().next().unwrap(); - quote! { #c } - } else { - let cs = token.chars().map(|c| Punct::new(c, Spacing::Joint)); - quote! { #(#cs)* } - } - }, - ); - let punctuation = single_byte_tokens - .clone() - .into_iter() - .chain(grammar.multi_byte_tokens.iter().map(|(_token, name)| format_ident!("{}", name))) - .collect::>(); + .filter(|(token, _name)| token.len() == 1) + .map(|(token, name)| (token.chars().next().unwrap(), format_ident!("{}", name))) + .unzip(); + + let punctuation_values = grammar.punct.iter().map(|(token, _name)| { + if "{}[]()".contains(token) { + let c = token.chars().next().unwrap(); + quote! { #c } + } else { + let cs = token.chars().map(|c| Punct::new(c, Spacing::Joint)); + quote! { #(#cs)* } + } + }); + let punctuation = + grammar.punct.iter().map(|(_token, name)| format_ident!("{}", name)).collect::>(); let full_keywords_values = &grammar.keywords; let full_keywords = @@ -294,8 +287,7 @@ fn reformat(text: impl std::fmt::Display) -> Result { #[derive(Deserialize, Debug)] struct Grammar { - single_byte_tokens: Vec<(String, String)>, - multi_byte_tokens: Vec<(String, String)>, + punct: Vec<(String, String)>, keywords: Vec, contextual_keywords: Vec, literals: Vec, -- cgit v1.2.3