Skip to content

Update syntax in docs #10635

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,8 @@ object Parsers {
/** Singleton ::= SimpleRef
* | SimpleLiteral
* | Singleton ‘.’ id
* -- not yet | Singleton ‘(’ Singletons ‘)’
* -- not yet | Singleton ‘[’ Types ‘]’
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not an issue of this PR, but why are Singletons required to be non-empty?

*/
def singleton(): Tree =
if isSimpleLiteral then simpleLiteral()
Expand Down
7 changes: 2 additions & 5 deletions docs/docs/internals/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ AnnotType ::= SimpleType {Annotation}

SimpleType ::= SimpleLiteral SingletonTypeTree(l)
| ‘?’ TypeBounds
| SimpleType1 { ‘(’ Singletons ‘)’ }
| SimpleType1
SimpleType1 ::= id Ident(name)
| Singleton ‘.’ id Select(t, name)
| Singleton ‘.’ ‘type’ SingletonTypeTree(p)
Expand All @@ -169,8 +169,6 @@ SimpleType1 ::= id
Singleton ::= SimpleRef
| SimpleLiteral
| Singleton ‘.’ id
-- not yet | Singleton ‘(’ Singletons ‘)’
-- not yet | Singleton ‘[’ Types ‘]’
Singletons ::= Singleton { ‘,’ Singleton }
FunArgType ::= Type
| ‘=>’ Type PrefixOp(=>, t)
Expand Down Expand Up @@ -205,11 +203,9 @@ Expr1 ::= [‘inline’] ‘if’ ‘(’ Expr ‘)’ {nl} Expr [[
| [SimpleExpr ‘.’] id ‘=’ Expr Assign(expr, expr)
| SimpleExpr1 ArgumentExprs ‘=’ Expr Assign(expr, expr)
| PostfixExpr [Ascription]
| StructuralInstance
| ‘inline’ InfixExpr MatchClause
Ascription ::= ‘:’ InfixType Typed(expr, tp)
| ‘:’ Annotation {Annotation} Typed(expr, Annotated(EmptyTree, annot)*)
StructuralInstance ::= ConstrApp {‘with’ ConstrApp} ‘with’ TemplateBody New templ
Catches ::= ‘catch’ (Expr | ExprCaseClause)
PostfixExpr ::= InfixExpr [id] PostfixOp(expr, op)
InfixExpr ::= PrefixExpr
Expand Down Expand Up @@ -400,6 +396,7 @@ ObjectDef ::= id [Template]
EnumDef ::= id ClassConstr InheritClauses EnumBody EnumDef(mods, name, tparams, template)
GivenDef ::= [GivenSig] (Type [‘=’ 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
ExtMethods ::= ExtMethod | [nl] ‘{’ ExtMethod {semi ExtMethod ‘}’
Expand Down
10 changes: 10 additions & 0 deletions docs/docs/reference/contextual/derivation.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,16 @@ ConstrApps ::= ConstrApp {‘with’ ConstrApp}
| ConstrApp {‘,’ ConstrApp}
```

Note: To align `extends` clauses and `derives` clauses, Scala 3 also allows multiple
extended types to be separated by commas. So the following is now legal:
```
class A extends B, C { ... }
```
It is equivalent to the old form
```
class A extends B with C { ... }
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will the with form be deprecated? Should we say something about which form is recommended?


### Discussion

This type class derivation framework is intentionally very small and low-level. There are essentially two pieces of
Expand Down
10 changes: 7 additions & 3 deletions docs/docs/reference/other-new-features/control-syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,20 @@ for
y <- ys
do
println(x + y)

try body
catch case ex: IOException => handle
```

The rules in detail are:

- The condition of an `if`-expression can be written without enclosing parentheses if it is followed by a `then`
or some [indented](./indentation.html) code on a following line.
- The condition of an `if`-expression can be written without enclosing parentheses if it is followed by a `then`.
- The condition of a `while`-loop can be written without enclosing parentheses if it is followed by a `do`.
- The enumerators of a `for`-expression can be written without enclosing parentheses or braces if they are followed by a `yield` or `do`.
- A `do` in a `for`-expression expresses a `for`-loop.

- A `catch` can be followed by a single case on the same line.
If there are multiple cases, these have to be appear within braces (just like in Scala-2)
or an indented block.
### Rewrites

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