more renames

This commit is contained in:
Aleksey Kladov 2018-08-11 10:56:40 +03:00
parent 2e971cdcbb
commit 78f41ea707
11 changed files with 79 additions and 21 deletions

View file

@ -141,8 +141,8 @@ struct Declaration<'f> (SyntaxNodeRef<'f>);
impl<'f> Declaration<'f> { impl<'f> Declaration<'f> {
fn cast(node: SyntaxNodeRef<'f>) -> Option<Declaration<'f>> { fn cast(node: SyntaxNodeRef<'f>) -> Option<Declaration<'f>> {
match node.kind() { match node.kind() {
| STRUCT | ENUM | FUNCTION | TRAIT_ITEM | STRUCT | ENUM | FUNCTION | TRAIT
| CONST_ITEM | STATIC_ITEM | MOD_ITEM | NAMED_FIELD | CONST_ITEM | STATIC_ITEM | MODULE | NAMED_FIELD
| TYPE_ITEM => Some(Declaration(node)), | TYPE_ITEM => Some(Declaration(node)),
_ => None _ => None
} }

View file

@ -4,6 +4,30 @@ use {
SyntaxKind::*, SyntaxKind::*,
}; };
#[derive(Debug, Clone, Copy)]
pub struct Enum<R: TreeRoot = Arc<SyntaxRoot>> {
syntax: SyntaxNode<R>,
}
impl<R: TreeRoot> AstNode<R> for Enum<R> {
fn cast(syntax: SyntaxNode<R>) -> Option<Self> {
match syntax.kind() {
ENUM => Some(Enum { syntax }),
_ => None,
}
}
fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
}
impl<R: TreeRoot> Enum<R> {
pub fn name(&self) -> Option<Name<R>> {
self.syntax()
.children()
.filter_map(Name::cast)
.next()
}
}
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
pub struct File<R: TreeRoot = Arc<SyntaxRoot>> { pub struct File<R: TreeRoot = Arc<SyntaxRoot>> {
syntax: SyntaxNode<R>, syntax: SyntaxNode<R>,
@ -68,3 +92,27 @@ impl<R: TreeRoot> AstNode<R> for Name<R> {
impl<R: TreeRoot> Name<R> {} impl<R: TreeRoot> Name<R> {}
#[derive(Debug, Clone, Copy)]
pub struct Struct<R: TreeRoot = Arc<SyntaxRoot>> {
syntax: SyntaxNode<R>,
}
impl<R: TreeRoot> AstNode<R> for Struct<R> {
fn cast(syntax: SyntaxNode<R>) -> Option<Self> {
match syntax.kind() {
STRUCT => Some(Struct { syntax }),
_ => None,
}
}
fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
}
impl<R: TreeRoot> Struct<R> {
pub fn name(&self) -> Option<Name<R>> {
self.syntax()
.children()
.filter_map(Name::cast)
.next()
}
}

View file

@ -112,11 +112,11 @@ Grammar(
"ENUM", "ENUM",
"FUNCTION", "FUNCTION",
"EXTERN_CRATE_ITEM", "EXTERN_CRATE_ITEM",
"MOD_ITEM", "MODULE",
"USE_ITEM", "USE_ITEM",
"STATIC_ITEM", "STATIC_ITEM",
"CONST_ITEM", "CONST_ITEM",
"TRAIT_ITEM", "TRAIT",
"IMPL_ITEM", "IMPL_ITEM",
"TYPE_ITEM", "TYPE_ITEM",
"MACRO_CALL", "MACRO_CALL",
@ -224,6 +224,16 @@ Grammar(
["name", "Name"] ["name", "Name"]
] ]
), ),
"Struct": (
options: [
["name", "Name"]
]
),
"Enum": (
options: [
["name", "Name"]
]
),
"Name": (), "Name": (),
}, },
) )

View file

@ -121,7 +121,7 @@ pub(super) fn maybe_item(p: &mut Parser) -> MaybeItem {
// unsafe auto trait T {} // unsafe auto trait T {}
TRAIT_KW => { TRAIT_KW => {
traits::trait_item(p); traits::trait_item(p);
TRAIT_ITEM TRAIT
} }
// test unsafe_impl // test unsafe_impl
@ -161,7 +161,7 @@ fn items_without_modifiers(p: &mut Parser) -> Option<SyntaxKind> {
} }
MOD_KW => { MOD_KW => {
mod_item(p); mod_item(p);
MOD_ITEM MODULE
} }
STRUCT_KW => { STRUCT_KW => {
structs::struct_item(p); structs::struct_item(p);

View file

@ -112,11 +112,11 @@ pub enum SyntaxKind {
ENUM, ENUM,
FUNCTION, FUNCTION,
EXTERN_CRATE_ITEM, EXTERN_CRATE_ITEM,
MOD_ITEM, MODULE,
USE_ITEM, USE_ITEM,
STATIC_ITEM, STATIC_ITEM,
CONST_ITEM, CONST_ITEM,
TRAIT_ITEM, TRAIT,
IMPL_ITEM, IMPL_ITEM,
TYPE_ITEM, TYPE_ITEM,
MACRO_CALL, MACRO_CALL,
@ -347,11 +347,11 @@ impl SyntaxKind {
ENUM => &SyntaxInfo { name: "ENUM" }, ENUM => &SyntaxInfo { name: "ENUM" },
FUNCTION => &SyntaxInfo { name: "FUNCTION" }, FUNCTION => &SyntaxInfo { name: "FUNCTION" },
EXTERN_CRATE_ITEM => &SyntaxInfo { name: "EXTERN_CRATE_ITEM" }, EXTERN_CRATE_ITEM => &SyntaxInfo { name: "EXTERN_CRATE_ITEM" },
MOD_ITEM => &SyntaxInfo { name: "MOD_ITEM" }, MODULE => &SyntaxInfo { name: "MODULE" },
USE_ITEM => &SyntaxInfo { name: "USE_ITEM" }, USE_ITEM => &SyntaxInfo { name: "USE_ITEM" },
STATIC_ITEM => &SyntaxInfo { name: "STATIC_ITEM" }, STATIC_ITEM => &SyntaxInfo { name: "STATIC_ITEM" },
CONST_ITEM => &SyntaxInfo { name: "CONST_ITEM" }, CONST_ITEM => &SyntaxInfo { name: "CONST_ITEM" },
TRAIT_ITEM => &SyntaxInfo { name: "TRAIT_ITEM" }, TRAIT => &SyntaxInfo { name: "TRAIT" },
IMPL_ITEM => &SyntaxInfo { name: "IMPL_ITEM" }, IMPL_ITEM => &SyntaxInfo { name: "IMPL_ITEM" },
TYPE_ITEM => &SyntaxInfo { name: "TYPE_ITEM" }, TYPE_ITEM => &SyntaxInfo { name: "TYPE_ITEM" },
MACRO_CALL => &SyntaxInfo { name: "MACRO_CALL" }, MACRO_CALL => &SyntaxInfo { name: "MACRO_CALL" },

View file

@ -1,5 +1,5 @@
FILE@[0; 18) FILE@[0; 18)
TRAIT_ITEM@[0; 17) TRAIT@[0; 17)
UNSAFE_KW@[0; 6) UNSAFE_KW@[0; 6)
WHITESPACE@[6; 7) WHITESPACE@[6; 7)
TRAIT_KW@[7; 12) TRAIT_KW@[7; 12)

View file

@ -1,5 +1,5 @@
FILE@[0; 23) FILE@[0; 23)
TRAIT_ITEM@[0; 22) TRAIT@[0; 22)
UNSAFE_KW@[0; 6) UNSAFE_KW@[0; 6)
WHITESPACE@[6; 7) WHITESPACE@[6; 7)
AUTO_KW@[7; 11) AUTO_KW@[7; 11)

View file

@ -1,5 +1,5 @@
FILE@[0; 42) FILE@[0; 42)
TRAIT_ITEM@[0; 41) TRAIT@[0; 41)
TRAIT_KW@[0; 5) TRAIT_KW@[0; 5)
WHITESPACE@[5; 6) WHITESPACE@[5; 6)
NAME@[6; 7) NAME@[6; 7)

View file

@ -1,5 +1,5 @@
FILE@[0; 16) FILE@[0; 16)
TRAIT_ITEM@[0; 15) TRAIT@[0; 15)
AUTO_KW@[0; 4) AUTO_KW@[0; 4)
WHITESPACE@[4; 5) WHITESPACE@[4; 5)
TRAIT_KW@[5; 10) TRAIT_KW@[5; 10)

View file

@ -1,5 +1,5 @@
FILE@[0; 22) FILE@[0; 22)
TRAIT_ITEM@[0; 21) TRAIT@[0; 21)
TRAIT_KW@[0; 5) TRAIT_KW@[0; 5)
WHITESPACE@[5; 6) WHITESPACE@[5; 6)
NAME@[6; 7) NAME@[6; 7)

View file

@ -1,12 +1,12 @@
FILE@[0; 118) FILE@[0; 118)
MOD_ITEM@[0; 6) MODULE@[0; 6)
MOD_KW@[0; 3) MOD_KW@[0; 3)
WHITESPACE@[3; 4) WHITESPACE@[3; 4)
NAME@[4; 5) NAME@[4; 5)
IDENT@[4; 5) "a" IDENT@[4; 5) "a"
SEMI@[5; 6) SEMI@[5; 6)
WHITESPACE@[6; 8) WHITESPACE@[6; 8)
MOD_ITEM@[8; 17) MODULE@[8; 17)
MOD_KW@[8; 11) MOD_KW@[8; 11)
WHITESPACE@[11; 12) WHITESPACE@[11; 12)
NAME@[12; 13) NAME@[12; 13)
@ -16,7 +16,7 @@ FILE@[0; 118)
WHITESPACE@[15; 16) WHITESPACE@[15; 16)
R_CURLY@[16; 17) R_CURLY@[16; 17)
WHITESPACE@[17; 19) WHITESPACE@[17; 19)
MOD_ITEM@[19; 65) MODULE@[19; 65)
MOD_KW@[19; 22) MOD_KW@[19; 22)
WHITESPACE@[22; 23) WHITESPACE@[22; 23)
NAME@[23; 24) NAME@[23; 24)
@ -49,7 +49,7 @@ FILE@[0; 118)
WHITESPACE@[63; 64) WHITESPACE@[63; 64)
R_CURLY@[64; 65) R_CURLY@[64; 65)
WHITESPACE@[65; 67) WHITESPACE@[65; 67)
MOD_ITEM@[67; 118) MODULE@[67; 118)
MOD_KW@[67; 70) MOD_KW@[67; 70)
WHITESPACE@[70; 71) WHITESPACE@[70; 71)
NAME@[71; 72) NAME@[71; 72)
@ -65,14 +65,14 @@ FILE@[0; 118)
IDENT@[82; 86) "attr" IDENT@[82; 86) "attr"
R_BRACK@[86; 87) R_BRACK@[86; 87)
WHITESPACE@[87; 92) WHITESPACE@[87; 92)
MOD_ITEM@[92; 98) MODULE@[92; 98)
MOD_KW@[92; 95) MOD_KW@[92; 95)
WHITESPACE@[95; 96) WHITESPACE@[95; 96)
NAME@[96; 97) NAME@[96; 97)
IDENT@[96; 97) "e" IDENT@[96; 97) "e"
SEMI@[97; 98) SEMI@[97; 98)
WHITESPACE@[98; 103) WHITESPACE@[98; 103)
MOD_ITEM@[103; 116) MODULE@[103; 116)
MOD_KW@[103; 106) MOD_KW@[103; 106)
WHITESPACE@[106; 107) WHITESPACE@[106; 107)
NAME@[107; 108) NAME@[107; 108)