Skip to content

Commit 22b7540

Browse files
committed
Support nested comments
1 parent 96511fe commit 22b7540

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

Diff for: mode/lean/lean.js

+7-13
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,19 @@
1616
token: function(stream, state) {
1717
if (stream.eatSpace()) return null;
1818

19-
if (state.inComment) {
20-
if (stream.match(/.*?-\//)) {
21-
state.inComment = false;
19+
if (state.commentLevel > 0) {
20+
if (stream.match(/.*?\/-/)) {
21+
state.commentLevel += 1;
22+
} else if (stream.match(/.*?-\//)) {
23+
state.commentLevel -= 1;
2224
} else {
2325
stream.skipToEnd();
2426
}
2527
return "comment";
2628
}
2729

28-
29-
if (state.inComment) {
30-
if (stream.match(/-\//)) {
31-
state.inComment = false;
32-
}
33-
return "comment";
34-
}
35-
3630
if (stream.match(/\/-/)) {
37-
state.inComment = true;
31+
state.commentLevel += 1;
3832
return "comment";
3933
}
4034

@@ -99,7 +93,7 @@
9993
return null;
10094
},
10195
startState: function() {
102-
return { inDefinition: false, inComment: false };
96+
return { inDefinition: false, commentLevel: 0 };
10397
}
10498
};
10599
});

0 commit comments

Comments
 (0)