diff options
author | Ville Penttinen <[email protected]> | 2019-03-30 15:11:21 +0000 |
---|---|---|
committer | Ville Penttinen <[email protected]> | 2019-03-30 15:11:21 +0000 |
commit | 23fdc562bf06bd001ec728d63a8f5b945bd96700 (patch) | |
tree | ace25468b177e1fa5899ca18daee48cc420372ed /crates/ra_syntax/src | |
parent | 9ebd14a14e20aebc8e176a8dcb22376eb3a4d73e (diff) |
Add new TYPE_BOUND_LIST and TYPE_BOUND syntax kinds
These are now used when parsing type bounds. In addition parsing paths inside a
bound now does not recursively parse paths, rather they are treated as separate
bounds, separated by +.
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r-- | crates/ra_syntax/src/ast/generated.rs | 68 | ||||
-rw-r--r-- | crates/ra_syntax/src/grammar.ron | 13 |
2 files changed, 81 insertions, 0 deletions
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index 47a37e4d1..faf80bc32 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs | |||
@@ -4369,6 +4369,74 @@ impl TypeArgList { | |||
4369 | } | 4369 | } |
4370 | } | 4370 | } |
4371 | 4371 | ||
4372 | // TypeBound | ||
4373 | #[derive(Debug, PartialEq, Eq, Hash)] | ||
4374 | #[repr(transparent)] | ||
4375 | pub struct TypeBound { | ||
4376 | pub(crate) syntax: SyntaxNode, | ||
4377 | } | ||
4378 | unsafe impl TransparentNewType for TypeBound { | ||
4379 | type Repr = rowan::SyntaxNode<RaTypes>; | ||
4380 | } | ||
4381 | |||
4382 | impl AstNode for TypeBound { | ||
4383 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { | ||
4384 | match syntax.kind() { | ||
4385 | TYPE_BOUND => Some(TypeBound::from_repr(syntax.into_repr())), | ||
4386 | _ => None, | ||
4387 | } | ||
4388 | } | ||
4389 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
4390 | } | ||
4391 | |||
4392 | impl ToOwned for TypeBound { | ||
4393 | type Owned = TreeArc<TypeBound>; | ||
4394 | fn to_owned(&self) -> TreeArc<TypeBound> { TreeArc::cast(self.syntax.to_owned()) } | ||
4395 | } | ||
4396 | |||
4397 | |||
4398 | impl TypeBound { | ||
4399 | pub fn type_ref(&self) -> Option<&TypeRef> { | ||
4400 | super::child_opt(self) | ||
4401 | } | ||
4402 | |||
4403 | pub fn lifetime(&self) -> Option<&Lifetime> { | ||
4404 | super::child_opt(self) | ||
4405 | } | ||
4406 | } | ||
4407 | |||
4408 | // TypeBoundList | ||
4409 | #[derive(Debug, PartialEq, Eq, Hash)] | ||
4410 | #[repr(transparent)] | ||
4411 | pub struct TypeBoundList { | ||
4412 | pub(crate) syntax: SyntaxNode, | ||
4413 | } | ||
4414 | unsafe impl TransparentNewType for TypeBoundList { | ||
4415 | type Repr = rowan::SyntaxNode<RaTypes>; | ||
4416 | } | ||
4417 | |||
4418 | impl AstNode for TypeBoundList { | ||
4419 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { | ||
4420 | match syntax.kind() { | ||
4421 | TYPE_BOUND_LIST => Some(TypeBoundList::from_repr(syntax.into_repr())), | ||
4422 | _ => None, | ||
4423 | } | ||
4424 | } | ||
4425 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
4426 | } | ||
4427 | |||
4428 | impl ToOwned for TypeBoundList { | ||
4429 | type Owned = TreeArc<TypeBoundList>; | ||
4430 | fn to_owned(&self) -> TreeArc<TypeBoundList> { TreeArc::cast(self.syntax.to_owned()) } | ||
4431 | } | ||
4432 | |||
4433 | |||
4434 | impl TypeBoundList { | ||
4435 | pub fn bounds(&self) -> impl Iterator<Item = &TypeBound> { | ||
4436 | super::children(self) | ||
4437 | } | ||
4438 | } | ||
4439 | |||
4372 | // TypeParam | 4440 | // TypeParam |
4373 | #[derive(Debug, PartialEq, Eq, Hash)] | 4441 | #[derive(Debug, PartialEq, Eq, Hash)] |
4374 | #[repr(transparent)] | 4442 | #[repr(transparent)] |
diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron index ad6d74162..660a2b207 100644 --- a/crates/ra_syntax/src/grammar.ron +++ b/crates/ra_syntax/src/grammar.ron | |||
@@ -243,6 +243,8 @@ Grammar( | |||
243 | "PARAM", | 243 | "PARAM", |
244 | "SELF_PARAM", | 244 | "SELF_PARAM", |
245 | "ARG_LIST", | 245 | "ARG_LIST", |
246 | "TYPE_BOUND", | ||
247 | "TYPE_BOUND_LIST", | ||
246 | ], | 248 | ], |
247 | ast: { | 249 | ast: { |
248 | "SourceFile": ( | 250 | "SourceFile": ( |
@@ -577,6 +579,17 @@ Grammar( | |||
577 | traits: ["AttrsOwner"], | 579 | traits: ["AttrsOwner"], |
578 | ), | 580 | ), |
579 | "Lifetime": ( traits: ["AstToken"] ), | 581 | "Lifetime": ( traits: ["AstToken"] ), |
582 | "TypeBound": ( | ||
583 | options: [ | ||
584 | "TypeRef", | ||
585 | "Lifetime", | ||
586 | ] | ||
587 | ), | ||
588 | "TypeBoundList": ( | ||
589 | collections: [ | ||
590 | ["bounds", "TypeBound"], | ||
591 | ] | ||
592 | ), | ||
580 | "WhereClause": (), | 593 | "WhereClause": (), |
581 | "ExprStmt": ( | 594 | "ExprStmt": ( |
582 | options: [ ["expr", "Expr"] ] | 595 | options: [ ["expr", "Expr"] ] |