]> git.lizzy.rs Git - rust.git/blobdiff - crates/parser/src/grammar.rs
Add semicolons for consistency
[rust.git] / crates / parser / src / grammar.rs
index 9bdf0b5fa24bfe4879e10d7157547270f604a968..2b874d6e1c363df4c88225e27cccb3d199e3c5cf 100644 (file)
@@ -6,9 +6,9 @@
 //! each submodule starts with `use super::*` import and exports
 //! "public" productions via `pub(super)`.
 //!
-//! See docs for `Parser` to learn about API, available to the grammar,
-//! and see docs for `Event` to learn how this actually manages to
-//! produce parse trees.
+//! See docs for [`Parser`](super::parser::Parser) to learn about API,
+//! available to the grammar, and see docs for [`Event`](super::event::Event)
+//! to learn how this actually manages to produce parse trees.
 //!
 //! Code in this module also contains inline tests, which start with
 //! `// test name-of-the-test` comment and look like this:
 //! node or an error, rules like `opt_where_clause` may produce nothing.
 //! Non-opt rules typically start with `assert!(p.at(FIRST_TOKEN))`, the
 //! caller is responsible for branching on the first token.
+
 mod attributes;
 mod expressions;
 mod items;
 mod params;
 mod paths;
 mod patterns;
-mod type_args;
-mod type_params;
+mod generic_args;
+mod generic_params;
 mod types;
 
 use crate::{
     parser::{CompletedMarker, Marker, Parser},
     SyntaxKind::{self, *},
-    TokenSet,
+    TokenSet, T,
 };
 
-pub(crate) fn root(p: &mut Parser) {
-    let m = p.start();
-    p.eat(SHEBANG);
-    items::mod_contents(p, false);
-    m.complete(p, SOURCE_FILE);
-}
-
-/// Various pieces of syntax that can be parsed by macros by example
-pub(crate) mod fragments {
+pub(crate) mod entry_points {
     use super::*;
 
-    pub(crate) use super::{
-        expressions::block_expr, paths::type_path as path, patterns::pattern_single, types::type_,
-    };
+    pub(crate) fn source_file(p: &mut Parser) {
+        let m = p.start();
+        p.eat(SHEBANG);
+        items::mod_contents(p, false);
+        m.complete(p, SOURCE_FILE);
+    }
+
+    pub(crate) use expressions::block_expr;
+
+    pub(crate) use paths::type_path as path;
+
+    pub(crate) use patterns::pattern_single as pattern;
+
+    pub(crate) use types::type_;
 
     pub(crate) fn expr(p: &mut Parser) {
-        let _ = expressions::expr_with_attrs(p);
+        let _ = expressions::expr(p);
     }
 
     pub(crate) fn stmt(p: &mut Parser) {
-        expressions::stmt(p, expressions::StmtWithSemi::No, true)
+        expressions::stmt(p, expressions::StmtWithSemi::No, true);
     }
 
     pub(crate) fn stmt_optional_semi(p: &mut Parser) {
-        expressions::stmt(p, expressions::StmtWithSemi::Optional, false)
+        expressions::stmt(p, expressions::StmtWithSemi::Optional, false);
     }
 
-    pub(crate) fn opt_visibility(p: &mut Parser) {
-        let _ = super::opt_visibility(p);
+    pub(crate) fn visibility(p: &mut Parser) {
+        let _ = opt_visibility(p);
     }
 
     // Parse a meta item , which excluded [], e.g : #[ MetaItem ]
@@ -80,7 +84,7 @@ pub(crate) fn meta_item(p: &mut Parser) {
     }
 
     pub(crate) fn item(p: &mut Parser) {
-        items::item_or_macro(p, true)
+        items::item_or_macro(p, true);
     }
 
     pub(crate) fn macro_items(p: &mut Parser) {
@@ -105,7 +109,7 @@ pub(crate) fn macro_stmts(p: &mut Parser) {
     }
 
     pub(crate) fn attr(p: &mut Parser) {
-        attributes::outer_attrs(p)
+        attributes::outer_attrs(p);
     }
 }
 
@@ -161,23 +165,17 @@ fn opt_visibility(p: &mut Parser) -> bool {
                     // 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);
+                    T![crate] | T![self] | T![super] | T![ident] if p.nth(2) != T![:] => {
+                        p.bump(T!['(']);
+                        paths::use_path(p);
                         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();
+                        p.bump(T!['(']);
+                        p.bump(T![in]);
                         paths::use_path(p);
                         p.expect(T![')']);
                     }
@@ -185,22 +183,25 @@ fn opt_visibility(p: &mut Parser) -> bool {
                 }
             }
             m.complete(p, VISIBILITY);
+            true
         }
         // test crate_keyword_vis
         // crate fn main() { }
         // struct S { crate field: u32 }
         // struct T(crate u32);
-        //
-        // test crate_keyword_path
-        // fn foo() { crate::foo(); }
-        T![crate] if !p.nth_at(1, T![::]) => {
+        T![crate] => {
+            if p.nth_at(1, T![::]) {
+                // test crate_keyword_path
+                // fn foo() { crate::foo(); }
+                return false;
+            }
             let m = p.start();
             p.bump(T![crate]);
             m.complete(p, VISIBILITY);
+            true
         }
-        _ => return false,
+        _ => false,
     }
-    true
 }
 
 fn opt_rename(p: &mut Parser) {
@@ -245,7 +246,7 @@ fn name_r(p: &mut Parser, recovery: TokenSet) {
 }
 
 fn name(p: &mut Parser) {
-    name_r(p, TokenSet::EMPTY)
+    name_r(p, TokenSet::EMPTY);
 }
 
 fn name_ref(p: &mut Parser) {