Skip to content

Commit d4dbbce

Browse files
committed
[dart mode] Support nested block comments
Closes codemirror#3878
1 parent fa1a355 commit d4dbbce

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

mode/dart/dart.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@
7272
return null;
7373
}
7474
return false;
75+
},
76+
77+
"/": function(stream, state) {
78+
if (!stream.eat("*")) return false
79+
state.tokenize = tokenNestedComment(1)
80+
return state.tokenize(stream, state)
7581
}
7682
}
7783
});
@@ -121,6 +127,27 @@
121127
return "variable";
122128
}
123129

130+
function tokenNestedComment(depth) {
131+
return function (stream, state) {
132+
var ch
133+
while (ch = stream.next()) {
134+
if (ch == "*" && stream.eat("/")) {
135+
if (depth == 1) {
136+
state.tokenize = null
137+
break
138+
} else {
139+
state.tokenize = tokenNestedComment(depth - 1)
140+
return state.tokenize(stream, state)
141+
}
142+
} else if (ch == "/" && stream.eat("*")) {
143+
state.tokenize = tokenNestedComment(depth + 1)
144+
return state.tokenize(stream, state)
145+
}
146+
}
147+
return "comment"
148+
}
149+
}
150+
124151
CodeMirror.registerHelper("hintWords", "application/dart", keywords.concat(atoms).concat(builtins));
125152

126153
// This is needed to make loading through meta.js work.

0 commit comments

Comments
 (0)