]> git.lizzy.rs Git - rust.git/commitdiff
Add AST for extern crate
authorFlorian Diebold <flodiebold@gmail.com>
Fri, 1 Feb 2019 23:33:54 +0000 (00:33 +0100)
committerFlorian Diebold <flodiebold@gmail.com>
Mon, 4 Feb 2019 20:49:34 +0000 (21:49 +0100)
Also change it to parse the crate name as a NAME_REF, not a NAME.

crates/ra_syntax/src/ast/generated.rs
crates/ra_syntax/src/grammar.ron
crates/ra_syntax/src/grammar/items.rs
crates/ra_syntax/tests/data/parser/inline/ok/0060_extern_crate.txt
crates/ra_syntax/tests/data/parser/ok/0007_extern_crate.txt

index 60480c69998e23f6301ef9703fd53524a6891be5..a8d60e882d759a1f210983a86ee49d3ba6bac408 100644 (file)
@@ -970,7 +970,15 @@ fn to_owned(&self) -> TreeArc<ExternCrateItem> { TreeArc::cast(self.syntax.to_ow
 }
 
 
-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)]
index a2ccd7cb9466f5489ee3874fdffb746ce92dbb4e..2ed1fd1b88668382139c2a90e8bc794a7b310a89 100644 (file)
@@ -601,7 +601,9 @@ Grammar(
         "UseTreeList": (
             collections: [["use_trees", "UseTree"]]
         ),
-        "ExternCrateItem": (),
+        "ExternCrateItem": (
+            options: ["NameRef", "Alias"],
+        ),
         "ArgList": (
             collections: [
                 ["args", "Expr"]
index 18039cd3f8daa3b22ac0efd53a38ba0eef9ee152..84c18a2932ac0288c836e8d309dcd62108622a71 100644 (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);
 }
index 7ffdc7fbdb93c50bde6c1947dbbe5b042383ba16..a7b4287878f47545e5f3cffb2329bd270f47d7c3 100644 (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)
index 5adf3f2769c68f69cd85d272066544bf382c3782..5558d952e5374af68fc3bc23b213c5e371df5bdf 100644 (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)