From 78f41ea707cc8aeaa8d1ba8a7216cb8712f13e98 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 11 Aug 2018 10:56:40 +0300 Subject: more renames --- crates/libsyntax2/src/ast/generated.rs | 48 +++++++++++++++++++++++++ crates/libsyntax2/src/grammar.ron | 14 ++++++-- crates/libsyntax2/src/grammar/items/mod.rs | 4 +-- crates/libsyntax2/src/syntax_kinds/generated.rs | 8 ++--- 4 files changed, 66 insertions(+), 8 deletions(-) (limited to 'crates/libsyntax2/src') diff --git a/crates/libsyntax2/src/ast/generated.rs b/crates/libsyntax2/src/ast/generated.rs index 12e5a1c3e..c9b587ecb 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 Enum> { + syntax: SyntaxNode, +} + +impl AstNode for Enum { + fn cast(syntax: SyntaxNode) -> Option { + match syntax.kind() { + ENUM => Some(Enum { syntax }), + _ => None, + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl Enum { + pub fn name(&self) -> Option> { + self.syntax() + .children() + .filter_map(Name::cast) + .next() + } +} + #[derive(Debug, Clone, Copy)] pub struct File> { syntax: SyntaxNode, @@ -68,3 +92,27 @@ impl AstNode for Name { impl Name {} +#[derive(Debug, Clone, Copy)] +pub struct Struct> { + syntax: SyntaxNode, +} + +impl AstNode for Struct { + fn cast(syntax: SyntaxNode) -> Option { + match syntax.kind() { + STRUCT => Some(Struct { syntax }), + _ => None, + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl Struct { + pub fn name(&self) -> Option> { + self.syntax() + .children() + .filter_map(Name::cast) + .next() + } +} + diff --git a/crates/libsyntax2/src/grammar.ron b/crates/libsyntax2/src/grammar.ron index 650f72212..a8916c5c7 100644 --- a/crates/libsyntax2/src/grammar.ron +++ b/crates/libsyntax2/src/grammar.ron @@ -112,11 +112,11 @@ Grammar( "ENUM", "FUNCTION", "EXTERN_CRATE_ITEM", - "MOD_ITEM", + "MODULE", "USE_ITEM", "STATIC_ITEM", "CONST_ITEM", - "TRAIT_ITEM", + "TRAIT", "IMPL_ITEM", "TYPE_ITEM", "MACRO_CALL", @@ -224,6 +224,16 @@ Grammar( ["name", "Name"] ] ), + "Struct": ( + options: [ + ["name", "Name"] + ] + ), + "Enum": ( + options: [ + ["name", "Name"] + ] + ), "Name": (), }, ) diff --git a/crates/libsyntax2/src/grammar/items/mod.rs b/crates/libsyntax2/src/grammar/items/mod.rs index be4ff976a..6f401ea1b 100644 --- a/crates/libsyntax2/src/grammar/items/mod.rs +++ b/crates/libsyntax2/src/grammar/items/mod.rs @@ -121,7 +121,7 @@ pub(super) fn maybe_item(p: &mut Parser) -> MaybeItem { // unsafe auto trait T {} TRAIT_KW => { traits::trait_item(p); - TRAIT_ITEM + TRAIT } // test unsafe_impl @@ -161,7 +161,7 @@ fn items_without_modifiers(p: &mut Parser) -> Option { } MOD_KW => { mod_item(p); - MOD_ITEM + MODULE } STRUCT_KW => { structs::struct_item(p); diff --git a/crates/libsyntax2/src/syntax_kinds/generated.rs b/crates/libsyntax2/src/syntax_kinds/generated.rs index 7d2fb60f6..c45a4800c 100644 --- a/crates/libsyntax2/src/syntax_kinds/generated.rs +++ b/crates/libsyntax2/src/syntax_kinds/generated.rs @@ -112,11 +112,11 @@ pub enum SyntaxKind { ENUM, FUNCTION, EXTERN_CRATE_ITEM, - MOD_ITEM, + MODULE, USE_ITEM, STATIC_ITEM, CONST_ITEM, - TRAIT_ITEM, + TRAIT, IMPL_ITEM, TYPE_ITEM, MACRO_CALL, @@ -347,11 +347,11 @@ impl SyntaxKind { ENUM => &SyntaxInfo { name: "ENUM" }, FUNCTION => &SyntaxInfo { name: "FUNCTION" }, EXTERN_CRATE_ITEM => &SyntaxInfo { name: "EXTERN_CRATE_ITEM" }, - MOD_ITEM => &SyntaxInfo { name: "MOD_ITEM" }, + MODULE => &SyntaxInfo { name: "MODULE" }, USE_ITEM => &SyntaxInfo { name: "USE_ITEM" }, STATIC_ITEM => &SyntaxInfo { name: "STATIC_ITEM" }, CONST_ITEM => &SyntaxInfo { name: "CONST_ITEM" }, - TRAIT_ITEM => &SyntaxInfo { name: "TRAIT_ITEM" }, + TRAIT => &SyntaxInfo { name: "TRAIT" }, IMPL_ITEM => &SyntaxInfo { name: "IMPL_ITEM" }, TYPE_ITEM => &SyntaxInfo { name: "TYPE_ITEM" }, MACRO_CALL => &SyntaxInfo { name: "MACRO_CALL" }, -- cgit v1.2.3