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/libeditor/src/lib.rs | 4 +- 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 ++-- .../tests/data/parser/inline/0007_unsafe_trait.txt | 2 +- .../data/parser/inline/0009_unsafe_auto_trait.txt | 2 +- .../tests/data/parser/inline/0056_trait_item.txt | 2 +- .../tests/data/parser/inline/0057_auto_trait.txt | 2 +- .../tests/data/parser/inline/0091_fn_decl.txt | 2 +- .../tests/data/parser/ok/0008_mod_item.txt | 12 +++--- 11 files changed, 79 insertions(+), 21 deletions(-) diff --git a/crates/libeditor/src/lib.rs b/crates/libeditor/src/lib.rs index df0938e90..293fafae7 100644 --- a/crates/libeditor/src/lib.rs +++ b/crates/libeditor/src/lib.rs @@ -141,8 +141,8 @@ struct Declaration<'f> (SyntaxNodeRef<'f>); impl<'f> Declaration<'f> { fn cast(node: SyntaxNodeRef<'f>) -> Option> { match node.kind() { - | STRUCT | ENUM | FUNCTION | TRAIT_ITEM - | CONST_ITEM | STATIC_ITEM | MOD_ITEM | NAMED_FIELD + | STRUCT | ENUM | FUNCTION | TRAIT + | CONST_ITEM | STATIC_ITEM | MODULE | NAMED_FIELD | TYPE_ITEM => Some(Declaration(node)), _ => None } 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" }, diff --git a/crates/libsyntax2/tests/data/parser/inline/0007_unsafe_trait.txt b/crates/libsyntax2/tests/data/parser/inline/0007_unsafe_trait.txt index afa6637d3..a98c05c77 100644 --- a/crates/libsyntax2/tests/data/parser/inline/0007_unsafe_trait.txt +++ b/crates/libsyntax2/tests/data/parser/inline/0007_unsafe_trait.txt @@ -1,5 +1,5 @@ FILE@[0; 18) - TRAIT_ITEM@[0; 17) + TRAIT@[0; 17) UNSAFE_KW@[0; 6) WHITESPACE@[6; 7) TRAIT_KW@[7; 12) diff --git a/crates/libsyntax2/tests/data/parser/inline/0009_unsafe_auto_trait.txt b/crates/libsyntax2/tests/data/parser/inline/0009_unsafe_auto_trait.txt index 825a56f17..dac09a654 100644 --- a/crates/libsyntax2/tests/data/parser/inline/0009_unsafe_auto_trait.txt +++ b/crates/libsyntax2/tests/data/parser/inline/0009_unsafe_auto_trait.txt @@ -1,5 +1,5 @@ FILE@[0; 23) - TRAIT_ITEM@[0; 22) + TRAIT@[0; 22) UNSAFE_KW@[0; 6) WHITESPACE@[6; 7) AUTO_KW@[7; 11) diff --git a/crates/libsyntax2/tests/data/parser/inline/0056_trait_item.txt b/crates/libsyntax2/tests/data/parser/inline/0056_trait_item.txt index ba4e0ebc8..b9dc6a0fd 100644 --- a/crates/libsyntax2/tests/data/parser/inline/0056_trait_item.txt +++ b/crates/libsyntax2/tests/data/parser/inline/0056_trait_item.txt @@ -1,5 +1,5 @@ FILE@[0; 42) - TRAIT_ITEM@[0; 41) + TRAIT@[0; 41) TRAIT_KW@[0; 5) WHITESPACE@[5; 6) NAME@[6; 7) diff --git a/crates/libsyntax2/tests/data/parser/inline/0057_auto_trait.txt b/crates/libsyntax2/tests/data/parser/inline/0057_auto_trait.txt index 6bb4ffdba..c7679b643 100644 --- a/crates/libsyntax2/tests/data/parser/inline/0057_auto_trait.txt +++ b/crates/libsyntax2/tests/data/parser/inline/0057_auto_trait.txt @@ -1,5 +1,5 @@ FILE@[0; 16) - TRAIT_ITEM@[0; 15) + TRAIT@[0; 15) AUTO_KW@[0; 4) WHITESPACE@[4; 5) TRAIT_KW@[5; 10) diff --git a/crates/libsyntax2/tests/data/parser/inline/0091_fn_decl.txt b/crates/libsyntax2/tests/data/parser/inline/0091_fn_decl.txt index 5a76af652..a6e144776 100644 --- a/crates/libsyntax2/tests/data/parser/inline/0091_fn_decl.txt +++ b/crates/libsyntax2/tests/data/parser/inline/0091_fn_decl.txt @@ -1,5 +1,5 @@ FILE@[0; 22) - TRAIT_ITEM@[0; 21) + TRAIT@[0; 21) TRAIT_KW@[0; 5) WHITESPACE@[5; 6) NAME@[6; 7) diff --git a/crates/libsyntax2/tests/data/parser/ok/0008_mod_item.txt b/crates/libsyntax2/tests/data/parser/ok/0008_mod_item.txt index b8470478f..86d92a8f4 100644 --- a/crates/libsyntax2/tests/data/parser/ok/0008_mod_item.txt +++ b/crates/libsyntax2/tests/data/parser/ok/0008_mod_item.txt @@ -1,12 +1,12 @@ FILE@[0; 118) - MOD_ITEM@[0; 6) + MODULE@[0; 6) MOD_KW@[0; 3) WHITESPACE@[3; 4) NAME@[4; 5) IDENT@[4; 5) "a" SEMI@[5; 6) WHITESPACE@[6; 8) - MOD_ITEM@[8; 17) + MODULE@[8; 17) MOD_KW@[8; 11) WHITESPACE@[11; 12) NAME@[12; 13) @@ -16,7 +16,7 @@ FILE@[0; 118) WHITESPACE@[15; 16) R_CURLY@[16; 17) WHITESPACE@[17; 19) - MOD_ITEM@[19; 65) + MODULE@[19; 65) MOD_KW@[19; 22) WHITESPACE@[22; 23) NAME@[23; 24) @@ -49,7 +49,7 @@ FILE@[0; 118) WHITESPACE@[63; 64) R_CURLY@[64; 65) WHITESPACE@[65; 67) - MOD_ITEM@[67; 118) + MODULE@[67; 118) MOD_KW@[67; 70) WHITESPACE@[70; 71) NAME@[71; 72) @@ -65,14 +65,14 @@ FILE@[0; 118) IDENT@[82; 86) "attr" R_BRACK@[86; 87) WHITESPACE@[87; 92) - MOD_ITEM@[92; 98) + MODULE@[92; 98) MOD_KW@[92; 95) WHITESPACE@[95; 96) NAME@[96; 97) IDENT@[96; 97) "e" SEMI@[97; 98) WHITESPACE@[98; 103) - MOD_ITEM@[103; 116) + MODULE@[103; 116) MOD_KW@[103; 106) WHITESPACE@[106; 107) NAME@[107; 108) -- cgit v1.2.3