Skip to content

Commit 22bf6d1

Browse files
committed
Implement nested multiline comments for pseudo parsing
1 parent a9135b5 commit 22bf6d1

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

semanticdb/input/src/main/scala/example/Classes.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package example
22

33
class CDep[X]
4-
class CDependenat[X](var x1: CDep[X])
4+
class CDependenat[X /* This is a comment /* and a nested comment
5+
*/*/](var x1: CDep[X])
56
class CVarArg(var x1 : Int)
67

78

semanticdb/src/dotty/semanticdb/SourceFile.scala

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,28 @@ class SourceFile(path: java.nio.file.Path) {
3131

3232
def nextCharacterSkipComments(start : Int): Int = {
3333
def aux(start : Int) : Int = {
34-
var i = start
34+
var i = start
3535
if (i+2 <= sourceCode.length && sourceCode.substring(i, i+2) == "//") {
3636
while (i < sourceCode.length && sourceCode(i) != '\n')
37-
i += 1
37+
i += 1
3838
return i+1
3939
} else if (i+2 <= sourceCode.length && sourceCode.substring(i, i+2) == "/*") {
40-
while (i + 2 <= sourceCode.length && sourceCode.substring(i, i+2) != "*/")
40+
var nestedCount = 0
41+
i += 2
42+
while (i + 2 <= sourceCode.length &&
43+
!(sourceCode.substring(i, i+2) == "*/" &&
44+
nestedCount == 0)) {
45+
val s = sourceCode.substring(i, i+2)
46+
if (s == "/*") {
47+
nestedCount += 1
48+
i += 1
49+
}
50+
if (s == "*/") {
51+
nestedCount -= 1
52+
i += 1
53+
}
4154
i += 1
55+
}
4256
return i+2
4357
} else {
4458
while (i < sourceCode.length && sourceCode(i).isWhitespace)

0 commit comments

Comments
 (0)