diff options
author | Florian Diebold <[email protected]> | 2019-02-01 23:33:54 +0000 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2019-02-04 20:49:34 +0000 |
commit | e163c908acff9260eff347541f0f3f57db551622 (patch) | |
tree | 1749bf4fa26b02d97d058c985083bd388ad71b91 /crates/ra_syntax | |
parent | 77a824c6a0db6ac2548841d290d5d61d1d23295c (diff) |
Add AST for extern crate
Also change it to parse the crate name as a NAME_REF, not a NAME.
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r-- | crates/ra_syntax/src/ast/generated.rs | 10 | ||||
-rw-r--r-- | crates/ra_syntax/src/grammar.ron | 4 | ||||
-rw-r--r-- | crates/ra_syntax/src/grammar/items.rs | 2 | ||||
-rw-r--r-- | crates/ra_syntax/tests/data/parser/inline/ok/0060_extern_crate.txt | 2 | ||||
-rw-r--r-- | crates/ra_syntax/tests/data/parser/ok/0007_extern_crate.txt | 4 |
5 files changed, 16 insertions, 6 deletions
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 { | |||
970 | } | 970 | } |
971 | 971 | ||
972 | 972 | ||
973 | impl ExternCrateItem {} | 973 | impl ExternCrateItem { |
974 | pub fn name_ref(&self) -> Option<&NameRef> { | ||
975 | super::child_opt(self) | ||
976 | } | ||
977 | |||
978 | pub fn alias(&self) -> Option<&Alias> { | ||
979 | super::child_opt(self) | ||
980 | } | ||
981 | } | ||
974 | 982 | ||
975 | // FalseKw | 983 | // FalseKw |
976 | #[derive(Debug, PartialEq, Eq, Hash)] | 984 | #[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( | |||
601 | "UseTreeList": ( | 601 | "UseTreeList": ( |
602 | collections: [["use_trees", "UseTree"]] | 602 | collections: [["use_trees", "UseTree"]] |
603 | ), | 603 | ), |
604 | "ExternCrateItem": (), | 604 | "ExternCrateItem": ( |
605 | options: ["NameRef", "Alias"], | ||
606 | ), | ||
605 | "ArgList": ( | 607 | "ArgList": ( |
606 | collections: [ | 608 | collections: [ |
607 | ["args", "Expr"] | 609 | ["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) { | |||
247 | p.bump(); | 247 | p.bump(); |
248 | assert!(p.at(CRATE_KW)); | 248 | assert!(p.at(CRATE_KW)); |
249 | p.bump(); | 249 | p.bump(); |
250 | name(p); | 250 | name_ref(p); |
251 | opt_alias(p); | 251 | opt_alias(p); |
252 | p.expect(SEMI); | 252 | p.expect(SEMI); |
253 | } | 253 | } |
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0060_extern_crate.txt b/crates/ra_syntax/tests/data/parser/inline/ok/0060_extern_crate.txt index 7ffdc7fbd..a7b428787 100644 --- a/crates/ra_syntax/tests/data/parser/inline/ok/0060_extern_crate.txt +++ b/crates/ra_syntax/tests/data/parser/inline/ok/0060_extern_crate.txt | |||
@@ -4,7 +4,7 @@ SOURCE_FILE@[0; 18) | |||
4 | WHITESPACE@[6; 7) | 4 | WHITESPACE@[6; 7) |
5 | CRATE_KW@[7; 12) | 5 | CRATE_KW@[7; 12) |
6 | WHITESPACE@[12; 13) | 6 | WHITESPACE@[12; 13) |
7 | NAME@[13; 16) | 7 | NAME_REF@[13; 16) |
8 | IDENT@[13; 16) "foo" | 8 | IDENT@[13; 16) "foo" |
9 | SEMI@[16; 17) | 9 | SEMI@[16; 17) |
10 | WHITESPACE@[17; 18) | 10 | WHITESPACE@[17; 18) |
diff --git a/crates/ra_syntax/tests/data/parser/ok/0007_extern_crate.txt b/crates/ra_syntax/tests/data/parser/ok/0007_extern_crate.txt index 5adf3f276..5558d952e 100644 --- a/crates/ra_syntax/tests/data/parser/ok/0007_extern_crate.txt +++ b/crates/ra_syntax/tests/data/parser/ok/0007_extern_crate.txt | |||
@@ -4,7 +4,7 @@ SOURCE_FILE@[0; 43) | |||
4 | WHITESPACE@[6; 7) | 4 | WHITESPACE@[6; 7) |
5 | CRATE_KW@[7; 12) | 5 | CRATE_KW@[7; 12) |
6 | WHITESPACE@[12; 13) | 6 | WHITESPACE@[12; 13) |
7 | NAME@[13; 16) | 7 | NAME_REF@[13; 16) |
8 | IDENT@[13; 16) "foo" | 8 | IDENT@[13; 16) "foo" |
9 | SEMI@[16; 17) | 9 | SEMI@[16; 17) |
10 | WHITESPACE@[17; 18) | 10 | WHITESPACE@[17; 18) |
@@ -13,7 +13,7 @@ SOURCE_FILE@[0; 43) | |||
13 | WHITESPACE@[24; 25) | 13 | WHITESPACE@[24; 25) |
14 | CRATE_KW@[25; 30) | 14 | CRATE_KW@[25; 30) |
15 | WHITESPACE@[30; 31) | 15 | WHITESPACE@[30; 31) |
16 | NAME@[31; 34) | 16 | NAME_REF@[31; 34) |
17 | IDENT@[31; 34) "foo" | 17 | IDENT@[31; 34) "foo" |
18 | WHITESPACE@[34; 35) | 18 | WHITESPACE@[34; 35) |
19 | ALIAS@[35; 41) | 19 | ALIAS@[35; 41) |