From dd1f35c32d050da4c6f24b33d5ac661d2213d478 Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Sat, 28 Mar 2020 15:04:48 +0000 Subject: [PATCH 01/16] Add .vscode to .gitignore. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 6936990..4fb5d9e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /target **/*.rs.bk Cargo.lock +/.vscode From db0a29670c804af42956475a14a9cdc96c7fc6ba Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Sun, 29 Mar 2020 00:04:54 +0000 Subject: [PATCH 02/16] Update gll dependency. --- Cargo.toml | 4 ++-- src/bin/coverage.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index bf0707a..27f19cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,5 +33,5 @@ name = "snapshots" path = "src/bin/snapshots.rs" [patch.'crates-io'] -gll = { git = "https://github.com/rust-lang/gll", rev = "26d42a0117b9c48538ef20c872742e05070bb55e" } -grammer = { git = "https://github.com/lykenware/grammer", rev = "6f6f1320336d84b75805907fb302a28cb6d4cfb0" } +gll = { git = "https://github.com/rust-lang/gll", rev = "4c58803c1c4df4ca8798318d63d78454cc4450f6" } +grammer = { git = "https://github.com/LykenSol/grammer", rev = "eecb1b16cd234408d066fabec63786003925452d" } diff --git a/src/bin/coverage.rs b/src/bin/coverage.rs index 2681fe9..75ca720 100644 --- a/src/bin/coverage.rs +++ b/src/bin/coverage.rs @@ -171,7 +171,7 @@ fn ambiguity_check(handle: &ModuleContentsHandle) -> Result<(), MoreThanOne> { add_children(&[child]); } } - NodeShape::Choice => add_children(&[forest.one_choice(source)?]), + NodeShape::Choice(_) => add_children(&[forest.one_choice(source)?]), NodeShape::Split(..) => { let (left, right) = forest.one_split(source)?; add_children(&[left, right]) From 7936b13b826f447f01fe8859a6f9987a605db903 Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Sat, 28 Mar 2020 16:44:17 +0000 Subject: [PATCH 03/16] pat: support rest patterns, or_patterns and half_open_range_patterns. --- grammar/expr.lyg | 2 +- grammar/pat.lyg | 32 +++++++++++++++++--------------- src/bin/snapshots.rs | 3 +-- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/grammar/expr.lyg b/grammar/expr.lyg index 15b1ddd..910b2c6 100644 --- a/grammar/expr.lyg +++ b/grammar/expr.lyg @@ -125,6 +125,6 @@ ElseExpr = | If:If ; -MatchArm = attrs:OuterAttr* "|"? pats:Pat+ % "|" { "if" guard:Expr }? "=>" body:Expr ","?; +MatchArm = attrs:OuterAttr* "|"? pat:Pat { "if" guard:Expr }? "=>" body:Expr ","?; ClosureArg = pat:Pat { ":" ty:Type }?; diff --git a/grammar/pat.lyg b/grammar/pat.lyg index 58f72a6..e0c66f2 100644 --- a/grammar/pat.lyg +++ b/grammar/pat.lyg @@ -1,18 +1,30 @@ Pat = | Wild:"_" + | Rest:".." | Literal:{ minus:"-"? lit:LITERAL } // unstable(exclusive_range_pattern): - | Range:{ start:PatRangeValue ".." end:PatRangeValue } - | RangeInclusive:{ start:PatRangeValue { "..." | "..=" } end:PatRangeValue } + | Range:{ + | start:PatRangeValue ".." end:PatRangeValue + // unstable(half_open_range_patterns): + | start:PatRangeValue ".." | ".." end:PatRangeValue + } + | RangeInclusive:{ + | start:PatRangeValue { "..." | "..=" } end:PatRangeValue + // unstable(half_open_range_patterns): + | { "..." | "..=" } end:PatRangeValue + } | Binding:{ binding:Binding { "@" subpat:Pat }? } | Paren:{ "(" pat:Pat ")" } | Ref:{ "&" mutable:"mut"? pat:Pat } // unstable(box_patterns): | Box:{ "box" pat:Pat } - | Slice:{ "[" elems:SlicePatElem* %% "," "]" } - | Tuple:{ "(" fields:TuplePatField* %% "," ")" } + // unstable(or_patterns): + // FIXME(eddyb) find a way to express "2 or more" (like regex `{2,}`). + | Or:{ first_pat:Pat "|" pats:Pat+ % "|" } + | Slice:{ "[" elems:Pat* %% "," "]" } + | Tuple:{ "(" fields:Pat* %% "," ")" } | Path:QPath - | TupleStruct:{ path:Path "(" fields:TuplePatField* %% "," ")" } + | TupleStruct:{ path:Path "(" fields:Pat* %% "," ")" } | Struct:{ path:Path "{" fields:StructPatFieldsAndEllipsis "}" } | MacroCall:MacroCall ; @@ -24,16 +36,6 @@ PatRangeValue = Binding = boxed:"box"? reference:"ref"? mutable:"mut"? name:IDENT; -SlicePatElem = - | Subslice:{ subpat:Pat? ".." } - | Pat:Pat - ; - -TuplePatField = - | Ellipsis:".." - | Pat:Pat - ; - // FIXME(eddyb) find a way to express this `A* B?` pattern better StructPatFieldsAndEllipsis = | Fields:StructPatField* %% "," diff --git a/src/bin/snapshots.rs b/src/bin/snapshots.rs index 10e361f..06f0fd7 100644 --- a/src/bin/snapshots.rs +++ b/src/bin/snapshots.rs @@ -66,8 +66,7 @@ fn test_snapshot(file: walkdir::DirEntry) { // macro.lyg MacroCall MacroInput ItemMacroCall ItemMacroInput // pat.lyg - Pat PatRangeValue Binding SlicePatElem TuplePatField StructPatFieldsAndEllipsis - StructPatField + Pat PatRangeValue Binding StructPatFieldsAndEllipsis StructPatField // path.lyg Path RelativePath PathSegment QSelf QPath // stmt.lyg From 72d5a0a22a4ed33856f412e9a34d3fd8340f09e4 Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Sat, 28 Mar 2020 16:46:15 +0000 Subject: [PATCH 04/16] generics: support associated_type_bounds. --- grammar/generics.lyg | 13 ++++++++----- src/bin/snapshots.rs | 4 ++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/grammar/generics.lyg b/grammar/generics.lyg index 3762e10..32363fd 100644 --- a/grammar/generics.lyg +++ b/grammar/generics.lyg @@ -25,19 +25,22 @@ TypeTraitBound = unbound:"?"? binder:ForAllBinder? path:Path; // Generic args of a path segment. GenericArgs = - | AngleBracket:{ "<" args_and_bindings:AngleBracketGenericArgsAndBindings? ">" } + | AngleBracket:{ "<" args_and_bindings:AngleBracketGenericArgsAndConstraints? ">" } | Paren:{ "(" inputs:Type* %% "," ")" { "->" output:Type }? } ; // FIXME(eddyb) find a way to express this `A* B*` pattern better -AngleBracketGenericArgsAndBindings = +AngleBracketGenericArgsAndConstraints = | Args:GenericArg+ %% "," - | Bindings:TypeBinding+ %% "," - | ArgsAndBindings:{ args:GenericArg+ % "," "," bindings:TypeBinding+ %% "," } + | Constraints:AssocTypeConstraint+ %% "," + | ArgsAndConstraints:{ args:GenericArg+ % "," "," constraints:AssocTypeConstraint+ %% "," } ; GenericArg = | Lifetime:LIFETIME | Type:Type ; -TypeBinding = name:IDENT "=" ty:Type; +AssocTypeConstraint = + | Eq:{ name:IDENT "=" ty:Type } + // unstable(associated_type_bounds): + | Bound:{ name:IDENT ":" bounds:TypeBound* %% "+" }; diff --git a/src/bin/snapshots.rs b/src/bin/snapshots.rs index 06f0fd7..dbb7345 100644 --- a/src/bin/snapshots.rs +++ b/src/bin/snapshots.rs @@ -57,8 +57,8 @@ fn test_snapshot(file: walkdir::DirEntry) { If Cond ElseExpr MatchArm ClosureArg // generics.lyg Generics GenericParam GenericParamKind ForAllBinder WhereClause WhereBound LifetimeBound - TypeBound TypeTraitBound GenericArgs AngleBracketGenericArgsAndBindings GenericArg - TypeBinding + TypeBound TypeTraitBound GenericArgs AngleBracketGenericArgsAndConstraints GenericArg + AssocTypeConstraint // item.lyg ModuleContents Item ItemKind UseTree UseTreePrefix ForeignItem ForeignItemKind TraitItem TraitItemKind ImplItem ImplItemKind FnHeader FnDecl FnArgs FnArg EnumVariant EnumVariantKind From 82efb69db9d130b11e6dc960e9a0f4e9f0e02ae0 Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Sat, 28 Mar 2020 17:06:07 +0000 Subject: [PATCH 05/16] generics: support const_generics. --- grammar/generics.lyg | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/grammar/generics.lyg b/grammar/generics.lyg index 32363fd..6a0078c 100644 --- a/grammar/generics.lyg +++ b/grammar/generics.lyg @@ -3,6 +3,8 @@ GenericParam = attrs:OuterAttr* kind:GenericParamKind; GenericParamKind = | Lifetime:{ name:LIFETIME { ":" bounds:LifetimeBound* %% "+" }? } | Type:{ name:IDENT { ":" bounds:TypeBound* %% "+" }? { "=" default:Type }? } + // unstable(const_generics): + | Const:{ "const" name:IDENT ":" ty:Type } ; ForAllBinder = "for" generics:Generics; @@ -39,6 +41,8 @@ AngleBracketGenericArgsAndConstraints = GenericArg = | Lifetime:LIFETIME | Type:Type + // unstable(const_generics): + | Const:{ neg:"-"? lit:LITERAL | "{" expr:Expr "}" } ; AssocTypeConstraint = | Eq:{ name:IDENT "=" ty:Type } From c815b25f6560035b746b8043e9cda7a48156710f Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Sat, 28 Mar 2020 17:16:16 +0000 Subject: [PATCH 06/16] item: support function parameter attributes. --- grammar/item.lyg | 11 ++++++----- src/bin/snapshots.rs | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/grammar/item.lyg b/grammar/item.lyg index b198a8b..6efb1d9 100644 --- a/grammar/item.lyg +++ b/grammar/item.lyg @@ -85,15 +85,16 @@ ImplItemKind = ; FnHeader = constness:"const"? unsafety:"unsafe"? asyncness:"async"? { "extern" abi:Abi }?; -FnDecl = name:IDENT generics:Generics? "(" args:FnArgs? ")" { "->" ret_ty:Type }? where_clause:WhereClause?; +FnDecl = name:IDENT generics:Generics? "(" params:FnParams? ")" { "->" ret_ty:Type }? where_clause:WhereClause?; // FIXME(eddyb) find a way to express this `A* B?` pattern better -FnArgs = - | Regular:FnArg+ %% "," +FnParams = + | Regular:FnParam+ %% "," | Variadic:"..." - | RegularAndVariadic:{ args:FnArg+ % "," "," "..." } + | RegularAndVariadic:{ args:FnParam+ % "," "," "..." } ; -FnArg = +FnParam = attrs:OuterAttr* kind:FnParamKind; +FnParamKind = | SelfValue:{ mutable:"mut"? "self" } | SelfRef:{ "&" lt:LIFETIME? mutable:"mut"? "self" } | Regular:FnSigInput diff --git a/src/bin/snapshots.rs b/src/bin/snapshots.rs index dbb7345..c4c7703 100644 --- a/src/bin/snapshots.rs +++ b/src/bin/snapshots.rs @@ -61,8 +61,8 @@ fn test_snapshot(file: walkdir::DirEntry) { AssocTypeConstraint // item.lyg ModuleContents Item ItemKind UseTree UseTreePrefix ForeignItem ForeignItemKind TraitItem - TraitItemKind ImplItem ImplItemKind FnHeader FnDecl FnArgs FnArg EnumVariant EnumVariantKind - StructBody TupleField RecordField + TraitItemKind ImplItem ImplItemKind FnHeader FnDecl FnParams FnParam EnumVariant + EnumVariantKind StructBody TupleField RecordField // macro.lyg MacroCall MacroInput ItemMacroCall ItemMacroInput // pat.lyg From 3d773d9a17a103bb0a9bdb406a4c46454a7e5340 Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Sat, 28 Mar 2020 17:31:49 +0000 Subject: [PATCH 07/16] item: swap "async" and "unsafe" in FnHeader. --- grammar/item.lyg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grammar/item.lyg b/grammar/item.lyg index 6efb1d9..b58e867 100644 --- a/grammar/item.lyg +++ b/grammar/item.lyg @@ -84,7 +84,7 @@ ImplItemKind = | MacroCall:ItemMacroCall ; -FnHeader = constness:"const"? unsafety:"unsafe"? asyncness:"async"? { "extern" abi:Abi }?; +FnHeader = constness:"const"? asyncness:"async"? unsafety:"unsafe"? { "extern" abi:Abi }?; FnDecl = name:IDENT generics:Generics? "(" params:FnParams? ")" { "->" ret_ty:Type }? where_clause:WhereClause?; // FIXME(eddyb) find a way to express this `A* B?` pattern better From 159762b2a16879fe1f6b6c2fcc5c8a2cf2c170a3 Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Sat, 28 Mar 2020 18:43:28 +0000 Subject: [PATCH 08/16] item: support c_variadic. --- grammar/item.lyg | 6 ++++-- grammar/type.lyg | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/grammar/item.lyg b/grammar/item.lyg index b58e867..b5e368f 100644 --- a/grammar/item.lyg +++ b/grammar/item.lyg @@ -90,8 +90,8 @@ FnDecl = name:IDENT generics:Generics? "(" params:FnParams? ")" { "->" ret_ty:Ty // FIXME(eddyb) find a way to express this `A* B?` pattern better FnParams = | Regular:FnParam+ %% "," - | Variadic:"..." - | RegularAndVariadic:{ args:FnParam+ % "," "," "..." } + | CVariadic:FnCVariadicParam + | RegularAndCVariadic:{ args:FnParam+ % "," "," c_variadic:FnCVariadicParam } ; FnParam = attrs:OuterAttr* kind:FnParamKind; FnParamKind = @@ -99,6 +99,8 @@ FnParamKind = | SelfRef:{ "&" lt:LIFETIME? mutable:"mut"? "self" } | Regular:FnSigInput ; +// unstable(c_variadic): +FnCVariadicParam = { pat:Pat ":" }? "..."; EnumVariant = attrs:OuterAttr* name:IDENT kind:EnumVariantKind { "=" discr:Expr }?; EnumVariantKind = diff --git a/grammar/type.lyg b/grammar/type.lyg index 509b690..52fef97 100644 --- a/grammar/type.lyg +++ b/grammar/type.lyg @@ -21,7 +21,7 @@ Type = FnSigInputs = | Regular:FnSigInput+ %% "," - | Variadic:"..." - | RegularAndVariadic:{ inputs:FnSigInput+ % "," "," "..." } + | CVariadic:"..." + | RegularAndCVariadic:{ inputs:FnSigInput+ % "," "," "..." } ; FnSigInput = { pat:Pat ":" }? ty:Type; From d3d3d02e9b28399e550969edb7c5c0e06b279e5b Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Sat, 28 Mar 2020 21:58:31 +0000 Subject: [PATCH 09/16] item: support const_trait_impl. --- grammar/item.lyg | 2 ++ 1 file changed, 2 insertions(+) diff --git a/grammar/item.lyg b/grammar/item.lyg index b5e368f..2d1ae89 100644 --- a/grammar/item.lyg +++ b/grammar/item.lyg @@ -33,6 +33,8 @@ ItemKind = // unstable(specialization): defaultness:"default"? unsafety:"unsafe"? "impl" generics:Generics? + // unstable(const_trait_impl) + constness:"const"? { negate:"!"? trait_path:Path "for" }? ty:Type where_clause:WhereClause? "{" attrs:InnerAttr* impl_items:ImplItem* "}" } From d3aa7dafc0a597091d0f572e045dac698caf1c27 Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Sat, 28 Mar 2020 23:10:36 +0000 Subject: [PATCH 10/16] generics: support const_trait_bound_opt_out. --- grammar/generics.lyg | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/grammar/generics.lyg b/grammar/generics.lyg index 6a0078c..add7a71 100644 --- a/grammar/generics.lyg +++ b/grammar/generics.lyg @@ -23,7 +23,10 @@ TypeBound = | Trait:TypeTraitBound | TraitParen:{ "(" bound:TypeTraitBound ")" } ; -TypeTraitBound = unbound:"?"? binder:ForAllBinder? path:Path; +TypeTraitBound = + // unstable(const_trait_bound_opt_out): + maybe_const:{ "?" "const" }? + maybe:"?"? binder:ForAllBinder? path:Path; // Generic args of a path segment. GenericArgs = From 62017c0372c6001bd0aee14b11a1387351f50f04 Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Sun, 29 Mar 2020 00:27:19 +0000 Subject: [PATCH 11/16] expr: support raw_ref_op. --- grammar/expr.lyg | 2 ++ 1 file changed, 2 insertions(+) diff --git a/grammar/expr.lyg b/grammar/expr.lyg index 910b2c6..b6b49da 100644 --- a/grammar/expr.lyg +++ b/grammar/expr.lyg @@ -2,6 +2,8 @@ Expr = attrs:OuterAttr* kind:ExprKind; ExprKind = | Literal:LITERAL | Paren:{ "(" attrs:InnerAttr* expr:Expr ")" } + // unstable(raw_ref_op): + | RawAddrOf:{ "&" "raw" { "const" | mutable:"mut" } expr:Expr } | Borrow:{ "&" mutable:"mut"? expr:Expr } | Box:{ "box" expr:Expr } | Unary:{ op:UnaryOp expr:Expr } From 2c34092b805d0f34713fd554bf5038ac3cb77575 Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Sun, 29 Mar 2020 11:13:12 +0000 Subject: [PATCH 12/16] coverage: strip shebangs. --- src/bin/coverage.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/bin/coverage.rs b/src/bin/coverage.rs index 75ca720..023df18 100644 --- a/src/bin/coverage.rs +++ b/src/bin/coverage.rs @@ -100,6 +100,17 @@ impl From> for Error { /// using the `ModuleContents` rule, and pass the result to `f`. fn parse_file(path: &Path) -> ModuleContentsResult { let src = fs::read_to_string(path).unwrap(); + + // Strip shebang, using the same logic as `rustc_lexer`. + // FIXME(rust-lang/rust#70528) this may have to change in the future. + let src = if src.starts_with("#!") && !src.starts_with("#![") { + // Remove the first line's contents, i.e. up to the `\n`, + // but keep the `\n` so that the line numbers remain correct. + &src[src.find('\n').unwrap_or(src.len())..] + } else { + &src[..] + }; + let tts = src.parse::()?; let res = parse::ModuleContents::parse(tts)?; Ok(res) From eeeae039dc1010c12d0907b7957b9cc5971a1ec0 Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Sun, 29 Mar 2020 18:44:54 +0000 Subject: [PATCH 13/16] item: fix TraitAlias syntax. --- grammar/item.lyg | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/grammar/item.lyg b/grammar/item.lyg index 2d1ae89..597804b 100644 --- a/grammar/item.lyg +++ b/grammar/item.lyg @@ -25,9 +25,8 @@ ItemKind = } // unstable(trait_alias): | TraitAlias:{ - "trait" name:IDENT generics:Generics? - { ":" superbounds:TypeBound* %% "+" }? - where_clause:WhereClause? "=" bounds:TypeBound* %% "+" ";" + "trait" name:IDENT generics:Generics? "=" bounds:TypeBound* %% "+" + where_clause:WhereClause? ";" } | Impl:{ // unstable(specialization): From 4ede4eae237b2cf4312d0f8ecf8def6d794ce434 Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Sun, 29 Mar 2020 18:51:04 +0000 Subject: [PATCH 14/16] pat: allow attributes in StructPatField. --- grammar/pat.lyg | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/grammar/pat.lyg b/grammar/pat.lyg index e0c66f2..83f483d 100644 --- a/grammar/pat.lyg +++ b/grammar/pat.lyg @@ -43,7 +43,8 @@ StructPatFieldsAndEllipsis = | FieldsAndEllipsis:{ fields:StructPatField+ % "," "," ".." } ; -StructPatField = +StructPatField = attrs:OuterAttr* kind:StructPatFieldKind; +StructPatFieldKind = | Shorthand:Binding | Explicit:{ field:FieldName ":" pat:Pat } ; From 152276a55b1c5287bbf1ee1cf4a170d81c706ab3 Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Sun, 29 Mar 2020 18:53:56 +0000 Subject: [PATCH 15/16] item: fix Trait to allow inner attributes. --- grammar/item.lyg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grammar/item.lyg b/grammar/item.lyg index 597804b..ad9bf38 100644 --- a/grammar/item.lyg +++ b/grammar/item.lyg @@ -21,7 +21,7 @@ ItemKind = auto:"auto"? "trait" name:IDENT generics:Generics? { ":" superbounds:TypeBound* %% "+" }? - where_clause:WhereClause? "{" trait_items:TraitItem* "}" + where_clause:WhereClause? "{" attrs:InnerAttr* trait_items:TraitItem* "}" } // unstable(trait_alias): | TraitAlias:{ From 556030209725dc84a242b7afc11dab06ff4be542 Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Sun, 29 Mar 2020 19:49:14 +0000 Subject: [PATCH 16/16] item,expr,type: generalize parameter attributes to closures and fn(...) types. --- grammar/expr.lyg | 2 +- grammar/item.lyg | 4 ++-- grammar/type.lyg | 7 ++++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/grammar/expr.lyg b/grammar/expr.lyg index b6b49da..28ed079 100644 --- a/grammar/expr.lyg +++ b/grammar/expr.lyg @@ -129,4 +129,4 @@ ElseExpr = MatchArm = attrs:OuterAttr* "|"? pat:Pat { "if" guard:Expr }? "=>" body:Expr ","?; -ClosureArg = pat:Pat { ":" ty:Type }?; +ClosureArg = attrs:OuterAttr* pat:Pat { ":" ty:Type }?; diff --git a/grammar/item.lyg b/grammar/item.lyg index ad9bf38..4986fc5 100644 --- a/grammar/item.lyg +++ b/grammar/item.lyg @@ -98,10 +98,10 @@ FnParam = attrs:OuterAttr* kind:FnParamKind; FnParamKind = | SelfValue:{ mutable:"mut"? "self" } | SelfRef:{ "&" lt:LIFETIME? mutable:"mut"? "self" } - | Regular:FnSigInput + | Regular:{ { pat:Pat ":" }? ty:Type } ; // unstable(c_variadic): -FnCVariadicParam = { pat:Pat ":" }? "..."; +FnCVariadicParam = attrs:OuterAttr* { pat:Pat ":" }? "..."; EnumVariant = attrs:OuterAttr* name:IDENT kind:EnumVariantKind { "=" discr:Expr }?; EnumVariantKind = diff --git a/grammar/type.lyg b/grammar/type.lyg index 52fef97..18674bb 100644 --- a/grammar/type.lyg +++ b/grammar/type.lyg @@ -21,7 +21,8 @@ Type = FnSigInputs = | Regular:FnSigInput+ %% "," - | CVariadic:"..." - | RegularAndCVariadic:{ inputs:FnSigInput+ % "," "," "..." } + | CVariadic:FnSigCVariadicInput + | RegularAndCVariadic:{ inputs:FnSigInput+ % "," "," c_variadic:FnSigCVariadicInput } ; -FnSigInput = { pat:Pat ":" }? ty:Type; +FnSigInput = attrs:OuterAttr* { pat:Pat ":" }? ty:Type; +FnSigCVariadicInput = attrs:OuterAttr* "...";