From 12e3b4c70b5ef23b2fdfc197296d483680e125f9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 8 Feb 2019 14:49:43 +0300 Subject: reformat the world --- crates/ra_mbe/src/lib.rs | 28 ++++++++-------------------- crates/ra_mbe/src/mbe_expander.rs | 29 +++++++---------------------- crates/ra_mbe/src/mbe_parser.rs | 11 ++--------- crates/ra_mbe/src/syntax_bridge.rs | 25 +++++-------------------- 4 files changed, 22 insertions(+), 71 deletions(-) (limited to 'crates/ra_mbe/src') diff --git a/crates/ra_mbe/src/lib.rs b/crates/ra_mbe/src/lib.rs index 2c8ad4429..b09837831 100644 --- a/crates/ra_mbe/src/lib.rs +++ b/crates/ra_mbe/src/lib.rs @@ -137,18 +137,12 @@ impl_froms!(TokenTree: Leaf, Subtree); "#; let source_file = ast::SourceFile::parse(macro_definition); - let macro_definition = source_file - .syntax() - .descendants() - .find_map(ast::MacroCall::cast) - .unwrap(); + let macro_definition = + source_file.syntax().descendants().find_map(ast::MacroCall::cast).unwrap(); let source_file = ast::SourceFile::parse(macro_invocation); - let macro_invocation = source_file - .syntax() - .descendants() - .find_map(ast::MacroCall::cast) - .unwrap(); + let macro_invocation = + source_file.syntax().descendants().find_map(ast::MacroCall::cast).unwrap(); let definition_tt = ast_to_token_tree(macro_definition.token_tree().unwrap()).unwrap(); let invocation_tt = ast_to_token_tree(macro_invocation.token_tree().unwrap()).unwrap(); @@ -163,11 +157,8 @@ impl_froms!(TokenTree: Leaf, Subtree); fn create_rules(macro_definition: &str) -> MacroRules { let source_file = ast::SourceFile::parse(macro_definition); - let macro_definition = source_file - .syntax() - .descendants() - .find_map(ast::MacroCall::cast) - .unwrap(); + let macro_definition = + source_file.syntax().descendants().find_map(ast::MacroCall::cast).unwrap(); let definition_tt = ast_to_token_tree(macro_definition.token_tree().unwrap()).unwrap(); crate::MacroRules::parse(&definition_tt).unwrap() @@ -175,11 +166,8 @@ impl_froms!(TokenTree: Leaf, Subtree); fn assert_expansion(rules: &MacroRules, invocation: &str, expansion: &str) { let source_file = ast::SourceFile::parse(invocation); - let macro_invocation = source_file - .syntax() - .descendants() - .find_map(ast::MacroCall::cast) - .unwrap(); + let macro_invocation = + source_file.syntax().descendants().find_map(ast::MacroCall::cast).unwrap(); let invocation_tt = ast_to_token_tree(macro_invocation.token_tree().unwrap()).unwrap(); diff --git a/crates/ra_mbe/src/mbe_expander.rs b/crates/ra_mbe/src/mbe_expander.rs index fb1066eec..31531f4c9 100644 --- a/crates/ra_mbe/src/mbe_expander.rs +++ b/crates/ra_mbe/src/mbe_expander.rs @@ -133,11 +133,7 @@ fn match_lhs(pattern: &crate::Subtree, input: &mut TtCursor) -> Option } _ => return None, }, - crate::TokenTree::Repeat(crate::Repeat { - subtree, - kind: _, - separator, - }) => { + crate::TokenTree::Repeat(crate::Repeat { subtree, kind: _, separator }) => { while let Some(nested) = match_lhs(subtree, input) { res.push_nested(nested)?; if let Some(separator) = *separator { @@ -166,10 +162,7 @@ fn expand_subtree( .map(|it| expand_tt(it, bindings, nesting)) .collect::>>()?; - Some(tt::Subtree { - token_trees, - delimiter: template.delimiter, - }) + Some(tt::Subtree { token_trees, delimiter: template.delimiter }) } fn expand_tt( @@ -188,23 +181,15 @@ fn expand_tt( token_trees.push(t.into()) } nesting.pop().unwrap(); - tt::Subtree { - token_trees, - delimiter: tt::Delimiter::None, - } - .into() + tt::Subtree { token_trees, delimiter: tt::Delimiter::None }.into() } crate::TokenTree::Leaf(leaf) => match leaf { - crate::Leaf::Ident(ident) => tt::Leaf::from(tt::Ident { - text: ident.text.clone(), - }) - .into(), + crate::Leaf::Ident(ident) => { + tt::Leaf::from(tt::Ident { text: ident.text.clone() }).into() + } crate::Leaf::Punct(punct) => tt::Leaf::from(punct.clone()).into(), crate::Leaf::Var(v) => bindings.get(&v.text, nesting)?.clone(), - crate::Leaf::Literal(l) => tt::Leaf::from(tt::Literal { - text: l.text.clone(), - }) - .into(), + crate::Leaf::Literal(l) => tt::Leaf::from(tt::Literal { text: l.text.clone() }).into(), }, }; Some(res) diff --git a/crates/ra_mbe/src/mbe_parser.rs b/crates/ra_mbe/src/mbe_parser.rs index abad2e8c8..60e566ed2 100644 --- a/crates/ra_mbe/src/mbe_parser.rs +++ b/crates/ra_mbe/src/mbe_parser.rs @@ -52,10 +52,7 @@ fn parse_subtree(tt: &tt::Subtree) -> Option { }; token_trees.push(child); } - Some(crate::Subtree { - token_trees, - delimiter: tt.delimiter, - }) + Some(crate::Subtree { token_trees, delimiter: tt.delimiter }) } fn parse_var(p: &mut TtCursor) -> Option { @@ -92,9 +89,5 @@ fn parse_repeat(p: &mut TtCursor) -> Option { _ => return None, }; p.bump(); - Some(crate::Repeat { - subtree, - kind, - separator, - }) + Some(crate::Repeat { subtree, kind, separator }) } diff --git a/crates/ra_mbe/src/syntax_bridge.rs b/crates/ra_mbe/src/syntax_bridge.rs index 2dc04d4e7..9a2eceaba 100644 --- a/crates/ra_mbe/src/syntax_bridge.rs +++ b/crates/ra_mbe/src/syntax_bridge.rs @@ -23,23 +23,14 @@ fn convert_tt(tt: &SyntaxNode) -> Option { for char in child.leaf_text().unwrap().chars() { if let Some(char) = prev { token_trees.push( - tt::Leaf::from(tt::Punct { - char, - spacing: tt::Spacing::Joint, - }) - .into(), + tt::Leaf::from(tt::Punct { char, spacing: tt::Spacing::Joint }).into(), ); } prev = Some(char) } if let Some(char) = prev { - token_trees.push( - tt::Leaf::from(tt::Punct { - char, - spacing: tt::Spacing::Alone, - }) - .into(), - ); + token_trees + .push(tt::Leaf::from(tt::Punct { char, spacing: tt::Spacing::Alone }).into()); } } else { let child: tt::TokenTree = if child.kind() == TOKEN_TREE { @@ -48,10 +39,7 @@ fn convert_tt(tt: &SyntaxNode) -> Option { let text = child.leaf_text().unwrap().clone(); tt::Leaf::from(tt::Ident { text }).into() } else if child.kind().is_literal() { - tt::Leaf::from(tt::Literal { - text: child.leaf_text().unwrap().clone(), - }) - .into() + tt::Leaf::from(tt::Literal { text: child.leaf_text().unwrap().clone() }).into() } else { return None; }; @@ -59,9 +47,6 @@ fn convert_tt(tt: &SyntaxNode) -> Option { } } - let res = tt::Subtree { - delimiter, - token_trees, - }; + let res = tt::Subtree { delimiter, token_trees }; Some(res) } -- cgit v1.2.3