diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-21 10:46:17 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-21 10:46:17 +0000 |
commit | d77b5857c2420666e84dcd433f254e000e2843aa (patch) | |
tree | 416e333019e349bf4ee369f2548d9e6f6a9c67e9 /crates/ra_syntax/src/parsing/reparsing.rs | |
parent | 18b0c509f77a8e06141fee6668532cced1ebf5d8 (diff) | |
parent | 46179230a05331b1debd4dfa3bb197fa38d92347 (diff) |
Merge #867
867: This moves the parser to separate crate r=matklad a=matklad
That makes parser independent form both the token and the tree representation.
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src/parsing/reparsing.rs')
-rw-r--r-- | crates/ra_syntax/src/parsing/reparsing.rs | 21 |
1 files changed, 10 insertions, 11 deletions
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 @@ | |||
1 | use ra_text_edit::AtomTextEdit; | ||
2 | use ra_parser::Reparser; | ||
3 | |||
1 | use crate::{ | 4 | use crate::{ |
2 | SyntaxKind::*, TextRange, TextUnit, | 5 | SyntaxKind::*, TextRange, TextUnit, |
3 | algo, | 6 | algo, |
4 | syntax_node::{GreenNode, SyntaxNode}, | 7 | syntax_node::{GreenNode, SyntaxNode}, |
5 | syntax_error::SyntaxError, | 8 | syntax_error::SyntaxError, |
6 | parsing::{ | 9 | parsing::{ |
7 | grammar, parse_with, | 10 | input::ParserInput, |
8 | builder::TreeBuilder, | 11 | builder::TreeBuilder, |
9 | parser::Parser, | ||
10 | lexer::{tokenize, Token}, | 12 | lexer::{tokenize, Token}, |
11 | } | 13 | } |
12 | }; | 14 | }; |
13 | 15 | ||
14 | use ra_text_edit::AtomTextEdit; | ||
15 | |||
16 | pub(crate) fn incremental_reparse( | 16 | pub(crate) fn incremental_reparse( |
17 | node: &SyntaxNode, | 17 | node: &SyntaxNode, |
18 | edit: &AtomTextEdit, | 18 | edit: &AtomTextEdit, |
@@ -61,8 +61,10 @@ fn reparse_block<'node>( | |||
61 | if !is_balanced(&tokens) { | 61 | if !is_balanced(&tokens) { |
62 | return None; | 62 | return None; |
63 | } | 63 | } |
64 | let tree_sink = TreeBuilder::new(&text, &tokens); | 64 | let token_source = ParserInput::new(&text, &tokens); |
65 | let (green, new_errors) = parse_with(tree_sink, &text, &tokens, reparser); | 65 | let mut tree_sink = TreeBuilder::new(&text, &tokens); |
66 | reparser.parse(&token_source, &mut tree_sink); | ||
67 | let (green, new_errors) = tree_sink.finish(); | ||
66 | Some((node, green, new_errors)) | 68 | Some((node, green, new_errors)) |
67 | } | 69 | } |
68 | 70 | ||
@@ -78,15 +80,12 @@ fn is_contextual_kw(text: &str) -> bool { | |||
78 | } | 80 | } |
79 | } | 81 | } |
80 | 82 | ||
81 | fn find_reparsable_node( | 83 | fn find_reparsable_node(node: &SyntaxNode, range: TextRange) -> Option<(&SyntaxNode, Reparser)> { |
82 | node: &SyntaxNode, | ||
83 | range: TextRange, | ||
84 | ) -> Option<(&SyntaxNode, fn(&mut Parser))> { | ||
85 | let node = algo::find_covering_node(node, range); | 84 | let node = algo::find_covering_node(node, range); |
86 | node.ancestors().find_map(|node| { | 85 | node.ancestors().find_map(|node| { |
87 | let first_child = node.first_child().map(|it| it.kind()); | 86 | let first_child = node.first_child().map(|it| it.kind()); |
88 | let parent = node.parent().map(|it| it.kind()); | 87 | let parent = node.parent().map(|it| it.kind()); |
89 | grammar::reparser(node.kind(), first_child, parent).map(|r| (node, r)) | 88 | Reparser::for_node(node.kind(), first_child, parent).map(|r| (node, r)) |
90 | }) | 89 | }) |
91 | } | 90 | } |
92 | 91 | ||