From 1142112c70b705f59b7d559d9d72cdc831865158 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 14:51:08 +0200 Subject: Rename FnDef -> Fn --- xtask/src/ast_src.rs | 2 +- xtask/src/codegen/gen_syntax.rs | 7 ++----- xtask/src/codegen/rust.ungram | 46 ++++++++++++++++++++++++----------------- 3 files changed, 30 insertions(+), 25 deletions(-) (limited to 'xtask/src') diff --git a/xtask/src/ast_src.rs b/xtask/src/ast_src.rs index 3a58217c4..40693ed17 100644 --- a/xtask/src/ast_src.rs +++ b/xtask/src/ast_src.rs @@ -96,7 +96,7 @@ pub(crate) const KINDS_SRC: KindsSrc = KindsSrc { "STRUCT_DEF", "UNION_DEF", "ENUM_DEF", - "FN_DEF", + "FN", "RET_TYPE", "EXTERN_CRATE", "MODULE", diff --git a/xtask/src/codegen/gen_syntax.rs b/xtask/src/codegen/gen_syntax.rs index c77fc8a8d..072527208 100644 --- a/xtask/src/codegen/gen_syntax.rs +++ b/xtask/src/codegen/gen_syntax.rs @@ -471,6 +471,7 @@ impl Field { "::" => "coloncolon", "#" => "pound", "?" => "question_mark", + "," => "comma", _ => name, }; format_ident!("{}_token", name) @@ -599,13 +600,9 @@ fn lower_rule(acc: &mut Vec, grammar: &Grammar, rule: &Rule) { } } -// (T (',' T)* ','?)? +// (T (',' T)* ','?) fn lower_comma_list(acc: &mut Vec, grammar: &Grammar, rule: &Rule) -> bool { let rule = match rule { - Rule::Opt(it) => it, - _ => return false, - }; - let rule = match &**rule { Rule::Seq(it) => it, _ => return false, }; diff --git a/xtask/src/codegen/rust.ungram b/xtask/src/codegen/rust.ungram index 449b0242f..98968dece 100644 --- a/xtask/src/codegen/rust.ungram +++ b/xtask/src/codegen/rust.ungram @@ -8,7 +8,7 @@ Item = | EnumDef | ExternBlock | ExternCrate -| FnDef +| Fn | ImplDef | MacroCall | Module @@ -42,12 +42,33 @@ UseTree = UseTreeList = '{' (UseTree (',' UseTree)* ','?)? '}' -FnDef = - Attr* Visibility? Abi? 'const' 'default' 'async' 'unsafe' 'fn' Name TypeParamList? - ParamList RetType? +Fn = + Attr* Visibility? + 'default'? ('async' | 'const')? 'unsafe'? Abi? + 'fn' Name TypeParamList? ParamList RetType? WhereClause? (body:BlockExpr | ';') +Abi = + 'extern' 'string'? + +ParamList = + '('( + (Param (',' Param)* ','?)? + | SelfParam ','? + | SelfParam ',' (Param (',' Param)* ','?) + )')' + +SelfParam = + Attr* ( + ('&' 'lifetime'?)? 'mut'? 'self' + | 'mut'? 'self' ':' ascribed_type:TypeRef + ) + +Param = + Attr* Pat (':' ascribed_type:TypeRef) +| '...' + RetType = '->' TypeRef @@ -388,9 +409,6 @@ WherePred = WhereClause = 'where' predicates:WherePred* -Abi = - 'string' - ExprStmt = Attr* Expr ';' @@ -398,16 +416,6 @@ LetStmt = Attr* 'let' Pat (':' ascribed_type:TypeRef) '=' initializer:Expr ';' -ParamList = - '(' SelfParam Param* ')' - -SelfParam = - Attr* ('&' 'lifetime'?)? 'mut'? 'self' (':' ascribed_type:TypeRef) - -Param = - Attr* Pat (':' ascribed_type:TypeRef) -| '...' - Path = (qualifier:Path '::')? segment:PathSegment @@ -465,13 +473,13 @@ TypeRef = | DynTraitType AssocItem = - FnDef + Fn | TypeAliasDef | ConstDef | MacroCall ExternItem = - FnDef | StaticDef + Fn | StaticDef AttrInput = Literal -- cgit v1.2.3