aboutsummaryrefslogtreecommitdiff
path: root/src/parser/grammar
diff options
context:
space:
mode:
Diffstat (limited to 'src/parser/grammar')
-rw-r--r--src/parser/grammar/items/consts.rs2
-rw-r--r--src/parser/grammar/items/mod.rs12
-rw-r--r--src/parser/grammar/items/structs.rs9
-rw-r--r--src/parser/grammar/items/traits.rs2
-rw-r--r--src/parser/grammar/mod.rs22
-rw-r--r--src/parser/grammar/paths.rs3
6 files changed, 36 insertions, 14 deletions
diff --git a/src/parser/grammar/items/consts.rs b/src/parser/grammar/items/consts.rs
index c9881d681..8117af706 100644
--- a/src/parser/grammar/items/consts.rs
+++ b/src/parser/grammar/items/consts.rs
@@ -12,7 +12,7 @@ fn const_or_static(p: &mut Parser, kw: SyntaxKind) {
12 assert!(p.at(kw)); 12 assert!(p.at(kw));
13 p.bump(); 13 p.bump();
14 p.eat(MUT_KW); // TODO: validator to forbid const mut 14 p.eat(MUT_KW); // TODO: validator to forbid const mut
15 p.expect(IDENT); 15 name(p);
16 p.expect(COLON); 16 p.expect(COLON);
17 types::type_ref(p); 17 types::type_ref(p);
18 p.expect(EQ); 18 p.expect(EQ);
diff --git a/src/parser/grammar/items/mod.rs b/src/parser/grammar/items/mod.rs
index ffe86fa97..8bb821fb6 100644
--- a/src/parser/grammar/items/mod.rs
+++ b/src/parser/grammar/items/mod.rs
@@ -196,8 +196,9 @@ fn extern_crate_item(p: &mut Parser) {
196 p.bump(); 196 p.bump();
197 assert!(p.at(CRATE_KW)); 197 assert!(p.at(CRATE_KW));
198 p.bump(); 198 p.bump();
199 199 name(p);
200 p.expect(IDENT) && alias(p) && p.expect(SEMI); 200 alias(p);
201 p.expect(SEMI);
201} 202}
202 203
203fn extern_block(p: &mut Parser) { 204fn extern_block(p: &mut Parser) {
@@ -210,7 +211,7 @@ fn fn_item(p: &mut Parser) {
210 assert!(p.at(FN_KW)); 211 assert!(p.at(FN_KW));
211 p.bump(); 212 p.bump();
212 213
213 p.expect(IDENT); 214 name(p);
214 if p.at(L_PAREN) { 215 if p.at(L_PAREN) {
215 fn_value_parameters(p); 216 fn_value_parameters(p);
216 } else { 217 } else {
@@ -235,7 +236,7 @@ fn type_item(p: &mut Parser) {
235 assert!(p.at(TYPE_KW)); 236 assert!(p.at(TYPE_KW));
236 p.bump(); 237 p.bump();
237 238
238 p.expect(IDENT); 239 name(p);
239 240
240 // test type_item_type_params 241 // test type_item_type_params
241 // type Result<T> = (); 242 // type Result<T> = ();
@@ -254,7 +255,8 @@ fn mod_item(p: &mut Parser) {
254 assert!(p.at(MOD_KW)); 255 assert!(p.at(MOD_KW));
255 p.bump(); 256 p.bump();
256 257
257 if p.expect(IDENT) && !p.eat(SEMI) { 258 name(p);
259 if !p.eat(SEMI) {
258 if p.expect(L_CURLY) { 260 if p.expect(L_CURLY) {
259 mod_contents(p, true); 261 mod_contents(p, true);
260 p.expect(R_CURLY); 262 p.expect(R_CURLY);
diff --git a/src/parser/grammar/items/structs.rs b/src/parser/grammar/items/structs.rs
index 640b940e4..eca0d2e64 100644
--- a/src/parser/grammar/items/structs.rs
+++ b/src/parser/grammar/items/structs.rs
@@ -4,9 +4,7 @@ pub(super) fn struct_item(p: &mut Parser) {
4 assert!(p.at(STRUCT_KW)); 4 assert!(p.at(STRUCT_KW));
5 p.bump(); 5 p.bump();
6 6
7 if !p.expect(IDENT) { 7 name(p);
8 return;
9 }
10 type_params::list(p); 8 type_params::list(p);
11 match p.current() { 9 match p.current() {
12 WHERE_KW => { 10 WHERE_KW => {
@@ -43,7 +41,7 @@ pub(super) fn struct_item(p: &mut Parser) {
43pub(super) fn enum_item(p: &mut Parser) { 41pub(super) fn enum_item(p: &mut Parser) {
44 assert!(p.at(ENUM_KW)); 42 assert!(p.at(ENUM_KW));
45 p.bump(); 43 p.bump();
46 p.expect(IDENT); 44 name(p);
47 type_params::list(p); 45 type_params::list(p);
48 type_params::where_clause(p); 46 type_params::where_clause(p);
49 if p.expect(L_CURLY) { 47 if p.expect(L_CURLY) {
@@ -88,7 +86,8 @@ fn named_fields(p: &mut Parser) {
88 fn named_field(p: &mut Parser) { 86 fn named_field(p: &mut Parser) {
89 let field = p.start(); 87 let field = p.start();
90 visibility(p); 88 visibility(p);
91 if p.expect(IDENT) { 89 if p.at(IDENT) {
90 name(p);
92 p.expect(COLON); 91 p.expect(COLON);
93 types::type_ref(p); 92 types::type_ref(p);
94 field.complete(p, NAMED_FIELD); 93 field.complete(p, NAMED_FIELD);
diff --git a/src/parser/grammar/items/traits.rs b/src/parser/grammar/items/traits.rs
index 3bef9639f..9961a88fe 100644
--- a/src/parser/grammar/items/traits.rs
+++ b/src/parser/grammar/items/traits.rs
@@ -3,7 +3,7 @@ use super::*;
3pub(super) fn trait_item(p: &mut Parser) { 3pub(super) fn trait_item(p: &mut Parser) {
4 assert!(p.at(TRAIT_KW)); 4 assert!(p.at(TRAIT_KW));
5 p.bump(); 5 p.bump();
6 p.expect(IDENT); 6 name(p);
7 p.expect(L_CURLY); 7 p.expect(L_CURLY);
8 p.expect(R_CURLY); 8 p.expect(R_CURLY);
9} 9}
diff --git a/src/parser/grammar/mod.rs b/src/parser/grammar/mod.rs
index b949583ff..abf9fe86c 100644
--- a/src/parser/grammar/mod.rs
+++ b/src/parser/grammar/mod.rs
@@ -44,12 +44,32 @@ fn alias(p: &mut Parser) -> bool {
44 if p.at(AS_KW) { 44 if p.at(AS_KW) {
45 let alias = p.start(); 45 let alias = p.start();
46 p.bump(); 46 p.bump();
47 p.expect(IDENT); 47 name(p);
48 alias.complete(p, ALIAS); 48 alias.complete(p, ALIAS);
49 } 49 }
50 true //FIXME: return false if three are errors 50 true //FIXME: return false if three are errors
51} 51}
52 52
53fn name(p: &mut Parser) {
54 if p.at(IDENT) {
55 let m = p.start();
56 p.bump();
57 m.complete(p, NAME);
58 } else {
59 p.error("expected a name");
60 }
61}
62
63fn name_ref(p: &mut Parser) {
64 if p.at(IDENT) {
65 let m = p.start();
66 p.bump();
67 m.complete(p, NAME_REF);
68 } else {
69 p.error("expected identifier");
70 }
71}
72
53fn error_block(p: &mut Parser, message: &str) { 73fn error_block(p: &mut Parser, message: &str) {
54 assert!(p.at(L_CURLY)); 74 assert!(p.at(L_CURLY));
55 let err = p.start(); 75 let err = p.start();
diff --git a/src/parser/grammar/paths.rs b/src/parser/grammar/paths.rs
index a7fc90774..6ed315c3d 100644
--- a/src/parser/grammar/paths.rs
+++ b/src/parser/grammar/paths.rs
@@ -42,7 +42,8 @@ fn path_segment(p: &mut Parser, first: bool) {
42 p.eat(COLONCOLON); 42 p.eat(COLONCOLON);
43 } 43 }
44 match p.current() { 44 match p.current() {
45 IDENT | SELF_KW | SUPER_KW => p.bump(), 45 IDENT => name_ref(p),
46 SELF_KW | SUPER_KW => p.bump(),
46 _ => { 47 _ => {
47 p.error("expected identifier"); 48 p.error("expected identifier");
48 } 49 }