Skip to content

Commit b6a1a3d

Browse files
committed
Update syntax in docs
1 parent bbdbdf2 commit b6a1a3d

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,8 @@ object Parsers {
10911091
/** Singleton ::= SimpleRef
10921092
* | SimpleLiteral
10931093
* | Singleton ‘.’ id
1094+
* -- not yet | Singleton ‘(’ Singletons ‘)’
1095+
* -- not yet | Singleton ‘[’ Types ‘]’
10941096
*/
10951097
def singleton(): Tree =
10961098
if isSimpleLiteral then simpleLiteral()

docs/docs/internals/syntax.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ AnnotType ::= SimpleType {Annotation}
157157
158158
SimpleType ::= SimpleLiteral SingletonTypeTree(l)
159159
| ‘?’ TypeBounds
160-
| SimpleType1 { ‘(’ Singletons ‘)’ }
160+
| SimpleType1
161161
SimpleType1 ::= id Ident(name)
162162
| Singleton ‘.’ id Select(t, name)
163163
| Singleton ‘.’ ‘type’ SingletonTypeTree(p)
@@ -169,8 +169,6 @@ SimpleType1 ::= id
169169
Singleton ::= SimpleRef
170170
| SimpleLiteral
171171
| Singleton ‘.’ id
172-
-- not yet | Singleton ‘(’ Singletons ‘)’
173-
-- not yet | Singleton ‘[’ Types ‘]’
174172
Singletons ::= Singleton { ‘,’ Singleton }
175173
FunArgType ::= Type
176174
| ‘=>’ Type PrefixOp(=>, t)
@@ -205,11 +203,9 @@ Expr1 ::= [‘inline’] ‘if’ ‘(’ Expr ‘)’ {nl} Expr [[
205203
| [SimpleExpr ‘.’] id ‘=’ Expr Assign(expr, expr)
206204
| SimpleExpr1 ArgumentExprs ‘=’ Expr Assign(expr, expr)
207205
| PostfixExpr [Ascription]
208-
| StructuralInstance
209206
| ‘inline’ InfixExpr MatchClause
210207
Ascription ::= ‘:’ InfixType Typed(expr, tp)
211208
| ‘:’ Annotation {Annotation} Typed(expr, Annotated(EmptyTree, annot)*)
212-
StructuralInstance ::= ConstrApp {‘with’ ConstrApp} ‘with’ TemplateBody New templ
213209
Catches ::= ‘catch’ (Expr | ExprCaseClause)
214210
PostfixExpr ::= InfixExpr [id] PostfixOp(expr, op)
215211
InfixExpr ::= PrefixExpr
@@ -400,6 +396,7 @@ ObjectDef ::= id [Template]
400396
EnumDef ::= id ClassConstr InheritClauses EnumBody EnumDef(mods, name, tparams, template)
401397
GivenDef ::= [GivenSig] (Type [‘=’ Expr] | StructuralInstance)
402398
GivenSig ::= [id] [DefTypeParamClause] {UsingParamClause} ‘:’ -- one of `id`, `DefParamClause`, `UsingParamClause` must be present
399+
StructuralInstance ::= ConstrApp {‘with’ ConstrApp} ‘with’ TemplateBody
403400
Extension ::= ‘extension’ [DefTypeParamClause] ‘(’ DefParam ‘)’
404401
{UsingParamClause}] ExtMethods
405402
ExtMethods ::= ExtMethod | [nl] ‘{’ ExtMethod {semi ExtMethod ‘}’

docs/docs/reference/contextual/derivation.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,16 @@ ConstrApps ::= ConstrApp {‘with’ ConstrApp}
371371
| ConstrApp {‘,’ ConstrApp}
372372
```
373373

374+
Note: To align `extends` clauses and `derives` clauses, Scala 3 also allows multiple
375+
extended types to be separated by commas. So the following is now legal:
376+
```
377+
class A extends B, C { ... }
378+
```
379+
It is equivalent to the old form
380+
```
381+
class A extends B with C { ... }
382+
```
383+
374384
### Discussion
375385

376386
This type class derivation framework is intentionally very small and low-level. There are essentially two pieces of

docs/docs/reference/other-new-features/control-syntax.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,20 @@ for
2626
y <- ys
2727
do
2828
println(x + y)
29+
30+
try body
31+
catch case ex: IOException => handle
2932
```
3033

3134
The rules in detail are:
3235

33-
- The condition of an `if`-expression can be written without enclosing parentheses if it is followed by a `then`
34-
or some [indented](./indentation.html) code on a following line.
36+
- The condition of an `if`-expression can be written without enclosing parentheses if it is followed by a `then`.
3537
- The condition of a `while`-loop can be written without enclosing parentheses if it is followed by a `do`.
3638
- The enumerators of a `for`-expression can be written without enclosing parentheses or braces if they are followed by a `yield` or `do`.
3739
- A `do` in a `for`-expression expresses a `for`-loop.
38-
40+
- A `catch` can be followed by a single case on the same line.
41+
If there are multiple cases, these have to be appear within braces (just like in Scala-2)
42+
or an indented block.
3943
### Rewrites
4044

4145
The Dotty compiler can rewrite source code from old syntax to new syntax and back.

0 commit comments

Comments
 (0)