You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If an `<indent>` is inserted, the indentation width of the token on the next line
67
67
is pushed onto `IW`, which makes it the new current indentation width.
@@ -90,65 +90,57 @@ if x < 0
90
90
Indentation tokens are only inserted in regions where newline statement separators are also inferred:
91
91
at the toplevel, inside braces `{...}`, but not inside parentheses `(...)`, patterns or types.
92
92
93
-
###NewRole of With
93
+
###OptionalBracesAroundTemplateBodies
94
94
95
-
To make bracews optional for constructs like classbodies, the syntax of the language is changed so that a classbody or similar construct may optionally be prefixed with`with`. Since `with` can start an indentation region, this means that all of the following syntaxes are allowed and are equivalent:
96
-
```scala
97
-
traitA {
98
-
deff:Any
99
-
}
100
-
classC(x: Int) extendsA {
101
-
deff= x
102
-
}
103
-
typeT=A {
104
-
deff:Int
105
-
}
106
-
```
107
-
---
108
-
```scala
109
-
traitA: {
110
-
deff:Int
111
-
}
112
-
classC(x: Int) extendsA: {
113
-
deff= x
114
-
}
115
-
typeT=A: {
116
-
deff:Int
117
-
}
118
-
```
119
-
---
95
+
TheScala grammar uses the term _template body_ for the definitions of a class, trait, object, giveninstance or extension that are normally enclosed in braces. The braces around a template body can also be omitted by means of the following rule:
96
+
97
+
If at the point where a template body can start there is a `:` that occurs at the end
98
+
of a line, and that is followed by at least one indented statement, the recognized
99
+
token is changed from ":" to ": at end of line". The latter token is one of the tokens
100
+
that can start an indentation region. TheScala grammar is changed so an optional ": at end of line" is allowed in front of a template body.
101
+
102
+
Analogous rules apply forenumbodies, typerefinements, definitions in an instance creation expressions, and local packages containing nested definitions.
103
+
104
+
With these new rules, the following constructs are all valid:
It is assumed here that braces following a `with` can be transparently replaced by an
139
-
indentation region.
121
+
given [T] withOrd[T] as Ord[List[T]]:
122
+
defcompare(x: List[T], y: List[T]) =???
140
123
141
-
With the new indentation rules, the previously allowed syntax
142
-
```
143
-
classAextendsBwith
144
-
C
124
+
extension on (xs: List[Int]):
125
+
defsecond:Int= xs.tail.head
126
+
127
+
newA:
128
+
deff=3
129
+
130
+
packagep:
131
+
defa=1
132
+
packageq:
133
+
defb=2
145
134
```
146
-
becomes illegal since `C` above would be terated asa nested statement inside `A`. More generally, a `with` that separates parent constructors cannot be at the end of a line. One has to write
instead (or replace the "`with`" by a "`,`"). When compiling in Scala-2 mode, a migration warning is issued for the illegal syntax and a (manual) rewrite is suggested.
143
+
Here, `colonEol` stands for": at end of line", asdescribed above.
0 commit comments