Skip to content

Commit 8b6e88f

Browse files
committed
Allow successive opening comments.
Fixes scala#1052.
1 parent 742ae75 commit 8b6e88f

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

src/dotty/tools/dotc/parsing/Scanners.scala

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -539,21 +539,21 @@ object Scanners {
539539
if ((ch != CR) && (ch != LF) && (ch != SU)) skipLine()
540540
}
541541
@tailrec
542-
def skipBlock(openComments: Int): Unit = {
543-
val last = ch
544-
nextChar()
542+
def skipComment(): Unit = {
545543
if (ch == '/') {
546544
nextChar()
547-
if (last == '*') {
548-
if (openComments > 0) skipBlock(openComments - 1)
549-
} else {
550-
if (ch == '*') { nextChar(); skipBlock(openComments + 1) }
551-
else skipBlock(openComments)
552-
}
545+
if (ch == '*') nestedComment()
546+
skipComment()
547+
}
548+
else if (ch == '*') {
549+
do nextChar() while (ch == '*')
550+
if (ch == '/') nextChar()
551+
else skipComment()
553552
}
554553
else if (ch == SU) incompleteInputError("unclosed comment")
555-
else skipBlock(openComments)
554+
else { nextChar(); skipComment() }
556555
}
556+
def nestedComment() = { nextChar(); skipComment() }
557557
val start = lastCharOffset
558558
def finishComment(): Boolean = {
559559
if (keepComments) {
@@ -565,7 +565,7 @@ object Scanners {
565565
}
566566
nextChar()
567567
if (ch == '/') { skipLine(); finishComment() }
568-
else if (ch == '*') { nextChar(); skipBlock(0); finishComment() }
568+
else if (ch == '*') { nextChar(); skipComment(); finishComment() }
569569
else false
570570
}
571571

tests/pos/i1052.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package hello
2+
3+
object world extends App {
4+
println("hello dotty!")
5+
/*/* one
6+
*/
7+
two
8+
*/
9+
println("foo")
10+
}

0 commit comments

Comments
 (0)