Skip to content

Commit a6d856c

Browse files
committed
Improve syntax highlighting in tutorial
1 parent 59cc863 commit a6d856c

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

doc/tutorial/lib/codemirror-rust.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -213,15 +213,19 @@ CodeMirror.defineMode("rust", function() {
213213
if (content == "||") return cont(poplex, pushlex("}", "block"), block);
214214
}
215215
if (content == "mutable" || (content.match(/^\w+$/) && cx.stream.peek() == ":"
216-
&& !cx.stream.match("::", false))) return pass(recliteral);
216+
&& !cx.stream.match("::", false)))
217+
return pass(record_of(expression));
217218
return pass(block);
218219
}
219-
function recliteral(type) {
220-
if (content == "mutable" || content == "with") {cx.marked = "keyword"; return cont(recliteral);}
221-
if (content.match(/^\w*$/)) {cx.marked = "variable"; return cont(recliteral);}
222-
if (type == ":") return cont(expression, recliteral);
223-
if (type == "}") return cont();
224-
return cont(recliteral);
220+
function record_of(comb) {
221+
function ro(type) {
222+
if (content == "mutable" || content == "with") {cx.marked = "keyword"; return cont(ro);}
223+
if (content.match(/^\w*$/)) {cx.marked = "variable"; return cont(ro);}
224+
if (type == ":") return cont(comb, ro);
225+
if (type == "}") return cont();
226+
return cont(ro);
227+
}
228+
return ro;
225229
}
226230
function blockvars(type) {
227231
if (type == "name") {cx.marked = "def"; return cont(blockvars);}
@@ -230,7 +234,7 @@ CodeMirror.defineMode("rust", function() {
230234
}
231235

232236
function letdef1(type) {
233-
if (type == ";") return cont();
237+
if (type.match(/[\]\)\};]/)) return cont();
234238
if (content == "=") return cont(expression, letdef2);
235239
if (type == ",") return cont(letdef1);
236240
return pass(pattern, maybetype, letdef1);
@@ -295,6 +299,7 @@ CodeMirror.defineMode("rust", function() {
295299
if (type == "atom") return cont(rtypemaybeparam);
296300
if (type == "op" || type == "obj") return cont(rtype);
297301
if (type == "fn") return cont(fntype);
302+
if (type == "{") return cont(pushlex("{"), record_of(rtype), poplex);
298303
return matchBrackets(type, rtype);
299304
}
300305
function rtypemaybeparam(type) {

0 commit comments

Comments
 (0)