Skip to content

Commit

Permalink
[julia mode] Julia 0.6 syntax updates
Browse files Browse the repository at this point in the history
  • Loading branch information
pabloferz committed Jul 8, 2017
1 parent a67f6a2 commit d444cd1
Showing 1 changed file with 33 additions and 32 deletions.
65 changes: 33 additions & 32 deletions mode/julia/julia.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,27 @@ CodeMirror.defineMode("julia", function(config, parserConf) {
var uChar = "([^\\u0027\\u005C\\uD800-\\uDFFF]|[\\uD800-\\uDFFF][\\uDC00-\\uDFFF])";

var operators = parserConf.operators || wordRegexp([
"\\.?[\\\\%*+\\-<>!=\\/^]=?", "\\.?[|&\\u00F7\\u2260\\u2264\\u2265]",
"\\u00D7", "\\u2208", "\\u2209", "\\u220B", "\\u220C", "\\u2229",
"\\u222A", "\\u2286", "\\u2288", "\\u228A", "\\u22c5", "\\?", "~", ":",
"\\$", "\\.[<>]", "<<=?", ">>>?=?", "\\.[<>=]=", "->?", "\\/\\/", "=>",
"<:", "\\bin\\b(?!\\()"], "");
"[<>]:", "[<>=]=", "<<=?", ">>>?=?", "=>", "->", "\\/\\/",
"[\\\\%*+\\-<>!=\\/^|&\\u00F7\\u22BB]=?", "\\?", "\\$", "~", ":",
"\\u00D7", "\\u2208", "\\u2209", "\\u220B", "\\u220C", "\\u2218",
"\\u221A", "\\u221B", "\\u2229", "\\u222A", "\\u2260", "\\u2264",
"\\u2265", "\\u2286", "\\u2288", "\\u228A", "\\u22C5",
"\\b(in|isa)\\b(?!\.?\\()"], "");
var delimiters = parserConf.delimiters || /^[;,()[\]{}]/;
var identifiers = parserConf.identifiers || /^[_A-Za-z\u00A1-\uFFFF][\w\u00A1-\uFFFF]*!*/;
var identifiers = parserConf.identifiers ||
/^[_A-Za-z\u00A1-\u2217\u2219-\uFFFF][\w\u00A1-\u2217\u2219-\uFFFF]*!*/;

var chars = wordRegexp([octChar, hexChar, sChar, uChar], "'");
var openers = wordRegexp(["begin", "function", "type", "immutable", "let",
"macro", "for", "while", "quote", "if", "else", "elseif", "try",
var openers = wordRegexp(["begin", "function", "type", "struct", "immutable",
"let", "macro", "for", "while", "quote", "if", "else", "elseif", "try",
"finally", "catch", "do"]);
var closers = wordRegexp(["end", "else", "elseif", "catch", "finally"]);
var keywords = wordRegexp(["if", "else", "elseif", "while", "for", "begin",
"let", "end", "do", "try", "catch", "finally", "return", "break",
"continue", "global", "local", "const", "export", "import", "importall",
"using", "function", "macro", "module", "baremodule", "type",
"immutable", "quote", "typealias", "abstract", "bitstype"]);
"using", "function", "where", "macro", "module", "baremodule", "struct",
"type", "mutable", "immutable", "quote", "typealias", "abstract",
"primitive", "bitstype"]);
var builtins = wordRegexp(["true", "false", "nothing", "NaN", "Inf"]);

var macro = /^@[_A-Za-z][\w]*/;
Expand Down Expand Up @@ -90,7 +93,9 @@ CodeMirror.defineMode("julia", function(config, parserConf) {
}
}

if (stream.match(/^\.{2,3}/)) {
if (stream.match(/\.{4,}/)) {
return "error";
} else if (stream.match(/\.{1,3}/)) {
return "operator";
}

Expand Down Expand Up @@ -128,15 +133,6 @@ CodeMirror.defineMode("julia", function(config, parserConf) {
state.leavingExpr = true;
}

var match;
if (match = stream.match(openers, false)) {
state.scopes.push(match[0]);
}

if (stream.match(closers, false)) {
state.scopes.pop();
}

if (inArray(state)) {
if (state.lastToken == "end" && stream.match(/^:/)) {
return "operator";
Expand All @@ -146,29 +142,39 @@ CodeMirror.defineMode("julia", function(config, parserConf) {
}
}

var match;
if (match = stream.match(openers, false)) {
state.scopes.push(match[0]);
}

if (stream.match(closers, false)) {
state.scopes.pop();
}

// Handle type annotations
if (stream.match(/^::(?![:\$])/)) {
state.tokenize = tokenAnnotation;
return state.tokenize(stream, state);
}

// Handle symbols
if (!leavingExpr && stream.match(symbol) || stream.match(/:\./)) {
if (!leavingExpr && stream.match(symbol) ||
stream.match(/:([<>]:|<<=?|>>>?=?|->|\/\/|\.{2,3}|[\.\\%*+\-<>!\/^|&]=?|[~\?\$])/)) {
return "builtin";
}

// Handle parametric types
if (stream.match(/^{[^}]*}(?=\()/)) {
return "builtin";
}
//if (stream.match(/^{[^}]*}(?=\()/)) {
// return "builtin";
//}

// Handle operators and Delimiters
if (stream.match(operators)) {
return "operator";
}

// Handle Number Literals
if (stream.match(/^[0-9\.]/, false)) {
if (stream.match(/^\.?\d/, false)) {
var imMatcher = RegExp(/^im\b/);
var numberLiteral = false;
// Floats
Expand Down Expand Up @@ -221,7 +227,7 @@ CodeMirror.defineMode("julia", function(config, parserConf) {

var isDefinition = state.isDefinition || state.lastToken == "function" ||
state.lastToken == "macro" || state.lastToken == "type" ||
state.lastToken == "immutable";
state.lastToken == "struct" || state.lastToken == "immutable";

if (stream.match(identifiers)) {
if (isDefinition) {
Expand Down Expand Up @@ -257,7 +263,7 @@ CodeMirror.defineMode("julia", function(config, parserConf) {
state.scopes.pop();
state.charsAdvanced += 1;
if (state.scopes.length <= state.firstParenPos) {
var isDefinition = stream.match(/^\s*?=(?!=)/, false);
var isDefinition = stream.match(/^(\s*where\s+[^\s=]+)*\s*?=(?!=)/, false);
stream.backUp(state.charsAdvanced);
state.firstParenPos = -1;
state.charsAdvanced = 0;
Expand Down Expand Up @@ -384,11 +390,6 @@ CodeMirror.defineMode("julia", function(config, parserConf) {
state.lastToken = current;
}

// Handle '.' connected identifiers
if (current === '.') {
style = stream.match(identifiers, false) || stream.match(macro, false) ||
stream.match(/\(/, false) ? "operator" : "error";
}
return style;
},

Expand Down

0 comments on commit d444cd1

Please sign in to comment.