From d5119133fc03694c6644cac9e307d1d496fc9bf2 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 11 Aug 2018 11:03:22 +0300 Subject: heck --- crates/libsyntax2/src/ast/generated.rs | 96 +++++++++++++++++++++++++++++ crates/libsyntax2/src/ast/generated.rs.tera | 2 +- crates/libsyntax2/src/grammar.ron | 20 ++++++ 3 files changed, 117 insertions(+), 1 deletion(-) (limited to 'crates/libsyntax2') diff --git a/crates/libsyntax2/src/ast/generated.rs b/crates/libsyntax2/src/ast/generated.rs index c9b587ecb..7a2a9c7d4 100644 --- a/crates/libsyntax2/src/ast/generated.rs +++ b/crates/libsyntax2/src/ast/generated.rs @@ -4,6 +4,30 @@ use { SyntaxKind::*, }; +#[derive(Debug, Clone, Copy)] +pub struct ConstItem> { + syntax: SyntaxNode, +} + +impl AstNode for ConstItem { + fn cast(syntax: SyntaxNode) -> Option { + match syntax.kind() { + CONST_ITEM => Some(ConstItem { syntax }), + _ => None, + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ConstItem { + pub fn name(&self) -> Option> { + self.syntax() + .children() + .filter_map(Name::cast) + .next() + } +} + #[derive(Debug, Clone, Copy)] pub struct Enum> { syntax: SyntaxNode, @@ -75,6 +99,30 @@ impl Function { } } +#[derive(Debug, Clone, Copy)] +pub struct Module> { + syntax: SyntaxNode, +} + +impl AstNode for Module { + fn cast(syntax: SyntaxNode) -> Option { + match syntax.kind() { + MODULE => Some(Module { syntax }), + _ => None, + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl Module { + pub fn name(&self) -> Option> { + self.syntax() + .children() + .filter_map(Name::cast) + .next() + } +} + #[derive(Debug, Clone, Copy)] pub struct Name> { syntax: SyntaxNode, @@ -92,6 +140,30 @@ impl AstNode for Name { impl Name {} +#[derive(Debug, Clone, Copy)] +pub struct StaticItem> { + syntax: SyntaxNode, +} + +impl AstNode for StaticItem { + fn cast(syntax: SyntaxNode) -> Option { + match syntax.kind() { + STATIC_ITEM => Some(StaticItem { syntax }), + _ => None, + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl StaticItem { + pub fn name(&self) -> Option> { + self.syntax() + .children() + .filter_map(Name::cast) + .next() + } +} + #[derive(Debug, Clone, Copy)] pub struct Struct> { syntax: SyntaxNode, @@ -116,3 +188,27 @@ impl Struct { } } +#[derive(Debug, Clone, Copy)] +pub struct Trait> { + syntax: SyntaxNode, +} + +impl AstNode for Trait { + fn cast(syntax: SyntaxNode) -> Option { + match syntax.kind() { + TRAIT => Some(Trait { syntax }), + _ => None, + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl Trait { + pub fn name(&self) -> Option> { + self.syntax() + .children() + .filter_map(Name::cast) + .next() + } +} + diff --git a/crates/libsyntax2/src/ast/generated.rs.tera b/crates/libsyntax2/src/ast/generated.rs.tera index 09630e427..86b8b05d1 100644 --- a/crates/libsyntax2/src/ast/generated.rs.tera +++ b/crates/libsyntax2/src/ast/generated.rs.tera @@ -12,7 +12,7 @@ pub struct {{ node }}> { impl AstNode for {{ node }} { fn cast(syntax: SyntaxNode) -> Option { match syntax.kind() { - {{ node | upper }} => Some({{ node }} { syntax }), + {{ node | SCREAM }} => Some({{ node }} { syntax }), _ => None, } } diff --git a/crates/libsyntax2/src/grammar.ron b/crates/libsyntax2/src/grammar.ron index a8916c5c7..c9470d4fa 100644 --- a/crates/libsyntax2/src/grammar.ron +++ b/crates/libsyntax2/src/grammar.ron @@ -234,6 +234,26 @@ Grammar( ["name", "Name"] ] ), + "Trait": ( + options: [ + ["name", "Name"] + ] + ), + "Module": ( + options: [ + ["name", "Name"] + ] + ), + "ConstItem": ( + options: [ + ["name", "Name"] + ] + ), + "StaticItem": ( + options: [ + ["name", "Name"] + ] + ), "Name": (), }, ) -- cgit v1.2.3