aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/libsyntax2/src')
-rw-r--r--crates/libsyntax2/src/ast/generated.rs35
-rw-r--r--crates/libsyntax2/src/ast/mod.rs16
-rw-r--r--crates/libsyntax2/src/grammar.ron50
3 files changed, 84 insertions, 17 deletions
diff --git a/crates/libsyntax2/src/ast/generated.rs b/crates/libsyntax2/src/ast/generated.rs
index 0651da26d..d0e07fddc 100644
--- a/crates/libsyntax2/src/ast/generated.rs
+++ b/crates/libsyntax2/src/ast/generated.rs
@@ -64,6 +64,7 @@ impl<'a> AstNode<'a> for ConstDef<'a> {
64} 64}
65 65
66impl<'a> ast::NameOwner<'a> for ConstDef<'a> {} 66impl<'a> ast::NameOwner<'a> for ConstDef<'a> {}
67impl<'a> ast::TypeParamsOwner<'a> for ConstDef<'a> {}
67impl<'a> ast::AttrsOwner<'a> for ConstDef<'a> {} 68impl<'a> ast::AttrsOwner<'a> for ConstDef<'a> {}
68impl<'a> ConstDef<'a> {} 69impl<'a> ConstDef<'a> {}
69 70
@@ -102,6 +103,7 @@ impl<'a> AstNode<'a> for EnumDef<'a> {
102} 103}
103 104
104impl<'a> ast::NameOwner<'a> for EnumDef<'a> {} 105impl<'a> ast::NameOwner<'a> for EnumDef<'a> {}
106impl<'a> ast::TypeParamsOwner<'a> for EnumDef<'a> {}
105impl<'a> ast::AttrsOwner<'a> for EnumDef<'a> {} 107impl<'a> ast::AttrsOwner<'a> for EnumDef<'a> {}
106impl<'a> EnumDef<'a> {} 108impl<'a> EnumDef<'a> {}
107 109
@@ -152,6 +154,7 @@ impl<'a> AstNode<'a> for FnDef<'a> {
152} 154}
153 155
154impl<'a> ast::NameOwner<'a> for FnDef<'a> {} 156impl<'a> ast::NameOwner<'a> for FnDef<'a> {}
157impl<'a> ast::TypeParamsOwner<'a> for FnDef<'a> {}
155impl<'a> ast::AttrsOwner<'a> for FnDef<'a> {} 158impl<'a> ast::AttrsOwner<'a> for FnDef<'a> {}
156impl<'a> FnDef<'a> {} 159impl<'a> FnDef<'a> {}
157 160
@@ -351,6 +354,7 @@ impl<'a> AstNode<'a> for NominalDef<'a> {
351} 354}
352 355
353impl<'a> ast::AttrsOwner<'a> for NominalDef<'a> {} 356impl<'a> ast::AttrsOwner<'a> for NominalDef<'a> {}
357impl<'a> ast::TypeParamsOwner<'a> for NominalDef<'a> {}
354impl<'a> NominalDef<'a> {} 358impl<'a> NominalDef<'a> {}
355 359
356// ParenType 360// ParenType
@@ -478,6 +482,7 @@ impl<'a> AstNode<'a> for StaticDef<'a> {
478} 482}
479 483
480impl<'a> ast::NameOwner<'a> for StaticDef<'a> {} 484impl<'a> ast::NameOwner<'a> for StaticDef<'a> {}
485impl<'a> ast::TypeParamsOwner<'a> for StaticDef<'a> {}
481impl<'a> ast::AttrsOwner<'a> for StaticDef<'a> {} 486impl<'a> ast::AttrsOwner<'a> for StaticDef<'a> {}
482impl<'a> StaticDef<'a> {} 487impl<'a> StaticDef<'a> {}
483 488
@@ -498,6 +503,7 @@ impl<'a> AstNode<'a> for StructDef<'a> {
498} 503}
499 504
500impl<'a> ast::NameOwner<'a> for StructDef<'a> {} 505impl<'a> ast::NameOwner<'a> for StructDef<'a> {}
506impl<'a> ast::TypeParamsOwner<'a> for StructDef<'a> {}
501impl<'a> ast::AttrsOwner<'a> for StructDef<'a> {} 507impl<'a> ast::AttrsOwner<'a> for StructDef<'a> {}
502impl<'a> StructDef<'a> { 508impl<'a> StructDef<'a> {
503 pub fn fields(self) -> impl Iterator<Item = NamedField<'a>> + 'a { 509 pub fn fields(self) -> impl Iterator<Item = NamedField<'a>> + 'a {
@@ -580,9 +586,28 @@ impl<'a> AstNode<'a> for TypeDef<'a> {
580} 586}
581 587
582impl<'a> ast::NameOwner<'a> for TypeDef<'a> {} 588impl<'a> ast::NameOwner<'a> for TypeDef<'a> {}
589impl<'a> ast::TypeParamsOwner<'a> for TypeDef<'a> {}
583impl<'a> ast::AttrsOwner<'a> for TypeDef<'a> {} 590impl<'a> ast::AttrsOwner<'a> for TypeDef<'a> {}
584impl<'a> TypeDef<'a> {} 591impl<'a> TypeDef<'a> {}
585 592
593// TypeParamList
594#[derive(Debug, Clone, Copy)]
595pub struct TypeParamList<'a> {
596 syntax: SyntaxNodeRef<'a>,
597}
598
599impl<'a> AstNode<'a> for TypeParamList<'a> {
600 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
601 match syntax.kind() {
602 TYPE_PARAM_LIST => Some(TypeParamList { syntax }),
603 _ => None,
604 }
605 }
606 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
607}
608
609impl<'a> TypeParamList<'a> {}
610
586// TypeRef 611// TypeRef
587#[derive(Debug, Clone, Copy)] 612#[derive(Debug, Clone, Copy)]
588pub enum TypeRef<'a> { 613pub enum TypeRef<'a> {
@@ -641,21 +666,21 @@ impl<'a> AstNode<'a> for TypeRef<'a> {
641 666
642impl<'a> TypeRef<'a> {} 667impl<'a> TypeRef<'a> {}
643 668
644// Whitespace 669// WhereClause
645#[derive(Debug, Clone, Copy)] 670#[derive(Debug, Clone, Copy)]
646pub struct Whitespace<'a> { 671pub struct WhereClause<'a> {
647 syntax: SyntaxNodeRef<'a>, 672 syntax: SyntaxNodeRef<'a>,
648} 673}
649 674
650impl<'a> AstNode<'a> for Whitespace<'a> { 675impl<'a> AstNode<'a> for WhereClause<'a> {
651 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 676 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
652 match syntax.kind() { 677 match syntax.kind() {
653 WHITESPACE => Some(Whitespace { syntax }), 678 WHERE_CLAUSE => Some(WhereClause { syntax }),
654 _ => None, 679 _ => None,
655 } 680 }
656 } 681 }
657 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 682 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
658} 683}
659 684
660impl<'a> Whitespace<'a> {} 685impl<'a> WhereClause<'a> {}
661 686
diff --git a/crates/libsyntax2/src/ast/mod.rs b/crates/libsyntax2/src/ast/mod.rs
index 5b9a07db4..1784b871e 100644
--- a/crates/libsyntax2/src/ast/mod.rs
+++ b/crates/libsyntax2/src/ast/mod.rs
@@ -24,6 +24,22 @@ pub trait NameOwner<'a>: AstNode<'a> {
24 } 24 }
25} 25}
26 26
27pub trait TypeParamsOwner<'a>: AstNode<'a> {
28 fn type_param_list(self) -> Option<TypeParamList<'a>> {
29 self.syntax()
30 .children()
31 .filter_map(TypeParamList::cast)
32 .next()
33 }
34
35 fn where_clause(self) -> Option<WhereClause<'a>> {
36 self.syntax()
37 .children()
38 .filter_map(WhereClause::cast)
39 .next()
40 }
41}
42
27pub trait AttrsOwner<'a>: AstNode<'a> { 43pub trait AttrsOwner<'a>: AstNode<'a> {
28 fn attrs(&self) -> Box<Iterator<Item=Attr<'a>> + 'a> { 44 fn attrs(&self) -> Box<Iterator<Item=Attr<'a>> + 'a> {
29 let it = self.syntax().children() 45 let it = self.syntax().children()
diff --git a/crates/libsyntax2/src/grammar.ron b/crates/libsyntax2/src/grammar.ron
index 8e644d3c4..83b56c349 100644
--- a/crates/libsyntax2/src/grammar.ron
+++ b/crates/libsyntax2/src/grammar.ron
@@ -222,15 +222,27 @@ Grammar(
222 ["modules", "Module"], 222 ["modules", "Module"],
223 ] 223 ]
224 ), 224 ),
225 "FnDef": ( traits: ["NameOwner", "AttrsOwner"] ), 225 "FnDef": ( traits: [
226 "NameOwner",
227 "TypeParamsOwner",
228 "AttrsOwner",
229 ] ),
226 "StructDef": ( 230 "StructDef": (
227 traits: ["NameOwner", "AttrsOwner"], 231 traits: [
232 "NameOwner",
233 "TypeParamsOwner",
234 "AttrsOwner",
235 ],
228 collections: [ 236 collections: [
229 ["fields", "NamedField"] 237 ["fields", "NamedField"]
230 ] 238 ]
231 ), 239 ),
232 "NamedField": ( traits: ["NameOwner", "AttrsOwner"] ), 240 "NamedField": ( traits: ["NameOwner", "AttrsOwner"] ),
233 "EnumDef": ( traits: ["NameOwner", "AttrsOwner"] ), 241 "EnumDef": ( traits: [
242 "NameOwner",
243 "TypeParamsOwner",
244 "AttrsOwner",
245 ] ),
234 "TraitDef": ( traits: ["NameOwner", "AttrsOwner"] ), 246 "TraitDef": ( traits: ["NameOwner", "AttrsOwner"] ),
235 "Module": ( 247 "Module": (
236 traits: ["NameOwner", "AttrsOwner"], 248 traits: ["NameOwner", "AttrsOwner"],
@@ -238,16 +250,23 @@ Grammar(
238 ["modules", "Module"] 250 ["modules", "Module"]
239 ] 251 ]
240 ), 252 ),
241 "ConstDef": ( traits: ["NameOwner", "AttrsOwner"] ), 253 "ConstDef": ( traits: [
242 "StaticDef": ( traits: ["NameOwner", "AttrsOwner"] ), 254 "NameOwner",
243 "TypeDef": ( traits: ["NameOwner", "AttrsOwner"] ), 255 "TypeParamsOwner",
256 "AttrsOwner",
257 ] ),
258 "StaticDef": ( traits: [
259 "NameOwner",
260 "TypeParamsOwner",
261 "AttrsOwner",
262 ] ),
263 "TypeDef": ( traits: [
264 "NameOwner",
265 "TypeParamsOwner",
266 "AttrsOwner",
267 ] ),
244 "ImplItem": (), 268 "ImplItem": (),
245 269
246 "Name": (),
247 "NameRef": (),
248 "Attr": ( options: [ ["value", "TokenTree"] ] ),
249 "TokenTree": (),
250
251 "ParenType": (), 270 "ParenType": (),
252 "TupleType": (), 271 "TupleType": (),
253 "NeverType": (), 272 "NeverType": (),
@@ -280,7 +299,14 @@ Grammar(
280 299
281 "NominalDef": ( 300 "NominalDef": (
282 enum: ["StructDef", "EnumDef"], 301 enum: ["StructDef", "EnumDef"],
283 traits: [ "AttrsOwner" ], 302 traits: [ "AttrsOwner", "TypeParamsOwner" ],
284 ), 303 ),
304
305 "Name": (),
306 "NameRef": (),
307 "Attr": ( options: [ ["value", "TokenTree"] ] ),
308 "TokenTree": (),
309 "TypeParamList": (),
310 "WhereClause": (),
285 }, 311 },
286) 312)