Skip to content

Commit

Permalink
Merge pull request #3666 from kitbellew/3664
Browse files Browse the repository at this point in the history
ScannerTokens: keep multiple outdents to swap `,`
  • Loading branch information
kitbellew committed Mar 22, 2024
2 parents 07a450a + 83a6e86 commit c8d5b6b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
Expand Up @@ -21,9 +21,9 @@ private[parsers] class LazyTokenIterator private (

import scannerTokens._

private def getNextTokenRef(): TokenRef = {
if (curr.next eq null) nextToken(curr) else curr.next
}
@inline
private def getNextTokenRef(): TokenRef =
nextToken(curr)

override def next(): Unit = {
prev = curr
Expand Down
Expand Up @@ -325,15 +325,16 @@ final class ScannerTokens(val tokens: Tokens)(implicit dialect: Dialect) {
}
}

@inline
private[parsers] def nextToken(ref: TokenRef): TokenRef = {
val next = nextToken(ref.token, ref.pos, ref.nextPos, ref.regions)
ref.next = next
next
private[parsers] def nextToken(ref: TokenRef): TokenRef = ref.next match {
case null =>
val next = nextToken(ref.token, ref.pos, ref.nextPos, ref.regions)
ref.next = next
next
case nref => nref
}

@tailrec
private[parsers] def nextToken(
private def nextToken(
prevToken: Token,
prevPos: Int,
currPos: Int,
Expand Down
Expand Up @@ -1675,6 +1675,36 @@ class SignificantIndentationSuite extends BaseDottySuite {
runTestAssert[Stat](code, layout)(tree)
}

test("#3542 apply with optional braces in intermediate arg, with multiple outdents") {
val code =
"""|A(
| foo = x =>
| x match
| case baz => baz,
| bar = bar
|)
|""".stripMargin
val layout =
"""|A(foo = x => x match {
| case baz => baz
|}, bar = bar)
|""".stripMargin
val tree = Term.Apply(
tname("A"),
List(
Term.Assign(
tname("foo"),
Term.Function(
List(tparam("x")),
Term.Match(tname("x"), List(Case(Pat.Var(tname("baz")), None, tname("baz"))), Nil)
)
),
Term.Assign(tname("bar"), tname("bar"))
)
)
runTestAssert[Stat](code, layout)(tree)
}

test("indented-double-apply") {
runTestAssert[Stat](
"""|def method =
Expand Down

0 comments on commit c8d5b6b

Please sign in to comment.