From 9eb14e11706ebf9a60b0afbe9bc82a99a816bc02 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 10 Sep 2019 22:12:37 +0300 Subject: cleanup expansion to item list --- crates/ra_mbe/src/syntax_bridge.rs | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) (limited to 'crates/ra_mbe/src/syntax_bridge.rs') diff --git a/crates/ra_mbe/src/syntax_bridge.rs b/crates/ra_mbe/src/syntax_bridge.rs index 26524adf9..2d035307b 100644 --- a/crates/ra_mbe/src/syntax_bridge.rs +++ b/crates/ra_mbe/src/syntax_bridge.rs @@ -46,25 +46,6 @@ pub fn syntax_node_to_token_tree(node: &SyntaxNode) -> Option<(tt::Subtree, Toke // * TraitItems(SmallVec<[ast::TraitItem; 1]>) // * ImplItems(SmallVec<[ast::ImplItem; 1]>) // * ForeignItems(SmallVec<[ast::ForeignItem; 1]> -// -// - -fn token_tree_to_syntax_node(tt: &tt::Subtree, f: F) -> Result, ExpandError> -where - F: Fn(&mut dyn ra_parser::TokenSource, &mut dyn ra_parser::TreeSink), -{ - let tokens = [tt.clone().into()]; - let buffer = TokenBuffer::new(&tokens); - let mut token_source = SubtreeTokenSource::new(&buffer); - let mut tree_sink = TtTreeSink::new(buffer.begin()); - f(&mut token_source, &mut tree_sink); - if tree_sink.roots.len() != 1 { - return Err(ExpandError::ConversionError); - } - //FIXME: would be cool to report errors - let parse = tree_sink.inner.finish(); - Ok(parse) -} fn fragment_to_syntax_node( tt: &tt::Subtree, @@ -115,17 +96,11 @@ pub fn token_tree_to_macro_stmts(tt: &tt::Subtree) -> Result Result, ExpandError> { +pub fn token_tree_to_items(tt: &tt::Subtree) -> Result, ExpandError> { let parse = fragment_to_syntax_node(tt, Items)?; parse.cast().ok_or_else(|| crate::ExpandError::ConversionError) } -/// Parses the token tree (result of macro expansion) as a sequence of items -pub fn token_tree_to_ast_item_list(tt: &tt::Subtree) -> Parse { - let parse = token_tree_to_syntax_node(tt, ra_parser::parse).unwrap(); - parse.cast().unwrap() -} - impl TokenMap { pub fn relative_range_of(&self, tt: tt::TokenId) -> Option { let idx = tt.0 as usize; -- cgit v1.2.3