diff options
author | Florian Diebold <[email protected]> | 2018-12-25 12:01:47 +0000 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2018-12-25 14:16:42 +0000 |
commit | 4cb7b0f2af9787abe1c73fc3922e9b426a96e0ef (patch) | |
tree | 80e0ec0685f17b6470a7ff3b1f47abd1f9b6b9ab /crates/ra_syntax/src/ast.rs | |
parent | 6fcd38cc81bdcc9921da767872dfce65ee7d2d27 (diff) |
Add AST definitions for struct/variant fields etc.
Fixes #117
Diffstat (limited to 'crates/ra_syntax/src/ast.rs')
-rw-r--r-- | crates/ra_syntax/src/ast.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index f12479fb4..5dbf9b221 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs | |||
@@ -363,3 +363,34 @@ impl<'a, N: AstNode<'a>> Iterator for AstChildren<'a, N> { | |||
363 | } | 363 | } |
364 | } | 364 | } |
365 | } | 365 | } |
366 | |||
367 | #[derive(Debug, Clone, PartialEq, Eq)] | ||
368 | pub enum StructFlavor<'a> { | ||
369 | Tuple(PosFieldList<'a>), | ||
370 | Named(NamedFieldDefList<'a>), | ||
371 | Unit, | ||
372 | } | ||
373 | |||
374 | impl<'a> StructFlavor<'a> { | ||
375 | fn from_node<N: AstNode<'a>>(node: N) -> StructFlavor<'a> { | ||
376 | if let Some(nfdl) = child_opt::<_, NamedFieldDefList>(node) { | ||
377 | StructFlavor::Named(nfdl) | ||
378 | } else if let Some(pfl) = child_opt::<_, PosFieldList>(node) { | ||
379 | StructFlavor::Tuple(pfl) | ||
380 | } else { | ||
381 | StructFlavor::Unit | ||
382 | } | ||
383 | } | ||
384 | } | ||
385 | |||
386 | impl<'a> StructDef<'a> { | ||
387 | pub fn flavor(self) -> StructFlavor<'a> { | ||
388 | StructFlavor::from_node(self) | ||
389 | } | ||
390 | } | ||
391 | |||
392 | impl<'a> EnumVariant<'a> { | ||
393 | pub fn flavor(self) -> StructFlavor<'a> { | ||
394 | StructFlavor::from_node(self) | ||
395 | } | ||
396 | } | ||