aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-31 13:10:37 +0100
committerAleksey Kladov <[email protected]>2018-08-31 13:10:37 +0100
commit78d60a549d0711ffea10e2898bff46ebc739f637 (patch)
tree6333fd564c04dab2b73f71761f1d26d040b5ed0e /crates/libsyntax2/src
parent05a9d42f542c8eb876d06791579d948b2f571e04 (diff)
default method name to type name
Diffstat (limited to 'crates/libsyntax2/src')
-rw-r--r--crates/libsyntax2/src/ast/generated.rs78
-rw-r--r--crates/libsyntax2/src/ast/generated.rs.tera7
-rw-r--r--crates/libsyntax2/src/grammar.ron45
3 files changed, 47 insertions, 83 deletions
diff --git a/crates/libsyntax2/src/ast/generated.rs b/crates/libsyntax2/src/ast/generated.rs
index 0668dbfa7..58dcf574e 100644
--- a/crates/libsyntax2/src/ast/generated.rs
+++ b/crates/libsyntax2/src/ast/generated.rs
@@ -78,8 +78,7 @@ impl<'a> AstNode<'a> for Attr<'a> {
78 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 78 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
79} 79}
80 80
81impl<'a> Attr<'a> { 81impl<'a> Attr<'a> {pub fn value(self) -> Option<TokenTree<'a>> {
82 pub fn value(self) -> Option<TokenTree<'a>> {
83 super::child_opt(self) 82 super::child_opt(self)
84 } 83 }
85} 84}
@@ -141,8 +140,7 @@ impl<'a> Block<'a> {
141 pub fn statements(self) -> impl Iterator<Item = Stmt<'a>> + 'a { 140 pub fn statements(self) -> impl Iterator<Item = Stmt<'a>> + 'a {
142 super::children(self) 141 super::children(self)
143 } 142 }
144 143pub fn expr(self) -> Option<Expr<'a>> {
145 pub fn expr(self) -> Option<Expr<'a>> {
146 super::child_opt(self) 144 super::child_opt(self)
147 } 145 }
148} 146}
@@ -163,8 +161,7 @@ impl<'a> AstNode<'a> for BlockExpr<'a> {
163 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 161 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
164} 162}
165 163
166impl<'a> BlockExpr<'a> { 164impl<'a> BlockExpr<'a> {pub fn block(self) -> Option<Block<'a>> {
167 pub fn block(self) -> Option<Block<'a>> {
168 super::child_opt(self) 165 super::child_opt(self)
169 } 166 }
170} 167}
@@ -203,12 +200,10 @@ impl<'a> AstNode<'a> for CallExpr<'a> {
203 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 200 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
204} 201}
205 202
206impl<'a> CallExpr<'a> { 203impl<'a> CallExpr<'a> {pub fn expr(self) -> Option<Expr<'a>> {
207 pub fn expr(self) -> Option<Expr<'a>> {
208 super::child_opt(self) 204 super::child_opt(self)
209 } 205 }
210 206pub fn arg_list(self) -> Option<ArgList<'a>> {
211 pub fn arg_list(self) -> Option<ArgList<'a>> {
212 super::child_opt(self) 207 super::child_opt(self)
213 } 208 }
214} 209}
@@ -247,12 +242,10 @@ impl<'a> AstNode<'a> for Condition<'a> {
247 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 242 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
248} 243}
249 244
250impl<'a> Condition<'a> { 245impl<'a> Condition<'a> {pub fn pat(self) -> Option<Pat<'a>> {
251 pub fn pat(self) -> Option<Pat<'a>> {
252 super::child_opt(self) 246 super::child_opt(self)
253 } 247 }
254 248pub fn expr(self) -> Option<Expr<'a>> {
255 pub fn expr(self) -> Option<Expr<'a>> {
256 super::child_opt(self) 249 super::child_opt(self)
257 } 250 }
258} 251}
@@ -466,8 +459,7 @@ impl<'a> AstNode<'a> for ExprStmt<'a> {
466 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 459 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
467} 460}
468 461
469impl<'a> ExprStmt<'a> { 462impl<'a> ExprStmt<'a> {pub fn expr(self) -> Option<Expr<'a>> {
470 pub fn expr(self) -> Option<Expr<'a>> {
471 super::child_opt(self) 463 super::child_opt(self)
472 } 464 }
473} 465}
@@ -545,16 +537,13 @@ impl<'a> AstNode<'a> for FnDef<'a> {
545impl<'a> ast::NameOwner<'a> for FnDef<'a> {} 537impl<'a> ast::NameOwner<'a> for FnDef<'a> {}
546impl<'a> ast::TypeParamsOwner<'a> for FnDef<'a> {} 538impl<'a> ast::TypeParamsOwner<'a> for FnDef<'a> {}
547impl<'a> ast::AttrsOwner<'a> for FnDef<'a> {} 539impl<'a> ast::AttrsOwner<'a> for FnDef<'a> {}
548impl<'a> FnDef<'a> { 540impl<'a> FnDef<'a> {pub fn param_list(self) -> Option<ParamList<'a>> {
549 pub fn param_list(self) -> Option<ParamList<'a>> {
550 super::child_opt(self) 541 super::child_opt(self)
551 } 542 }
552 543pub fn body(self) -> Option<Block<'a>> {
553 pub fn body(self) -> Option<Block<'a>> {
554 super::child_opt(self) 544 super::child_opt(self)
555 } 545 }
556 546pub fn ret_type(self) -> Option<RetType<'a>> {
557 pub fn ret_type(self) -> Option<RetType<'a>> {
558 super::child_opt(self) 547 super::child_opt(self)
559 } 548 }
560} 549}
@@ -594,12 +583,10 @@ impl<'a> AstNode<'a> for ForExpr<'a> {
594} 583}
595 584
596impl<'a> ast::LoopBodyOwner<'a> for ForExpr<'a> {} 585impl<'a> ast::LoopBodyOwner<'a> for ForExpr<'a> {}
597impl<'a> ForExpr<'a> { 586impl<'a> ForExpr<'a> {pub fn pat(self) -> Option<Pat<'a>> {
598 pub fn pat(self) -> Option<Pat<'a>> {
599 super::child_opt(self) 587 super::child_opt(self)
600 } 588 }
601 589pub fn iterable(self) -> Option<Expr<'a>> {
602 pub fn iterable(self) -> Option<Expr<'a>> {
603 super::child_opt(self) 590 super::child_opt(self)
604 } 591 }
605} 592}
@@ -638,8 +625,7 @@ impl<'a> AstNode<'a> for IfExpr<'a> {
638 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 625 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
639} 626}
640 627
641impl<'a> IfExpr<'a> { 628impl<'a> IfExpr<'a> {pub fn condition(self) -> Option<Condition<'a>> {
642 pub fn condition(self) -> Option<Condition<'a>> {
643 super::child_opt(self) 629 super::child_opt(self)
644 } 630 }
645} 631}
@@ -732,12 +718,10 @@ impl<'a> AstNode<'a> for LambdaExpr<'a> {
732 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 718 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
733} 719}
734 720
735impl<'a> LambdaExpr<'a> { 721impl<'a> LambdaExpr<'a> {pub fn param_list(self) -> Option<ParamList<'a>> {
736 pub fn param_list(self) -> Option<ParamList<'a>> {
737 super::child_opt(self) 722 super::child_opt(self)
738 } 723 }
739 724pub fn body(self) -> Option<Expr<'a>> {
740 pub fn body(self) -> Option<Expr<'a>> {
741 super::child_opt(self) 725 super::child_opt(self)
742 } 726 }
743} 727}
@@ -758,12 +742,10 @@ impl<'a> AstNode<'a> for LetStmt<'a> {
758 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 742 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
759} 743}
760 744
761impl<'a> LetStmt<'a> { 745impl<'a> LetStmt<'a> {pub fn pat(self) -> Option<Pat<'a>> {
762 pub fn pat(self) -> Option<Pat<'a>> {
763 super::child_opt(self) 746 super::child_opt(self)
764 } 747 }
765 748pub fn initializer(self) -> Option<Expr<'a>> {
766 pub fn initializer(self) -> Option<Expr<'a>> {
767 super::child_opt(self) 749 super::child_opt(self)
768 } 750 }
769} 751}
@@ -802,8 +784,7 @@ impl<'a> AstNode<'a> for LifetimeParam<'a> {
802 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 784 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
803} 785}
804 786
805impl<'a> LifetimeParam<'a> { 787impl<'a> LifetimeParam<'a> {pub fn lifetime(self) -> Option<Lifetime<'a>> {
806 pub fn lifetime(self) -> Option<Lifetime<'a>> {
807 super::child_opt(self) 788 super::child_opt(self)
808 } 789 }
809} 790}
@@ -1162,8 +1143,7 @@ impl<'a> AstNode<'a> for Param<'a> {
1162 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 1143 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1163} 1144}
1164 1145
1165impl<'a> Param<'a> { 1146impl<'a> Param<'a> {pub fn pat(self) -> Option<Pat<'a>> {
1166 pub fn pat(self) -> Option<Pat<'a>> {
1167 super::child_opt(self) 1147 super::child_opt(self)
1168 } 1148 }
1169} 1149}
@@ -1291,8 +1271,7 @@ impl<'a> AstNode<'a> for Path<'a> {
1291 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 1271 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1292} 1272}
1293 1273
1294impl<'a> Path<'a> { 1274impl<'a> Path<'a> {pub fn segment(self) -> Option<PathSegment<'a>> {
1295 pub fn segment(self) -> Option<PathSegment<'a>> {
1296 super::child_opt(self) 1275 super::child_opt(self)
1297 } 1276 }
1298} 1277}
@@ -1349,8 +1328,7 @@ impl<'a> AstNode<'a> for PathSegment<'a> {
1349 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 1328 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1350} 1329}
1351 1330
1352impl<'a> PathSegment<'a> { 1331impl<'a> PathSegment<'a> {pub fn name_ref(self) -> Option<NameRef<'a>> {
1353 pub fn name_ref(self) -> Option<NameRef<'a>> {
1354 super::child_opt(self) 1332 super::child_opt(self)
1355 } 1333 }
1356} 1334}
@@ -2012,8 +1990,7 @@ impl<'a> AstNode<'a> for UseItem<'a> {
2012 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 1990 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
2013} 1991}
2014 1992
2015impl<'a> UseItem<'a> { 1993impl<'a> UseItem<'a> {pub fn use_tree(self) -> Option<UseTree<'a>> {
2016 pub fn use_tree(self) -> Option<UseTree<'a>> {
2017 super::child_opt(self) 1994 super::child_opt(self)
2018 } 1995 }
2019} 1996}
@@ -2034,12 +2011,10 @@ impl<'a> AstNode<'a> for UseTree<'a> {
2034 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 2011 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
2035} 2012}
2036 2013
2037impl<'a> UseTree<'a> { 2014impl<'a> UseTree<'a> {pub fn path(self) -> Option<Path<'a>> {
2038 pub fn path(self) -> Option<Path<'a>> {
2039 super::child_opt(self) 2015 super::child_opt(self)
2040 } 2016 }
2041 2017pub fn use_tree_list(self) -> Option<UseTreeList<'a>> {
2042 pub fn use_tree_list(self) -> Option<UseTreeList<'a>> {
2043 super::child_opt(self) 2018 super::child_opt(self)
2044 } 2019 }
2045} 2020}
@@ -2101,8 +2076,7 @@ impl<'a> AstNode<'a> for WhileExpr<'a> {
2101} 2076}
2102 2077
2103impl<'a> ast::LoopBodyOwner<'a> for WhileExpr<'a> {} 2078impl<'a> ast::LoopBodyOwner<'a> for WhileExpr<'a> {}
2104impl<'a> WhileExpr<'a> { 2079impl<'a> WhileExpr<'a> {pub fn condition(self) -> Option<Condition<'a>> {
2105 pub fn condition(self) -> Option<Condition<'a>> {
2106 super::child_opt(self) 2080 super::child_opt(self)
2107 } 2081 }
2108} 2082}
diff --git a/crates/libsyntax2/src/ast/generated.rs.tera b/crates/libsyntax2/src/ast/generated.rs.tera
index 69f9236b7..a72e9b732 100644
--- a/crates/libsyntax2/src/ast/generated.rs.tera
+++ b/crates/libsyntax2/src/ast/generated.rs.tera
@@ -65,8 +65,15 @@ impl<'a> {{ node }}<'a> {
65 65
66{%- if methods.options -%} 66{%- if methods.options -%}
67{%- for m in methods.options -%} 67{%- for m in methods.options -%}
68
69{%- if m is string -%}
70{%- set method_name = m | snake -%}
71{%- set ChildName = m %}
72{%- else -%}
68{%- set method_name = m.0 -%} 73{%- set method_name = m.0 -%}
69{%- set ChildName = m.1 %} 74{%- set ChildName = m.1 %}
75{%- endif -%}
76
70 pub fn {{ method_name }}(self) -> Option<{{ ChildName }}<'a>> { 77 pub fn {{ method_name }}(self) -> Option<{{ ChildName }}<'a>> {
71 super::child_opt(self) 78 super::child_opt(self)
72 } 79 }
diff --git a/crates/libsyntax2/src/grammar.ron b/crates/libsyntax2/src/grammar.ron
index da18da8a9..77730e306 100644
--- a/crates/libsyntax2/src/grammar.ron
+++ b/crates/libsyntax2/src/grammar.ron
@@ -250,11 +250,7 @@ Grammar(
250 "TypeParamsOwner", 250 "TypeParamsOwner",
251 "AttrsOwner", 251 "AttrsOwner",
252 ], 252 ],
253 options: [ 253 options: [ "ParamList", ["body", "Block"], "RetType" ],
254 ["param_list", "ParamList"],
255 ["body", "Block"],
256 ["ret_type", "RetType"]
257 ],
258 ), 254 ),
259 "RetType": (), 255 "RetType": (),
260 "StructDef": ( 256 "StructDef": (
@@ -346,12 +342,12 @@ Grammar(
346 "PathExpr": (), 342 "PathExpr": (),
347 "LambdaExpr": ( 343 "LambdaExpr": (
348 options: [ 344 options: [
349 ["param_list", "ParamList"], 345 "ParamList",
350 ["body", "Expr"], 346 ["body", "Expr"],
351 ] 347 ]
352 ), 348 ),
353 "IfExpr": ( 349 "IfExpr": (
354 options: [ ["condition", "Condition"] ] 350 options: [ "Condition" ]
355 ), 351 ),
356 "LoopExpr": ( 352 "LoopExpr": (
357 traits: ["LoopBodyOwner"], 353 traits: ["LoopBodyOwner"],
@@ -359,21 +355,19 @@ Grammar(
359 "ForExpr": ( 355 "ForExpr": (
360 traits: ["LoopBodyOwner"], 356 traits: ["LoopBodyOwner"],
361 options: [ 357 options: [
362 ["pat", "Pat"], 358 "Pat",
363 ["iterable", "Expr"], 359 ["iterable", "Expr"],
364 ] 360 ]
365 ), 361 ),
366 "WhileExpr": ( 362 "WhileExpr": (
367 traits: ["LoopBodyOwner"], 363 traits: ["LoopBodyOwner"],
368 options: [ 364 options: [ "Condition" ]
369 ["condition", "Condition"],
370 ]
371 ), 365 ),
372 "ContinueExpr": (), 366 "ContinueExpr": (),
373 "BreakExpr": (), 367 "BreakExpr": (),
374 "Label": (), 368 "Label": (),
375 "BlockExpr": ( 369 "BlockExpr": (
376 options: [ ["block", "Block"] ] 370 options: [ "Block" ]
377 ), 371 ),
378 "ReturnExpr": (), 372 "ReturnExpr": (),
379 "MatchExpr": (), 373 "MatchExpr": (),
@@ -384,10 +378,7 @@ Grammar(
384 "NamedFieldList": (), 378 "NamedFieldList": (),
385 "NamedField": (), 379 "NamedField": (),
386 "CallExpr": ( 380 "CallExpr": (
387 options: [ 381 options: [ "Expr", "ArgList" ]
388 [ "expr", "Expr" ],
389 [ "arg_list", "ArgList" ],
390 ]
391 ), 382 ),
392 "IndexExpr": (), 383 "IndexExpr": (),
393 "MethodCallExpr": (), 384 "MethodCallExpr": (),
@@ -474,7 +465,7 @@ Grammar(
474 ] 465 ]
475 ), 466 ),
476 "TypeParam": ( traits: ["NameOwner"] ), 467 "TypeParam": ( traits: ["NameOwner"] ),
477 "LifetimeParam": ( options: [ ["lifetime", "Lifetime"] ] ), 468 "LifetimeParam": ( options: [ "Lifetime" ] ),
478 "Lifetime": (), 469 "Lifetime": (),
479 "WhereClause": (), 470 "WhereClause": (),
480 "ExprStmt": ( 471 "ExprStmt": (
@@ -485,16 +476,13 @@ Grammar(
485 ["initializer", "Expr"], 476 ["initializer", "Expr"],
486 ]), 477 ]),
487 "Condition": ( 478 "Condition": (
488 options: [ 479 options: [ "Pat", "Expr" ]
489 [ "pat", "Pat" ],
490 [ "expr", "Expr" ],
491 ]
492 ), 480 ),
493 "Stmt": ( 481 "Stmt": (
494 enum: ["ExprStmt", "LetStmt"], 482 enum: ["ExprStmt", "LetStmt"],
495 ), 483 ),
496 "Block": ( 484 "Block": (
497 options: [["expr", "Expr"]], 485 options: [ "Expr" ],
498 collections: [ 486 collections: [
499 ["statements", "Stmt"], 487 ["statements", "Stmt"],
500 ] 488 ]
@@ -505,16 +493,13 @@ Grammar(
505 ] 493 ]
506 ), 494 ),
507 "Param": ( 495 "Param": (
508 options: [["pat", "Pat"]], 496 options: [ "Pat" ],
509 ), 497 ),
510 "UseItem": ( 498 "UseItem": (
511 options: [["use_tree", "UseTree"]] 499 options: [ "UseTree" ]
512 ), 500 ),
513 "UseTree": ( 501 "UseTree": (
514 options: [ 502 options: [ "Path", "UseTreeList" ]
515 ["path", "Path"],
516 ["use_tree_list", "UseTreeList"],
517 ]
518 ), 503 ),
519 "UseTreeList": ( 504 "UseTreeList": (
520 collections: [["use_trees", "UseTree"]] 505 collections: [["use_trees", "UseTree"]]
@@ -531,9 +516,7 @@ Grammar(
531 ] 516 ]
532 ), 517 ),
533 "PathSegment": ( 518 "PathSegment": (
534 options: [ 519 options: [ "NameRef" ]
535 ["name_ref", "NameRef"]
536 ]
537 ), 520 ),
538 }, 521 },
539) 522)