New CodeMirror Library version 3.16
Replacing the CodeMirror Version to 3.16 Adding files to ..templates/designer/index.html to use the new extended control codeMirror.js and codeMirrorField.js
This commit is contained in:
92
gulliver/js/codemirror/mode/python/python.js
vendored
92
gulliver/js/codemirror/mode/python/python.js
vendored
@@ -4,13 +4,14 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
|
||||
function wordRegexp(words) {
|
||||
return new RegExp("^((" + words.join(")|(") + "))\\b");
|
||||
}
|
||||
|
||||
|
||||
var singleOperators = parserConf.singleOperators || new RegExp("^[\\+\\-\\*/%&|\\^~<>!]");
|
||||
var singleDelimiters = parserConf.singleDelimiters || new RegExp('^[\\(\\)\\[\\]\\{\\}@,:`=;\\.]');
|
||||
var doubleOperators = parserConf.doubleOperators || new RegExp("^((==)|(!=)|(<=)|(>=)|(<>)|(<<)|(>>)|(//)|(\\*\\*))");
|
||||
var doubleDelimiters = parserConf.doubleDelimiters || new RegExp("^((\\+=)|(\\-=)|(\\*=)|(%=)|(/=)|(&=)|(\\|=)|(\\^=))");
|
||||
var tripleDelimiters = parserConf.tripleDelimiters || new RegExp("^((//=)|(>>=)|(<<=)|(\\*\\*=))");
|
||||
var identifiers = parserConf.identifiers|| new RegExp("^[_A-Za-z][_A-Za-z0-9]*");
|
||||
var hangingIndent = parserConf.hangingIndent || parserConf.indentUnit;
|
||||
|
||||
var wordOperators = wordRegexp(['and', 'or', 'not', 'is', 'in']);
|
||||
var commonkeywords = ['as', 'assert', 'break', 'class', 'continue',
|
||||
@@ -36,6 +37,12 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
|
||||
var py3 = {'builtins': ['ascii', 'bytes', 'exec', 'print'],
|
||||
'keywords': ['nonlocal', 'False', 'True', 'None']};
|
||||
|
||||
if(parserConf.extra_keywords != undefined){
|
||||
commonkeywords = commonkeywords.concat(parserConf.extra_keywords);
|
||||
}
|
||||
if(parserConf.extra_builtins != undefined){
|
||||
commonBuiltins = commonBuiltins.concat(parserConf.extra_builtins);
|
||||
}
|
||||
if (!!parserConf.version && parseInt(parserConf.version, 10) === 3) {
|
||||
commonkeywords = commonkeywords.concat(py3.keywords);
|
||||
commonBuiltins = commonBuiltins.concat(py3.builtins);
|
||||
@@ -72,15 +79,15 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
|
||||
if (stream.eatSpace()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
var ch = stream.peek();
|
||||
|
||||
|
||||
// Handle Comments
|
||||
if (ch === '#') {
|
||||
stream.skipToEnd();
|
||||
return 'comment';
|
||||
}
|
||||
|
||||
|
||||
// Handle Number Literals
|
||||
if (stream.match(/^[0-9\.]/, false)) {
|
||||
var floatLiteral = false;
|
||||
@@ -116,13 +123,13 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
|
||||
return 'number';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Handle Strings
|
||||
if (stream.match(stringPrefixes)) {
|
||||
state.tokenize = tokenStringFactory(stream.current());
|
||||
return state.tokenize(stream, state);
|
||||
}
|
||||
|
||||
|
||||
// Handle operators and Delimiters
|
||||
if (stream.match(tripleDelimiters) || stream.match(doubleDelimiters)) {
|
||||
return null;
|
||||
@@ -135,31 +142,34 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
|
||||
if (stream.match(singleDelimiters)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
if (stream.match(keywords)) {
|
||||
return 'keyword';
|
||||
}
|
||||
|
||||
|
||||
if (stream.match(builtins)) {
|
||||
return 'builtin';
|
||||
}
|
||||
|
||||
|
||||
if (stream.match(identifiers)) {
|
||||
if (state.lastToken == 'def' || state.lastToken == 'class') {
|
||||
return 'def';
|
||||
}
|
||||
return 'variable';
|
||||
}
|
||||
|
||||
|
||||
// Handle non-detected items
|
||||
stream.next();
|
||||
return ERRORCLASS;
|
||||
}
|
||||
|
||||
|
||||
function tokenStringFactory(delimiter) {
|
||||
while ('rub'.indexOf(delimiter.charAt(0).toLowerCase()) >= 0) {
|
||||
delimiter = delimiter.substr(1);
|
||||
}
|
||||
var singleline = delimiter.length == 1;
|
||||
var OUTCLASS = 'string';
|
||||
|
||||
|
||||
function tokenString(stream, state) {
|
||||
while (!stream.eol()) {
|
||||
stream.eatWhile(/[^'"\\]/);
|
||||
@@ -187,7 +197,7 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
|
||||
tokenString.isString = true;
|
||||
return tokenString;
|
||||
}
|
||||
|
||||
|
||||
function indent(stream, state, type) {
|
||||
type = type || 'py';
|
||||
var indentUnit = 0;
|
||||
@@ -202,6 +212,11 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (stream.match(/\s*($|#)/, false)) {
|
||||
// An open paren/bracket/brace with only space or comments after it
|
||||
// on the line will indent the next line a fixed amount, to make it
|
||||
// easier to put arguments, list items, etc. on their own lines.
|
||||
indentUnit = stream.indentation() + hangingIndent;
|
||||
} else {
|
||||
indentUnit = stream.column() + stream.current().length;
|
||||
}
|
||||
@@ -210,7 +225,7 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
|
||||
type: type
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function dedent(stream, state, type) {
|
||||
type = type || 'py';
|
||||
if (state.scopes.length == 1) return;
|
||||
@@ -252,24 +267,24 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
|
||||
// Handle '.' connected identifiers
|
||||
if (current === '.') {
|
||||
style = stream.match(identifiers, false) ? null : ERRORCLASS;
|
||||
if (style === null && state.lastToken === 'meta') {
|
||||
if (style === null && state.lastStyle === 'meta') {
|
||||
// Apply 'meta' style to '.' connected identifiers when
|
||||
// appropriate.
|
||||
style = 'meta';
|
||||
}
|
||||
return style;
|
||||
}
|
||||
|
||||
|
||||
// Handle decorators
|
||||
if (current === '@') {
|
||||
return stream.match(identifiers, false) ? 'meta' : ERRORCLASS;
|
||||
}
|
||||
|
||||
if ((style === 'variable' || style === 'builtin')
|
||||
&& state.lastToken === 'meta') {
|
||||
&& state.lastStyle === 'meta') {
|
||||
style = 'meta';
|
||||
}
|
||||
|
||||
|
||||
// Handle scope changes.
|
||||
if (current === 'pass' || current === 'return') {
|
||||
state.dedent += 1;
|
||||
@@ -298,7 +313,7 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
|
||||
if (state.scopes.length > 1) state.scopes.shift();
|
||||
state.dedent -= 1;
|
||||
}
|
||||
|
||||
|
||||
return style;
|
||||
}
|
||||
|
||||
@@ -307,34 +322,53 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
|
||||
return {
|
||||
tokenize: tokenBase,
|
||||
scopes: [{offset:basecolumn || 0, type:'py'}],
|
||||
lastStyle: null,
|
||||
lastToken: null,
|
||||
lambda: false,
|
||||
dedent: 0
|
||||
};
|
||||
},
|
||||
|
||||
|
||||
token: function(stream, state) {
|
||||
var style = tokenLexer(stream, state);
|
||||
|
||||
state.lastToken = style;
|
||||
|
||||
if (stream.eol() && stream.lambda) {
|
||||
|
||||
state.lastStyle = style;
|
||||
|
||||
var current = stream.current();
|
||||
if (current && style) {
|
||||
state.lastToken = current;
|
||||
}
|
||||
|
||||
if (stream.eol() && state.lambda) {
|
||||
state.lambda = false;
|
||||
}
|
||||
|
||||
return style;
|
||||
},
|
||||
|
||||
|
||||
indent: function(state) {
|
||||
if (state.tokenize != tokenBase) {
|
||||
return state.tokenize.isString ? CodeMirror.Pass : 0;
|
||||
}
|
||||
|
||||
|
||||
return state.scopes[0].offset;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
lineComment: "#",
|
||||
fold: "indent"
|
||||
};
|
||||
return external;
|
||||
});
|
||||
|
||||
CodeMirror.defineMIME("text/x-python", "python");
|
||||
|
||||
(function() {
|
||||
"use strict";
|
||||
var words = function(str){return str.split(' ');};
|
||||
|
||||
CodeMirror.defineMIME("text/x-cython", {
|
||||
name: "python",
|
||||
extra_keywords: words("by cdef cimport cpdef ctypedef enum except"+
|
||||
"extern gil include nogil property public"+
|
||||
"readonly struct union DEF IF ELIF ELSE")
|
||||
});
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user