aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_syntax/src/parsing/grammar.rs34
-rw-r--r--crates/ra_syntax/src/parsing/reparsing.rs26
2 files changed, 27 insertions, 33 deletions
diff --git a/crates/ra_syntax/src/parsing/grammar.rs b/crates/ra_syntax/src/parsing/grammar.rs
index bf86443de..bcdcd9f57 100644
--- a/crates/ra_syntax/src/parsing/grammar.rs
+++ b/crates/ra_syntax/src/parsing/grammar.rs
@@ -36,14 +36,8 @@ mod type_args;
36mod type_params; 36mod type_params;
37mod types; 37mod types;
38 38
39pub(crate) use self::{
40 expressions::block,
41 items::{
42 enum_variant_list, extern_item_list, impl_item_list, match_arm_list, mod_item_list,
43 named_field_def_list, named_field_list, token_tree, trait_item_list, use_tree_list,
44 },
45};
46use crate::{ 39use crate::{
40 SyntaxNode,
47 SyntaxKind::{self, *}, 41 SyntaxKind::{self, *},
48 parsing::{ 42 parsing::{
49 token_set::TokenSet, 43 token_set::TokenSet,
@@ -51,13 +45,37 @@ use crate::{
51 }, 45 },
52}; 46};
53 47
54pub(crate) fn root(p: &mut Parser) { 48pub(super) fn root(p: &mut Parser) {
55 let m = p.start(); 49 let m = p.start();
56 p.eat(SHEBANG); 50 p.eat(SHEBANG);
57 items::mod_contents(p, false); 51 items::mod_contents(p, false);
58 m.complete(p, SOURCE_FILE); 52 m.complete(p, SOURCE_FILE);
59} 53}
60 54
55pub(super) fn reparser(node: &SyntaxNode) -> Option<fn(&mut Parser)> {
56 let res = match node.kind() {
57 BLOCK => expressions::block,
58 NAMED_FIELD_DEF_LIST => items::named_field_def_list,
59 NAMED_FIELD_LIST => items::named_field_list,
60 ENUM_VARIANT_LIST => items::enum_variant_list,
61 MATCH_ARM_LIST => items::match_arm_list,
62 USE_TREE_LIST => items::use_tree_list,
63 EXTERN_ITEM_LIST => items::extern_item_list,
64 TOKEN_TREE if node.first_child().unwrap().kind() == L_CURLY => items::token_tree,
65 ITEM_LIST => {
66 let parent = node.parent().unwrap();
67 match parent.kind() {
68 IMPL_BLOCK => items::impl_item_list,
69 TRAIT_DEF => items::trait_item_list,
70 MODULE => items::mod_item_list,
71 _ => return None,
72 }
73 }
74 _ => return None,
75 };
76 Some(res)
77}
78
61#[derive(Clone, Copy, PartialEq, Eq)] 79#[derive(Clone, Copy, PartialEq, Eq)]
62enum BlockLike { 80enum BlockLike {
63 Block, 81 Block,
diff --git a/crates/ra_syntax/src/parsing/reparsing.rs b/crates/ra_syntax/src/parsing/reparsing.rs
index 994e7e212..0a24dae0e 100644
--- a/crates/ra_syntax/src/parsing/reparsing.rs
+++ b/crates/ra_syntax/src/parsing/reparsing.rs
@@ -81,31 +81,7 @@ fn is_contextual_kw(text: &str) -> bool {
81type ParseFn = fn(&mut Parser); 81type ParseFn = fn(&mut Parser);
82fn find_reparsable_node(node: &SyntaxNode, range: TextRange) -> Option<(&SyntaxNode, ParseFn)> { 82fn find_reparsable_node(node: &SyntaxNode, range: TextRange) -> Option<(&SyntaxNode, ParseFn)> {
83 let node = algo::find_covering_node(node, range); 83 let node = algo::find_covering_node(node, range);
84 return node.ancestors().filter_map(|node| reparser(node).map(|r| (node, r))).next(); 84 node.ancestors().find_map(grammar::reparser).map(|r| (node, r))
85
86 fn reparser(node: &SyntaxNode) -> Option<ParseFn> {
87 let res = match node.kind() {
88 BLOCK => grammar::block,
89 NAMED_FIELD_DEF_LIST => grammar::named_field_def_list,
90 NAMED_FIELD_LIST => grammar::named_field_list,
91 ENUM_VARIANT_LIST => grammar::enum_variant_list,
92 MATCH_ARM_LIST => grammar::match_arm_list,
93 USE_TREE_LIST => grammar::use_tree_list,
94 EXTERN_ITEM_LIST => grammar::extern_item_list,
95 TOKEN_TREE if node.first_child().unwrap().kind() == L_CURLY => grammar::token_tree,
96 ITEM_LIST => {
97 let parent = node.parent().unwrap();
98 match parent.kind() {
99 IMPL_BLOCK => grammar::impl_item_list,
100 TRAIT_DEF => grammar::trait_item_list,
101 MODULE => grammar::mod_item_list,
102 _ => return None,
103 }
104 }
105 _ => return None,
106 };
107 Some(res)
108 }
109} 85}
110 86
111fn is_balanced(tokens: &[Token]) -> bool { 87fn is_balanced(tokens: &[Token]) -> bool {