From 199e3b73c712a74e36bbb75eebf9e9418f1b1341 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 14 Aug 2018 14:45:56 +0300 Subject: fields are part of the structure --- crates/libsyntax2/src/ast/generated.rs | 27 ++++++++++++++++++++++++++- crates/libsyntax2/src/grammar.ron | 9 ++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) (limited to 'crates/libsyntax2') diff --git a/crates/libsyntax2/src/ast/generated.rs b/crates/libsyntax2/src/ast/generated.rs index 80670ce71..1ec05c950 100644 --- a/crates/libsyntax2/src/ast/generated.rs +++ b/crates/libsyntax2/src/ast/generated.rs @@ -249,6 +249,25 @@ impl AstNode for NameRef { impl NameRef {} +// NamedField +#[derive(Debug, Clone, Copy)] +pub struct NamedField> { + syntax: SyntaxNode, +} + +impl AstNode for NamedField { + fn cast(syntax: SyntaxNode) -> Option { + match syntax.kind() { + NAMED_FIELD => Some(NamedField { syntax }), + _ => None, + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ast::NameOwner for NamedField {} +impl NamedField {} + // NeverType #[derive(Debug, Clone, Copy)] pub struct NeverType> { @@ -436,7 +455,13 @@ impl AstNode for StructDef { } impl ast::NameOwner for StructDef {} -impl StructDef {} +impl StructDef { + pub fn fields<'a>(&'a self) -> impl Iterator> + 'a { + self.syntax() + .children() + .filter_map(NamedField::cast) + } +} // TraitDef #[derive(Debug, Clone, Copy)] diff --git a/crates/libsyntax2/src/grammar.ron b/crates/libsyntax2/src/grammar.ron index 3ae403bb5..aa28ab922 100644 --- a/crates/libsyntax2/src/grammar.ron +++ b/crates/libsyntax2/src/grammar.ron @@ -222,7 +222,13 @@ Grammar( ] ), "FnDef": ( traits: ["NameOwner"] ), - "StructDef": ( traits: ["NameOwner"] ), + "StructDef": ( + traits: ["NameOwner"], + collections: [ + ["fields", "NamedField"] + ] + ), + "NamedField": ( traits: ["NameOwner"] ), "EnumDef": ( traits: ["NameOwner"] ), "TraitDef": ( traits: ["NameOwner"] ), "Module": ( traits: ["NameOwner"] ), @@ -230,6 +236,7 @@ Grammar( "StaticDef": ( traits: ["NameOwner"] ), "TypeDef": ( traits: ["NameOwner"] ), "ImplItem": (), + "Name": (), "NameRef": (), -- cgit v1.2.3