aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_syntax/src/ast/generated/nodes.rs169
-rw-r--r--xtask/src/codegen/rust.ungram36
2 files changed, 103 insertions, 102 deletions
diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs
index 9064398a9..286be1032 100644
--- a/crates/ra_syntax/src/ast/generated/nodes.rs
+++ b/crates/ra_syntax/src/ast/generated/nodes.rs
@@ -473,6 +473,7 @@ pub struct LifetimeParam {
473 pub(crate) syntax: SyntaxNode, 473 pub(crate) syntax: SyntaxNode,
474} 474}
475impl ast::AttrsOwner for LifetimeParam {} 475impl ast::AttrsOwner for LifetimeParam {}
476impl ast::TypeBoundsOwner for LifetimeParam {}
476impl LifetimeParam { 477impl LifetimeParam {
477 pub fn lifetime_token(&self) -> Option<SyntaxToken> { 478 pub fn lifetime_token(&self) -> Option<SyntaxToken> {
478 support::token(&self.syntax, T![lifetime]) 479 support::token(&self.syntax, T![lifetime])
@@ -503,6 +504,19 @@ impl ConstParam {
503 pub fn default_val(&self) -> Option<Expr> { support::child(&self.syntax) } 504 pub fn default_val(&self) -> Option<Expr> { support::child(&self.syntax) }
504} 505}
505#[derive(Debug, Clone, PartialEq, Eq, Hash)] 506#[derive(Debug, Clone, PartialEq, Eq, Hash)]
507pub struct WherePred {
508 pub(crate) syntax: SyntaxNode,
509}
510impl ast::TypeBoundsOwner for WherePred {}
511impl 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)]
506pub struct Literal { 520pub struct Literal {
507 pub(crate) syntax: SyntaxNode, 521 pub(crate) syntax: SyntaxNode,
508} 522}
@@ -520,6 +534,29 @@ impl TokenTree {
520 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } 534 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
521} 535}
522#[derive(Debug, Clone, PartialEq, Eq, Hash)] 536#[derive(Debug, Clone, PartialEq, Eq, Hash)]
537pub struct LetStmt {
538 pub(crate) syntax: SyntaxNode,
539}
540impl ast::AttrsOwner for LetStmt {}
541impl 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)]
551pub struct ExprStmt {
552 pub(crate) syntax: SyntaxNode,
553}
554impl ast::AttrsOwner for ExprStmt {}
555impl 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)]
523pub struct ParenType { 560pub struct ParenType {
524 pub(crate) syntax: SyntaxNode, 561 pub(crate) syntax: SyntaxNode,
525} 562}
@@ -1179,42 +1216,6 @@ impl MacroStmts {
1179 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 1216 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1180} 1217}
1181#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1218#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1182pub struct WherePred {
1183 pub(crate) syntax: SyntaxNode,
1184}
1185impl ast::TypeBoundsOwner for WherePred {}
1186impl 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)]
1195pub struct ExprStmt {
1196 pub(crate) syntax: SyntaxNode,
1197}
1198impl ast::AttrsOwner for ExprStmt {}
1199impl 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)]
1204pub struct LetStmt {
1205 pub(crate) syntax: SyntaxNode,
1206}
1207impl ast::AttrsOwner for LetStmt {}
1208impl 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)]
1218pub struct PathSegment { 1219pub struct PathSegment {
1219 pub(crate) syntax: SyntaxNode, 1220 pub(crate) syntax: SyntaxNode,
1220} 1221}
@@ -1880,6 +1881,17 @@ impl AstNode for ConstParam {
1880 } 1881 }
1881 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1882 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1882} 1883}
1884impl 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}
1883impl AstNode for Literal { 1895impl AstNode for Literal {
1884 fn can_cast(kind: SyntaxKind) -> bool { kind == LITERAL } 1896 fn can_cast(kind: SyntaxKind) -> bool { kind == LITERAL }
1885 fn cast(syntax: SyntaxNode) -> Option<Self> { 1897 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -1902,6 +1914,28 @@ impl AstNode for TokenTree {
1902 } 1914 }
1903 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1915 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1904} 1916}
1917impl 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}
1928impl 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}
1905impl AstNode for ParenType { 1939impl AstNode for ParenType {
1906 fn can_cast(kind: SyntaxKind) -> bool { kind == PAREN_TYPE } 1940 fn can_cast(kind: SyntaxKind) -> bool { kind == PAREN_TYPE }
1907 fn cast(syntax: SyntaxNode) -> Option<Self> { 1941 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -2672,39 +2706,6 @@ impl AstNode for MacroStmts {
2672 } 2706 }
2673 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2707 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2674} 2708}
2675impl 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}
2686impl 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}
2697impl 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}
2708impl AstNode for PathSegment { 2709impl AstNode for PathSegment {
2709 fn can_cast(kind: SyntaxKind) -> bool { kind == PATH_SEGMENT } 2710 fn can_cast(kind: SyntaxKind) -> bool { kind == PATH_SEGMENT }
2710 fn cast(syntax: SyntaxNode) -> Option<Self> { 2711 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -3671,6 +3672,11 @@ impl std::fmt::Display for ConstParam {
3671 std::fmt::Display::fmt(self.syntax(), f) 3672 std::fmt::Display::fmt(self.syntax(), f)
3672 } 3673 }
3673} 3674}
3675impl 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}
3674impl std::fmt::Display for Literal { 3680impl std::fmt::Display for Literal {
3675 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3681 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3676 std::fmt::Display::fmt(self.syntax(), f) 3682 std::fmt::Display::fmt(self.syntax(), f)
@@ -3681,6 +3687,16 @@ impl std::fmt::Display for TokenTree {
3681 std::fmt::Display::fmt(self.syntax(), f) 3687 std::fmt::Display::fmt(self.syntax(), f)
3682 } 3688 }
3683} 3689}
3690impl 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}
3695impl 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}
3684impl std::fmt::Display for ParenType { 3700impl std::fmt::Display for ParenType {
3685 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3701 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3686 std::fmt::Display::fmt(self.syntax(), f) 3702 std::fmt::Display::fmt(self.syntax(), f)
@@ -4031,21 +4047,6 @@ impl std::fmt::Display for MacroStmts {
4031 std::fmt::Display::fmt(self.syntax(), f) 4047 std::fmt::Display::fmt(self.syntax(), f)
4032 } 4048 }
4033} 4049}
4034impl 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}
4039impl 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}
4044impl 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}
4049impl std::fmt::Display for PathSegment { 4050impl std::fmt::Display for PathSegment {
4050 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 4051 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4051 std::fmt::Display::fmt(self.syntax(), f) 4052 std::fmt::Display::fmt(self.syntax(), f)
diff --git a/xtask/src/codegen/rust.ungram b/xtask/src/codegen/rust.ungram
index 32f2808ea..8271509cf 100644
--- a/xtask/src/codegen/rust.ungram
+++ b/xtask/src/codegen/rust.ungram
@@ -175,7 +175,13 @@ ConstParam =
175 ('=' default_val:Expr)? 175 ('=' default_val:Expr)?
176 176
177LifetimeParam = 177LifetimeParam =
178 Attr* 'lifetime' 178 Attr* 'lifetime' (':' TypeBoundList?)?
179
180WhereClause =
181 'where' predicates:(WherePred (',' WherePred)* ','?)
182
183WherePred =
184 ('for' GenericParamList)? ('lifetime' | Type) ':' TypeBoundList
179 185
180Visibility = 186Visibility =
181 'pub' ('(' 187 'pub' ('('
@@ -188,6 +194,17 @@ Visibility =
188Attr = 194Attr =
189 '#' '!'? '[' Path ('=' Literal | TokenTree)? ']' 195 '#' '!'? '[' Path ('=' Literal | TokenTree)? ']'
190 196
197Stmt =
198 LetStmt
199| ExprStmt
200
201LetStmt =
202 Attr* 'let' Pat (':' Type)?
203 '=' initializer:Expr ';'
204
205ExprStmt =
206 Attr* Expr ';'?
207
191Type = 208Type =
192 ParenType 209 ParenType
193| TupleType 210| TupleType
@@ -450,19 +467,6 @@ MacroStmts =
450 statements:Stmt* 467 statements:Stmt*
451 Expr? 468 Expr?
452 469
453WherePred =
454 ('for' GenericParamList)? ('lifetime' | Type) ':' TypeBoundList
455
456WhereClause =
457 'where' predicates:WherePred*
458
459ExprStmt =
460 Attr* Expr ';'
461
462LetStmt =
463 Attr* 'let' Pat (':' Type)
464 '=' initializer:Expr ';'
465
466Path = 470Path =
467 (qualifier:Path '::')? segment:PathSegment 471 (qualifier:Path '::')? segment:PathSegment
468 472
@@ -490,10 +494,6 @@ LifetimeArg =
490ConstArg = 494ConstArg =
491 Literal | BlockExpr BlockExpr 495 Literal | BlockExpr BlockExpr
492 496
493Stmt =
494 LetStmt
495| ExprStmt
496
497Pat = 497Pat =
498 OrPat 498 OrPat
499| ParenPat 499| ParenPat