aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/libeditor/src/lib.rs4
-rw-r--r--crates/libsyntax2/src/ast/generated.rs48
-rw-r--r--crates/libsyntax2/src/grammar.ron14
-rw-r--r--crates/libsyntax2/src/grammar/items/mod.rs4
-rw-r--r--crates/libsyntax2/src/syntax_kinds/generated.rs8
-rw-r--r--crates/libsyntax2/tests/data/parser/inline/0007_unsafe_trait.txt2
-rw-r--r--crates/libsyntax2/tests/data/parser/inline/0009_unsafe_auto_trait.txt2
-rw-r--r--crates/libsyntax2/tests/data/parser/inline/0056_trait_item.txt2
-rw-r--r--crates/libsyntax2/tests/data/parser/inline/0057_auto_trait.txt2
-rw-r--r--crates/libsyntax2/tests/data/parser/inline/0091_fn_decl.txt2
-rw-r--r--crates/libsyntax2/tests/data/parser/ok/0008_mod_item.txt12
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>);
141impl<'f> Declaration<'f> { 141impl<'f> Declaration<'f> {
142 fn cast(node: SyntaxNodeRef<'f>) -> Option<Declaration<'f>> { 142 fn cast(node: SyntaxNodeRef<'f>) -> Option<Declaration<'f>> {
143 match node.kind() { 143 match node.kind() {
144 | STRUCT | ENUM | FUNCTION | TRAIT_ITEM 144 | STRUCT | ENUM | FUNCTION | TRAIT
145 | CONST_ITEM | STATIC_ITEM | MOD_ITEM | NAMED_FIELD 145 | CONST_ITEM | STATIC_ITEM | MODULE | NAMED_FIELD
146 | TYPE_ITEM => Some(Declaration(node)), 146 | TYPE_ITEM => Some(Declaration(node)),
147 _ => None 147 _ => None
148 } 148 }
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
@@ -5,6 +5,30 @@ use {
5}; 5};
6 6
7#[derive(Debug, Clone, Copy)] 7#[derive(Debug, Clone, Copy)]
8pub struct Enum<R: TreeRoot = Arc<SyntaxRoot>> {
9 syntax: SyntaxNode<R>,
10}
11
12impl<R: TreeRoot> AstNode<R> for Enum<R> {
13 fn cast(syntax: SyntaxNode<R>) -> Option<Self> {
14 match syntax.kind() {
15 ENUM => Some(Enum { syntax }),
16 _ => None,
17 }
18 }
19 fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
20}
21
22impl<R: TreeRoot> Enum<R> {
23 pub fn name(&self) -> Option<Name<R>> {
24 self.syntax()
25 .children()
26 .filter_map(Name::cast)
27 .next()
28 }
29}
30
31#[derive(Debug, Clone, Copy)]
8pub struct File<R: TreeRoot = Arc<SyntaxRoot>> { 32pub struct File<R: TreeRoot = Arc<SyntaxRoot>> {
9 syntax: SyntaxNode<R>, 33 syntax: SyntaxNode<R>,
10} 34}
@@ -68,3 +92,27 @@ impl<R: TreeRoot> AstNode<R> for Name<R> {
68 92
69impl<R: TreeRoot> Name<R> {} 93impl<R: TreeRoot> Name<R> {}
70 94
95#[derive(Debug, Clone, Copy)]
96pub struct Struct<R: TreeRoot = Arc<SyntaxRoot>> {
97 syntax: SyntaxNode<R>,
98}
99
100impl<R: TreeRoot> AstNode<R> for Struct<R> {
101 fn cast(syntax: SyntaxNode<R>) -> Option<Self> {
102 match syntax.kind() {
103 STRUCT => Some(Struct { syntax }),
104 _ => None,
105 }
106 }
107 fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
108}
109
110impl<R: TreeRoot> Struct<R> {
111 pub fn name(&self) -> Option<Name<R>> {
112 self.syntax()
113 .children()
114 .filter_map(Name::cast)
115 .next()
116 }
117}
118
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(
112 "ENUM", 112 "ENUM",
113 "FUNCTION", 113 "FUNCTION",
114 "EXTERN_CRATE_ITEM", 114 "EXTERN_CRATE_ITEM",
115 "MOD_ITEM", 115 "MODULE",
116 "USE_ITEM", 116 "USE_ITEM",
117 "STATIC_ITEM", 117 "STATIC_ITEM",
118 "CONST_ITEM", 118 "CONST_ITEM",
119 "TRAIT_ITEM", 119 "TRAIT",
120 "IMPL_ITEM", 120 "IMPL_ITEM",
121 "TYPE_ITEM", 121 "TYPE_ITEM",
122 "MACRO_CALL", 122 "MACRO_CALL",
@@ -224,6 +224,16 @@ Grammar(
224 ["name", "Name"] 224 ["name", "Name"]
225 ] 225 ]
226 ), 226 ),
227 "Struct": (
228 options: [
229 ["name", "Name"]
230 ]
231 ),
232 "Enum": (
233 options: [
234 ["name", "Name"]
235 ]
236 ),
227 "Name": (), 237 "Name": (),
228 }, 238 },
229) 239)
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 {
121 // unsafe auto trait T {} 121 // unsafe auto trait T {}
122 TRAIT_KW => { 122 TRAIT_KW => {
123 traits::trait_item(p); 123 traits::trait_item(p);
124 TRAIT_ITEM 124 TRAIT
125 } 125 }
126 126
127 // test unsafe_impl 127 // test unsafe_impl
@@ -161,7 +161,7 @@ fn items_without_modifiers(p: &mut Parser) -> Option<SyntaxKind> {
161 } 161 }
162 MOD_KW => { 162 MOD_KW => {
163 mod_item(p); 163 mod_item(p);
164 MOD_ITEM 164 MODULE
165 } 165 }
166 STRUCT_KW => { 166 STRUCT_KW => {
167 structs::struct_item(p); 167 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 {
112 ENUM, 112 ENUM,
113 FUNCTION, 113 FUNCTION,
114 EXTERN_CRATE_ITEM, 114 EXTERN_CRATE_ITEM,
115 MOD_ITEM, 115 MODULE,
116 USE_ITEM, 116 USE_ITEM,
117 STATIC_ITEM, 117 STATIC_ITEM,
118 CONST_ITEM, 118 CONST_ITEM,
119 TRAIT_ITEM, 119 TRAIT,
120 IMPL_ITEM, 120 IMPL_ITEM,
121 TYPE_ITEM, 121 TYPE_ITEM,
122 MACRO_CALL, 122 MACRO_CALL,
@@ -347,11 +347,11 @@ impl SyntaxKind {
347 ENUM => &SyntaxInfo { name: "ENUM" }, 347 ENUM => &SyntaxInfo { name: "ENUM" },
348 FUNCTION => &SyntaxInfo { name: "FUNCTION" }, 348 FUNCTION => &SyntaxInfo { name: "FUNCTION" },
349 EXTERN_CRATE_ITEM => &SyntaxInfo { name: "EXTERN_CRATE_ITEM" }, 349 EXTERN_CRATE_ITEM => &SyntaxInfo { name: "EXTERN_CRATE_ITEM" },
350 MOD_ITEM => &SyntaxInfo { name: "MOD_ITEM" }, 350 MODULE => &SyntaxInfo { name: "MODULE" },
351 USE_ITEM => &SyntaxInfo { name: "USE_ITEM" }, 351 USE_ITEM => &SyntaxInfo { name: "USE_ITEM" },
352 STATIC_ITEM => &SyntaxInfo { name: "STATIC_ITEM" }, 352 STATIC_ITEM => &SyntaxInfo { name: "STATIC_ITEM" },
353 CONST_ITEM => &SyntaxInfo { name: "CONST_ITEM" }, 353 CONST_ITEM => &SyntaxInfo { name: "CONST_ITEM" },
354 TRAIT_ITEM => &SyntaxInfo { name: "TRAIT_ITEM" }, 354 TRAIT => &SyntaxInfo { name: "TRAIT" },
355 IMPL_ITEM => &SyntaxInfo { name: "IMPL_ITEM" }, 355 IMPL_ITEM => &SyntaxInfo { name: "IMPL_ITEM" },
356 TYPE_ITEM => &SyntaxInfo { name: "TYPE_ITEM" }, 356 TYPE_ITEM => &SyntaxInfo { name: "TYPE_ITEM" },
357 MACRO_CALL => &SyntaxInfo { name: "MACRO_CALL" }, 357 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 @@
1FILE@[0; 18) 1FILE@[0; 18)
2 TRAIT_ITEM@[0; 17) 2 TRAIT@[0; 17)
3 UNSAFE_KW@[0; 6) 3 UNSAFE_KW@[0; 6)
4 WHITESPACE@[6; 7) 4 WHITESPACE@[6; 7)
5 TRAIT_KW@[7; 12) 5 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 @@
1FILE@[0; 23) 1FILE@[0; 23)
2 TRAIT_ITEM@[0; 22) 2 TRAIT@[0; 22)
3 UNSAFE_KW@[0; 6) 3 UNSAFE_KW@[0; 6)
4 WHITESPACE@[6; 7) 4 WHITESPACE@[6; 7)
5 AUTO_KW@[7; 11) 5 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 @@
1FILE@[0; 42) 1FILE@[0; 42)
2 TRAIT_ITEM@[0; 41) 2 TRAIT@[0; 41)
3 TRAIT_KW@[0; 5) 3 TRAIT_KW@[0; 5)
4 WHITESPACE@[5; 6) 4 WHITESPACE@[5; 6)
5 NAME@[6; 7) 5 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 @@
1FILE@[0; 16) 1FILE@[0; 16)
2 TRAIT_ITEM@[0; 15) 2 TRAIT@[0; 15)
3 AUTO_KW@[0; 4) 3 AUTO_KW@[0; 4)
4 WHITESPACE@[4; 5) 4 WHITESPACE@[4; 5)
5 TRAIT_KW@[5; 10) 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 @@
1FILE@[0; 22) 1FILE@[0; 22)
2 TRAIT_ITEM@[0; 21) 2 TRAIT@[0; 21)
3 TRAIT_KW@[0; 5) 3 TRAIT_KW@[0; 5)
4 WHITESPACE@[5; 6) 4 WHITESPACE@[5; 6)
5 NAME@[6; 7) 5 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 @@
1FILE@[0; 118) 1FILE@[0; 118)
2 MOD_ITEM@[0; 6) 2 MODULE@[0; 6)
3 MOD_KW@[0; 3) 3 MOD_KW@[0; 3)
4 WHITESPACE@[3; 4) 4 WHITESPACE@[3; 4)
5 NAME@[4; 5) 5 NAME@[4; 5)
6 IDENT@[4; 5) "a" 6 IDENT@[4; 5) "a"
7 SEMI@[5; 6) 7 SEMI@[5; 6)
8 WHITESPACE@[6; 8) 8 WHITESPACE@[6; 8)
9 MOD_ITEM@[8; 17) 9 MODULE@[8; 17)
10 MOD_KW@[8; 11) 10 MOD_KW@[8; 11)
11 WHITESPACE@[11; 12) 11 WHITESPACE@[11; 12)
12 NAME@[12; 13) 12 NAME@[12; 13)
@@ -16,7 +16,7 @@ FILE@[0; 118)
16 WHITESPACE@[15; 16) 16 WHITESPACE@[15; 16)
17 R_CURLY@[16; 17) 17 R_CURLY@[16; 17)
18 WHITESPACE@[17; 19) 18 WHITESPACE@[17; 19)
19 MOD_ITEM@[19; 65) 19 MODULE@[19; 65)
20 MOD_KW@[19; 22) 20 MOD_KW@[19; 22)
21 WHITESPACE@[22; 23) 21 WHITESPACE@[22; 23)
22 NAME@[23; 24) 22 NAME@[23; 24)
@@ -49,7 +49,7 @@ FILE@[0; 118)
49 WHITESPACE@[63; 64) 49 WHITESPACE@[63; 64)
50 R_CURLY@[64; 65) 50 R_CURLY@[64; 65)
51 WHITESPACE@[65; 67) 51 WHITESPACE@[65; 67)
52 MOD_ITEM@[67; 118) 52 MODULE@[67; 118)
53 MOD_KW@[67; 70) 53 MOD_KW@[67; 70)
54 WHITESPACE@[70; 71) 54 WHITESPACE@[70; 71)
55 NAME@[71; 72) 55 NAME@[71; 72)
@@ -65,14 +65,14 @@ FILE@[0; 118)
65 IDENT@[82; 86) "attr" 65 IDENT@[82; 86) "attr"
66 R_BRACK@[86; 87) 66 R_BRACK@[86; 87)
67 WHITESPACE@[87; 92) 67 WHITESPACE@[87; 92)
68 MOD_ITEM@[92; 98) 68 MODULE@[92; 98)
69 MOD_KW@[92; 95) 69 MOD_KW@[92; 95)
70 WHITESPACE@[95; 96) 70 WHITESPACE@[95; 96)
71 NAME@[96; 97) 71 NAME@[96; 97)
72 IDENT@[96; 97) "e" 72 IDENT@[96; 97) "e"
73 SEMI@[97; 98) 73 SEMI@[97; 98)
74 WHITESPACE@[98; 103) 74 WHITESPACE@[98; 103)
75 MOD_ITEM@[103; 116) 75 MODULE@[103; 116)
76 MOD_KW@[103; 106) 76 MOD_KW@[103; 106)
77 WHITESPACE@[106; 107) 77 WHITESPACE@[106; 107)
78 NAME@[107; 108) 78 NAME@[107; 108)