Skip to content

Commit a420945

Browse files
committed
Patch indentation when removing braces (cosmetic)
1 parent 236c117 commit a420945

File tree

1 file changed

+47
-47
lines changed

1 file changed

+47
-47
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,6 +1245,7 @@ object Parsers:
12451245
case _ =>
12461246
syntaxErrorOrIncomplete(IllegalLiteral())
12471247
atSpan(negOffset) { Literal(Constant(null)) }
1248+
}
12481249
nextToken()
12491250
t
12501251
else atSpan(negOffset):
@@ -1256,6 +1257,8 @@ object Parsers:
12561257
case TRUE | FALSE | NULL => literalOf(tok)
12571258
case THIS => This(EmptyTypeIdent)
12581259
case _ => Ident(in.name)
1260+
}
1261+
}
12591262
nextToken()
12601263
Quote(t, Nil)
12611264
else
@@ -1292,10 +1295,11 @@ object Parsers:
12921295
atSpan(in.offset) {
12931296
if (in.token == IDENTIFIER)
12941297
termIdent()
1295-
else if (in.token == USCORE && inPattern)
1298+
else if (in.token == USCORE && inPattern) {
12961299
nextToken()
12971300
Ident(nme.WILDCARD)
1298-
else if (in.token == THIS)
1301+
}
1302+
else if (in.token == THIS) {
12991303
nextToken()
13001304
This(EmptyTypeIdent)
13011305
else if (in.token == LBRACE)
@@ -1526,9 +1530,9 @@ object Parsers:
15261530
var isValParamList = false
15271531

15281532
val t =
1529-
if (in.token == LPAREN)
1533+
if (in.token == LPAREN) {
15301534
nextToken()
1531-
if (in.token == RPAREN)
1535+
if (in.token == RPAREN) {
15321536
nextToken()
15331537
functionRest(Nil)
15341538
else
@@ -1575,7 +1579,7 @@ object Parsers:
15751579
val tparams = typeParamClause(ParamOwner.TypeParam)
15761580
if (in.token == TLARROW)
15771581
atSpan(start, skipToken())(LambdaTypeTree(tparams, toplevelTyp()))
1578-
else if (in.token == ARROW || isPureArrow(nme.PUREARROW))
1582+
else if (in.token == ARROW || isPureArrow(nme.PUREARROW)) {
15791583
val arrowOffset = skipToken()
15801584
val body = toplevelTyp()
15811585
atSpan(start, arrowOffset):
@@ -1737,9 +1741,8 @@ object Parsers:
17371741
atSpan(in.offset):
17381742
val inPattern = (staged & StageKind.QuotedPattern) != 0
17391743
val expr =
1740-
if (in.name.length == 1)
1744+
if (in.name.length == 1) {
17411745
nextToken()
1742-
val inPattern = (staged & StageKind.QuotedPattern) != 0
17431746
withinStaged(StageKind.Spliced)(if (inPattern) inBraces(pattern()) else stagedBlock())
17441747
else atSpan(in.offset + 1):
17451748
val id = Ident(in.name.drop(1))
@@ -1932,7 +1935,7 @@ object Parsers:
19321935
*/
19331936
def paramValueType(): Tree =
19341937
val t = maybeInto(toplevelTyp)
1935-
if (isIdent(nme.raw.STAR))
1938+
if (isIdent(nme.raw.STAR)) {
19361939
nextToken()
19371940
atSpan(startOffset(t)) { PostfixOp(t, Ident(tpnme.raw.STAR)) }
19381941
else t
@@ -2112,7 +2115,7 @@ object Parsers:
21122115
case IF =>
21132116
ifExpr(in.offset, If)
21142117
case WHILE =>
2115-
atSpan(skipToken()):
2118+
atSpan(skipToken()) {
21162119
val cond = condExpr(DO)
21172120
newLinesOpt()
21182121
val body = subExpr()
@@ -2123,7 +2126,7 @@ object Parsers:
21232126
|use `while <body> ; <cond> do ()` instead.${rewriteNotice()}""",
21242127
in.sourcePos(), from = `3.0`)
21252128
val start = skipToken()
2126-
atSpan(start):
2129+
atSpan(start) {
21272130
val body = expr()
21282131
if (isStatSep) nextToken()
21292132
val whileStart = in.offset
@@ -2141,7 +2144,7 @@ object Parsers:
21412144
WhileDo(Block(body, cond), Literal(Constant(())))
21422145
case TRY =>
21432146
val tryOffset = in.offset
2144-
atSpan(skipToken()):
2147+
atSpan(skipToken()) {
21452148
val body = expr()
21462149
val (handler, handlerStart) =
21472150
if in.token == CATCH then
@@ -2162,7 +2165,7 @@ object Parsers:
21622165
case _ =>
21632166

21642167
val finalizer =
2165-
if (in.token == FINALLY)
2168+
if (in.token == FINALLY) {
21662169
nextToken();
21672170
val expr = subExpr()
21682171
if expr.span.exists then expr
@@ -2178,7 +2181,7 @@ object Parsers:
21782181
case THROW =>
21792182
atSpan(skipToken()) { Throw(expr()) }
21802183
case RETURN =>
2181-
atSpan(skipToken()):
2184+
atSpan(skipToken()) {
21822185
Return(if (isExprIntro) expr() else EmptyTree, EmptyTree)
21832186
case FOR =>
21842187
forExpr()
@@ -2205,7 +2208,7 @@ object Parsers:
22052208
if in.token == EQUALS then
22062209
t match
22072210
case Ident(_) | Select(_, _) | Apply(_, _) | PrefixOp(_, _) =>
2208-
atSpan(startOffset(t), skipToken()):
2211+
atSpan(startOffset(t), skipToken()) {
22092212
val loc = if location.inArgs then location else Location.ElseWhere
22102213
Assign(t, subPart(() => expr(loc)))
22112214
case _ =>
@@ -2251,7 +2254,7 @@ object Parsers:
22512254
* `if' Expr `then' Expr [[semi] else Expr]
22522255
*/
22532256
def ifExpr(start: Offset, mkIf: (Tree, Tree, Tree) => If): If =
2254-
atSpan(start, skipToken()):
2257+
atSpan(start, skipToken()) {
22552258
val cond = condExpr(THEN)
22562259
newLinesOpt()
22572260
val thenp = subExpr()
@@ -2262,7 +2265,7 @@ object Parsers:
22622265
/** MatchClause ::= `match' `{' CaseClauses `}'
22632266
*/
22642267
def matchClause(t: Tree): Match =
2265-
atSpan(startOffset(t), skipToken()):
2268+
atSpan(startOffset(t), skipToken()) {
22662269
Match(t, inBracesOrIndented(caseClauses(() => caseClause())))
22672270

22682271
/** `match' `{' TypeCaseClauses `}'
@@ -2312,7 +2315,7 @@ object Parsers:
23122315
makeParameter(bindingName(), typedOpt(), mods1)
23132316

23142317
def bindingName(): TermName =
2315-
if (in.token == USCORE)
2318+
if (in.token == USCORE) {
23162319
nextToken()
23172320
WildcardParamName.fresh()
23182321
else ident()
@@ -2416,8 +2419,8 @@ object Parsers:
24162419
canApply = false
24172420
blockExpr(inStatSeq)
24182421
case QUOTE =>
2419-
atSpan(skipToken()):
2420-
withinStaged(StageKind.Quoted | (if (location.inPattern) StageKind.QuotedPattern else 0)):
2422+
atSpan(skipToken()) {
2423+
withinStaged(StageKind.Quoted | (if (location.inPattern) StageKind.QuotedPattern else 0)) {
24212424
val body =
24222425
if (in.token == LBRACKET) inBrackets(typ())
24232426
else stagedBlock()
@@ -2466,7 +2469,7 @@ object Parsers:
24662469
makeParameter(name.asTermName, typedOpt(), Modifiers(), isBackquoted = isBackquoted(id))
24672470
case _ => t
24682471
else if isColonLambda then
2469-
val app = atSpan(startOffset(t), skipToken()):
2472+
val app = atSpan(startOffset(t), skipToken()) {
24702473
Apply(t, expr(Location.InColonArg) :: Nil)
24712474
simpleExprRest(app, location, canApply = true)
24722475
else t
@@ -2597,7 +2600,7 @@ object Parsers:
25972600
def enumerators(): List[Tree] = generator() :: enumeratorsRest()
25982601

25992602
def enumeratorsRest(): List[Tree] =
2600-
if (isStatSep)
2603+
if (isStatSep) {
26012604
nextToken()
26022605
if (in.token == DO || in.token == YIELD || in.token == RBRACE) Nil
26032606
else enumerator() :: enumeratorsRest()
@@ -2619,7 +2622,7 @@ object Parsers:
26192622

26202623
/** Generator ::= [‘case’] Pattern `<-' Expr
26212624
*/
2622-
def generator(): Tree =
2625+
def generator(): Tree = {
26232626
val casePat = if (in.token == CASE) { nextToken(); true } else false
26242627
generatorRest(pattern1(), casePat)
26252628

@@ -2637,13 +2640,13 @@ object Parsers:
26372640
* | ‘for’ Enumerators (‘do‘ | ‘yield’) Expr
26382641
*/
26392642
def forExpr(): Tree =
2640-
atSpan(skipToken()):
2643+
atSpan(skipToken()) {
26412644
var wrappedEnums = true
26422645
val start = in.offset
26432646
val forEnd = in.lastOffset
26442647
val leading = in.token
26452648
val enums =
2646-
if (leading == LBRACE || leading == LPAREN && followingIsEnclosedGenerators())
2649+
if (leading == LBRACE || leading == LPAREN && followingIsEnclosedGenerators()) {
26472650
nextToken()
26482651
val res =
26492652
if (leading == LBRACE || in.token == CASE)
@@ -2687,7 +2690,7 @@ object Parsers:
26872690
patch(source, ts.last.span.endPos, ")")
26882691
ts
26892692
newLinesOpt()
2690-
if (in.token == YIELD)
2693+
if (in.token == YIELD) {
26912694
nextToken()
26922695
ForYield(enums, subExpr())
26932696
else if (in.token == DO)
@@ -2740,7 +2743,7 @@ object Parsers:
27402743
rejectWildcardType(infixType())
27412744
CaseDef(pat, EmptyTree, atSpan(accept(ARROW)) {
27422745
val t = indentedRegionAfterArrow(rejectWildcardType(typ()), inCaseDef = true)
2743-
if in.token == SEMI then in.nextToken()
2746+
if in.token == SEMI then nextToken()
27442747
newLinesOptWhenFollowedBy(CASE)
27452748
t
27462749
})
@@ -2802,7 +2805,7 @@ object Parsers:
28022805
val pattern2: () => Tree = () => pattern3() match
28032806
case p @ Ident(name) if in.token == AT =>
28042807
val offset = skipToken()
2805-
pattern3() match
2808+
pattern3() match {
28062809
case pt @ Bind(nme.WILDCARD, pt1: Typed) if pt.mods.is(Given) =>
28072810
atSpan(startOffset(p), 0) { Bind(name, pt1).withMods(pt.mods) }
28082811
case Typed(Ident(nme.WILDCARD), pt @ Ident(tpnme.WILDCARD_STAR)) =>
@@ -2850,7 +2853,7 @@ object Parsers:
28502853
case XMLSTART =>
28512854
xmlLiteralPattern()
28522855
case GIVEN =>
2853-
atSpan(in.offset):
2856+
atSpan(in.offset) {
28542857
val givenMod = atSpan(skipToken())(Mod.Given())
28552858
val typed = Typed(Ident(nme.WILDCARD), refinedType())
28562859
Bind(nme.WILDCARD, typed).withMods(addMod(Modifiers(), givenMod))
@@ -2974,7 +2977,7 @@ object Parsers:
29742977
val isAccessMod = accessModifierTokens contains in.token
29752978
val mods1 = addModifier(mods)
29762979
loop(if (isAccessMod) accessQualifierOpt(mods1) else mods1)
2977-
else if (in.isNewLine && (mods.hasFlags || mods.hasAnnotations))
2980+
else if (in.isNewLine && (mods.hasFlags || mods.hasAnnotations)) {
29782981
nextToken()
29792982
loop(mods)
29802983
else
@@ -3087,7 +3090,7 @@ object Parsers:
30873090
mods |= Contravariant
30883091
atSpan(start, nameStart):
30893092
val name =
3090-
if (isAbstractOwner && in.token == USCORE)
3093+
if (isAbstractOwner && in.token == USCORE) {
30913094
nextToken()
30923095
WildcardParamName.fresh().toTypeName
30933096
else ident().toTypeName
@@ -3348,7 +3351,7 @@ object Parsers:
33483351
patch(source, Span(in.offset, in.offset + 2),
33493352
if testChar(in.offset - 1, ' ') && testChar(in.offset + 2, ' ') then "as"
33503353
else " as ")
3351-
atSpan(startOffset(from), skipToken()):
3354+
atSpan(startOffset(from), skipToken()) {
33523355
val to = if in.token == USCORE then wildcardIdent() else termIdent()
33533356
ImportSelector(from, if to.name == nme.ERROR then EmptyTree else to)
33543357
else ImportSelector(from)
@@ -3505,7 +3508,7 @@ object Parsers:
35053508
else
35063509
false
35073510

3508-
if (in.token == THIS)
3511+
if (in.token == THIS) {
35093512
nextToken()
35103513
val vparamss = termParamClauses(numLeadParams = numLeadParams)
35113514
if (vparamss.isEmpty || vparamss.head.take(1).exists(_.mods.isOneOf(GivenOrImplicit)))
@@ -3562,11 +3565,8 @@ object Parsers:
35623565
atSpan(in.offset):
35633566
inBracesOrIndented:
35643567
val stats = selfInvocation() :: (
3565-
if isStatSep then
3566-
nextToken()
3567-
blockStatSeq()
3568-
else Nil
3569-
)
3568+
if (isStatSep) { nextToken(); blockStatSeq() }
3569+
else Nil)
35703570
Block(stats, Literal(Constant(())))
35713571
else Block(selfInvocation() :: Nil, Literal(Constant(())))
35723572

@@ -3597,7 +3597,7 @@ object Parsers:
35973597
makeTypeDef(toplevelTyp())
35983598
case SUBTYPE | SUPERTYPE =>
35993599
val bounds = typeBounds()
3600-
if (in.token == EQUALS)
3600+
if (in.token == EQUALS) {
36013601
val eqOffset = skipToken()
36023602
var rhs = toplevelTyp()
36033603
rhs match
@@ -3703,7 +3703,7 @@ object Parsers:
37033703

37043704
atSpan(start, nameStart):
37053705
val id = termIdent()
3706-
if (in.token == COMMA)
3706+
if (in.token == COMMA) {
37073707
nextToken()
37083708
val ids = commaSeparated(() => termIdent())
37093709
PatDef(mods1, id :: ids, TypeTree(), EmptyTree)
@@ -3720,7 +3720,7 @@ object Parsers:
37203720
/** [`extends' ConstrApps] */
37213721
def caseTemplate(constr: DefDef): Template =
37223722
val parents =
3723-
if (in.token == EXTENDS)
3723+
if (in.token == EXTENDS) {
37243724
nextToken()
37253725
constrApps()
37263726
else Nil
@@ -3889,9 +3889,9 @@ object Parsers:
38893889
*/
38903890
def template(constr: DefDef, isEnum: Boolean = false): Template =
38913891
val parents =
3892-
if (in.token == EXTENDS)
3892+
if (in.token == EXTENDS) {
38933893
nextToken()
3894-
if (in.token == LBRACE || in.token == COLONeol)
3894+
if (in.token == LBRACE || in.token == COLONeol) {
38953895
report.errorOrMigrationWarning(
38963896
em"`extends` must be followed by at least one parent",
38973897
in.sourcePos(), from = `3.0`)
@@ -3900,7 +3900,7 @@ object Parsers:
39003900
else Nil
39013901
newLinesOptWhenFollowedBy(nme.derives)
39023902
val derived =
3903-
if (isIdent(nme.derives))
3903+
if (isIdent(nme.derives)) {
39043904
nextToken()
39053905
commaSeparated(() => convertToTypeId(qualId()))
39063906
else Nil
@@ -3979,9 +3979,9 @@ object Parsers:
39793979
val stats = new ListBuffer[Tree]
39803980
while
39813981
var empty = false
3982-
if (in.token == PACKAGE)
3982+
if (in.token == PACKAGE) {
39833983
val start = skipToken()
3984-
if (in.token == OBJECT)
3984+
if (in.token == OBJECT) {
39853985
nextToken()
39863986
stats += objectDef(start, Modifiers(Package))
39873987
else stats += packaging(start)
@@ -4149,9 +4149,9 @@ object Parsers:
41494149
val ts = new ListBuffer[Tree]
41504150
while (in.token == SEMI) nextToken()
41514151
val start = in.offset
4152-
if (in.token == PACKAGE)
4152+
if (in.token == PACKAGE) {
41534153
nextToken()
4154-
if (in.token == OBJECT)
4154+
if (in.token == OBJECT) {
41554155
nextToken()
41564156
ts += objectDef(start, Modifiers(Package))
41574157
if (in.token != EOF)

0 commit comments

Comments
 (0)