aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r--crates/ra_syntax/src/parsing/grammar.rs26
-rw-r--r--crates/ra_syntax/src/parsing/reparsing.rs6
2 files changed, 18 insertions, 14 deletions
diff --git a/crates/ra_syntax/src/parsing/grammar.rs b/crates/ra_syntax/src/parsing/grammar.rs
index 7ca9c223c..800d5a4a2 100644
--- a/crates/ra_syntax/src/parsing/grammar.rs
+++ b/crates/ra_syntax/src/parsing/grammar.rs
@@ -37,7 +37,6 @@ mod type_params;
37mod types; 37mod types;
38 38
39use crate::{ 39use crate::{
40 SyntaxNode,
41 SyntaxKind::{self, *}, 40 SyntaxKind::{self, *},
42 parsing::{ 41 parsing::{
43 token_set::TokenSet, 42 token_set::TokenSet,
@@ -52,8 +51,12 @@ pub(super) fn root(p: &mut Parser) {
52 m.complete(p, SOURCE_FILE); 51 m.complete(p, SOURCE_FILE);
53} 52}
54 53
55pub(super) fn reparser(node: &SyntaxNode) -> Option<fn(&mut Parser)> { 54pub(super) fn reparser(
56 let res = match node.kind() { 55 node: SyntaxKind,
56 first_child: Option<SyntaxKind>,
57 parent: Option<SyntaxKind>,
58) -> Option<fn(&mut Parser)> {
59 let res = match node {
57 BLOCK => expressions::block, 60 BLOCK => expressions::block,
58 NAMED_FIELD_DEF_LIST => items::named_field_def_list, 61 NAMED_FIELD_DEF_LIST => items::named_field_def_list,
59 NAMED_FIELD_LIST => items::named_field_list, 62 NAMED_FIELD_LIST => items::named_field_list,
@@ -61,16 +64,13 @@ pub(super) fn reparser(node: &SyntaxNode) -> Option<fn(&mut Parser)> {
61 MATCH_ARM_LIST => items::match_arm_list, 64 MATCH_ARM_LIST => items::match_arm_list,
62 USE_TREE_LIST => items::use_tree_list, 65 USE_TREE_LIST => items::use_tree_list,
63 EXTERN_ITEM_LIST => items::extern_item_list, 66 EXTERN_ITEM_LIST => items::extern_item_list,
64 TOKEN_TREE if node.first_child().unwrap().kind() == L_CURLY => items::token_tree, 67 TOKEN_TREE if first_child? == L_CURLY => items::token_tree,
65 ITEM_LIST => { 68 ITEM_LIST => match parent? {
66 let parent = node.parent().unwrap(); 69 IMPL_BLOCK => items::impl_item_list,
67 match parent.kind() { 70 TRAIT_DEF => items::trait_item_list,
68 IMPL_BLOCK => items::impl_item_list, 71 MODULE => items::mod_item_list,
69 TRAIT_DEF => items::trait_item_list, 72 _ => return None,
70 MODULE => items::mod_item_list, 73 },
71 _ => return None,
72 }
73 }
74 _ => return None, 74 _ => return None,
75 }; 75 };
76 Some(res) 76 Some(res)
diff --git a/crates/ra_syntax/src/parsing/reparsing.rs b/crates/ra_syntax/src/parsing/reparsing.rs
index f4c2251d7..2c860b3df 100644
--- a/crates/ra_syntax/src/parsing/reparsing.rs
+++ b/crates/ra_syntax/src/parsing/reparsing.rs
@@ -83,7 +83,11 @@ fn find_reparsable_node(
83 range: TextRange, 83 range: TextRange,
84) -> Option<(&SyntaxNode, fn(&mut Parser))> { 84) -> Option<(&SyntaxNode, fn(&mut Parser))> {
85 let node = algo::find_covering_node(node, range); 85 let node = algo::find_covering_node(node, range);
86 node.ancestors().find_map(|node| grammar::reparser(node).map(|r| (node, r))) 86 node.ancestors().find_map(|node| {
87 let first_child = node.first_child().map(|it| it.kind());
88 let parent = node.parent().map(|it| it.kind());
89 grammar::reparser(node.kind(), first_child, parent).map(|r| (node, r))
90 })
87} 91}
88 92
89fn is_balanced(tokens: &[Token]) -> bool { 93fn is_balanced(tokens: &[Token]) -> bool {