Skip to content

Commit

Permalink
Improve block comment tokenizers
Browse files Browse the repository at this point in the history
FIX: Fix a bug where tokenizing of block comments got confused when nested comment start/end
markers appeared directly next to each other.

See https://discuss.codemirror.net/t/block-comments-not-closed-correctly/6182
  • Loading branch information
marijnh committed Apr 5, 2023
1 parent 4de07b4 commit be95e91
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,18 +194,17 @@ export function tokensFor(d: Dialect) {
input.acceptToken(LineComment)
} else if (next == Ch.Slash && input.next == Ch.Star) {
input.advance()
for (let prev = -1, depth = 1;;) {
for (let depth = 1;;) {
let cur: number = input.next
if (input.next < 0) break
input.advance()
if (prev == Ch.Star && (input as any).next == Ch.Slash) {
if (cur == Ch.Star && (input as any).next == Ch.Slash) {
depth--
if (!depth) { input.advance(); break }
prev = -1
} else if (prev == Ch.Slash && input.next == Ch.Star) {
input.advance()
if (!depth) break
} else if (cur == Ch.Slash && input.next == Ch.Star) {
depth++
prev = -1
} else {
prev = input.next
input.advance()
}
}
input.acceptToken(BlockComment)
Expand Down

0 comments on commit be95e91

Please sign in to comment.