]> git.lizzy.rs Git - rust.git/blobdiff - crates/parser/src/grammar.rs
Wrap remaining self/super/crate in Name{Ref}
[rust.git] / crates / parser / src / grammar.rs
index 88468bc9716e0f6087ce0ae29b520de68c798642..6913e9ec2f3fbb31382f7c989caff5c9abf49809 100644 (file)
@@ -20,7 +20,7 @@
 //!
 //! After adding a new inline-test, run `cargo xtask codegen` to
 //! extract it as a standalone text-fixture into
-//! `crates/ra_syntax/test_data/parser/`, and run `cargo test` once to
+//! `crates/syntax/test_data/parser/`, and run `cargo test` once to
 //! create the "gold" value.
 //!
 //! Coding convention: rules like `where_clause` always produce either a
@@ -55,17 +55,21 @@ pub(crate) mod fragments {
     use super::*;
 
     pub(crate) use super::{
-        expressions::block_expr, paths::type_path as path, patterns::pattern, types::type_,
+        expressions::block_expr, paths::type_path as path, patterns::pattern_single, types::type_,
     };
 
     pub(crate) fn expr(p: &mut Parser) {
-        let _ = expressions::expr(p);
+        let _ = expressions::expr_with_attrs(p);
     }
 
     pub(crate) fn stmt(p: &mut Parser) {
         expressions::stmt(p, expressions::StmtWithSemi::No)
     }
 
+    pub(crate) fn stmt_optional_semi(p: &mut Parser) {
+        expressions::stmt(p, expressions::StmtWithSemi::Optional)
+    }
+
     pub(crate) fn opt_visibility(p: &mut Parser) {
         let _ = super::opt_visibility(p);
     }
@@ -133,6 +137,10 @@ pub(crate) fn macro_stmts(p: &mut Parser) {
 
         m.complete(p, MACRO_STMTS);
     }
+
+    pub(crate) fn attr(p: &mut Parser) {
+        attributes::outer_attrs(p)
+    }
 }
 
 pub(crate) fn reparser(
@@ -142,19 +150,19 @@ pub(crate) fn reparser(
 ) -> Option<fn(&mut Parser)> {
     let res = match node {
         BLOCK_EXPR => expressions::block_expr,
-        RECORD_FIELD_LIST => items::record_field_def_list,
-        RECORD_EXPR_FIELD_LIST => items::record_field_list,
-        VARIANT_LIST => items::enum_variant_list,
+        RECORD_FIELD_LIST => items::record_field_list,
+        RECORD_EXPR_FIELD_LIST => items::record_expr_field_list,
+        VARIANT_LIST => items::variant_list,
         MATCH_ARM_LIST => items::match_arm_list,
         USE_TREE_LIST => items::use_tree_list,
         EXTERN_ITEM_LIST => items::extern_item_list,
         TOKEN_TREE if first_child? == T!['{'] => items::token_tree,
         ASSOC_ITEM_LIST => match parent? {
-            IMPL => items::impl_item_list,
-            TRAIT => items::trait_item_list,
+            IMPL => items::assoc_item_list,
+            TRAIT => items::assoc_item_list,
             _ => return None,
         },
-        ITEM_LIST => items::mod_item_list,
+        ITEM_LIST => items::item_list,
         _ => return None,
     };
     Some(res)
@@ -182,13 +190,25 @@ fn opt_visibility(p: &mut Parser) -> bool {
                     // test crate_visibility
                     // pub(crate) struct S;
                     // pub(self) struct S;
-                    // pub(self) struct S;
-                    // pub(self) struct S;
-                    T![crate] | T![self] | T![super] => {
+                    // pub(super) struct S;
+
+                    // test pub_parens_typepath
+                    // struct B(pub (super::A));
+                    // struct B(pub (crate::A,));
+                    T![crate] | T![self] | T![super] if p.nth(2) != T![:] => {
                         p.bump_any();
+                        let path_m = p.start();
+                        let path_segment_m = p.start();
+                        let name_ref_m = p.start();
                         p.bump_any();
+                        name_ref_m.complete(p, NAME_REF);
+                        path_segment_m.complete(p, PATH_SEGMENT);
+                        path_m.complete(p, PATH);
                         p.expect(T![')']);
                     }
+                    // test crate_visibility_in
+                    // pub(in super::A) struct S;
+                    // pub(in crate) struct S;
                     T![in] => {
                         p.bump_any();
                         p.bump_any();
@@ -217,7 +237,7 @@ fn opt_visibility(p: &mut Parser) -> bool {
     true
 }
 
-fn opt_alias(p: &mut Parser) {
+fn opt_rename(p: &mut Parser) {
     if p.at(T![as]) {
         let m = p.start();
         p.bump(T![as]);
@@ -232,14 +252,11 @@ fn abi(p: &mut Parser) {
     assert!(p.at(T![extern]));
     let abi = p.start();
     p.bump(T![extern]);
-    match p.current() {
-        STRING | RAW_STRING => p.bump_any(),
-        _ => (),
-    }
+    p.eat(STRING);
     abi.complete(p, ABI);
 }
 
-fn opt_fn_ret_type(p: &mut Parser) -> bool {
+fn opt_ret_type(p: &mut Parser) -> bool {
     if p.at(T![->]) {
         let m = p.start();
         p.bump(T![->]);
@@ -282,6 +299,13 @@ fn name_ref_or_index(p: &mut Parser) {
     m.complete(p, NAME_REF);
 }
 
+fn lifetime(p: &mut Parser) {
+    assert!(p.at(LIFETIME_IDENT));
+    let m = p.start();
+    p.bump(LIFETIME_IDENT);
+    m.complete(p, LIFETIME);
+}
+
 fn error_block(p: &mut Parser, message: &str) {
     assert!(p.at(T!['{']));
     let m = p.start();