aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/parsing/grammar.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src/parsing/grammar.rs')
-rw-r--r--crates/ra_syntax/src/parsing/grammar.rs34
1 files changed, 26 insertions, 8 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,