Unnamed repository; edit this file 'description' to name the repository.
internal: improve style
Group related stuff together, use only on path for parsing extern blocks (they actually have modifiers). Perhaps we should get rid of items_without_modifiers altogether? Better to handle these kinds on diagnostics in validation layer...
Aleksey Kladov 2021-08-30
parent 8dc3b46 · commit 4452f9e
-rw-r--r--crates/parser/src/grammar/items.rs40
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0010_extern_block.rast28
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0010_extern_block.rs1
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0167_unsafe_extern_block.rast13
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0167_unsafe_extern_block.rs1
5 files changed, 40 insertions, 43 deletions
diff --git a/crates/parser/src/grammar/items.rs b/crates/parser/src/grammar/items.rs
index 9763df63f2..3421078bba 100644
--- a/crates/parser/src/grammar/items.rs
+++ b/crates/parser/src/grammar/items.rs
@@ -213,8 +213,9 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker) -> Result<(), Marker> {
type_alias(p, m);
}
- // test unsafe_extern_block
+ // test extern_block
// unsafe extern "C" {}
+ // extern {}
T!['{'] if has_extern => {
extern_item_list(p);
m.complete(p, EXTERN_BLOCK);
@@ -240,10 +241,11 @@ fn items_without_modifiers(p: &mut Parser, m: Marker) -> Result<(), Marker> {
// test extern_crate
// extern crate foo;
T![extern] if la == T![crate] => extern_crate(p, m),
- T![type] => {
- type_alias(p, m);
- }
+ T![use] => use_item::use_(p, m),
T![mod] => mod_item(p, m),
+
+ T![type] => type_alias(p, m),
+
T![struct] => {
// test struct_items
// struct Foo;
@@ -256,14 +258,7 @@ fn items_without_modifiers(p: &mut Parser, m: Marker) -> Result<(), Marker> {
// }
adt::strukt(p, m);
}
- // test pub_macro_def
- // pub macro m($:ident) {}
- T![macro] => {
- macro_def(p, m);
- }
- IDENT if p.at_contextual_kw("macro_rules") && p.nth(1) == BANG => {
- macro_rules(p, m);
- }
+ T![enum] => adt::enum_(p, m),
IDENT if p.at_contextual_kw("union") && p.nth(1) == IDENT => {
// test union_items
// union Foo {}
@@ -273,17 +268,19 @@ fn items_without_modifiers(p: &mut Parser, m: Marker) -> Result<(), Marker> {
// }
adt::union(p, m);
}
- T![enum] => adt::enum_(p, m),
- T![use] => use_item::use_(p, m),
+
+ // test pub_macro_def
+ // pub macro m($:ident) {}
+ T![macro] => {
+ macro_def(p, m);
+ }
+ IDENT if p.at_contextual_kw("macro_rules") && p.nth(1) == BANG => {
+ macro_rules(p, m);
+ }
+
T![const] if (la == IDENT || la == T![_] || la == T![mut]) => consts::konst(p, m),
T![static] => consts::static_(p, m),
- // test extern_block
- // extern {}
- T![extern] if la == T!['{'] || (la == STRING && p.nth(2) == T!['{']) => {
- abi(p);
- extern_item_list(p);
- m.complete(p, EXTERN_BLOCK);
- }
+
_ => return Err(m),
};
Ok(())
@@ -292,6 +289,7 @@ fn items_without_modifiers(p: &mut Parser, m: Marker) -> Result<(), Marker> {
fn extern_crate(p: &mut Parser, m: Marker) {
assert!(p.at(T![extern]));
p.bump(T![extern]);
+
assert!(p.at(T![crate]));
p.bump(T![crate]);
diff --git a/crates/syntax/test_data/parser/inline/ok/0010_extern_block.rast b/crates/syntax/test_data/parser/inline/ok/0010_extern_block.rast
index 869875875e..beac566e59 100644
--- a/crates/syntax/test_data/parser/inline/ok/0010_extern_block.rast
+++ b/crates/syntax/test_data/parser/inline/ok/0010_extern_block.rast
@@ -1,9 +1,21 @@
diff --git a/crates/syntax/test_data/parser/inline/ok/0010_extern_block.rs b/crates/syntax/test_data/parser/inline/ok/0010_extern_block.rs
index 26a9ccd1e6..bee5ac8453 100644
--- a/crates/syntax/test_data/parser/inline/ok/0010_extern_block.rs
+++ b/crates/syntax/test_data/parser/inline/ok/0010_extern_block.rs
@@ -1 +1,2 @@
+unsafe extern "C" {}
extern {}
diff --git a/crates/syntax/test_data/parser/inline/ok/0167_unsafe_extern_block.rast b/crates/syntax/test_data/parser/inline/ok/0167_unsafe_extern_block.rast
deleted file mode 100644
index 8044e6674d..0000000000
--- a/crates/syntax/test_data/parser/inline/ok/0167_unsafe_extern_block.rast
+++ /dev/null
@@ -1,13 +0,0 @@
diff --git a/crates/syntax/test_data/parser/inline/ok/0167_unsafe_extern_block.rs b/crates/syntax/test_data/parser/inline/ok/0167_unsafe_extern_block.rs
deleted file mode 100644
index 9475aec15c..0000000000
--- a/crates/syntax/test_data/parser/inline/ok/0167_unsafe_extern_block.rs
+++ /dev/null
@@ -1 +0,0 @@
-unsafe extern "C" {}