diff options
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r-- | crates/ra_syntax/src/ast/extensions.rs | 11 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/generated.rs | 54 | ||||
-rw-r--r-- | crates/ra_syntax/src/grammar.ron | 17 |
3 files changed, 65 insertions, 17 deletions
diff --git a/crates/ra_syntax/src/ast/extensions.rs b/crates/ra_syntax/src/ast/extensions.rs index 513ed7920..a8f625176 100644 --- a/crates/ra_syntax/src/ast/extensions.rs +++ b/crates/ra_syntax/src/ast/extensions.rs | |||
@@ -196,17 +196,6 @@ impl StructKind { | |||
196 | } | 196 | } |
197 | 197 | ||
198 | impl ast::StructDef { | 198 | impl ast::StructDef { |
199 | pub fn is_union(&self) -> bool { | ||
200 | for child in self.syntax().children_with_tokens() { | ||
201 | match child.kind() { | ||
202 | T![struct] => return false, | ||
203 | T![union] => return true, | ||
204 | _ => (), | ||
205 | } | ||
206 | } | ||
207 | false | ||
208 | } | ||
209 | |||
210 | pub fn kind(&self) -> StructKind { | 199 | pub fn kind(&self) -> StructKind { |
211 | StructKind::from_node(self) | 200 | StructKind::from_node(self) |
212 | } | 201 | } |
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index de506d7cd..c06076e3d 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs | |||
@@ -1856,6 +1856,7 @@ impl Module { | |||
1856 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1856 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1857 | pub enum ModuleItem { | 1857 | pub enum ModuleItem { |
1858 | StructDef(StructDef), | 1858 | StructDef(StructDef), |
1859 | UnionDef(UnionDef), | ||
1859 | EnumDef(EnumDef), | 1860 | EnumDef(EnumDef), |
1860 | FnDef(FnDef), | 1861 | FnDef(FnDef), |
1861 | TraitDef(TraitDef), | 1862 | TraitDef(TraitDef), |
@@ -1872,6 +1873,11 @@ impl From<StructDef> for ModuleItem { | |||
1872 | ModuleItem::StructDef(node) | 1873 | ModuleItem::StructDef(node) |
1873 | } | 1874 | } |
1874 | } | 1875 | } |
1876 | impl From<UnionDef> for ModuleItem { | ||
1877 | fn from(node: UnionDef) -> ModuleItem { | ||
1878 | ModuleItem::UnionDef(node) | ||
1879 | } | ||
1880 | } | ||
1875 | impl From<EnumDef> for ModuleItem { | 1881 | impl From<EnumDef> for ModuleItem { |
1876 | fn from(node: EnumDef) -> ModuleItem { | 1882 | fn from(node: EnumDef) -> ModuleItem { |
1877 | ModuleItem::EnumDef(node) | 1883 | ModuleItem::EnumDef(node) |
@@ -1925,14 +1931,15 @@ impl From<Module> for ModuleItem { | |||
1925 | impl AstNode for ModuleItem { | 1931 | impl AstNode for ModuleItem { |
1926 | fn can_cast(kind: SyntaxKind) -> bool { | 1932 | fn can_cast(kind: SyntaxKind) -> bool { |
1927 | match kind { | 1933 | match kind { |
1928 | STRUCT_DEF | ENUM_DEF | FN_DEF | TRAIT_DEF | TYPE_ALIAS_DEF | IMPL_BLOCK | USE_ITEM | 1934 | STRUCT_DEF | UNION_DEF | ENUM_DEF | FN_DEF | TRAIT_DEF | TYPE_ALIAS_DEF |
1929 | | EXTERN_CRATE_ITEM | CONST_DEF | STATIC_DEF | MODULE => true, | 1935 | | IMPL_BLOCK | USE_ITEM | EXTERN_CRATE_ITEM | CONST_DEF | STATIC_DEF | MODULE => true, |
1930 | _ => false, | 1936 | _ => false, |
1931 | } | 1937 | } |
1932 | } | 1938 | } |
1933 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1939 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
1934 | let res = match syntax.kind() { | 1940 | let res = match syntax.kind() { |
1935 | STRUCT_DEF => ModuleItem::StructDef(StructDef { syntax }), | 1941 | STRUCT_DEF => ModuleItem::StructDef(StructDef { syntax }), |
1942 | UNION_DEF => ModuleItem::UnionDef(UnionDef { syntax }), | ||
1936 | ENUM_DEF => ModuleItem::EnumDef(EnumDef { syntax }), | 1943 | ENUM_DEF => ModuleItem::EnumDef(EnumDef { syntax }), |
1937 | FN_DEF => ModuleItem::FnDef(FnDef { syntax }), | 1944 | FN_DEF => ModuleItem::FnDef(FnDef { syntax }), |
1938 | TRAIT_DEF => ModuleItem::TraitDef(TraitDef { syntax }), | 1945 | TRAIT_DEF => ModuleItem::TraitDef(TraitDef { syntax }), |
@@ -1950,6 +1957,7 @@ impl AstNode for ModuleItem { | |||
1950 | fn syntax(&self) -> &SyntaxNode { | 1957 | fn syntax(&self) -> &SyntaxNode { |
1951 | match self { | 1958 | match self { |
1952 | ModuleItem::StructDef(it) => &it.syntax, | 1959 | ModuleItem::StructDef(it) => &it.syntax, |
1960 | ModuleItem::UnionDef(it) => &it.syntax, | ||
1953 | ModuleItem::EnumDef(it) => &it.syntax, | 1961 | ModuleItem::EnumDef(it) => &it.syntax, |
1954 | ModuleItem::FnDef(it) => &it.syntax, | 1962 | ModuleItem::FnDef(it) => &it.syntax, |
1955 | ModuleItem::TraitDef(it) => &it.syntax, | 1963 | ModuleItem::TraitDef(it) => &it.syntax, |
@@ -2038,6 +2046,7 @@ impl NeverType {} | |||
2038 | pub enum NominalDef { | 2046 | pub enum NominalDef { |
2039 | StructDef(StructDef), | 2047 | StructDef(StructDef), |
2040 | EnumDef(EnumDef), | 2048 | EnumDef(EnumDef), |
2049 | UnionDef(UnionDef), | ||
2041 | } | 2050 | } |
2042 | impl From<StructDef> for NominalDef { | 2051 | impl From<StructDef> for NominalDef { |
2043 | fn from(node: StructDef) -> NominalDef { | 2052 | fn from(node: StructDef) -> NominalDef { |
@@ -2049,10 +2058,15 @@ impl From<EnumDef> for NominalDef { | |||
2049 | NominalDef::EnumDef(node) | 2058 | NominalDef::EnumDef(node) |
2050 | } | 2059 | } |
2051 | } | 2060 | } |
2061 | impl From<UnionDef> for NominalDef { | ||
2062 | fn from(node: UnionDef) -> NominalDef { | ||
2063 | NominalDef::UnionDef(node) | ||
2064 | } | ||
2065 | } | ||
2052 | impl AstNode for NominalDef { | 2066 | impl AstNode for NominalDef { |
2053 | fn can_cast(kind: SyntaxKind) -> bool { | 2067 | fn can_cast(kind: SyntaxKind) -> bool { |
2054 | match kind { | 2068 | match kind { |
2055 | STRUCT_DEF | ENUM_DEF => true, | 2069 | STRUCT_DEF | ENUM_DEF | UNION_DEF => true, |
2056 | _ => false, | 2070 | _ => false, |
2057 | } | 2071 | } |
2058 | } | 2072 | } |
@@ -2060,6 +2074,7 @@ impl AstNode for NominalDef { | |||
2060 | let res = match syntax.kind() { | 2074 | let res = match syntax.kind() { |
2061 | STRUCT_DEF => NominalDef::StructDef(StructDef { syntax }), | 2075 | STRUCT_DEF => NominalDef::StructDef(StructDef { syntax }), |
2062 | ENUM_DEF => NominalDef::EnumDef(EnumDef { syntax }), | 2076 | ENUM_DEF => NominalDef::EnumDef(EnumDef { syntax }), |
2077 | UNION_DEF => NominalDef::UnionDef(UnionDef { syntax }), | ||
2063 | _ => return None, | 2078 | _ => return None, |
2064 | }; | 2079 | }; |
2065 | Some(res) | 2080 | Some(res) |
@@ -2068,6 +2083,7 @@ impl AstNode for NominalDef { | |||
2068 | match self { | 2083 | match self { |
2069 | NominalDef::StructDef(it) => &it.syntax, | 2084 | NominalDef::StructDef(it) => &it.syntax, |
2070 | NominalDef::EnumDef(it) => &it.syntax, | 2085 | NominalDef::EnumDef(it) => &it.syntax, |
2086 | NominalDef::UnionDef(it) => &it.syntax, | ||
2071 | } | 2087 | } |
2072 | } | 2088 | } |
2073 | } | 2089 | } |
@@ -3789,6 +3805,38 @@ impl AstNode for TypeRef { | |||
3789 | } | 3805 | } |
3790 | impl TypeRef {} | 3806 | impl TypeRef {} |
3791 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 3807 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
3808 | pub struct UnionDef { | ||
3809 | pub(crate) syntax: SyntaxNode, | ||
3810 | } | ||
3811 | impl AstNode for UnionDef { | ||
3812 | fn can_cast(kind: SyntaxKind) -> bool { | ||
3813 | match kind { | ||
3814 | UNION_DEF => true, | ||
3815 | _ => false, | ||
3816 | } | ||
3817 | } | ||
3818 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
3819 | if Self::can_cast(syntax.kind()) { | ||
3820 | Some(Self { syntax }) | ||
3821 | } else { | ||
3822 | None | ||
3823 | } | ||
3824 | } | ||
3825 | fn syntax(&self) -> &SyntaxNode { | ||
3826 | &self.syntax | ||
3827 | } | ||
3828 | } | ||
3829 | impl ast::VisibilityOwner for UnionDef {} | ||
3830 | impl ast::NameOwner for UnionDef {} | ||
3831 | impl ast::TypeParamsOwner for UnionDef {} | ||
3832 | impl ast::AttrsOwner for UnionDef {} | ||
3833 | impl ast::DocCommentsOwner for UnionDef {} | ||
3834 | impl UnionDef { | ||
3835 | pub fn record_field_def_list(&self) -> Option<RecordFieldDefList> { | ||
3836 | AstChildren::new(&self.syntax).next() | ||
3837 | } | ||
3838 | } | ||
3839 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
3792 | pub struct UseItem { | 3840 | pub struct UseItem { |
3793 | pub(crate) syntax: SyntaxNode, | 3841 | pub(crate) syntax: SyntaxNode, |
3794 | } | 3842 | } |
diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron index 88d1dc109..d1be40abe 100644 --- a/crates/ra_syntax/src/grammar.ron +++ b/crates/ra_syntax/src/grammar.ron | |||
@@ -126,6 +126,7 @@ Grammar( | |||
126 | "SOURCE_FILE", | 126 | "SOURCE_FILE", |
127 | 127 | ||
128 | "STRUCT_DEF", | 128 | "STRUCT_DEF", |
129 | "UNION_DEF", | ||
129 | "ENUM_DEF", | 130 | "ENUM_DEF", |
130 | "FN_DEF", | 131 | "FN_DEF", |
131 | "RET_TYPE", | 132 | "RET_TYPE", |
@@ -285,6 +286,16 @@ Grammar( | |||
285 | "DocCommentsOwner" | 286 | "DocCommentsOwner" |
286 | ] | 287 | ] |
287 | ), | 288 | ), |
289 | "UnionDef": ( | ||
290 | traits: [ | ||
291 | "VisibilityOwner", | ||
292 | "NameOwner", | ||
293 | "TypeParamsOwner", | ||
294 | "AttrsOwner", | ||
295 | "DocCommentsOwner" | ||
296 | ], | ||
297 | options: ["RecordFieldDefList"], | ||
298 | ), | ||
288 | "RecordFieldDefList": (collections: [("fields", "RecordFieldDef")]), | 299 | "RecordFieldDefList": (collections: [("fields", "RecordFieldDef")]), |
289 | "RecordFieldDef": ( | 300 | "RecordFieldDef": ( |
290 | traits: [ | 301 | traits: [ |
@@ -388,7 +399,7 @@ Grammar( | |||
388 | ]), | 399 | ]), |
389 | 400 | ||
390 | "NominalDef": ( | 401 | "NominalDef": ( |
391 | enum: ["StructDef", "EnumDef"], | 402 | enum: ["StructDef", "EnumDef", "UnionDef"], |
392 | traits: [ | 403 | traits: [ |
393 | "NameOwner", | 404 | "NameOwner", |
394 | "TypeParamsOwner", | 405 | "TypeParamsOwner", |
@@ -396,9 +407,9 @@ Grammar( | |||
396 | ], | 407 | ], |
397 | ), | 408 | ), |
398 | "ModuleItem": ( | 409 | "ModuleItem": ( |
399 | enum: ["StructDef", "EnumDef", "FnDef", "TraitDef", "TypeAliasDef", "ImplBlock", | 410 | enum: ["StructDef", "UnionDef", "EnumDef", "FnDef", "TraitDef", "TypeAliasDef", "ImplBlock", |
400 | "UseItem", "ExternCrateItem", "ConstDef", "StaticDef", "Module" ], | 411 | "UseItem", "ExternCrateItem", "ConstDef", "StaticDef", "Module" ], |
401 | traits: ["AttrsOwner"] | 412 | traits: ["AttrsOwner"], |
402 | ), | 413 | ), |
403 | "ImplItem": ( | 414 | "ImplItem": ( |
404 | enum: ["FnDef", "TypeAliasDef", "ConstDef"], | 415 | enum: ["FnDef", "TypeAliasDef", "ConstDef"], |