Update CodeMirror to 5.13.5

This commit is contained in:
Cheng-Han, Wu 2016-04-20 18:11:40 +08:00
parent edc3a31dfd
commit 8bf516263c
84 changed files with 2837 additions and 504 deletions

View file

@ -14,27 +14,34 @@
CodeMirror.defineMode("julia", function(_conf, parserConf) {
var ERRORCLASS = 'error';
function wordRegexp(words) {
return new RegExp("^((" + words.join(")|(") + "))\\b");
function wordRegexp(words, end) {
if (typeof end === 'undefined') { end = "\\b"; }
return new RegExp("^((" + words.join(")|(") + "))" + end);
}
var octChar = "\\\\[0-7]{1,3}";
var hexChar = "\\\\x[A-Fa-f0-9]{1,2}";
var specialChar = "\\\\[abfnrtv0%?'\"\\\\]";
var singleChar = "([^\\u0027\\u005C\\uD800-\\uDFFF]|[\\uD800-\\uDFFF][\\uDC00-\\uDFFF])";
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][\w\u00A1-\uFFFF]*!*/;
var charsList = [octChar, hexChar, specialChar, singleChar];
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'];
var builtinList = ['true', 'false', 'nothing', 'NaN', 'Inf'];
//var stringPrefixes = new RegExp("^[br]?('|\")")
var stringPrefixes = /^(`|'|"{3}|([brv]?"))/;
var stringPrefixes = /^(`|"{3}|([brv]?"))/;
var chars = wordRegexp(charsList, "'");
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\u00A1-\uFFFF][_A-Za-z0-9\u00A1-\uFFFF]*!*/;
var typeAnnotation = /^::[^.,;"{()=$\s]+({[^}]*}+)*/;
var macro = /^@[_A-Za-z][\w]*/;
var symbol = /^:[_A-Za-z\u00A1-\uFFFF][\w\u00A1-\uFFFF]*!*/;
var typeAnnotation = /^::[^,;"{()=$\s]+({[^}]*}+)*/;
function inArray(state) {
var ch = currentScope(state);
@ -53,19 +60,10 @@ 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 multiline comments
if (stream.match(/^#=/, false)) {
state.tokenize = tokenComment;
return state.tokenize(stream, state);
}
// Handle scope changes
@ -100,6 +98,10 @@ CodeMirror.defineMode("julia", function(_conf, parserConf) {
state.scopes.push('[');
}
if (ch === '(') {
state.scopes.push('(');
}
var scope = currentScope(state);
if (scope == '[' && ch === ']') {
@ -137,33 +139,20 @@ CodeMirror.defineMode("julia", function(_conf, parserConf) {
// Handle Number Literals
if (stream.match(/^[0-9\.]/, false)) {
var imMatcher = RegExp(/^im\b/);
var floatLiteral = false;
var numberLiteral = false;
// Floats
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.leavingExpr = true;
return 'number';
}
if (stream.match(/^\d*\.(?!\.)\d*([Eef][\+\-]?\d+)?/i)) { numberLiteral = true; }
if (stream.match(/^\d+\.(?!\.)\d*/)) { numberLiteral = true; }
if (stream.match(/^\.\d+/)) { numberLiteral = true; }
if (stream.match(/^0x\.[0-9a-f]+p[\+\-]?\d+/i)) { numberLiteral = true; }
// Integers
var intLiteral = false;
// Hex
if (stream.match(/^0x[0-9a-f]+/i)) { intLiteral = true; }
// Binary
if (stream.match(/^0b[01]+/i)) { intLiteral = true; }
// Octal
if (stream.match(/^0o[0-7]+/i)) { intLiteral = true; }
// Decimal
if (stream.match(/^[1-9]\d*(e[\+\-]?\d+)?/)) {
intLiteral = true;
}
if (stream.match(/^0x[0-9a-f]+/i)) { numberLiteral = true; } // Hex
if (stream.match(/^0b[01]+/i)) { numberLiteral = true; } // Binary
if (stream.match(/^0o[0-7]+/i)) { numberLiteral = true; } // Octal
if (stream.match(/^[1-9]\d*(e[\+\-]?\d+)?/)) { numberLiteral = true; } // Decimal
// Zero by itself with no other piece of number.
if (stream.match(/^0(?![\dx])/i)) { intLiteral = true; }
if (intLiteral) {
if (stream.match(/^0(?![\dx])/i)) { numberLiteral = true; }
if (numberLiteral) {
// Integer literals may be "long"
stream.match(imMatcher);
state.leavingExpr = true;
@ -194,6 +183,12 @@ CodeMirror.defineMode("julia", function(_conf, parserConf) {
return 'operator';
}
// Handle Chars
if (stream.match(/^'/)) {
state.tokenize = tokenChar;
return state.tokenize(stream, state);
}
// Handle Strings
if (stream.match(stringPrefixes)) {
state.tokenize = tokenStringFactory(stream.current());
@ -269,7 +264,7 @@ CodeMirror.defineMode("julia", function(_conf, parserConf) {
// over two or more lines.
if (stream.match(/^$/g, false)) {
stream.backUp(state.charsAdvanced);
while (state.scopes.length > state.firstParenPos + 1)
while (state.scopes.length > state.firstParenPos)
state.scopes.pop();
state.firstParenPos = -1;
state.charsAdvanced = 0;
@ -279,33 +274,65 @@ CodeMirror.defineMode("julia", function(_conf, parserConf) {
return callOrDef(stream, state);
}
function tokenComment(stream, state) {
if (stream.match(/^#=/)) {
state.weakScopes++;
}
if (!stream.match(/.*?(?=(#=|=#))/)) {
stream.skipToEnd();
}
if (stream.match(/^=#/)) {
state.weakScopes--;
if (state.weakScopes == 0)
state.tokenize = tokenBase;
}
return 'comment';
}
function tokenChar(stream, state) {
var isChar = false, match;
if (stream.match(chars)) {
isChar = true;
} else if (match = stream.match(/\\u([a-f0-9]{1,4})(?=')/i)) {
var value = parseInt(match[1], 16);
if (value <= 55295 || value >= 57344) { // (U+0,U+D7FF), (U+E000,U+FFFF)
isChar = true;
stream.next();
}
} else if (match = stream.match(/\\U([A-Fa-f0-9]{5,8})(?=')/)) {
var value = parseInt(match[1], 16);
if (value <= 1114111) { // U+10FFFF
isChar = true;
stream.next();
}
}
if (isChar) {
state.leavingExpr = true;
state.tokenize = tokenBase;
return 'string';
}
if (!stream.match(/^[^']+(?=')/)) { stream.skipToEnd(); }
if (stream.match(/^'/)) { state.tokenize = tokenBase; }
return ERRORCLASS;
}
function tokenStringFactory(delimiter) {
while ('bruv'.indexOf(delimiter.charAt(0).toLowerCase()) >= 0) {
delimiter = delimiter.substr(1);
}
var singleline = delimiter == "'";
var OUTCLASS = 'string';
function tokenString(stream, state) {
while (!stream.eol()) {
stream.eatWhile(/[^'"\\]/);
stream.eatWhile(/[^"\\]/);
if (stream.eat('\\')) {
stream.next();
if (singleline && stream.eol()) {
return OUTCLASS;
}
} else if (stream.match(delimiter)) {
state.tokenize = tokenBase;
state.leavingExpr = true;
return OUTCLASS;
} else {
stream.eat(/['"]/);
}
}
if (singleline) {
if (parserConf.singleLineStringErrors) {
return ERRORCLASS;
} else {
state.tokenize = tokenBase;
stream.eat(/["]/);
}
}
return OUTCLASS;
@ -319,6 +346,7 @@ CodeMirror.defineMode("julia", function(_conf, parserConf) {
return {
tokenize: tokenBase,
scopes: [],
weakScopes: 0,
lastToken: null,
leavingExpr: false,
isDefinition: false,
@ -345,15 +373,15 @@ CodeMirror.defineMode("julia", function(_conf, parserConf) {
indent: function(state, textAfter) {
var delta = 0;
if (textAfter == "end" || textAfter == "]" || textAfter == "}" || textAfter == "else" || textAfter == "elseif" || textAfter == "catch" || textAfter == "finally") {
if (textAfter == "]" || textAfter == ")" || textAfter == "end" || textAfter == "else" || textAfter == "elseif" || textAfter == "catch" || textAfter == "finally") {
delta = -1;
}
return (state.scopes.length + delta) * _conf.indentUnit;
},
electricInput: /(end|else(if)?|catch|finally)$/,
lineComment: "#",
fold: "indent",
electricChars: "edlsifyh]}"
fold: "indent"
};
return external;
});