Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 22 additions & 16 deletions compiler/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala
Original file line number Diff line number Diff line change
Expand Up @@ -124,24 +124,30 @@ object SyntaxHighlighting {
}
}

val parser = new Parser(source)
val trees = parser.blockStatSeq()
TreeHighlighter.highlight(trees)

val highlighted = new StringBuilder()

for (idx <- colorAt.indices) {
val prev = if (idx == 0) NoColor else colorAt(idx - 1)
val curr = colorAt(idx)
if (curr != prev)
highlighted.append(curr)
highlighted.append(in(idx))
}
try
val parser = new Parser(source)
val trees = parser.blockStatSeq()
TreeHighlighter.highlight(trees)


val highlighted = new StringBuilder()

if (colorAt.last != NoColor)
highlighted.append(NoColor)
for (idx <- colorAt.indices) {
val prev = if (idx == 0) NoColor else colorAt(idx - 1)
val curr = colorAt(idx)
if (curr != prev)
highlighted.append(curr)
highlighted.append(in(idx))
}

if (colorAt.last != NoColor)
highlighted.append(NoColor)

highlighted.toString
highlighted.toString
catch
case e: StackOverflowError =>
in
}
}

}
13 changes: 13 additions & 0 deletions compiler/test/dotty/tools/repl/ReplCompilerTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -458,3 +458,16 @@ class ReplVerboseTests extends ReplTest(ReplTest.defaultOptions :+ "-verbose"):
}

end ReplVerboseTests

class ReplHighlightTests extends ReplTest(ReplTest.defaultOptions.filterNot(_.startsWith("-color")) :+ "-color:always"):
@Test def i18596: Unit = initially:
run("""(1 to 500).foldRight("x") { case (_, n) => s"<x>$n</x>" }""")

@Test def i16904: Unit = initially:
run(""""works not fine"* 10000""")

run("""
case class Tree(left: Tree, right: Tree)
def deepTree(depth: Int): Tree
deepTree(300)""")