Skip to content

Commit 490b879

Browse files
committed
Add explanation to docs
1 parent 7b2708f commit 490b879

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

docs/docs/reference/other-new-features/indentation.md

+11-9
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ or
6969
Colons at the end of lines are their own token, distinct from normal `:`.
7070
The Scala grammar is changed so that colons at end of lines are accepted at all points
7171
where an opening brace is legal, except if the previous token can already start an
72-
indentation region.
72+
indentation region. Special provisions are taken so that method result types can still use a colon on
73+
the end of a line, followed by the actual type on the next.
7374

7475
### Special Treatment of Case Clauses
7576

@@ -93,7 +94,6 @@ case 5 => print("V")
9394
println(".")
9495
```
9596

96-
9797
### The End Marker
9898

9999
Indentation-based syntax has many advantages over other conventions. But one possible problem is that it makes it hard to discern when a large indentation region ends, since there is no specific token that delineates the end. Braces are not much better since a brace by itself also contains no information about what region is closed.
@@ -148,14 +148,16 @@ enum IndentWidth:
148148
def < (that: IndentWidth): Boolean = this <= that && !(that <= this)
149149

150150
override def toString: String =
151-
def kind(ch: Char) = ch match
152-
case ' ' => "space"
153-
case '\t' => "tab"
154-
case _ => s"'$ch'-character"
155-
156151
this match
157-
case Run(ch, n) => s"$n ${kind(ch)}${if (n == 1) "" else "s"}"
158-
case Conc(l, r) => s"$l, $r"
152+
case Run(ch, n) =>
153+
val kind = ch match
154+
case ' ' => "space"
155+
case '\t' => "tab"
156+
case _ => s"'$ch'-character"
157+
val suffix = if n == 1 then "" else "s"
158+
s"$n $kind$suffix"
159+
case Conc(l, r) =>
160+
s"$l, $r"
159161

160162
object IndentWidth:
161163
private inline val MaxCached = 40

0 commit comments

Comments
 (0)