From c47f9e2d37d4797550638e2a7a4fd3538e9edae9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 21 Feb 2019 13:37:32 +0300 Subject: fix compilation --- crates/ra_syntax/src/parsing/builder.rs | 15 ++++++++------- crates/ra_syntax/src/parsing/input.rs | 7 +++---- crates/ra_syntax/src/parsing/reparsing.rs | 21 ++++++++++----------- 3 files changed, 21 insertions(+), 22 deletions(-) (limited to 'crates/ra_syntax/src/parsing') diff --git a/crates/ra_syntax/src/parsing/builder.rs b/crates/ra_syntax/src/parsing/builder.rs index 1041c6a7b..0775b0900 100644 --- a/crates/ra_syntax/src/parsing/builder.rs +++ b/crates/ra_syntax/src/parsing/builder.rs @@ -1,7 +1,9 @@ +use ra_parser::{TreeSink, ParseError}; + use crate::{ SmolStr, SyntaxError, SyntaxErrorKind, TextUnit, TextRange, SyntaxKind::{self, *}, - parsing::{TreeSink, ParseError, Token}, + parsing::Token, syntax_node::{GreenNode, RaTypes}, }; @@ -17,8 +19,6 @@ pub(crate) struct TreeBuilder<'a> { } impl<'a> TreeSink for TreeBuilder<'a> { - type Tree = (GreenNode, Vec); - fn leaf(&mut self, kind: SyntaxKind, n_tokens: u8) { self.eat_trivias(); let n_tokens = n_tokens as usize; @@ -65,10 +65,6 @@ impl<'a> TreeSink for TreeBuilder<'a> { let error = SyntaxError::new(SyntaxErrorKind::ParseError(error), self.text_pos); self.errors.push(error) } - - fn finish(self) -> (GreenNode, Vec) { - (self.inner.finish(), self.errors) - } } impl<'a> TreeBuilder<'a> { @@ -82,6 +78,11 @@ impl<'a> TreeBuilder<'a> { inner: GreenNodeBuilder::new(), } } + + pub(super) fn finish(self) -> (GreenNode, Vec) { + (self.inner.finish(), self.errors) + } + fn eat_trivias(&mut self) { while let Some(&token) = self.tokens.get(self.token_pos) { if !token.kind.is_trivia() { diff --git a/crates/ra_syntax/src/parsing/input.rs b/crates/ra_syntax/src/parsing/input.rs index 96c03bb11..58be795bc 100644 --- a/crates/ra_syntax/src/parsing/input.rs +++ b/crates/ra_syntax/src/parsing/input.rs @@ -1,9 +1,8 @@ +use ra_parser::TokenSource; + use crate::{ SyntaxKind, SyntaxKind::EOF, TextRange, TextUnit, - parsing::{ - TokenSource, - lexer::Token, - }, + parsing::lexer::Token, }; impl<'t> TokenSource for ParserInput<'t> { diff --git a/crates/ra_syntax/src/parsing/reparsing.rs b/crates/ra_syntax/src/parsing/reparsing.rs index 2c860b3df..ffcb512ad 100644 --- a/crates/ra_syntax/src/parsing/reparsing.rs +++ b/crates/ra_syntax/src/parsing/reparsing.rs @@ -1,18 +1,18 @@ +use ra_text_edit::AtomTextEdit; +use ra_parser::Reparser; + use crate::{ SyntaxKind::*, TextRange, TextUnit, algo, syntax_node::{GreenNode, SyntaxNode}, syntax_error::SyntaxError, parsing::{ - grammar, parse_with, + input::ParserInput, builder::TreeBuilder, - parser::Parser, lexer::{tokenize, Token}, } }; -use ra_text_edit::AtomTextEdit; - pub(crate) fn incremental_reparse( node: &SyntaxNode, edit: &AtomTextEdit, @@ -61,8 +61,10 @@ fn reparse_block<'node>( if !is_balanced(&tokens) { return None; } - let tree_sink = TreeBuilder::new(&text, &tokens); - let (green, new_errors) = parse_with(tree_sink, &text, &tokens, reparser); + let token_source = ParserInput::new(&text, &tokens); + let mut tree_sink = TreeBuilder::new(&text, &tokens); + reparser.parse(&token_source, &mut tree_sink); + let (green, new_errors) = tree_sink.finish(); Some((node, green, new_errors)) } @@ -78,15 +80,12 @@ fn is_contextual_kw(text: &str) -> bool { } } -fn find_reparsable_node( - node: &SyntaxNode, - range: TextRange, -) -> Option<(&SyntaxNode, fn(&mut Parser))> { +fn find_reparsable_node(node: &SyntaxNode, range: TextRange) -> Option<(&SyntaxNode, Reparser)> { let node = algo::find_covering_node(node, range); node.ancestors().find_map(|node| { let first_child = node.first_child().map(|it| it.kind()); let parent = node.parent().map(|it| it.kind()); - grammar::reparser(node.kind(), first_child, parent).map(|r| (node, r)) + Reparser::for_node(node.kind(), first_child, parent).map(|r| (node, r)) }) } -- cgit v1.2.3