From b937262c9b75a361b95a6a27260a71c737e035bf Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 21 Aug 2018 18:30:10 +0300 Subject: Module map implementation --- crates/libsyntax2/src/ast/generated.rs | 14 +++++++++++++- crates/libsyntax2/src/grammar.ron | 10 ++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) (limited to 'crates/libsyntax2') diff --git a/crates/libsyntax2/src/ast/generated.rs b/crates/libsyntax2/src/ast/generated.rs index e8a87eba5..610b5198c 100644 --- a/crates/libsyntax2/src/ast/generated.rs +++ b/crates/libsyntax2/src/ast/generated.rs @@ -127,6 +127,12 @@ impl<'a> File<'a> { .children() .filter_map(FnDef::cast) } + + pub fn modules(self) -> impl Iterator> + 'a { + self.syntax() + .children() + .filter_map(Module::cast) + } } // FnDef @@ -239,7 +245,13 @@ impl<'a> AstNode<'a> for Module<'a> { impl<'a> ast::NameOwner<'a> for Module<'a> {} impl<'a> ast::AttrsOwner<'a> for Module<'a> {} -impl<'a> Module<'a> {} +impl<'a> Module<'a> { + pub fn modules(self) -> impl Iterator> + 'a { + self.syntax() + .children() + .filter_map(Module::cast) + } +} // Name #[derive(Debug, Clone, Copy)] diff --git a/crates/libsyntax2/src/grammar.ron b/crates/libsyntax2/src/grammar.ron index abeffb2c3..8e644d3c4 100644 --- a/crates/libsyntax2/src/grammar.ron +++ b/crates/libsyntax2/src/grammar.ron @@ -218,7 +218,8 @@ Grammar( ast: { "File": ( collections: [ - ["functions", "FnDef"] + ["functions", "FnDef"], + ["modules", "Module"], ] ), "FnDef": ( traits: ["NameOwner", "AttrsOwner"] ), @@ -231,7 +232,12 @@ Grammar( "NamedField": ( traits: ["NameOwner", "AttrsOwner"] ), "EnumDef": ( traits: ["NameOwner", "AttrsOwner"] ), "TraitDef": ( traits: ["NameOwner", "AttrsOwner"] ), - "Module": ( traits: ["NameOwner", "AttrsOwner"] ), + "Module": ( + traits: ["NameOwner", "AttrsOwner"], + collections: [ + ["modules", "Module"] + ] + ), "ConstDef": ( traits: ["NameOwner", "AttrsOwner"] ), "StaticDef": ( traits: ["NameOwner", "AttrsOwner"] ), "TypeDef": ( traits: ["NameOwner", "AttrsOwner"] ), -- cgit v1.2.3