Skip to content

Commit

Permalink
Remove old mention of the fewerBraces
Browse files Browse the repository at this point in the history
  • Loading branch information
Kordyjan committed Nov 17, 2022
1 parent 8f8c3a4 commit 921e63f
Showing 1 changed file with 0 additions and 59 deletions.
59 changes: 0 additions & 59 deletions docs/_docs/reference/other-new-features/indentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -502,62 +502,3 @@ indented regions where possible. When invoked with options `-rewrite -no-indent`
The `-indent` option only works on [new-style syntax](./control-syntax.md). So to go from old-style syntax to new-style indented code one has to invoke the compiler twice, first with options `-rewrite -new-syntax`, then again with options
`-rewrite -indent`. To go in the opposite direction, from indented code to old-style syntax, it's `-rewrite -no-indent`, followed by `-rewrite -old-syntax`.

### Variant: Indentation Marker `:` for Arguments

Generally, the possible indentation regions coincide with those regions where braces `{...}` are also legal, no matter whether the braces enclose an expression or a set of definitions. There is one exception, though: Arguments to functions can be enclosed in braces but they cannot be simply indented instead. Making indentation always significant for function arguments would be too restrictive and fragile.

To allow such arguments to be written without braces, a variant of the indentation scheme is implemented under language import
```scala
import language.experimental.fewerBraces
```
In this variant, a `<colon>` token is also recognized where function argument would be expected. Examples:

```scala
times(10):
println("ah")
println("ha")
```

or

```scala
credentials `++`:
val file = Path.userHome / ".credentials"
if file.exists
then Seq(Credentials(file))
else Seq()
```

or

```scala
xs.map:
x =>
val y = x - 1
y * y
```
What's more, a `:` in these settings can also be followed on the same line by the parameter part and arrow of a lambda. So the last example could be compressed to this:

```scala
xs.map: x =>
val y = x - 1
y * y
```
and the following would also be legal:
```scala
xs.foldLeft(0): (x, y) =>
x + y
```

The grammar changes for this variant are as follows.

```
SimpleExpr ::= ...
| SimpleExpr ColonArgument
InfixExpr ::= ...
| InfixExpr id ColonArgument
ColonArgument ::= colon [LambdaStart]
indent (CaseClauses | Block) outdent
LambdaStart ::= FunParams (‘=>|?=>’)
| HkTypeParamClause=>
```

0 comments on commit 921e63f

Please sign in to comment.