Skip to content

Commit

Permalink
Add explanation to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
odersky committed Aug 22, 2019
1 parent 7b2708f commit 490b879
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions docs/docs/reference/other-new-features/indentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ or
Colons at the end of lines are their own token, distinct from normal `:`.
The Scala grammar is changed so that colons at end of lines are accepted at all points
where an opening brace is legal, except if the previous token can already start an
indentation region.
indentation region. Special provisions are taken so that method result types can still use a colon on
the end of a line, followed by the actual type on the next.

### Special Treatment of Case Clauses

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


### The End Marker

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.
Expand Down Expand Up @@ -148,14 +148,16 @@ enum IndentWidth:
def < (that: IndentWidth): Boolean = this <= that && !(that <= this)

override def toString: String =
def kind(ch: Char) = ch match
case ' ' => "space"
case '\t' => "tab"
case _ => s"'$ch'-character"

this match
case Run(ch, n) => s"$n ${kind(ch)}${if (n == 1) "" else "s"}"
case Conc(l, r) => s"$l, $r"
case Run(ch, n) =>
val kind = ch match
case ' ' => "space"
case '\t' => "tab"
case _ => s"'$ch'-character"
val suffix = if n == 1 then "" else "s"
s"$n $kind$suffix"
case Conc(l, r) =>
s"$l, $r"

object IndentWidth:
private inline val MaxCached = 40
Expand Down

0 comments on commit 490b879

Please sign in to comment.