summaryrefslogtreecommitdiff
path: root/public/vendor/codemirror/mode/julia/julia.js
diff options
context:
space:
mode:
authorWu Cheng-Han2016-01-17 14:28:04 -0600
committerWu Cheng-Han2016-01-17 14:28:04 -0600
commiteaa8ccaccb1091820d0a8d1223996a6dd057347d (patch)
tree6b4aaa3b3d1a2fed68147510142663222533775a /public/vendor/codemirror/mode/julia/julia.js
parentce65e58096d57ace02723d11a125673f9d48c293 (diff)
Upgrade CodeMirror to 5.10.1 and now support fullscreen, jump-to-line in editor
Diffstat (limited to 'public/vendor/codemirror/mode/julia/julia.js')
-rw-r--r--[-rwxr-xr-x]public/vendor/codemirror/mode/julia/julia.js223
1 files changed, 144 insertions, 79 deletions
diff --git a/public/vendor/codemirror/mode/julia/julia.js b/public/vendor/codemirror/mode/julia/julia.js
index d0a74cef..4471896b 100755..100644
--- a/public/vendor/codemirror/mode/julia/julia.js
+++ b/public/vendor/codemirror/mode/julia/julia.js
@@ -18,35 +18,34 @@ CodeMirror.defineMode("julia", function(_conf, parserConf) {
return new RegExp("^((" + words.join(")|(") + "))\\b");
}
- var operators = parserConf.operators || /^\.?[|&^\\%*+\-<>!=\/]=?|\?|~|:|\$|\.[<>]|<<=?|>>>?=?|\.[<>=]=|->?|\/\/|\bin\b/;
+ var operators = parserConf.operators || /^\.?[|&^\\%*+\-<>!=\/]=?|\?|~|:|\$|\.[<>]|<<=?|>>>?=?|\.[<>=]=|->?|\/\/|\bin\b(?!\()|[\u2208\u2209](?!\()/;
var delimiters = parserConf.delimiters || /^[;,()[\]{}]/;
- var identifiers = parserConf.identifiers|| /^[_A-Za-z\u00A1-\uFFFF][_A-Za-z0-9\u00A1-\uFFFF]*!*/;
+ var identifiers = parserConf.identifiers || /^[_A-Za-z\u00A1-\uFFFF][_A-Za-z0-9\u00A1-\uFFFF]*!*/;
var blockOpeners = ["begin", "function", "type", "immutable", "let", "macro", "for", "while", "quote", "if", "else", "elseif", "try", "finally", "catch", "do"];
var blockClosers = ["end", "else", "elseif", "catch", "finally"];
- var keywordList = ['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', 'ccall'];
- var builtinList = ['true', 'false', 'enumerate', 'open', 'close', 'nothing', 'NaN', 'Inf', 'print', 'println', 'Int', 'Int8', 'Uint8', 'Int16', 'Uint16', 'Int32', 'Uint32', 'Int64', 'Uint64', 'Int128', 'Uint128', 'Bool', 'Char', 'Float16', 'Float32', 'Float64', 'Array', 'Vector', 'Matrix', 'String', 'UTF8String', 'ASCIIString', 'error', 'warn', 'info', '@printf'];
+ var keywordList = ['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'];
+ var builtinList = ['true', 'false', 'nothing', 'NaN', 'Inf'];
//var stringPrefixes = new RegExp("^[br]?('|\")")
- var stringPrefixes = /^(`|'|"{3}|([br]?"))/;
+ var stringPrefixes = /^(`|'|"{3}|([brv]?"))/;
var keywords = wordRegexp(keywordList);
var builtins = wordRegexp(builtinList);
var openers = wordRegexp(blockOpeners);
var closers = wordRegexp(blockClosers);
var macro = /^@[_A-Za-z][_A-Za-z0-9]*/;
- var symbol = /^:[_A-Za-z][_A-Za-z0-9]*/;
+ var symbol = /^:[_A-Za-z\u00A1-\uFFFF][_A-Za-z0-9\u00A1-\uFFFF]*!*/;
+ var typeAnnotation = /^::[^.,;"{()=$\s]+({[^}]*}+)*/;
- function in_array(state) {
- var ch = cur_scope(state);
- if(ch=="[" || ch=="{") {
+ function inArray(state) {
+ var ch = currentScope(state);
+ if (ch == '[') {
return true;
}
- else {
- return false;
- }
+ return false;
}
- function cur_scope(state) {
- if(state.scopes.length==0) {
+ function currentScope(state) {
+ if (state.scopes.length == 0) {
return null;
}
return state.scopes[state.scopes.length - 1];
@@ -54,20 +53,34 @@ CodeMirror.defineMode("julia", function(_conf, parserConf) {
// tokenizers
function tokenBase(stream, state) {
+ //Handle multiline comments
+ if (stream.match(/^#=\s*/)) {
+ state.scopes.push('#=');
+ }
+ if (currentScope(state) == '#=' && stream.match(/^=#/)) {
+ state.scopes.pop();
+ return 'comment';
+ }
+ if (state.scopes.indexOf('#=') >= 0) {
+ if (!stream.match(/.*?(?=(#=|=#))/)) {
+ stream.skipToEnd();
+ }
+ return 'comment';
+ }
+
// Handle scope changes
- var leaving_expr = state.leaving_expr;
- if(stream.sol()) {
- leaving_expr = false;
+ var leavingExpr = state.leavingExpr;
+ if (stream.sol()) {
+ leavingExpr = false;
}
- state.leaving_expr = false;
- if(leaving_expr) {
- if(stream.match(/^'+/)) {
+ state.leavingExpr = false;
+ if (leavingExpr) {
+ if (stream.match(/^'+/)) {
return 'operator';
}
-
}
- if(stream.match(/^\.{2,3}/)) {
+ if (stream.match(/^\.{2,3}/)) {
return 'operator';
}
@@ -76,56 +89,51 @@ CodeMirror.defineMode("julia", function(_conf, parserConf) {
}
var ch = stream.peek();
- // Handle Comments
+
+ // Handle single line comments
if (ch === '#') {
- stream.skipToEnd();
- return 'comment';
- }
- if(ch==='[') {
- state.scopes.push("[");
+ stream.skipToEnd();
+ return 'comment';
}
- if(ch==='{') {
- state.scopes.push("{");
+ if (ch === '[') {
+ state.scopes.push('[');
}
- var scope=cur_scope(state);
+ var scope = currentScope(state);
- if(scope==='[' && ch===']') {
+ if (scope == '[' && ch === ']') {
state.scopes.pop();
- state.leaving_expr=true;
+ state.leavingExpr = true;
}
- if(scope==='{' && ch==='}') {
+ if (scope == '(' && ch === ')') {
state.scopes.pop();
- state.leaving_expr=true;
- }
-
- if(ch===')') {
- state.leaving_expr = true;
+ state.leavingExpr = true;
}
var match;
- if(!in_array(state) && (match=stream.match(openers, false))) {
+ if (!inArray(state) && (match=stream.match(openers, false))) {
state.scopes.push(match);
}
- if(!in_array(state) && stream.match(closers, false)) {
+ if (!inArray(state) && stream.match(closers, false)) {
state.scopes.pop();
}
- if(in_array(state)) {
- if(stream.match(/^end/)) {
+ if (inArray(state)) {
+ if (state.lastToken == 'end' && stream.match(/^:/)) {
+ return 'operator';
+ }
+ if (stream.match(/^end/)) {
return 'number';
}
-
}
- if(stream.match(/^=>/)) {
+ if (stream.match(/^=>/)) {
return 'operator';
}
-
// Handle Number Literals
if (stream.match(/^[0-9\.]/, false)) {
var imMatcher = RegExp(/^im\b/);
@@ -134,10 +142,11 @@ CodeMirror.defineMode("julia", function(_conf, parserConf) {
if (stream.match(/^\d*\.(?!\.)\d+([ef][\+\-]?\d+)?/i)) { floatLiteral = true; }
if (stream.match(/^\d+\.(?!\.)\d*/)) { floatLiteral = true; }
if (stream.match(/^\.\d+/)) { floatLiteral = true; }
+ if (stream.match(/^0x\.[0-9a-f]+p[\+\-]?\d+/i)) { floatLiteral = true; }
if (floatLiteral) {
// Float literals may be "imaginary"
stream.match(imMatcher);
- state.leaving_expr = true;
+ state.leavingExpr = true;
return 'number';
}
// Integers
@@ -157,18 +166,27 @@ CodeMirror.defineMode("julia", function(_conf, parserConf) {
if (intLiteral) {
// Integer literals may be "long"
stream.match(imMatcher);
- state.leaving_expr = true;
+ state.leavingExpr = true;
return 'number';
}
}
- if(stream.match(/^(::)|(<:)/)) {
+ if (stream.match(/^<:/)) {
return 'operator';
}
+ if (stream.match(typeAnnotation)) {
+ return 'builtin';
+ }
+
// Handle symbols
- if(!leaving_expr && stream.match(symbol)) {
- return 'string';
+ if (!leavingExpr && stream.match(symbol) || stream.match(/:\./)) {
+ return 'builtin';
+ }
+
+ // Handle parametric types
+ if (stream.match(/^{[^}]*}(?=\()/)) {
+ return 'builtin';
}
// Handle operators and Delimiters
@@ -176,7 +194,6 @@ CodeMirror.defineMode("julia", function(_conf, parserConf) {
return 'operator';
}
-
// Handle Strings
if (stream.match(stringPrefixes)) {
state.tokenize = tokenStringFactory(stream.current());
@@ -187,7 +204,6 @@ CodeMirror.defineMode("julia", function(_conf, parserConf) {
return 'meta';
}
-
if (stream.match(delimiters)) {
return null;
}
@@ -200,21 +216,74 @@ CodeMirror.defineMode("julia", function(_conf, parserConf) {
return 'builtin';
}
+ var isDefinition = state.isDefinition ||
+ state.lastToken == 'function' ||
+ state.lastToken == 'macro' ||
+ state.lastToken == 'type' ||
+ state.lastToken == 'immutable';
if (stream.match(identifiers)) {
- state.leaving_expr=true;
+ if (isDefinition) {
+ if (stream.peek() === '.') {
+ state.isDefinition = true;
+ return 'variable';
+ }
+ state.isDefinition = false;
+ return 'def';
+ }
+ if (stream.match(/^({[^}]*})*\(/, false)) {
+ return callOrDef(stream, state);
+ }
+ state.leavingExpr = true;
return 'variable';
}
+
// Handle non-detected items
stream.next();
return ERRORCLASS;
}
+ function callOrDef(stream, state) {
+ var match = stream.match(/^(\(\s*)/);
+ if (match) {
+ if (state.firstParenPos < 0)
+ state.firstParenPos = state.scopes.length;
+ state.scopes.push('(');
+ state.charsAdvanced += match[1].length;
+ }
+ if (currentScope(state) == '(' && stream.match(/^\)/)) {
+ state.scopes.pop();
+ state.charsAdvanced += 1;
+ if (state.scopes.length <= state.firstParenPos) {
+ var isDefinition = stream.match(/^\s*?=(?!=)/, false);
+ stream.backUp(state.charsAdvanced);
+ state.firstParenPos = -1;
+ state.charsAdvanced = 0;
+ if (isDefinition)
+ return 'def';
+ return 'builtin';
+ }
+ }
+ // Unfortunately javascript does not support multiline strings, so we have
+ // to undo anything done upto here if a function call or definition splits
+ // over two or more lines.
+ if (stream.match(/^$/g, false)) {
+ stream.backUp(state.charsAdvanced);
+ while (state.scopes.length > state.firstParenPos + 1)
+ state.scopes.pop();
+ state.firstParenPos = -1;
+ state.charsAdvanced = 0;
+ return 'builtin';
+ }
+ state.charsAdvanced += stream.match(/^([^()]*)/)[1].length;
+ return callOrDef(stream, state);
+ }
+
function tokenStringFactory(delimiter) {
- while ('rub'.indexOf(delimiter.charAt(0).toLowerCase()) >= 0) {
+ while ('bruv'.indexOf(delimiter.charAt(0).toLowerCase()) >= 0) {
delimiter = delimiter.substr(1);
}
- var singleline = delimiter.length == 1;
+ var singleline = delimiter == "'";
var OUTCLASS = 'string';
function tokenString(stream, state) {
@@ -245,45 +314,41 @@ CodeMirror.defineMode("julia", function(_conf, parserConf) {
return tokenString;
}
- function tokenLexer(stream, state) {
- var style = state.tokenize(stream, state);
- var current = stream.current();
-
- // Handle '.' connected identifiers
- if (current === '.') {
- style = stream.match(identifiers, false) ? null : ERRORCLASS;
- if (style === null && state.lastStyle === 'meta') {
- // Apply 'meta' style to '.' connected identifiers when
- // appropriate.
- style = 'meta';
- }
- return style;
- }
-
- return style;
- }
-
var external = {
startState: function() {
return {
tokenize: tokenBase,
scopes: [],
- leaving_expr: false
+ lastToken: null,
+ leavingExpr: false,
+ isDefinition: false,
+ charsAdvanced: 0,
+ firstParenPos: -1
};
},
token: function(stream, state) {
- var style = tokenLexer(stream, state);
- state.lastStyle = style;
+ var style = state.tokenize(stream, state);
+ var current = stream.current();
+
+ if (current && style) {
+ state.lastToken = current;
+ }
+
+ // Handle '.' connected identifiers
+ if (current === '.') {
+ style = stream.match(identifiers, false) || stream.match(macro, false) ||
+ stream.match(/\(/, false) ? 'operator' : ERRORCLASS;
+ }
return style;
},
indent: function(state, textAfter) {
var delta = 0;
- if(textAfter=="end" || textAfter=="]" || textAfter=="}" || textAfter=="else" || textAfter=="elseif" || textAfter=="catch" || textAfter=="finally") {
+ if (textAfter == "end" || textAfter == "]" || textAfter == "}" || textAfter == "else" || textAfter == "elseif" || textAfter == "catch" || textAfter == "finally") {
delta = -1;
}
- return (state.scopes.length + delta) * 4;
+ return (state.scopes.length + delta) * _conf.indentUnit;
},
lineComment: "#",