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/codegen/gen_syntax.rs | 7 ++----- xtask/src/codegen/rust.ungram | 46 ++++++++++++++++++++++++----------------- 2 files changed, 29 insertions(+), 24 deletions(-) (limited to 'xtask/src/codegen') 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 From eb2f8063444b11257111f4f8ade990ec810e0361 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 15:25:46 +0200 Subject: Rename TypeAliasDef -> TypeAlias --- xtask/src/codegen/rust.ungram | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'xtask/src/codegen') diff --git a/xtask/src/codegen/rust.ungram b/xtask/src/codegen/rust.ungram index 98968dece..760a8dd95 100644 --- a/xtask/src/codegen/rust.ungram +++ b/xtask/src/codegen/rust.ungram @@ -15,7 +15,7 @@ Item = | StaticDef | StructDef | TraitDef -| TypeAliasDef +| TypeAlias | UnionDef | Use @@ -72,6 +72,10 @@ Param = RetType = '->' TypeRef +TypeAlias = + Attr* Visibility? 'default'? 'type' Name TypeParamList? (':' TypeBoundList?)? WhereClause? + '=' TypeRef ';' + StructDef = Attr* Visibility? 'struct' Name TypeParamList? ( WhereClause? (RecordFieldDefList | ';') @@ -124,10 +128,6 @@ StaticDef = Attr* Visibility? 'static'? 'mut'? 'static' Name ':' ascribed_type:TypeRef '=' body:Expr ';' -TypeAliasDef = - Attr* Visibility? 'default'? 'type' Name TypeParamList? WhereClause? (':' TypeBoundList?)? - '=' TypeRef ';' - ImplDef = Attr* Visibility? 'const'? 'default'? 'unsafe'? 'impl' TypeParamList? '!'? 'for' WhereClause? @@ -474,7 +474,7 @@ TypeRef = AssocItem = Fn -| TypeAliasDef +| TypeAlias | ConstDef | MacroCall -- cgit v1.2.3