From e163c908acff9260eff347541f0f3f57db551622 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 2 Feb 2019 00:33:54 +0100 Subject: Add AST for extern crate Also change it to parse the crate name as a NAME_REF, not a NAME. --- crates/ra_syntax/src/ast/generated.rs | 10 +++++++++- crates/ra_syntax/src/grammar.ron | 4 +++- crates/ra_syntax/src/grammar/items.rs | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) (limited to 'crates/ra_syntax/src') diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index 60480c699..a8d60e882 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs @@ -970,7 +970,15 @@ impl ToOwned for ExternCrateItem { } -impl ExternCrateItem {} +impl ExternCrateItem { + pub fn name_ref(&self) -> Option<&NameRef> { + super::child_opt(self) + } + + pub fn alias(&self) -> Option<&Alias> { + super::child_opt(self) + } +} // FalseKw #[derive(Debug, PartialEq, Eq, Hash)] diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron index a2ccd7cb9..2ed1fd1b8 100644 --- a/crates/ra_syntax/src/grammar.ron +++ b/crates/ra_syntax/src/grammar.ron @@ -601,7 +601,9 @@ Grammar( "UseTreeList": ( collections: [["use_trees", "UseTree"]] ), - "ExternCrateItem": (), + "ExternCrateItem": ( + options: ["NameRef", "Alias"], + ), "ArgList": ( collections: [ ["args", "Expr"] diff --git a/crates/ra_syntax/src/grammar/items.rs b/crates/ra_syntax/src/grammar/items.rs index 18039cd3f..84c18a293 100644 --- a/crates/ra_syntax/src/grammar/items.rs +++ b/crates/ra_syntax/src/grammar/items.rs @@ -247,7 +247,7 @@ fn extern_crate_item(p: &mut Parser) { p.bump(); assert!(p.at(CRATE_KW)); p.bump(); - name(p); + name_ref(p); opt_alias(p); p.expect(SEMI); } -- cgit v1.2.3