Add AST for extern crate

Also change it to parse the crate name as a NAME_REF, not a NAME.
This commit is contained in:
Florian Diebold 2019-02-02 00:33:54 +01:00
parent 77a824c6a0
commit e163c908ac
5 changed files with 16 additions and 6 deletions

View File

@ -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)]

View File

@ -601,7 +601,9 @@ Grammar(
"UseTreeList": (
collections: [["use_trees", "UseTree"]]
),
"ExternCrateItem": (),
"ExternCrateItem": (
options: ["NameRef", "Alias"],
),
"ArgList": (
collections: [
["args", "Expr"]

View File

@ -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);
}

View File

@ -4,7 +4,7 @@ SOURCE_FILE@[0; 18)
WHITESPACE@[6; 7)
CRATE_KW@[7; 12)
WHITESPACE@[12; 13)
NAME@[13; 16)
NAME_REF@[13; 16)
IDENT@[13; 16) "foo"
SEMI@[16; 17)
WHITESPACE@[17; 18)

View File

@ -4,7 +4,7 @@ SOURCE_FILE@[0; 43)
WHITESPACE@[6; 7)
CRATE_KW@[7; 12)
WHITESPACE@[12; 13)
NAME@[13; 16)
NAME_REF@[13; 16)
IDENT@[13; 16) "foo"
SEMI@[16; 17)
WHITESPACE@[17; 18)
@ -13,7 +13,7 @@ SOURCE_FILE@[0; 43)
WHITESPACE@[24; 25)
CRATE_KW@[25; 30)
WHITESPACE@[30; 31)
NAME@[31; 34)
NAME_REF@[31; 34)
IDENT@[31; 34) "foo"
WHITESPACE@[34; 35)
ALIAS@[35; 41)