Skip to content

Commit d724f2b

Browse files
committed
Fixes to syntax and docs
1 parent d79c66e commit d724f2b

File tree

4 files changed

+15
-12
lines changed

4 files changed

+15
-12
lines changed

docs/docs/internals/syntax.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ ObjectDef ::= id [Template]
388388
EnumDef ::= id ClassConstr InheritClauses EnumBody EnumDef(mods, name, tparams, template)
389389
GivenDef ::= [GivenSig (‘:’ | <:)] Type ‘=’ Expr
390390
| [GivenSig ‘:’] [ConstrApp {‘,’ ConstrApp }] [TemplateBody]
391-
| [id ‘:’] [ExtParamClause] TemplateBody
391+
| [GivenSig ‘:’] [ExtParamClause] TemplateBody
392392
GivenSig ::= [id] [DefTypeParamClause] {GivenParamClause}
393393
ExtParamClause ::= [DefTypeParamClause] ‘(’ DefParam ‘)’ {GivenParamClause}
394394
Template ::= InheritClauses [TemplateBody] Template(constr, parents, self, stats)

docs/docs/reference/contextual-new/delegates.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,6 @@ GivenDef ::= [GivenSig (‘:’ | <:)] Type ‘=’ Expr
8282
| [GivenSig ‘:’] [ConstrApp {‘,’ ConstrApp }] [TemplateBody]
8383
GivenSig ::= [id] [DefTypeParamClause] {GivenParamClause}
8484
GivenParamClause ::= ‘(’ ‘given’ (DefParams | GivenTypes) ‘)’
85-
GivenTypes ::= AnnotType {‘,’ AnnotType}
85+
GivenTypes ::= Type {‘,’ Type}
8686
```
8787
The identifier `id` can be omitted only if some types are implemented or the template body defines at least one extension method.

docs/docs/reference/contextual-new/extension-methods.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ So `circle.circumference` translates to `CircleOps.circumference(circle)`, provi
8080

8181
### Given Instances for Extension Methods
8282

83-
Given instances that define extension methods can also be defined without an `as` clause. E.g.,
83+
Given instances that define extension methods can also be defined without a parent. E.g.,
8484

8585
```scala
86-
given StringOps {
86+
given stringOps: {
8787
def (xs: Seq[String]) longestStrings: Seq[String] = {
8888
val maxLength = xs.map(_.length).max
8989
xs.filter(_.length == maxLength)
@@ -98,18 +98,18 @@ If such given instances are anonymous (as in the second clause), their name is s
9898

9999
### Given Instances with Collective Parameters
100100

101-
If a given instance has several extension methods one can pull out the left parameter section
101+
If a given instance has no parent but several extension methods one can pull out the left parameter section
102102
as well as any type parameters of these extension methods into the given instance itself.
103103
For instance, here is a given instance with two extension methods.
104104
```scala
105-
given ListOps {
105+
given listOps: {
106106
def (xs: List[T]) second[T]: T = xs.tail.head
107107
def (xs: List[T]) third[T]: T = xs.tail.tail.head
108108
}
109109
```
110110
The repetition in the parameters can be avoided by moving the parameters into the given instance itself. The following version is a shorthand for the code above.
111111
```scala
112-
given ListOps[T](xs: List[T]) {
112+
given listOps: [T](xs: List[T]) {
113113
def second: T = xs.tail.head
114114
def third: T = xs.tail.tail.head
115115
}
@@ -168,6 +168,7 @@ to the [current syntax](../../internals/syntax.md).
168168
```
169169
DefSig ::= ...
170170
| ‘(’ DefParam ‘)’ [nl] id [DefTypeParamClause] DefParamClauses
171-
GivenBody ::= ...
172-
| ‘(’ DefParam ‘)’ TemplateBody
171+
GivenDef ::= ...
172+
[GivenSig ‘:’] [ExtParamClause] TemplateBody
173+
ExtParamClause ::= [DefTypeParamClause] ‘(’ DefParam ‘)’ {GivenParamClause}
173174
```

docs/docs/reference/contextual-new/implicit-function-types-spec.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ title: "Implicit Function Types - More Details"
66
## Syntax
77

88
Type ::= ...
9-
| `(' `given' FunArgTypes `)' `=>' Type
10-
Expr ::= ...
11-
| `(' `given' FunParams `)' `=>' Expr
9+
| FunArgTypes ‘=>’ Typee
10+
FunArgTypes ::= InfixType
11+
| ‘(’ [ ‘[given]’ FunArgType {‘,’ FunArgType } ] ‘)’
12+
| ‘(’ ‘[given]’ TypedFunParam {‘,’ TypedFunParam } ‘)’
13+
Bindings ::= ‘(’ [[‘given’] Binding {‘,’ Binding}] ‘)’
1214

1315
Implicit function types associate to the right, e.g.
1416
`(given S) => (given T) => U` is the same as `(given S) => ((given T) => U)`.

0 commit comments

Comments
 (0)