aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordarksv <[email protected]>2018-09-10 19:14:09 +0100
committerdarksv <[email protected]>2018-09-10 19:14:09 +0100
commit64d07c1bd475c4945db8d7cd1fa1a61e467b079b (patch)
tree3184113f1d146e887eae6d667ff9c16b2138160b
parent4f647096665b2ca3725ba1f7415a21fbc46044bb (diff)
Implement reparsing for remaining blocks
-rw-r--r--crates/libsyntax2/src/grammar/expressions/atom.rs2
-rw-r--r--crates/libsyntax2/src/grammar/expressions/mod.rs3
-rw-r--r--crates/libsyntax2/src/grammar/items/mod.rs15
-rw-r--r--crates/libsyntax2/src/grammar/items/nominal.rs2
-rw-r--r--crates/libsyntax2/src/grammar/items/traits.rs4
-rw-r--r--crates/libsyntax2/src/grammar/items/use_item.rs2
-rw-r--r--crates/libsyntax2/src/grammar/mod.rs17
-rw-r--r--crates/libsyntax2/src/lib.rs15
-rw-r--r--crates/libsyntax2/tests/test/main.rs61
9 files changed, 93 insertions, 28 deletions
diff --git a/crates/libsyntax2/src/grammar/expressions/atom.rs b/crates/libsyntax2/src/grammar/expressions/atom.rs
index 8335c700f..f01df56bc 100644
--- a/crates/libsyntax2/src/grammar/expressions/atom.rs
+++ b/crates/libsyntax2/src/grammar/expressions/atom.rs
@@ -287,7 +287,7 @@ fn match_expr(p: &mut Parser) -> CompletedMarker {
287 m.complete(p, MATCH_EXPR) 287 m.complete(p, MATCH_EXPR)
288} 288}
289 289
290fn match_arm_list(p: &mut Parser) { 290pub(crate) fn match_arm_list(p: &mut Parser) {
291 assert!(p.at(L_CURLY)); 291 assert!(p.at(L_CURLY));
292 let m = p.start(); 292 let m = p.start();
293 p.eat(L_CURLY); 293 p.eat(L_CURLY);
diff --git a/crates/libsyntax2/src/grammar/expressions/mod.rs b/crates/libsyntax2/src/grammar/expressions/mod.rs
index d5ee91ad8..20e0fa328 100644
--- a/crates/libsyntax2/src/grammar/expressions/mod.rs
+++ b/crates/libsyntax2/src/grammar/expressions/mod.rs
@@ -2,6 +2,7 @@ mod atom;
2 2
3use super::*; 3use super::*;
4pub(super) use self::atom::{literal, LITERAL_FIRST}; 4pub(super) use self::atom::{literal, LITERAL_FIRST};
5pub(crate) use self::atom::match_arm_list;
5 6
6const EXPR_FIRST: TokenSet = LHS_FIRST; 7const EXPR_FIRST: TokenSet = LHS_FIRST;
7 8
@@ -419,7 +420,7 @@ fn path_expr(p: &mut Parser, r: Restrictions) -> CompletedMarker {
419// S { x, y: 32, }; 420// S { x, y: 32, };
420// S { x, y: 32, ..Default::default() }; 421// S { x, y: 32, ..Default::default() };
421// } 422// }
422fn named_field_list(p: &mut Parser) { 423pub(crate) fn named_field_list(p: &mut Parser) {
423 assert!(p.at(L_CURLY)); 424 assert!(p.at(L_CURLY));
424 let m = p.start(); 425 let m = p.start();
425 p.bump(); 426 p.bump();
diff --git a/crates/libsyntax2/src/grammar/items/mod.rs b/crates/libsyntax2/src/grammar/items/mod.rs
index 85d7fe770..8c19aa179 100644
--- a/crates/libsyntax2/src/grammar/items/mod.rs
+++ b/crates/libsyntax2/src/grammar/items/mod.rs
@@ -5,7 +5,12 @@ mod traits;
5mod use_item; 5mod use_item;
6 6
7use super::*; 7use super::*;
8pub(crate) use self::nominal::named_field_def_list; 8pub(crate) use self::{
9 expressions::{named_field_list, match_arm_list},
10 nominal::{enum_variant_list, named_field_def_list},
11 traits::{trait_item_list, impl_item_list},
12 use_item::use_tree_list,
13};
9 14
10// test mod_contents 15// test mod_contents
11// fn foo() {} 16// fn foo() {}
@@ -223,7 +228,7 @@ fn extern_crate_item(p: &mut Parser) {
223 p.expect(SEMI); 228 p.expect(SEMI);
224} 229}
225 230
226fn extern_item_list(p: &mut Parser) { 231pub(crate) fn extern_item_list(p: &mut Parser) {
227 assert!(p.at(L_CURLY)); 232 assert!(p.at(L_CURLY));
228 let m = p.start(); 233 let m = p.start();
229 p.bump(); 234 p.bump();
@@ -295,7 +300,7 @@ fn type_def(p: &mut Parser) {
295 p.expect(SEMI); 300 p.expect(SEMI);
296} 301}
297 302
298fn mod_item(p: &mut Parser) { 303pub(crate) fn mod_item(p: &mut Parser) {
299 assert!(p.at(MOD_KW)); 304 assert!(p.at(MOD_KW));
300 p.bump(); 305 p.bump();
301 306
@@ -307,7 +312,7 @@ fn mod_item(p: &mut Parser) {
307 } 312 }
308} 313}
309 314
310fn mod_item_list(p: &mut Parser) { 315pub(crate) fn mod_item_list(p: &mut Parser) {
311 assert!(p.at(L_CURLY)); 316 assert!(p.at(L_CURLY));
312 let m = p.start(); 317 let m = p.start();
313 p.bump(); 318 p.bump();
@@ -343,7 +348,7 @@ pub(super) fn macro_call_after_excl(p: &mut Parser) -> BlockLike {
343 flavor 348 flavor
344} 349}
345 350
346pub(super) fn token_tree(p: &mut Parser) { 351pub(crate) fn token_tree(p: &mut Parser) {
347 let closing_paren_kind = match p.current() { 352 let closing_paren_kind = match p.current() {
348 L_CURLY => R_CURLY, 353 L_CURLY => R_CURLY,
349 L_PAREN => R_PAREN, 354 L_PAREN => R_PAREN,
diff --git a/crates/libsyntax2/src/grammar/items/nominal.rs b/crates/libsyntax2/src/grammar/items/nominal.rs
index 3db5b24af..11c43e371 100644
--- a/crates/libsyntax2/src/grammar/items/nominal.rs
+++ b/crates/libsyntax2/src/grammar/items/nominal.rs
@@ -51,7 +51,7 @@ pub(super) fn enum_def(p: &mut Parser) {
51 } 51 }
52} 52}
53 53
54fn enum_variant_list(p: &mut Parser) { 54pub(crate) fn enum_variant_list(p: &mut Parser) {
55 assert!(p.at(L_CURLY)); 55 assert!(p.at(L_CURLY));
56 let m = p.start(); 56 let m = p.start();
57 p.bump(); 57 p.bump();
diff --git a/crates/libsyntax2/src/grammar/items/traits.rs b/crates/libsyntax2/src/grammar/items/traits.rs
index 9d21d4d36..c21cfb1a9 100644
--- a/crates/libsyntax2/src/grammar/items/traits.rs
+++ b/crates/libsyntax2/src/grammar/items/traits.rs
@@ -25,7 +25,7 @@ pub(super) fn trait_def(p: &mut Parser) {
25// fn foo() {} 25// fn foo() {}
26// fn bar(&self); 26// fn bar(&self);
27// } 27// }
28fn trait_item_list(p: &mut Parser) { 28pub(crate) fn trait_item_list(p: &mut Parser) {
29 assert!(p.at(L_CURLY)); 29 assert!(p.at(L_CURLY));
30 let m = p.start(); 30 let m = p.start();
31 p.bump(); 31 p.bump();
@@ -74,7 +74,7 @@ pub(super) fn impl_item(p: &mut Parser) {
74// fn foo() {} 74// fn foo() {}
75// fn bar(&self) {} 75// fn bar(&self) {}
76// } 76// }
77fn impl_item_list(p: &mut Parser) { 77pub(crate) fn impl_item_list(p: &mut Parser) {
78 assert!(p.at(L_CURLY)); 78 assert!(p.at(L_CURLY));
79 let m = p.start(); 79 let m = p.start();
80 p.bump(); 80 p.bump();
diff --git a/crates/libsyntax2/src/grammar/items/use_item.rs b/crates/libsyntax2/src/grammar/items/use_item.rs
index 2fbf2234a..1ee4349fd 100644
--- a/crates/libsyntax2/src/grammar/items/use_item.rs
+++ b/crates/libsyntax2/src/grammar/items/use_item.rs
@@ -53,7 +53,7 @@ fn use_tree(p: &mut Parser) {
53 m.complete(p, USE_TREE); 53 m.complete(p, USE_TREE);
54} 54}
55 55
56fn use_tree_list(p: &mut Parser) { 56pub(crate) fn use_tree_list(p: &mut Parser) {
57 assert!(p.at(L_CURLY)); 57 assert!(p.at(L_CURLY));
58 let m = p.start(); 58 let m = p.start();
59 p.bump(); 59 p.bump();
diff --git a/crates/libsyntax2/src/grammar/mod.rs b/crates/libsyntax2/src/grammar/mod.rs
index e19805b9d..2cb11dc1e 100644
--- a/crates/libsyntax2/src/grammar/mod.rs
+++ b/crates/libsyntax2/src/grammar/mod.rs
@@ -37,8 +37,21 @@ use {
37 SyntaxKind::{self, *}, 37 SyntaxKind::{self, *},
38}; 38};
39pub(crate) use self::{ 39pub(crate) use self::{
40 expressions::block, 40 expressions::{
41 items::named_field_def_list, 41 block,
42 },
43 items::{
44 enum_variant_list,
45 extern_item_list,
46 impl_item_list,
47 match_arm_list,
48 mod_item_list,
49 named_field_def_list,
50 named_field_list,
51 token_tree,
52 trait_item_list,
53 use_tree_list,
54 },
42}; 55};
43 56
44pub(crate) fn root(p: &mut Parser) { 57pub(crate) fn root(p: &mut Parser) {
diff --git a/crates/libsyntax2/src/lib.rs b/crates/libsyntax2/src/lib.rs
index d955c01e7..74e8e7338 100644
--- a/crates/libsyntax2/src/lib.rs
+++ b/crates/libsyntax2/src/lib.rs
@@ -144,6 +144,21 @@ fn find_reparsable_node(node: SyntaxNodeRef, range: TextRange) -> Option<(Syntax
144 let res = match node.kind() { 144 let res = match node.kind() {
145 BLOCK => grammar::block, 145 BLOCK => grammar::block,
146 NAMED_FIELD_DEF_LIST => grammar::named_field_def_list, 146 NAMED_FIELD_DEF_LIST => grammar::named_field_def_list,
147 NAMED_FIELD_LIST => grammar::named_field_list,
148 ENUM_VARIANT_LIST => grammar::enum_variant_list,
149 MATCH_ARM_LIST => grammar::match_arm_list,
150 USE_TREE_LIST => grammar::use_tree_list,
151 EXTERN_ITEM_LIST => grammar::extern_item_list,
152 TOKEN_TREE => grammar::token_tree,
153 ITEM_LIST => {
154 let parent = node.parent().unwrap();
155 match parent.kind() {
156 IMPL_ITEM => grammar::impl_item_list,
157 TRAIT_DEF => grammar::trait_item_list,
158 MODULE => grammar::mod_item_list,
159 _ => return None,
160 }
161 },
147 _ => return None, 162 _ => return None,
148 }; 163 };
149 Some(res) 164 Some(res)
diff --git a/crates/libsyntax2/tests/test/main.rs b/crates/libsyntax2/tests/test/main.rs
index 014faa2c6..24058efa9 100644
--- a/crates/libsyntax2/tests/test/main.rs
+++ b/crates/libsyntax2/tests/test/main.rs
@@ -24,21 +24,6 @@ fn lexer_tests() {
24} 24}
25 25
26#[test] 26#[test]
27fn parser_tests() {
28 dir_tests(&["parser/inline", "parser/ok", "parser/err"], |text| {
29 let file = File::parse(text);
30 dump_tree(file.syntax())
31 })
32}
33
34#[test]
35fn parser_fuzz_tests() {
36 for (_, text) in collect_tests(&["parser/fuzz-failures"]) {
37 check_fuzz_invariants(&text)
38 }
39}
40
41#[test]
42fn reparse_test() { 27fn reparse_test() {
43 fn do_check(before: &str, replace_with: &str) { 28 fn do_check(before: &str, replace_with: &str) {
44 let (range, before) = extract_range(before); 29 let (range, before) = extract_range(before);
@@ -73,6 +58,52 @@ fn foo {
73 <|>92<|>; 58 <|>92<|>;
74} 59}
75", "62"); 60", "62");
61 do_check(r"
62mod foo {
63 fn <|><|>
64}
65", "bar");
66 do_check(r"
67trait Foo {
68 type <|>Foo<|>;
69}
70", "Output");
71 do_check(r"
72impl IntoIterator<Item=i32> for Foo {
73 f<|><|>
74}
75", "n next(");
76 do_check(r"
77use a::b::{foo,<|>,bar<|>};
78 ", "baz");
79 do_check(r"
80pub enum A {
81 Foo<|><|>
82}
83", "\nBar;\n");
84 do_check(r"
85foo!{a, b<|><|> d}
86", ", c[3]");
87 do_check(r"
88extern {
89 fn<|>;<|>
90}
91", " exit(code: c_int)");
92}
93
94#[test]
95fn parser_tests() {
96 dir_tests(&["parser/inline", "parser/ok", "parser/err"], |text| {
97 let file = File::parse(text);
98 dump_tree(file.syntax())
99 })
100}
101
102#[test]
103fn parser_fuzz_tests() {
104 for (_, text) in collect_tests(&["parser/fuzz-failures"]) {
105 check_fuzz_invariants(&text)
106 }
76} 107}
77 108
78 109