Skip to content

Commit 3407d6f

Browse files
bors[bot]matklad
andauthored
Merge #5622
5622: Finalize WhereClause gramamr r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2 parents 84bf024 + 4d38b0d commit 3407d6f

File tree

2 files changed

+103
-102
lines changed

2 files changed

+103
-102
lines changed

crates/ra_syntax/src/ast/generated/nodes.rs

Lines changed: 85 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ pub struct LifetimeParam {
473473
pub(crate) syntax: SyntaxNode,
474474
}
475475
impl ast::AttrsOwner for LifetimeParam {}
476+
impl ast::TypeBoundsOwner for LifetimeParam {}
476477
impl LifetimeParam {
477478
pub fn lifetime_token(&self) -> Option<SyntaxToken> {
478479
support::token(&self.syntax, T![lifetime])
@@ -503,6 +504,19 @@ impl ConstParam {
503504
pub fn default_val(&self) -> Option<Expr> { support::child(&self.syntax) }
504505
}
505506
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
507+
pub struct WherePred {
508+
pub(crate) syntax: SyntaxNode,
509+
}
510+
impl ast::TypeBoundsOwner for WherePred {}
511+
impl WherePred {
512+
pub fn for_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![for]) }
513+
pub fn generic_param_list(&self) -> Option<GenericParamList> { support::child(&self.syntax) }
514+
pub fn lifetime_token(&self) -> Option<SyntaxToken> {
515+
support::token(&self.syntax, T![lifetime])
516+
}
517+
pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
518+
}
519+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
506520
pub struct Literal {
507521
pub(crate) syntax: SyntaxNode,
508522
}
@@ -520,6 +534,29 @@ impl TokenTree {
520534
pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
521535
}
522536
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
537+
pub struct LetStmt {
538+
pub(crate) syntax: SyntaxNode,
539+
}
540+
impl ast::AttrsOwner for LetStmt {}
541+
impl LetStmt {
542+
pub fn let_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![let]) }
543+
pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
544+
pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
545+
pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
546+
pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
547+
pub fn initializer(&self) -> Option<Expr> { support::child(&self.syntax) }
548+
pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
549+
}
550+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
551+
pub struct ExprStmt {
552+
pub(crate) syntax: SyntaxNode,
553+
}
554+
impl ast::AttrsOwner for ExprStmt {}
555+
impl ExprStmt {
556+
pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
557+
pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
558+
}
559+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
523560
pub struct ParenType {
524561
pub(crate) syntax: SyntaxNode,
525562
}
@@ -1179,42 +1216,6 @@ impl MacroStmts {
11791216
pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
11801217
}
11811218
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1182-
pub struct WherePred {
1183-
pub(crate) syntax: SyntaxNode,
1184-
}
1185-
impl ast::TypeBoundsOwner for WherePred {}
1186-
impl WherePred {
1187-
pub fn for_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![for]) }
1188-
pub fn generic_param_list(&self) -> Option<GenericParamList> { support::child(&self.syntax) }
1189-
pub fn lifetime_token(&self) -> Option<SyntaxToken> {
1190-
support::token(&self.syntax, T![lifetime])
1191-
}
1192-
pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
1193-
}
1194-
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1195-
pub struct ExprStmt {
1196-
pub(crate) syntax: SyntaxNode,
1197-
}
1198-
impl ast::AttrsOwner for ExprStmt {}
1199-
impl ExprStmt {
1200-
pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1201-
pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
1202-
}
1203-
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1204-
pub struct LetStmt {
1205-
pub(crate) syntax: SyntaxNode,
1206-
}
1207-
impl ast::AttrsOwner for LetStmt {}
1208-
impl LetStmt {
1209-
pub fn let_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![let]) }
1210-
pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
1211-
pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
1212-
pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
1213-
pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
1214-
pub fn initializer(&self) -> Option<Expr> { support::child(&self.syntax) }
1215-
pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
1216-
}
1217-
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
12181219
pub struct PathSegment {
12191220
pub(crate) syntax: SyntaxNode,
12201221
}
@@ -1880,6 +1881,17 @@ impl AstNode for ConstParam {
18801881
}
18811882
fn syntax(&self) -> &SyntaxNode { &self.syntax }
18821883
}
1884+
impl AstNode for WherePred {
1885+
fn can_cast(kind: SyntaxKind) -> bool { kind == WHERE_PRED }
1886+
fn cast(syntax: SyntaxNode) -> Option<Self> {
1887+
if Self::can_cast(syntax.kind()) {
1888+
Some(Self { syntax })
1889+
} else {
1890+
None
1891+
}
1892+
}
1893+
fn syntax(&self) -> &SyntaxNode { &self.syntax }
1894+
}
18831895
impl AstNode for Literal {
18841896
fn can_cast(kind: SyntaxKind) -> bool { kind == LITERAL }
18851897
fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -1902,6 +1914,28 @@ impl AstNode for TokenTree {
19021914
}
19031915
fn syntax(&self) -> &SyntaxNode { &self.syntax }
19041916
}
1917+
impl AstNode for LetStmt {
1918+
fn can_cast(kind: SyntaxKind) -> bool { kind == LET_STMT }
1919+
fn cast(syntax: SyntaxNode) -> Option<Self> {
1920+
if Self::can_cast(syntax.kind()) {
1921+
Some(Self { syntax })
1922+
} else {
1923+
None
1924+
}
1925+
}
1926+
fn syntax(&self) -> &SyntaxNode { &self.syntax }
1927+
}
1928+
impl AstNode for ExprStmt {
1929+
fn can_cast(kind: SyntaxKind) -> bool { kind == EXPR_STMT }
1930+
fn cast(syntax: SyntaxNode) -> Option<Self> {
1931+
if Self::can_cast(syntax.kind()) {
1932+
Some(Self { syntax })
1933+
} else {
1934+
None
1935+
}
1936+
}
1937+
fn syntax(&self) -> &SyntaxNode { &self.syntax }
1938+
}
19051939
impl AstNode for ParenType {
19061940
fn can_cast(kind: SyntaxKind) -> bool { kind == PAREN_TYPE }
19071941
fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -2672,39 +2706,6 @@ impl AstNode for MacroStmts {
26722706
}
26732707
fn syntax(&self) -> &SyntaxNode { &self.syntax }
26742708
}
2675-
impl AstNode for WherePred {
2676-
fn can_cast(kind: SyntaxKind) -> bool { kind == WHERE_PRED }
2677-
fn cast(syntax: SyntaxNode) -> Option<Self> {
2678-
if Self::can_cast(syntax.kind()) {
2679-
Some(Self { syntax })
2680-
} else {
2681-
None
2682-
}
2683-
}
2684-
fn syntax(&self) -> &SyntaxNode { &self.syntax }
2685-
}
2686-
impl AstNode for ExprStmt {
2687-
fn can_cast(kind: SyntaxKind) -> bool { kind == EXPR_STMT }
2688-
fn cast(syntax: SyntaxNode) -> Option<Self> {
2689-
if Self::can_cast(syntax.kind()) {
2690-
Some(Self { syntax })
2691-
} else {
2692-
None
2693-
}
2694-
}
2695-
fn syntax(&self) -> &SyntaxNode { &self.syntax }
2696-
}
2697-
impl AstNode for LetStmt {
2698-
fn can_cast(kind: SyntaxKind) -> bool { kind == LET_STMT }
2699-
fn cast(syntax: SyntaxNode) -> Option<Self> {
2700-
if Self::can_cast(syntax.kind()) {
2701-
Some(Self { syntax })
2702-
} else {
2703-
None
2704-
}
2705-
}
2706-
fn syntax(&self) -> &SyntaxNode { &self.syntax }
2707-
}
27082709
impl AstNode for PathSegment {
27092710
fn can_cast(kind: SyntaxKind) -> bool { kind == PATH_SEGMENT }
27102711
fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -3671,6 +3672,11 @@ impl std::fmt::Display for ConstParam {
36713672
std::fmt::Display::fmt(self.syntax(), f)
36723673
}
36733674
}
3675+
impl std::fmt::Display for WherePred {
3676+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3677+
std::fmt::Display::fmt(self.syntax(), f)
3678+
}
3679+
}
36743680
impl std::fmt::Display for Literal {
36753681
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
36763682
std::fmt::Display::fmt(self.syntax(), f)
@@ -3681,6 +3687,16 @@ impl std::fmt::Display for TokenTree {
36813687
std::fmt::Display::fmt(self.syntax(), f)
36823688
}
36833689
}
3690+
impl std::fmt::Display for LetStmt {
3691+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3692+
std::fmt::Display::fmt(self.syntax(), f)
3693+
}
3694+
}
3695+
impl std::fmt::Display for ExprStmt {
3696+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3697+
std::fmt::Display::fmt(self.syntax(), f)
3698+
}
3699+
}
36843700
impl std::fmt::Display for ParenType {
36853701
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
36863702
std::fmt::Display::fmt(self.syntax(), f)
@@ -4031,21 +4047,6 @@ impl std::fmt::Display for MacroStmts {
40314047
std::fmt::Display::fmt(self.syntax(), f)
40324048
}
40334049
}
4034-
impl std::fmt::Display for WherePred {
4035-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4036-
std::fmt::Display::fmt(self.syntax(), f)
4037-
}
4038-
}
4039-
impl std::fmt::Display for ExprStmt {
4040-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4041-
std::fmt::Display::fmt(self.syntax(), f)
4042-
}
4043-
}
4044-
impl std::fmt::Display for LetStmt {
4045-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4046-
std::fmt::Display::fmt(self.syntax(), f)
4047-
}
4048-
}
40494050
impl std::fmt::Display for PathSegment {
40504051
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
40514052
std::fmt::Display::fmt(self.syntax(), f)

xtask/src/codegen/rust.ungram

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,13 @@ ConstParam =
175175
('=' default_val:Expr)?
176176

177177
LifetimeParam =
178-
Attr* 'lifetime'
178+
Attr* 'lifetime' (':' TypeBoundList?)?
179+
180+
WhereClause =
181+
'where' predicates:(WherePred (',' WherePred)* ','?)
182+
183+
WherePred =
184+
('for' GenericParamList)? ('lifetime' | Type) ':' TypeBoundList
179185

180186
Visibility =
181187
'pub' ('('
@@ -188,6 +194,17 @@ Visibility =
188194
Attr =
189195
'#' '!'? '[' Path ('=' Literal | TokenTree)? ']'
190196

197+
Stmt =
198+
LetStmt
199+
| ExprStmt
200+
201+
LetStmt =
202+
Attr* 'let' Pat (':' Type)?
203+
'=' initializer:Expr ';'
204+
205+
ExprStmt =
206+
Attr* Expr ';'?
207+
191208
Type =
192209
ParenType
193210
| TupleType
@@ -450,19 +467,6 @@ MacroStmts =
450467
statements:Stmt*
451468
Expr?
452469

453-
WherePred =
454-
('for' GenericParamList)? ('lifetime' | Type) ':' TypeBoundList
455-
456-
WhereClause =
457-
'where' predicates:WherePred*
458-
459-
ExprStmt =
460-
Attr* Expr ';'
461-
462-
LetStmt =
463-
Attr* 'let' Pat (':' Type)
464-
'=' initializer:Expr ';'
465-
466470
Path =
467471
(qualifier:Path '::')? segment:PathSegment
468472

@@ -490,10 +494,6 @@ LifetimeArg =
490494
ConstArg =
491495
Literal | BlockExpr BlockExpr
492496

493-
Stmt =
494-
LetStmt
495-
| ExprStmt
496-
497497
Pat =
498498
OrPat
499499
| ParenPat

0 commit comments

Comments
 (0)