diff --git a/crates/libsyntax2/src/ast/generated.rs b/crates/libsyntax2/src/ast/generated.rs index 0668dbfa7a..58dcf574ea 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> { fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } } -impl<'a> Attr<'a> { - pub fn value(self) -> Option> { +impl<'a> Attr<'a> {pub fn value(self) -> Option> { super::child_opt(self) } } @@ -141,8 +140,7 @@ impl<'a> Block<'a> { pub fn statements(self) -> impl Iterator> + 'a { super::children(self) } - - pub fn expr(self) -> Option> { +pub fn expr(self) -> Option> { super::child_opt(self) } } @@ -163,8 +161,7 @@ impl<'a> AstNode<'a> for BlockExpr<'a> { fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } } -impl<'a> BlockExpr<'a> { - pub fn block(self) -> Option> { +impl<'a> BlockExpr<'a> {pub fn block(self) -> Option> { super::child_opt(self) } } @@ -203,12 +200,10 @@ impl<'a> AstNode<'a> for CallExpr<'a> { fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } } -impl<'a> CallExpr<'a> { - pub fn expr(self) -> Option> { +impl<'a> CallExpr<'a> {pub fn expr(self) -> Option> { super::child_opt(self) } - - pub fn arg_list(self) -> Option> { +pub fn arg_list(self) -> Option> { super::child_opt(self) } } @@ -247,12 +242,10 @@ impl<'a> AstNode<'a> for Condition<'a> { fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } } -impl<'a> Condition<'a> { - pub fn pat(self) -> Option> { +impl<'a> Condition<'a> {pub fn pat(self) -> Option> { super::child_opt(self) } - - pub fn expr(self) -> Option> { +pub fn expr(self) -> Option> { super::child_opt(self) } } @@ -466,8 +459,7 @@ impl<'a> AstNode<'a> for ExprStmt<'a> { fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } } -impl<'a> ExprStmt<'a> { - pub fn expr(self) -> Option> { +impl<'a> ExprStmt<'a> {pub fn expr(self) -> Option> { super::child_opt(self) } } @@ -545,16 +537,13 @@ impl<'a> AstNode<'a> for FnDef<'a> { impl<'a> ast::NameOwner<'a> for FnDef<'a> {} impl<'a> ast::TypeParamsOwner<'a> for FnDef<'a> {} impl<'a> ast::AttrsOwner<'a> for FnDef<'a> {} -impl<'a> FnDef<'a> { - pub fn param_list(self) -> Option> { +impl<'a> FnDef<'a> {pub fn param_list(self) -> Option> { super::child_opt(self) } - - pub fn body(self) -> Option> { +pub fn body(self) -> Option> { super::child_opt(self) } - - pub fn ret_type(self) -> Option> { +pub fn ret_type(self) -> Option> { super::child_opt(self) } } @@ -594,12 +583,10 @@ impl<'a> AstNode<'a> for ForExpr<'a> { } impl<'a> ast::LoopBodyOwner<'a> for ForExpr<'a> {} -impl<'a> ForExpr<'a> { - pub fn pat(self) -> Option> { +impl<'a> ForExpr<'a> {pub fn pat(self) -> Option> { super::child_opt(self) } - - pub fn iterable(self) -> Option> { +pub fn iterable(self) -> Option> { super::child_opt(self) } } @@ -638,8 +625,7 @@ impl<'a> AstNode<'a> for IfExpr<'a> { fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } } -impl<'a> IfExpr<'a> { - pub fn condition(self) -> Option> { +impl<'a> IfExpr<'a> {pub fn condition(self) -> Option> { super::child_opt(self) } } @@ -732,12 +718,10 @@ impl<'a> AstNode<'a> for LambdaExpr<'a> { fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } } -impl<'a> LambdaExpr<'a> { - pub fn param_list(self) -> Option> { +impl<'a> LambdaExpr<'a> {pub fn param_list(self) -> Option> { super::child_opt(self) } - - pub fn body(self) -> Option> { +pub fn body(self) -> Option> { super::child_opt(self) } } @@ -758,12 +742,10 @@ impl<'a> AstNode<'a> for LetStmt<'a> { fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } } -impl<'a> LetStmt<'a> { - pub fn pat(self) -> Option> { +impl<'a> LetStmt<'a> {pub fn pat(self) -> Option> { super::child_opt(self) } - - pub fn initializer(self) -> Option> { +pub fn initializer(self) -> Option> { super::child_opt(self) } } @@ -802,8 +784,7 @@ impl<'a> AstNode<'a> for LifetimeParam<'a> { fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } } -impl<'a> LifetimeParam<'a> { - pub fn lifetime(self) -> Option> { +impl<'a> LifetimeParam<'a> {pub fn lifetime(self) -> Option> { super::child_opt(self) } } @@ -1162,8 +1143,7 @@ impl<'a> AstNode<'a> for Param<'a> { fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } } -impl<'a> Param<'a> { - pub fn pat(self) -> Option> { +impl<'a> Param<'a> {pub fn pat(self) -> Option> { super::child_opt(self) } } @@ -1291,8 +1271,7 @@ impl<'a> AstNode<'a> for Path<'a> { fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } } -impl<'a> Path<'a> { - pub fn segment(self) -> Option> { +impl<'a> Path<'a> {pub fn segment(self) -> Option> { super::child_opt(self) } } @@ -1349,8 +1328,7 @@ impl<'a> AstNode<'a> for PathSegment<'a> { fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } } -impl<'a> PathSegment<'a> { - pub fn name_ref(self) -> Option> { +impl<'a> PathSegment<'a> {pub fn name_ref(self) -> Option> { super::child_opt(self) } } @@ -2012,8 +1990,7 @@ impl<'a> AstNode<'a> for UseItem<'a> { fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } } -impl<'a> UseItem<'a> { - pub fn use_tree(self) -> Option> { +impl<'a> UseItem<'a> {pub fn use_tree(self) -> Option> { super::child_opt(self) } } @@ -2034,12 +2011,10 @@ impl<'a> AstNode<'a> for UseTree<'a> { fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } } -impl<'a> UseTree<'a> { - pub fn path(self) -> Option> { +impl<'a> UseTree<'a> {pub fn path(self) -> Option> { super::child_opt(self) } - - pub fn use_tree_list(self) -> Option> { +pub fn use_tree_list(self) -> Option> { super::child_opt(self) } } @@ -2101,8 +2076,7 @@ impl<'a> AstNode<'a> for WhileExpr<'a> { } impl<'a> ast::LoopBodyOwner<'a> for WhileExpr<'a> {} -impl<'a> WhileExpr<'a> { - pub fn condition(self) -> Option> { +impl<'a> WhileExpr<'a> {pub fn condition(self) -> Option> { super::child_opt(self) } } diff --git a/crates/libsyntax2/src/ast/generated.rs.tera b/crates/libsyntax2/src/ast/generated.rs.tera index 69f9236b7c..a72e9b7324 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> { {%- if methods.options -%} {%- for m in methods.options -%} + +{%- if m is string -%} +{%- set method_name = m | snake -%} +{%- set ChildName = m %} +{%- else -%} {%- set method_name = m.0 -%} {%- set ChildName = m.1 %} +{%- endif -%} + pub fn {{ method_name }}(self) -> Option<{{ ChildName }}<'a>> { super::child_opt(self) } diff --git a/crates/libsyntax2/src/grammar.ron b/crates/libsyntax2/src/grammar.ron index da18da8a98..77730e3062 100644 --- a/crates/libsyntax2/src/grammar.ron +++ b/crates/libsyntax2/src/grammar.ron @@ -250,11 +250,7 @@ Grammar( "TypeParamsOwner", "AttrsOwner", ], - options: [ - ["param_list", "ParamList"], - ["body", "Block"], - ["ret_type", "RetType"] - ], + options: [ "ParamList", ["body", "Block"], "RetType" ], ), "RetType": (), "StructDef": ( @@ -346,12 +342,12 @@ Grammar( "PathExpr": (), "LambdaExpr": ( options: [ - ["param_list", "ParamList"], + "ParamList", ["body", "Expr"], ] ), "IfExpr": ( - options: [ ["condition", "Condition"] ] + options: [ "Condition" ] ), "LoopExpr": ( traits: ["LoopBodyOwner"], @@ -359,21 +355,19 @@ Grammar( "ForExpr": ( traits: ["LoopBodyOwner"], options: [ - ["pat", "Pat"], + "Pat", ["iterable", "Expr"], ] ), "WhileExpr": ( traits: ["LoopBodyOwner"], - options: [ - ["condition", "Condition"], - ] + options: [ "Condition" ] ), "ContinueExpr": (), "BreakExpr": (), "Label": (), "BlockExpr": ( - options: [ ["block", "Block"] ] + options: [ "Block" ] ), "ReturnExpr": (), "MatchExpr": (), @@ -384,10 +378,7 @@ Grammar( "NamedFieldList": (), "NamedField": (), "CallExpr": ( - options: [ - [ "expr", "Expr" ], - [ "arg_list", "ArgList" ], - ] + options: [ "Expr", "ArgList" ] ), "IndexExpr": (), "MethodCallExpr": (), @@ -474,7 +465,7 @@ Grammar( ] ), "TypeParam": ( traits: ["NameOwner"] ), - "LifetimeParam": ( options: [ ["lifetime", "Lifetime"] ] ), + "LifetimeParam": ( options: [ "Lifetime" ] ), "Lifetime": (), "WhereClause": (), "ExprStmt": ( @@ -485,16 +476,13 @@ Grammar( ["initializer", "Expr"], ]), "Condition": ( - options: [ - [ "pat", "Pat" ], - [ "expr", "Expr" ], - ] + options: [ "Pat", "Expr" ] ), "Stmt": ( enum: ["ExprStmt", "LetStmt"], ), "Block": ( - options: [["expr", "Expr"]], + options: [ "Expr" ], collections: [ ["statements", "Stmt"], ] @@ -505,16 +493,13 @@ Grammar( ] ), "Param": ( - options: [["pat", "Pat"]], + options: [ "Pat" ], ), "UseItem": ( - options: [["use_tree", "UseTree"]] + options: [ "UseTree" ] ), "UseTree": ( - options: [ - ["path", "Path"], - ["use_tree_list", "UseTreeList"], - ] + options: [ "Path", "UseTreeList" ] ), "UseTreeList": ( collections: [["use_trees", "UseTree"]] @@ -531,9 +516,7 @@ Grammar( ] ), "PathSegment": ( - options: [ - ["name_ref", "NameRef"] - ] + options: [ "NameRef" ] ), }, ) diff --git a/crates/tools/src/main.rs b/crates/tools/src/main.rs index d7f34d7577..5bfaf18f17 100644 --- a/crates/tools/src/main.rs +++ b/crates/tools/src/main.rs @@ -10,7 +10,7 @@ extern crate commandspec; extern crate heck; use clap::{App, Arg, SubCommand}; -use heck::{CamelCase, ShoutySnakeCase}; +use heck::{CamelCase, ShoutySnakeCase, SnakeCase}; use std::{ collections::HashMap, fs, @@ -91,6 +91,9 @@ fn render_template(template: &str) -> Result { tera.register_filter("camel", |arg, _| { Ok(arg.as_str().unwrap().to_camel_case().into()) }); + tera.register_filter("snake", |arg, _| { + Ok(arg.as_str().unwrap().to_snake_case().into()) + }); tera.register_filter("SCREAM", |arg, _| { Ok(arg.as_str().unwrap().to_shouty_snake_case().into()) });