From 216020931170affb9cb7ed37fd252cc753b6dd3c Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 15 Jul 2021 14:12:32 +0200 Subject: [PATCH] Fix syntax of extension methods Allow leading using parameter clauses. This aligns spec and actual parser. Fixes #13027 --- compiler/src/dotty/tools/dotc/parsing/Parsers.scala | 2 +- docs/docs/internals/syntax.md | 4 ++-- docs/docs/reference/contextual/extension-methods.md | 4 ++-- docs/docs/reference/syntax.md | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 5e360f5a4a01..dabfcea2df98 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -3627,7 +3627,7 @@ object Parsers { finalizeDef(gdef, mods1, start) } - /** Extension ::= ‘extension’ [DefTypeParamClause] ‘(’ DefParam ‘)’ + /** Extension ::= ‘extension’ [DefTypeParamClause] {UsingParamClause} ‘(’ DefParam ‘)’ * {UsingParamClause} ExtMethods */ def extension(): ExtMethods = diff --git a/docs/docs/internals/syntax.md b/docs/docs/internals/syntax.md index 3522923ad47e..f3f60dc50a13 100644 --- a/docs/docs/internals/syntax.md +++ b/docs/docs/internals/syntax.md @@ -414,8 +414,8 @@ EnumDef ::= id ClassConstr InheritClauses EnumBody GivenDef ::= [GivenSig] (AnnotType [‘=’ Expr] | StructuralInstance) GivenSig ::= [id] [DefTypeParamClause] {UsingParamClause} ‘:’ -- one of `id`, `DefParamClause`, `UsingParamClause` must be present StructuralInstance ::= ConstrApp {‘with’ ConstrApp} [‘with’ TemplateBody] -Extension ::= ‘extension’ [DefTypeParamClause] ‘(’ DefParam ‘)’ - {UsingParamClause} ExtMethods +Extension ::= ‘extension’ [DefTypeParamClause] {UsingParamClause} + ‘(’ DefParam ‘)’ {UsingParamClause} ExtMethods ExtMethods ::= ExtMethod | [nl] <<< ExtMethod {semi ExtMethod} >>> ExtMethod ::= {Annotation [nl]} {Modifier} ‘def’ DefDef Template ::= InheritClauses [TemplateBody] diff --git a/docs/docs/reference/contextual/extension-methods.md b/docs/docs/reference/contextual/extension-methods.md index 094e6b1c7465..2c6ee9c93520 100644 --- a/docs/docs/reference/contextual/extension-methods.md +++ b/docs/docs/reference/contextual/extension-methods.md @@ -288,8 +288,8 @@ to the [current syntax](../syntax.md). BlockStat ::= ... | Extension TemplateStat ::= ... | Extension TopStat ::= ... | Extension -Extension ::= ‘extension’ [DefTypeParamClause] ‘(’ DefParam ‘)’ - {UsingParamClause} ExtMethods +Extension ::= ‘extension’ [DefTypeParamClause] {UsingParamClause} + ‘(’ DefParam ‘)’ {UsingParamClause} ExtMethods ExtMethods ::= ExtMethod | [nl] <<< ExtMethod {semi ExtMethod} >>> ExtMethod ::= {Annotation [nl]} {Modifier} ‘def’ DefDef ``` diff --git a/docs/docs/reference/syntax.md b/docs/docs/reference/syntax.md index e3201d7f8739..2ececb4a87d4 100644 --- a/docs/docs/reference/syntax.md +++ b/docs/docs/reference/syntax.md @@ -400,8 +400,8 @@ EnumDef ::= id ClassConstr InheritClauses EnumBody GivenDef ::= [GivenSig] (AnnotType [‘=’ Expr] | StructuralInstance) GivenSig ::= [id] [DefTypeParamClause] {UsingParamClause} ‘:’ -- one of `id`, `DefParamClause`, `UsingParamClause` must be present StructuralInstance ::= ConstrApp {‘with’ ConstrApp} [‘with’ TemplateBody] -Extension ::= ‘extension’ [DefTypeParamClause] ‘(’ DefParam ‘)’ - {UsingParamClause} ExtMethods +Extension ::= ‘extension’ [DefTypeParamClause] {UsingParamClause} + ‘(’ DefParam ‘)’ {UsingParamClause} ExtMethods ExtMethods ::= ExtMethod | [nl] <<< ExtMethod {semi ExtMethod} >>> ExtMethod ::= {Annotation [nl]} {Modifier} ‘def’ DefDef Template ::= InheritClauses [TemplateBody]