Skip to content

Commit f3dde7c

Browse files
committed
[julia mode] Fix infinite recursion
I couldn't figure out what the original code was intended to do, but I've tried to fix the problem without changing it more than necessary. Closes #6428
1 parent 1c60749 commit f3dde7c

File tree

1 file changed

+32
-31
lines changed

1 file changed

+32
-31
lines changed

mode/julia/julia.js

+32-31
Original file line numberDiff line numberDiff line change
@@ -255,41 +255,43 @@ CodeMirror.defineMode("julia", function(config, parserConf) {
255255
}
256256

257257
function tokenCallOrDef(stream, state) {
258-
var match = stream.match(/^(\(\s*)/);
259-
if (match) {
260-
if (state.firstParenPos < 0)
261-
state.firstParenPos = state.scopes.length;
262-
state.scopes.push('(');
263-
state.charsAdvanced += match[1].length;
264-
}
265-
if (currentScope(state) == '(' && stream.match(/^\)/)) {
266-
state.scopes.pop();
267-
state.charsAdvanced += 1;
268-
if (state.scopes.length <= state.firstParenPos) {
269-
var isDefinition = stream.match(/^(\s*where\s+[^\s=]+)*\s*?=(?!=)/, false);
270-
stream.backUp(state.charsAdvanced);
258+
for (;;) {
259+
var match = stream.match(/^(\(\s*)/), charsAdvanced = 0;
260+
if (match) {
261+
if (state.firstParenPos < 0)
262+
state.firstParenPos = state.scopes.length;
263+
state.scopes.push('(');
264+
charsAdvanced += match[1].length;
265+
}
266+
if (currentScope(state) == '(' && stream.match(/^\)/)) {
267+
state.scopes.pop();
268+
charsAdvanced += 1;
269+
if (state.scopes.length <= state.firstParenPos) {
270+
var isDefinition = stream.match(/^(\s*where\s+[^\s=]+)*\s*?=(?!=)/, false);
271+
stream.backUp(charsAdvanced);
272+
state.firstParenPos = -1;
273+
state.tokenize = tokenBase;
274+
if (isDefinition)
275+
return "def";
276+
return "builtin";
277+
}
278+
}
279+
// Unfortunately javascript does not support multiline strings, so we have
280+
// to undo anything done upto here if a function call or definition splits
281+
// over two or more lines.
282+
if (stream.match(/^$/g, false)) {
283+
stream.backUp(charsAdvanced);
284+
while (state.scopes.length > state.firstParenPos)
285+
state.scopes.pop();
271286
state.firstParenPos = -1;
272-
state.charsAdvanced = 0;
273287
state.tokenize = tokenBase;
274-
if (isDefinition)
275-
return "def";
276288
return "builtin";
277289
}
290+
if (!stream.match(/^[^()]+/)) {
291+
stream.next()
292+
return null
293+
}
278294
}
279-
// Unfortunately javascript does not support multiline strings, so we have
280-
// to undo anything done upto here if a function call or definition splits
281-
// over two or more lines.
282-
if (stream.match(/^$/g, false)) {
283-
stream.backUp(state.charsAdvanced);
284-
while (state.scopes.length > state.firstParenPos)
285-
state.scopes.pop();
286-
state.firstParenPos = -1;
287-
state.charsAdvanced = 0;
288-
state.tokenize = tokenBase;
289-
return "builtin";
290-
}
291-
state.charsAdvanced += stream.match(/^([^()]*)/)[1].length;
292-
return state.tokenize(stream, state);
293295
}
294296

295297
function tokenAnnotation(stream, state) {
@@ -383,7 +385,6 @@ CodeMirror.defineMode("julia", function(config, parserConf) {
383385
nestedComments: 0,
384386
nestedGenerators: 0,
385387
nestedParameters: 0,
386-
charsAdvanced: 0,
387388
firstParenPos: -1
388389
};
389390
},

0 commit comments

Comments
 (0)