diff options
Diffstat (limited to 'src/parser/grammar/mod.rs')
-rw-r--r-- | src/parser/grammar/mod.rs | 144 |
1 files changed, 0 insertions, 144 deletions
diff --git a/src/parser/grammar/mod.rs b/src/parser/grammar/mod.rs deleted file mode 100644 index d4f9b80cf..000000000 --- a/src/parser/grammar/mod.rs +++ /dev/null | |||
@@ -1,144 +0,0 @@ | |||
1 | //! This is the actual "grammar" of the Rust language. | ||
2 | //! | ||
3 | //! Each function in this module and its children corresponds | ||
4 | //! to a production of the format grammar. Submodules roughly | ||
5 | //! correspond to different *areas* of the grammar. By convention, | ||
6 | //! each submodule starts with `use super::*` import and exports | ||
7 | //! "public" productions via `pub(super)`. | ||
8 | //! | ||
9 | //! See docs for `Parser` to learn about API, available to the grammar, | ||
10 | //! and see docs for `Event` to learn how this actually manages to | ||
11 | //! produce parse trees. | ||
12 | //! | ||
13 | //! Code in this module also contains inline tests, which start with | ||
14 | //! `// test name-of-the-test` comment and look like this: | ||
15 | //! | ||
16 | //! ``` | ||
17 | //! // test fn_item_with_zero_parameters | ||
18 | //! // fn foo() {} | ||
19 | //! ``` | ||
20 | //! | ||
21 | //! After adding a new inline-test, run `cargo collect-tests` to extract | ||
22 | //! it as a standalone text-fixture into `tests/data/parser/inline`, and | ||
23 | //! run `cargo test` once to create the "gold" value. | ||
24 | mod attributes; | ||
25 | mod expressions; | ||
26 | mod items; | ||
27 | mod paths; | ||
28 | mod patterns; | ||
29 | mod params; | ||
30 | mod type_params; | ||
31 | mod type_args; | ||
32 | mod types; | ||
33 | |||
34 | use { | ||
35 | parser::{ | ||
36 | parser::{CompletedMarker, Parser}, | ||
37 | token_set::TokenSet, | ||
38 | }, | ||
39 | SyntaxKind::{self, *}, | ||
40 | }; | ||
41 | |||
42 | pub(crate) fn file(p: &mut Parser) { | ||
43 | let file = p.start(); | ||
44 | p.eat(SHEBANG); | ||
45 | items::mod_contents(p, false); | ||
46 | file.complete(p, FILE); | ||
47 | } | ||
48 | |||
49 | fn visibility(p: &mut Parser) { | ||
50 | if p.at(PUB_KW) { | ||
51 | let vis = p.start(); | ||
52 | p.bump(); | ||
53 | if p.at(L_PAREN) { | ||
54 | match p.nth(1) { | ||
55 | // test crate_visibility | ||
56 | // pub(crate) struct S; | ||
57 | // pub(self) struct S; | ||
58 | // pub(self) struct S; | ||
59 | // pub(self) struct S; | ||
60 | CRATE_KW | SELF_KW | SUPER_KW => { | ||
61 | p.bump(); | ||
62 | p.bump(); | ||
63 | p.expect(R_PAREN); | ||
64 | } | ||
65 | IN_KW => { | ||
66 | p.bump(); | ||
67 | p.bump(); | ||
68 | paths::use_path(p); | ||
69 | p.expect(R_PAREN); | ||
70 | } | ||
71 | _ => (), | ||
72 | } | ||
73 | } | ||
74 | vis.complete(p, VISIBILITY); | ||
75 | } | ||
76 | } | ||
77 | |||
78 | fn alias(p: &mut Parser) -> bool { | ||
79 | if p.at(AS_KW) { | ||
80 | let alias = p.start(); | ||
81 | p.bump(); | ||
82 | name(p); | ||
83 | alias.complete(p, ALIAS); | ||
84 | } | ||
85 | true //FIXME: return false if three are errors | ||
86 | } | ||
87 | |||
88 | fn abi(p: &mut Parser) { | ||
89 | assert!(p.at(EXTERN_KW)); | ||
90 | let abi = p.start(); | ||
91 | p.bump(); | ||
92 | match p.current() { | ||
93 | STRING | RAW_STRING => p.bump(), | ||
94 | _ => (), | ||
95 | } | ||
96 | abi.complete(p, ABI); | ||
97 | } | ||
98 | |||
99 | fn fn_ret_type(p: &mut Parser) -> bool { | ||
100 | if p.at(THIN_ARROW) { | ||
101 | p.bump(); | ||
102 | types::type_(p); | ||
103 | true | ||
104 | } else { | ||
105 | false | ||
106 | } | ||
107 | } | ||
108 | |||
109 | fn name(p: &mut Parser) { | ||
110 | if p.at(IDENT) { | ||
111 | let m = p.start(); | ||
112 | p.bump(); | ||
113 | m.complete(p, NAME); | ||
114 | } else { | ||
115 | p.error("expected a name"); | ||
116 | } | ||
117 | } | ||
118 | |||
119 | fn name_ref(p: &mut Parser) { | ||
120 | if p.at(IDENT) { | ||
121 | let m = p.start(); | ||
122 | p.bump(); | ||
123 | m.complete(p, NAME_REF); | ||
124 | } else { | ||
125 | p.error("expected identifier"); | ||
126 | } | ||
127 | } | ||
128 | |||
129 | fn error_block(p: &mut Parser, message: &str) { | ||
130 | assert!(p.at(L_CURLY)); | ||
131 | let err = p.start(); | ||
132 | p.error(message); | ||
133 | p.bump(); | ||
134 | let mut level: u32 = 1; | ||
135 | while level > 0 && !p.at(EOF) { | ||
136 | match p.current() { | ||
137 | L_CURLY => level += 1, | ||
138 | R_CURLY => level -= 1, | ||
139 | _ => (), | ||
140 | } | ||
141 | p.bump(); | ||
142 | } | ||
143 | err.complete(p, ERROR); | ||
144 | } | ||