From fc0a9e266b9d663b1eeca3963495c68ca3384be2 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 10 Feb 2018 14:00:23 +0300 Subject: G: introduce names --- src/parser/grammar/items/mod.rs | 5 +++-- src/parser/grammar/mod.rs | 12 +++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) (limited to 'src/parser') diff --git a/src/parser/grammar/items/mod.rs b/src/parser/grammar/items/mod.rs index ffe86fa97..d671568b1 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) { p.bump(); assert!(p.at(CRATE_KW)); p.bump(); - - p.expect(IDENT) && alias(p) && p.expect(SEMI); + name(p); + alias(p); + p.expect(SEMI); } fn extern_block(p: &mut Parser) { diff --git a/src/parser/grammar/mod.rs b/src/parser/grammar/mod.rs index b949583ff..6e82d7c69 100644 --- a/src/parser/grammar/mod.rs +++ b/src/parser/grammar/mod.rs @@ -44,12 +44,22 @@ fn alias(p: &mut Parser) -> bool { if p.at(AS_KW) { let alias = p.start(); p.bump(); - p.expect(IDENT); + name(p); alias.complete(p, ALIAS); } true //FIXME: return false if three are errors } +fn name(p: &mut Parser) { + if p.at(IDENT) { + let m = p.start(); + p.bump(); + m.complete(p, NAME); + } else { + p.error("expected a name"); + } +} + fn error_block(p: &mut Parser, message: &str) { assert!(p.at(L_CURLY)); let err = p.start(); -- cgit v1.2.3 From 3c9d8ff42357711775c3aeb3af03f528ee779932 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 10 Feb 2018 14:04:31 +0300 Subject: G: names for fns --- src/parser/grammar/items/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/parser') diff --git a/src/parser/grammar/items/mod.rs b/src/parser/grammar/items/mod.rs index d671568b1..61ebc740f 100644 --- a/src/parser/grammar/items/mod.rs +++ b/src/parser/grammar/items/mod.rs @@ -211,7 +211,7 @@ fn fn_item(p: &mut Parser) { assert!(p.at(FN_KW)); p.bump(); - p.expect(IDENT); + name(p); if p.at(L_PAREN) { fn_value_parameters(p); } else { -- cgit v1.2.3 From f746fb6a93a4f0493fc8f5602372c267befe4e48 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 10 Feb 2018 14:08:46 +0300 Subject: G: use names in consts --- src/parser/grammar/items/consts.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/parser') 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) { assert!(p.at(kw)); p.bump(); p.eat(MUT_KW); // TODO: validator to forbid const mut - p.expect(IDENT); + name(p); p.expect(COLON); types::type_ref(p); p.expect(EQ); -- cgit v1.2.3 From ca6e93f091bc6f2e9dc26e842fc87d614089cf9d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 10 Feb 2018 14:10:02 +0300 Subject: G: use names in structs --- src/parser/grammar/items/structs.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/parser') diff --git a/src/parser/grammar/items/structs.rs b/src/parser/grammar/items/structs.rs index 640b940e4..3b1f8a38c 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) { assert!(p.at(STRUCT_KW)); p.bump(); - if !p.expect(IDENT) { - return; - } + name(p); type_params::list(p); match p.current() { WHERE_KW => { -- cgit v1.2.3 From 8a735b667295f8390394b2536337698cb9a384ce Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 10 Feb 2018 14:10:50 +0300 Subject: G: use names in enums --- src/parser/grammar/items/structs.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/parser') diff --git a/src/parser/grammar/items/structs.rs b/src/parser/grammar/items/structs.rs index 3b1f8a38c..3c122a56f 100644 --- a/src/parser/grammar/items/structs.rs +++ b/src/parser/grammar/items/structs.rs @@ -41,7 +41,7 @@ pub(super) fn struct_item(p: &mut Parser) { pub(super) fn enum_item(p: &mut Parser) { assert!(p.at(ENUM_KW)); p.bump(); - p.expect(IDENT); + name(p); type_params::list(p); type_params::where_clause(p); if p.expect(L_CURLY) { -- cgit v1.2.3 From c13e6db774acca952577fa7a18599b75b407f3c2 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 10 Feb 2018 14:13:30 +0300 Subject: G: use names in fields --- src/parser/grammar/items/structs.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/parser') diff --git a/src/parser/grammar/items/structs.rs b/src/parser/grammar/items/structs.rs index 3c122a56f..eca0d2e64 100644 --- a/src/parser/grammar/items/structs.rs +++ b/src/parser/grammar/items/structs.rs @@ -86,7 +86,8 @@ fn named_fields(p: &mut Parser) { fn named_field(p: &mut Parser) { let field = p.start(); visibility(p); - if p.expect(IDENT) { + if p.at(IDENT) { + name(p); p.expect(COLON); types::type_ref(p); field.complete(p, NAMED_FIELD); -- cgit v1.2.3 From fa2131365e8ff2a6fa4fcb47aa04e6d51a32943e Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 10 Feb 2018 14:15:04 +0300 Subject: G: use names in traits --- src/parser/grammar/items/traits.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/parser') 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::*; pub(super) fn trait_item(p: &mut Parser) { assert!(p.at(TRAIT_KW)); p.bump(); - p.expect(IDENT); + name(p); p.expect(L_CURLY); p.expect(R_CURLY); } -- cgit v1.2.3 From e792ec3eca6214329d053715a6477cc4f7a05672 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 10 Feb 2018 14:17:38 +0300 Subject: G: use name refs in paths --- src/parser/grammar/mod.rs | 10 ++++++++++ src/parser/grammar/paths.rs | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'src/parser') diff --git a/src/parser/grammar/mod.rs b/src/parser/grammar/mod.rs index 6e82d7c69..abf9fe86c 100644 --- a/src/parser/grammar/mod.rs +++ b/src/parser/grammar/mod.rs @@ -60,6 +60,16 @@ fn name(p: &mut Parser) { } } +fn name_ref(p: &mut Parser) { + if p.at(IDENT) { + let m = p.start(); + p.bump(); + m.complete(p, NAME_REF); + } else { + p.error("expected identifier"); + } +} + fn error_block(p: &mut Parser, message: &str) { assert!(p.at(L_CURLY)); 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) { p.eat(COLONCOLON); } match p.current() { - IDENT | SELF_KW | SUPER_KW => p.bump(), + IDENT => name_ref(p), + SELF_KW | SUPER_KW => p.bump(), _ => { p.error("expected identifier"); } -- cgit v1.2.3 From d68a187eb5adf489b5e1eef6aa23768b819d0e65 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 10 Feb 2018 14:22:31 +0300 Subject: G: use name in types --- src/parser/grammar/items/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/parser') diff --git a/src/parser/grammar/items/mod.rs b/src/parser/grammar/items/mod.rs index 61ebc740f..2d9580991 100644 --- a/src/parser/grammar/items/mod.rs +++ b/src/parser/grammar/items/mod.rs @@ -236,7 +236,7 @@ fn type_item(p: &mut Parser) { assert!(p.at(TYPE_KW)); p.bump(); - p.expect(IDENT); + name(p); // test type_item_type_params // type Result = (); -- cgit v1.2.3 From 199b3a1604095beee9eaeec541c8f158e85493ea Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 10 Feb 2018 14:23:18 +0300 Subject: G: use name in mods --- src/parser/grammar/items/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/parser') diff --git a/src/parser/grammar/items/mod.rs b/src/parser/grammar/items/mod.rs index 2d9580991..8bb821fb6 100644 --- a/src/parser/grammar/items/mod.rs +++ b/src/parser/grammar/items/mod.rs @@ -255,7 +255,8 @@ fn mod_item(p: &mut Parser) { assert!(p.at(MOD_KW)); p.bump(); - if p.expect(IDENT) && !p.eat(SEMI) { + name(p); + if !p.eat(SEMI) { if p.expect(L_CURLY) { mod_contents(p, true); p.expect(R_CURLY); -- cgit v1.2.3