aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-07-30 17:02:20 +0100
committerAleksey Kladov <[email protected]>2020-07-30 17:02:20 +0100
commit3cd4112bdc924c132cb0eab9d064511a215421ec (patch)
treef651b475d9c799a772fd37e89405f80a04ea953e /crates/ra_syntax/src/ast
parent6b25f640a6ad8e2322b5cc0664223b742459336d (diff)
Finalize const&static grammar
Diffstat (limited to 'crates/ra_syntax/src/ast')
-rw-r--r--crates/ra_syntax/src/ast/generated/nodes.rs85
-rw-r--r--crates/ra_syntax/src/ast/node_ext.rs4
2 files changed, 45 insertions, 44 deletions
diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs
index 6613b54ba..00a70fce0 100644
--- a/crates/ra_syntax/src/ast/generated/nodes.rs
+++ b/crates/ra_syntax/src/ast/generated/nodes.rs
@@ -28,16 +28,17 @@ impl Attr {
28 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } 28 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
29} 29}
30#[derive(Debug, Clone, PartialEq, Eq, Hash)] 30#[derive(Debug, Clone, PartialEq, Eq, Hash)]
31pub struct ConstDef { 31pub struct Const {
32 pub(crate) syntax: SyntaxNode, 32 pub(crate) syntax: SyntaxNode,
33} 33}
34impl ast::AttrsOwner for ConstDef {} 34impl ast::AttrsOwner for Const {}
35impl ast::NameOwner for ConstDef {} 35impl ast::NameOwner for Const {}
36impl ast::VisibilityOwner for ConstDef {} 36impl ast::VisibilityOwner for Const {}
37impl ast::TypeAscriptionOwner for ConstDef {} 37impl ast::TypeAscriptionOwner for Const {}
38impl ConstDef { 38impl Const {
39 pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) } 39 pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) }
40 pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } 40 pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) }
41 pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) }
41 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } 42 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
42 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } 43 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
43 pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) } 44 pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) }
@@ -139,14 +140,14 @@ impl Module {
139 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } 140 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
140} 141}
141#[derive(Debug, Clone, PartialEq, Eq, Hash)] 142#[derive(Debug, Clone, PartialEq, Eq, Hash)]
142pub struct StaticDef { 143pub struct Static {
143 pub(crate) syntax: SyntaxNode, 144 pub(crate) syntax: SyntaxNode,
144} 145}
145impl ast::AttrsOwner for StaticDef {} 146impl ast::AttrsOwner for Static {}
146impl ast::NameOwner for StaticDef {} 147impl ast::NameOwner for Static {}
147impl ast::VisibilityOwner for StaticDef {} 148impl ast::VisibilityOwner for Static {}
148impl ast::TypeAscriptionOwner for StaticDef {} 149impl ast::TypeAscriptionOwner for Static {}
149impl StaticDef { 150impl Static {
150 pub fn static_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![static]) } 151 pub fn static_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![static]) }
151 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } 152 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) }
152 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } 153 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
@@ -1272,7 +1273,7 @@ impl MetaItem {
1272} 1273}
1273#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1274#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1274pub enum Item { 1275pub enum Item {
1275 ConstDef(ConstDef), 1276 Const(Const),
1276 Enum(Enum), 1277 Enum(Enum),
1277 ExternBlock(ExternBlock), 1278 ExternBlock(ExternBlock),
1278 ExternCrate(ExternCrate), 1279 ExternCrate(ExternCrate),
@@ -1280,7 +1281,7 @@ pub enum Item {
1280 ImplDef(ImplDef), 1281 ImplDef(ImplDef),
1281 MacroCall(MacroCall), 1282 MacroCall(MacroCall),
1282 Module(Module), 1283 Module(Module),
1283 StaticDef(StaticDef), 1284 Static(Static),
1284 Struct(Struct), 1285 Struct(Struct),
1285 TraitDef(TraitDef), 1286 TraitDef(TraitDef),
1286 TypeAlias(TypeAlias), 1287 TypeAlias(TypeAlias),
@@ -1365,7 +1366,7 @@ pub enum Expr {
1365pub enum AssocItem { 1366pub enum AssocItem {
1366 Fn(Fn), 1367 Fn(Fn),
1367 TypeAlias(TypeAlias), 1368 TypeAlias(TypeAlias),
1368 ConstDef(ConstDef), 1369 Const(Const),
1369 MacroCall(MacroCall), 1370 MacroCall(MacroCall),
1370} 1371}
1371impl ast::AttrsOwner for AssocItem {} 1372impl ast::AttrsOwner for AssocItem {}
@@ -1384,7 +1385,7 @@ pub enum AttrInput {
1384#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1385#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1385pub enum ExternItem { 1386pub enum ExternItem {
1386 Fn(Fn), 1387 Fn(Fn),
1387 StaticDef(StaticDef), 1388 Static(Static),
1388} 1389}
1389impl ast::AttrsOwner for ExternItem {} 1390impl ast::AttrsOwner for ExternItem {}
1390impl ast::NameOwner for ExternItem {} 1391impl ast::NameOwner for ExternItem {}
@@ -1421,8 +1422,8 @@ impl AstNode for Attr {
1421 } 1422 }
1422 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1423 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1423} 1424}
1424impl AstNode for ConstDef { 1425impl AstNode for Const {
1425 fn can_cast(kind: SyntaxKind) -> bool { kind == CONST_DEF } 1426 fn can_cast(kind: SyntaxKind) -> bool { kind == CONST }
1426 fn cast(syntax: SyntaxNode) -> Option<Self> { 1427 fn cast(syntax: SyntaxNode) -> Option<Self> {
1427 if Self::can_cast(syntax.kind()) { 1428 if Self::can_cast(syntax.kind()) {
1428 Some(Self { syntax }) 1429 Some(Self { syntax })
@@ -1509,8 +1510,8 @@ impl AstNode for Module {
1509 } 1510 }
1510 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1511 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1511} 1512}
1512impl AstNode for StaticDef { 1513impl AstNode for Static {
1513 fn can_cast(kind: SyntaxKind) -> bool { kind == STATIC_DEF } 1514 fn can_cast(kind: SyntaxKind) -> bool { kind == STATIC }
1514 fn cast(syntax: SyntaxNode) -> Option<Self> { 1515 fn cast(syntax: SyntaxNode) -> Option<Self> {
1515 if Self::can_cast(syntax.kind()) { 1516 if Self::can_cast(syntax.kind()) {
1516 Some(Self { syntax }) 1517 Some(Self { syntax })
@@ -2774,8 +2775,8 @@ impl AstNode for MetaItem {
2774 } 2775 }
2775 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2776 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2776} 2777}
2777impl From<ConstDef> for Item { 2778impl From<Const> for Item {
2778 fn from(node: ConstDef) -> Item { Item::ConstDef(node) } 2779 fn from(node: Const) -> Item { Item::Const(node) }
2779} 2780}
2780impl From<Enum> for Item { 2781impl From<Enum> for Item {
2781 fn from(node: Enum) -> Item { Item::Enum(node) } 2782 fn from(node: Enum) -> Item { Item::Enum(node) }
@@ -2798,8 +2799,8 @@ impl From<MacroCall> for Item {
2798impl From<Module> for Item { 2799impl From<Module> for Item {
2799 fn from(node: Module) -> Item { Item::Module(node) } 2800 fn from(node: Module) -> Item { Item::Module(node) }
2800} 2801}
2801impl From<StaticDef> for Item { 2802impl From<Static> for Item {
2802 fn from(node: StaticDef) -> Item { Item::StaticDef(node) } 2803 fn from(node: Static) -> Item { Item::Static(node) }
2803} 2804}
2804impl From<Struct> for Item { 2805impl From<Struct> for Item {
2805 fn from(node: Struct) -> Item { Item::Struct(node) } 2806 fn from(node: Struct) -> Item { Item::Struct(node) }
@@ -2819,14 +2820,14 @@ impl From<Use> for Item {
2819impl AstNode for Item { 2820impl AstNode for Item {
2820 fn can_cast(kind: SyntaxKind) -> bool { 2821 fn can_cast(kind: SyntaxKind) -> bool {
2821 match kind { 2822 match kind {
2822 CONST_DEF | ENUM | EXTERN_BLOCK | EXTERN_CRATE | FN | IMPL_DEF | MACRO_CALL 2823 CONST | ENUM | EXTERN_BLOCK | EXTERN_CRATE | FN | IMPL_DEF | MACRO_CALL | MODULE
2823 | MODULE | STATIC_DEF | STRUCT | TRAIT_DEF | TYPE_ALIAS | UNION | USE => true, 2824 | STATIC | STRUCT | TRAIT_DEF | TYPE_ALIAS | UNION | USE => true,
2824 _ => false, 2825 _ => false,
2825 } 2826 }
2826 } 2827 }
2827 fn cast(syntax: SyntaxNode) -> Option<Self> { 2828 fn cast(syntax: SyntaxNode) -> Option<Self> {
2828 let res = match syntax.kind() { 2829 let res = match syntax.kind() {
2829 CONST_DEF => Item::ConstDef(ConstDef { syntax }), 2830 CONST => Item::Const(Const { syntax }),
2830 ENUM => Item::Enum(Enum { syntax }), 2831 ENUM => Item::Enum(Enum { syntax }),
2831 EXTERN_BLOCK => Item::ExternBlock(ExternBlock { syntax }), 2832 EXTERN_BLOCK => Item::ExternBlock(ExternBlock { syntax }),
2832 EXTERN_CRATE => Item::ExternCrate(ExternCrate { syntax }), 2833 EXTERN_CRATE => Item::ExternCrate(ExternCrate { syntax }),
@@ -2834,7 +2835,7 @@ impl AstNode for Item {
2834 IMPL_DEF => Item::ImplDef(ImplDef { syntax }), 2835 IMPL_DEF => Item::ImplDef(ImplDef { syntax }),
2835 MACRO_CALL => Item::MacroCall(MacroCall { syntax }), 2836 MACRO_CALL => Item::MacroCall(MacroCall { syntax }),
2836 MODULE => Item::Module(Module { syntax }), 2837 MODULE => Item::Module(Module { syntax }),
2837 STATIC_DEF => Item::StaticDef(StaticDef { syntax }), 2838 STATIC => Item::Static(Static { syntax }),
2838 STRUCT => Item::Struct(Struct { syntax }), 2839 STRUCT => Item::Struct(Struct { syntax }),
2839 TRAIT_DEF => Item::TraitDef(TraitDef { syntax }), 2840 TRAIT_DEF => Item::TraitDef(TraitDef { syntax }),
2840 TYPE_ALIAS => Item::TypeAlias(TypeAlias { syntax }), 2841 TYPE_ALIAS => Item::TypeAlias(TypeAlias { syntax }),
@@ -2846,7 +2847,7 @@ impl AstNode for Item {
2846 } 2847 }
2847 fn syntax(&self) -> &SyntaxNode { 2848 fn syntax(&self) -> &SyntaxNode {
2848 match self { 2849 match self {
2849 Item::ConstDef(it) => &it.syntax, 2850 Item::Const(it) => &it.syntax,
2850 Item::Enum(it) => &it.syntax, 2851 Item::Enum(it) => &it.syntax,
2851 Item::ExternBlock(it) => &it.syntax, 2852 Item::ExternBlock(it) => &it.syntax,
2852 Item::ExternCrate(it) => &it.syntax, 2853 Item::ExternCrate(it) => &it.syntax,
@@ -2854,7 +2855,7 @@ impl AstNode for Item {
2854 Item::ImplDef(it) => &it.syntax, 2855 Item::ImplDef(it) => &it.syntax,
2855 Item::MacroCall(it) => &it.syntax, 2856 Item::MacroCall(it) => &it.syntax,
2856 Item::Module(it) => &it.syntax, 2857 Item::Module(it) => &it.syntax,
2857 Item::StaticDef(it) => &it.syntax, 2858 Item::Static(it) => &it.syntax,
2858 Item::Struct(it) => &it.syntax, 2859 Item::Struct(it) => &it.syntax,
2859 Item::TraitDef(it) => &it.syntax, 2860 Item::TraitDef(it) => &it.syntax,
2860 Item::TypeAlias(it) => &it.syntax, 2861 Item::TypeAlias(it) => &it.syntax,
@@ -3256,8 +3257,8 @@ impl From<Fn> for AssocItem {
3256impl From<TypeAlias> for AssocItem { 3257impl From<TypeAlias> for AssocItem {
3257 fn from(node: TypeAlias) -> AssocItem { AssocItem::TypeAlias(node) } 3258 fn from(node: TypeAlias) -> AssocItem { AssocItem::TypeAlias(node) }
3258} 3259}
3259impl From<ConstDef> for AssocItem { 3260impl From<Const> for AssocItem {
3260 fn from(node: ConstDef) -> AssocItem { AssocItem::ConstDef(node) } 3261 fn from(node: Const) -> AssocItem { AssocItem::Const(node) }
3261} 3262}
3262impl From<MacroCall> for AssocItem { 3263impl From<MacroCall> for AssocItem {
3263 fn from(node: MacroCall) -> AssocItem { AssocItem::MacroCall(node) } 3264 fn from(node: MacroCall) -> AssocItem { AssocItem::MacroCall(node) }
@@ -3265,7 +3266,7 @@ impl From<MacroCall> for AssocItem {
3265impl AstNode for AssocItem { 3266impl AstNode for AssocItem {
3266 fn can_cast(kind: SyntaxKind) -> bool { 3267 fn can_cast(kind: SyntaxKind) -> bool {
3267 match kind { 3268 match kind {
3268 FN | TYPE_ALIAS | CONST_DEF | MACRO_CALL => true, 3269 FN | TYPE_ALIAS | CONST | MACRO_CALL => true,
3269 _ => false, 3270 _ => false,
3270 } 3271 }
3271 } 3272 }
@@ -3273,7 +3274,7 @@ impl AstNode for AssocItem {
3273 let res = match syntax.kind() { 3274 let res = match syntax.kind() {
3274 FN => AssocItem::Fn(Fn { syntax }), 3275 FN => AssocItem::Fn(Fn { syntax }),
3275 TYPE_ALIAS => AssocItem::TypeAlias(TypeAlias { syntax }), 3276 TYPE_ALIAS => AssocItem::TypeAlias(TypeAlias { syntax }),
3276 CONST_DEF => AssocItem::ConstDef(ConstDef { syntax }), 3277 CONST => AssocItem::Const(Const { syntax }),
3277 MACRO_CALL => AssocItem::MacroCall(MacroCall { syntax }), 3278 MACRO_CALL => AssocItem::MacroCall(MacroCall { syntax }),
3278 _ => return None, 3279 _ => return None,
3279 }; 3280 };
@@ -3283,7 +3284,7 @@ impl AstNode for AssocItem {
3283 match self { 3284 match self {
3284 AssocItem::Fn(it) => &it.syntax, 3285 AssocItem::Fn(it) => &it.syntax,
3285 AssocItem::TypeAlias(it) => &it.syntax, 3286 AssocItem::TypeAlias(it) => &it.syntax,
3286 AssocItem::ConstDef(it) => &it.syntax, 3287 AssocItem::Const(it) => &it.syntax,
3287 AssocItem::MacroCall(it) => &it.syntax, 3288 AssocItem::MacroCall(it) => &it.syntax,
3288 } 3289 }
3289 } 3290 }
@@ -3347,20 +3348,20 @@ impl AstNode for AttrInput {
3347impl From<Fn> for ExternItem { 3348impl From<Fn> for ExternItem {
3348 fn from(node: Fn) -> ExternItem { ExternItem::Fn(node) } 3349 fn from(node: Fn) -> ExternItem { ExternItem::Fn(node) }
3349} 3350}
3350impl From<StaticDef> for ExternItem { 3351impl From<Static> for ExternItem {
3351 fn from(node: StaticDef) -> ExternItem { ExternItem::StaticDef(node) } 3352 fn from(node: Static) -> ExternItem { ExternItem::Static(node) }
3352} 3353}
3353impl AstNode for ExternItem { 3354impl AstNode for ExternItem {
3354 fn can_cast(kind: SyntaxKind) -> bool { 3355 fn can_cast(kind: SyntaxKind) -> bool {
3355 match kind { 3356 match kind {
3356 FN | STATIC_DEF => true, 3357 FN | STATIC => true,
3357 _ => false, 3358 _ => false,
3358 } 3359 }
3359 } 3360 }
3360 fn cast(syntax: SyntaxNode) -> Option<Self> { 3361 fn cast(syntax: SyntaxNode) -> Option<Self> {
3361 let res = match syntax.kind() { 3362 let res = match syntax.kind() {
3362 FN => ExternItem::Fn(Fn { syntax }), 3363 FN => ExternItem::Fn(Fn { syntax }),
3363 STATIC_DEF => ExternItem::StaticDef(StaticDef { syntax }), 3364 STATIC => ExternItem::Static(Static { syntax }),
3364 _ => return None, 3365 _ => return None,
3365 }; 3366 };
3366 Some(res) 3367 Some(res)
@@ -3368,7 +3369,7 @@ impl AstNode for ExternItem {
3368 fn syntax(&self) -> &SyntaxNode { 3369 fn syntax(&self) -> &SyntaxNode {
3369 match self { 3370 match self {
3370 ExternItem::Fn(it) => &it.syntax, 3371 ExternItem::Fn(it) => &it.syntax,
3371 ExternItem::StaticDef(it) => &it.syntax, 3372 ExternItem::Static(it) => &it.syntax,
3372 } 3373 }
3373 } 3374 }
3374} 3375}
@@ -3465,7 +3466,7 @@ impl std::fmt::Display for Attr {
3465 std::fmt::Display::fmt(self.syntax(), f) 3466 std::fmt::Display::fmt(self.syntax(), f)
3466 } 3467 }
3467} 3468}
3468impl std::fmt::Display for ConstDef { 3469impl std::fmt::Display for Const {
3469 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3470 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3470 std::fmt::Display::fmt(self.syntax(), f) 3471 std::fmt::Display::fmt(self.syntax(), f)
3471 } 3472 }
@@ -3505,7 +3506,7 @@ impl std::fmt::Display for Module {
3505 std::fmt::Display::fmt(self.syntax(), f) 3506 std::fmt::Display::fmt(self.syntax(), f)
3506 } 3507 }
3507} 3508}
3508impl std::fmt::Display for StaticDef { 3509impl std::fmt::Display for Static {
3509 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3510 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3510 std::fmt::Display::fmt(self.syntax(), f) 3511 std::fmt::Display::fmt(self.syntax(), f)
3511 } 3512 }
diff --git a/crates/ra_syntax/src/ast/node_ext.rs b/crates/ra_syntax/src/ast/node_ext.rs
index 05ec49cec..4da1d5c11 100644
--- a/crates/ra_syntax/src/ast/node_ext.rs
+++ b/crates/ra_syntax/src/ast/node_ext.rs
@@ -483,8 +483,8 @@ impl ast::DocCommentsOwner for ast::Enum {}
483impl ast::DocCommentsOwner for ast::Variant {} 483impl ast::DocCommentsOwner for ast::Variant {}
484impl ast::DocCommentsOwner for ast::TraitDef {} 484impl ast::DocCommentsOwner for ast::TraitDef {}
485impl ast::DocCommentsOwner for ast::Module {} 485impl ast::DocCommentsOwner for ast::Module {}
486impl ast::DocCommentsOwner for ast::StaticDef {} 486impl ast::DocCommentsOwner for ast::Static {}
487impl ast::DocCommentsOwner for ast::ConstDef {} 487impl ast::DocCommentsOwner for ast::Const {}
488impl ast::DocCommentsOwner for ast::TypeAlias {} 488impl ast::DocCommentsOwner for ast::TypeAlias {}
489impl ast::DocCommentsOwner for ast::ImplDef {} 489impl ast::DocCommentsOwner for ast::ImplDef {}
490impl ast::DocCommentsOwner for ast::MacroCall {} 490impl ast::DocCommentsOwner for ast::MacroCall {}