Edit File by line
/home/barbar84/www/wp-conte.../plugins/wp-file-.../lib/codemirr.../mode/python
File: python.js
// CodeMirror, copyright (c) by Marijn Haverbeke and others
[0] Fix | Delete
// Distributed under an MIT license: http://codemirror.net/LICENSE
[1] Fix | Delete
[2] Fix | Delete
(function(mod) {
[3] Fix | Delete
if (typeof exports == "object" && typeof module == "object") // CommonJS
[4] Fix | Delete
mod(require("../../lib/codemirror"));
[5] Fix | Delete
else if (typeof define == "function" && define.amd) // AMD
[6] Fix | Delete
define(["../../lib/codemirror"], mod);
[7] Fix | Delete
else // Plain browser env
[8] Fix | Delete
mod(CodeMirror);
[9] Fix | Delete
})(function(CodeMirror) {
[10] Fix | Delete
"use strict";
[11] Fix | Delete
[12] Fix | Delete
function wordRegexp(words) {
[13] Fix | Delete
return new RegExp("^((" + words.join(")|(") + "))\\b");
[14] Fix | Delete
}
[15] Fix | Delete
[16] Fix | Delete
var wordOperators = wordRegexp(["and", "or", "not", "is"]);
[17] Fix | Delete
var commonKeywords = ["as", "assert", "break", "class", "continue",
[18] Fix | Delete
"def", "del", "elif", "else", "except", "finally",
[19] Fix | Delete
"for", "from", "global", "if", "import",
[20] Fix | Delete
"lambda", "pass", "raise", "return",
[21] Fix | Delete
"try", "while", "with", "yield", "in"];
[22] Fix | Delete
var commonBuiltins = ["abs", "all", "any", "bin", "bool", "bytearray", "callable", "chr",
[23] Fix | Delete
"classmethod", "compile", "complex", "delattr", "dict", "dir", "divmod",
[24] Fix | Delete
"enumerate", "eval", "filter", "float", "format", "frozenset",
[25] Fix | Delete
"getattr", "globals", "hasattr", "hash", "help", "hex", "id",
[26] Fix | Delete
"input", "int", "isinstance", "issubclass", "iter", "len",
[27] Fix | Delete
"list", "locals", "map", "max", "memoryview", "min", "next",
[28] Fix | Delete
"object", "oct", "open", "ord", "pow", "property", "range",
[29] Fix | Delete
"repr", "reversed", "round", "set", "setattr", "slice",
[30] Fix | Delete
"sorted", "staticmethod", "str", "sum", "super", "tuple",
[31] Fix | Delete
"type", "vars", "zip", "__import__", "NotImplemented",
[32] Fix | Delete
"Ellipsis", "__debug__"];
[33] Fix | Delete
CodeMirror.registerHelper("hintWords", "python", commonKeywords.concat(commonBuiltins));
[34] Fix | Delete
[35] Fix | Delete
function top(state) {
[36] Fix | Delete
return state.scopes[state.scopes.length - 1];
[37] Fix | Delete
}
[38] Fix | Delete
[39] Fix | Delete
CodeMirror.defineMode("python", function(conf, parserConf) {
[40] Fix | Delete
var ERRORCLASS = "error";
[41] Fix | Delete
[42] Fix | Delete
var singleDelimiters = parserConf.singleDelimiters || /^[\(\)\[\]\{\}@,:`=;\.]/;
[43] Fix | Delete
var doubleOperators = parserConf.doubleOperators || /^([!<>]==|<>|<<|>>|\/\/|\*\*)/;
[44] Fix | Delete
var doubleDelimiters = parserConf.doubleDelimiters || /^(\+=|\-=|\*=|%=|\/=|&=|\|=|\^=)/;
[45] Fix | Delete
var tripleDelimiters = parserConf.tripleDelimiters || /^(\/\/=|>>=|<<=|\*\*=)/;
[46] Fix | Delete
[47] Fix | Delete
var hangingIndent = parserConf.hangingIndent || conf.indentUnit;
[48] Fix | Delete
[49] Fix | Delete
var myKeywords = commonKeywords, myBuiltins = commonBuiltins;
[50] Fix | Delete
if (parserConf.extra_keywords != undefined)
[51] Fix | Delete
myKeywords = myKeywords.concat(parserConf.extra_keywords);
[52] Fix | Delete
[53] Fix | Delete
if (parserConf.extra_builtins != undefined)
[54] Fix | Delete
myBuiltins = myBuiltins.concat(parserConf.extra_builtins);
[55] Fix | Delete
[56] Fix | Delete
var py3 = !(parserConf.version && Number(parserConf.version) < 3)
[57] Fix | Delete
if (py3) {
[58] Fix | Delete
// since http://legacy.python.org/dev/peps/pep-0465/ @ is also an operator
[59] Fix | Delete
var singleOperators = parserConf.singleOperators || /^[\+\-\*\/%&|\^~<>!@]/;
[60] Fix | Delete
var identifiers = parserConf.identifiers|| /^[_A-Za-z\u00A1-\uFFFF][_A-Za-z0-9\u00A1-\uFFFF]*/;
[61] Fix | Delete
myKeywords = myKeywords.concat(["nonlocal", "False", "True", "None", "async", "await"]);
[62] Fix | Delete
myBuiltins = myBuiltins.concat(["ascii", "bytes", "exec", "print"]);
[63] Fix | Delete
var stringPrefixes = new RegExp("^(([rbuf]|(br))?('{3}|\"{3}|['\"]))", "i");
[64] Fix | Delete
} else {
[65] Fix | Delete
var singleOperators = parserConf.singleOperators || /^[\+\-\*\/%&|\^~<>!]/;
[66] Fix | Delete
var identifiers = parserConf.identifiers|| /^[_A-Za-z][_A-Za-z0-9]*/;
[67] Fix | Delete
myKeywords = myKeywords.concat(["exec", "print"]);
[68] Fix | Delete
myBuiltins = myBuiltins.concat(["apply", "basestring", "buffer", "cmp", "coerce", "execfile",
[69] Fix | Delete
"file", "intern", "long", "raw_input", "reduce", "reload",
[70] Fix | Delete
"unichr", "unicode", "xrange", "False", "True", "None"]);
[71] Fix | Delete
var stringPrefixes = new RegExp("^(([rub]|(ur)|(br))?('{3}|\"{3}|['\"]))", "i");
[72] Fix | Delete
}
[73] Fix | Delete
var keywords = wordRegexp(myKeywords);
[74] Fix | Delete
var builtins = wordRegexp(myBuiltins);
[75] Fix | Delete
[76] Fix | Delete
// tokenizers
[77] Fix | Delete
function tokenBase(stream, state) {
[78] Fix | Delete
if (stream.sol()) state.indent = stream.indentation()
[79] Fix | Delete
// Handle scope changes
[80] Fix | Delete
if (stream.sol() && top(state).type == "py") {
[81] Fix | Delete
var scopeOffset = top(state).offset;
[82] Fix | Delete
if (stream.eatSpace()) {
[83] Fix | Delete
var lineOffset = stream.indentation();
[84] Fix | Delete
if (lineOffset > scopeOffset)
[85] Fix | Delete
pushPyScope(state);
[86] Fix | Delete
else if (lineOffset < scopeOffset && dedent(stream, state))
[87] Fix | Delete
state.errorToken = true;
[88] Fix | Delete
return null;
[89] Fix | Delete
} else {
[90] Fix | Delete
var style = tokenBaseInner(stream, state);
[91] Fix | Delete
if (scopeOffset > 0 && dedent(stream, state))
[92] Fix | Delete
style += " " + ERRORCLASS;
[93] Fix | Delete
return style;
[94] Fix | Delete
}
[95] Fix | Delete
}
[96] Fix | Delete
return tokenBaseInner(stream, state);
[97] Fix | Delete
}
[98] Fix | Delete
[99] Fix | Delete
function tokenBaseInner(stream, state) {
[100] Fix | Delete
if (stream.eatSpace()) return null;
[101] Fix | Delete
[102] Fix | Delete
var ch = stream.peek();
[103] Fix | Delete
[104] Fix | Delete
// Handle Comments
[105] Fix | Delete
if (ch == "#") {
[106] Fix | Delete
stream.skipToEnd();
[107] Fix | Delete
return "comment";
[108] Fix | Delete
}
[109] Fix | Delete
[110] Fix | Delete
// Handle Number Literals
[111] Fix | Delete
if (stream.match(/^[0-9\.]/, false)) {
[112] Fix | Delete
var floatLiteral = false;
[113] Fix | Delete
// Floats
[114] Fix | Delete
if (stream.match(/^\d*\.\d+(e[\+\-]?\d+)?/i)) { floatLiteral = true; }
[115] Fix | Delete
if (stream.match(/^\d+\.\d*/)) { floatLiteral = true; }
[116] Fix | Delete
if (stream.match(/^\.\d+/)) { floatLiteral = true; }
[117] Fix | Delete
if (floatLiteral) {
[118] Fix | Delete
// Float literals may be "imaginary"
[119] Fix | Delete
stream.eat(/J/i);
[120] Fix | Delete
return "number";
[121] Fix | Delete
}
[122] Fix | Delete
// Integers
[123] Fix | Delete
var intLiteral = false;
[124] Fix | Delete
// Hex
[125] Fix | Delete
if (stream.match(/^0x[0-9a-f]+/i)) intLiteral = true;
[126] Fix | Delete
// Binary
[127] Fix | Delete
if (stream.match(/^0b[01]+/i)) intLiteral = true;
[128] Fix | Delete
// Octal
[129] Fix | Delete
if (stream.match(/^0o[0-7]+/i)) intLiteral = true;
[130] Fix | Delete
// Decimal
[131] Fix | Delete
if (stream.match(/^[1-9]\d*(e[\+\-]?\d+)?/)) {
[132] Fix | Delete
// Decimal literals may be "imaginary"
[133] Fix | Delete
stream.eat(/J/i);
[134] Fix | Delete
// TODO - Can you have imaginary longs?
[135] Fix | Delete
intLiteral = true;
[136] Fix | Delete
}
[137] Fix | Delete
// Zero by itself with no other piece of number.
[138] Fix | Delete
if (stream.match(/^0(?![\dx])/i)) intLiteral = true;
[139] Fix | Delete
if (intLiteral) {
[140] Fix | Delete
// Integer literals may be "long"
[141] Fix | Delete
stream.eat(/L/i);
[142] Fix | Delete
return "number";
[143] Fix | Delete
}
[144] Fix | Delete
}
[145] Fix | Delete
[146] Fix | Delete
// Handle Strings
[147] Fix | Delete
if (stream.match(stringPrefixes)) {
[148] Fix | Delete
state.tokenize = tokenStringFactory(stream.current());
[149] Fix | Delete
return state.tokenize(stream, state);
[150] Fix | Delete
}
[151] Fix | Delete
[152] Fix | Delete
// Handle operators and Delimiters
[153] Fix | Delete
if (stream.match(tripleDelimiters) || stream.match(doubleDelimiters))
[154] Fix | Delete
return "punctuation";
[155] Fix | Delete
[156] Fix | Delete
if (stream.match(doubleOperators) || stream.match(singleOperators))
[157] Fix | Delete
return "operator";
[158] Fix | Delete
[159] Fix | Delete
if (stream.match(singleDelimiters))
[160] Fix | Delete
return "punctuation";
[161] Fix | Delete
[162] Fix | Delete
if (state.lastToken == "." && stream.match(identifiers))
[163] Fix | Delete
return "property";
[164] Fix | Delete
[165] Fix | Delete
if (stream.match(keywords) || stream.match(wordOperators))
[166] Fix | Delete
return "keyword";
[167] Fix | Delete
[168] Fix | Delete
if (stream.match(builtins))
[169] Fix | Delete
return "builtin";
[170] Fix | Delete
[171] Fix | Delete
if (stream.match(/^(self|cls)\b/))
[172] Fix | Delete
return "variable-2";
[173] Fix | Delete
[174] Fix | Delete
if (stream.match(identifiers)) {
[175] Fix | Delete
if (state.lastToken == "def" || state.lastToken == "class")
[176] Fix | Delete
return "def";
[177] Fix | Delete
return "variable";
[178] Fix | Delete
}
[179] Fix | Delete
[180] Fix | Delete
// Handle non-detected items
[181] Fix | Delete
stream.next();
[182] Fix | Delete
return ERRORCLASS;
[183] Fix | Delete
}
[184] Fix | Delete
[185] Fix | Delete
function tokenStringFactory(delimiter) {
[186] Fix | Delete
while ("rubf".indexOf(delimiter.charAt(0).toLowerCase()) >= 0)
[187] Fix | Delete
delimiter = delimiter.substr(1);
[188] Fix | Delete
[189] Fix | Delete
var singleline = delimiter.length == 1;
[190] Fix | Delete
var OUTCLASS = "string";
[191] Fix | Delete
[192] Fix | Delete
function tokenString(stream, state) {
[193] Fix | Delete
while (!stream.eol()) {
[194] Fix | Delete
stream.eatWhile(/[^'"\\]/);
[195] Fix | Delete
if (stream.eat("\\")) {
[196] Fix | Delete
stream.next();
[197] Fix | Delete
if (singleline && stream.eol())
[198] Fix | Delete
return OUTCLASS;
[199] Fix | Delete
} else if (stream.match(delimiter)) {
[200] Fix | Delete
state.tokenize = tokenBase;
[201] Fix | Delete
return OUTCLASS;
[202] Fix | Delete
} else {
[203] Fix | Delete
stream.eat(/['"]/);
[204] Fix | Delete
}
[205] Fix | Delete
}
[206] Fix | Delete
if (singleline) {
[207] Fix | Delete
if (parserConf.singleLineStringErrors)
[208] Fix | Delete
return ERRORCLASS;
[209] Fix | Delete
else
[210] Fix | Delete
state.tokenize = tokenBase;
[211] Fix | Delete
}
[212] Fix | Delete
return OUTCLASS;
[213] Fix | Delete
}
[214] Fix | Delete
tokenString.isString = true;
[215] Fix | Delete
return tokenString;
[216] Fix | Delete
}
[217] Fix | Delete
[218] Fix | Delete
function pushPyScope(state) {
[219] Fix | Delete
while (top(state).type != "py") state.scopes.pop()
[220] Fix | Delete
state.scopes.push({offset: top(state).offset + conf.indentUnit,
[221] Fix | Delete
type: "py",
[222] Fix | Delete
align: null})
[223] Fix | Delete
}
[224] Fix | Delete
[225] Fix | Delete
function pushBracketScope(stream, state, type) {
[226] Fix | Delete
var align = stream.match(/^([\s\[\{\(]|#.*)*$/, false) ? null : stream.column() + 1
[227] Fix | Delete
state.scopes.push({offset: state.indent + hangingIndent,
[228] Fix | Delete
type: type,
[229] Fix | Delete
align: align})
[230] Fix | Delete
}
[231] Fix | Delete
[232] Fix | Delete
function dedent(stream, state) {
[233] Fix | Delete
var indented = stream.indentation();
[234] Fix | Delete
while (state.scopes.length > 1 && top(state).offset > indented) {
[235] Fix | Delete
if (top(state).type != "py") return true;
[236] Fix | Delete
state.scopes.pop();
[237] Fix | Delete
}
[238] Fix | Delete
return top(state).offset != indented;
[239] Fix | Delete
}
[240] Fix | Delete
[241] Fix | Delete
function tokenLexer(stream, state) {
[242] Fix | Delete
if (stream.sol()) state.beginningOfLine = true;
[243] Fix | Delete
[244] Fix | Delete
var style = state.tokenize(stream, state);
[245] Fix | Delete
var current = stream.current();
[246] Fix | Delete
[247] Fix | Delete
// Handle decorators
[248] Fix | Delete
if (state.beginningOfLine && current == "@")
[249] Fix | Delete
return stream.match(identifiers, false) ? "meta" : py3 ? "operator" : ERRORCLASS;
[250] Fix | Delete
[251] Fix | Delete
if (/\S/.test(current)) state.beginningOfLine = false;
[252] Fix | Delete
[253] Fix | Delete
if ((style == "variable" || style == "builtin")
[254] Fix | Delete
&& state.lastToken == "meta")
[255] Fix | Delete
style = "meta";
[256] Fix | Delete
[257] Fix | Delete
// Handle scope changes.
[258] Fix | Delete
if (current == "pass" || current == "return")
[259] Fix | Delete
state.dedent += 1;
[260] Fix | Delete
[261] Fix | Delete
if (current == "lambda") state.lambda = true;
[262] Fix | Delete
if (current == ":" && !state.lambda && top(state).type == "py")
[263] Fix | Delete
pushPyScope(state);
[264] Fix | Delete
[265] Fix | Delete
var delimiter_index = current.length == 1 ? "[({".indexOf(current) : -1;
[266] Fix | Delete
if (delimiter_index != -1)
[267] Fix | Delete
pushBracketScope(stream, state, "])}".slice(delimiter_index, delimiter_index+1));
[268] Fix | Delete
[269] Fix | Delete
delimiter_index = "])}".indexOf(current);
[270] Fix | Delete
if (delimiter_index != -1) {
[271] Fix | Delete
if (top(state).type == current) state.indent = state.scopes.pop().offset - hangingIndent
[272] Fix | Delete
else return ERRORCLASS;
[273] Fix | Delete
}
[274] Fix | Delete
if (state.dedent > 0 && stream.eol() && top(state).type == "py") {
[275] Fix | Delete
if (state.scopes.length > 1) state.scopes.pop();
[276] Fix | Delete
state.dedent -= 1;
[277] Fix | Delete
}
[278] Fix | Delete
[279] Fix | Delete
return style;
[280] Fix | Delete
}
[281] Fix | Delete
[282] Fix | Delete
var external = {
[283] Fix | Delete
startState: function(basecolumn) {
[284] Fix | Delete
return {
[285] Fix | Delete
tokenize: tokenBase,
[286] Fix | Delete
scopes: [{offset: basecolumn || 0, type: "py", align: null}],
[287] Fix | Delete
indent: basecolumn || 0,
[288] Fix | Delete
lastToken: null,
[289] Fix | Delete
lambda: false,
[290] Fix | Delete
dedent: 0
[291] Fix | Delete
};
[292] Fix | Delete
},
[293] Fix | Delete
[294] Fix | Delete
token: function(stream, state) {
[295] Fix | Delete
var addErr = state.errorToken;
[296] Fix | Delete
if (addErr) state.errorToken = false;
[297] Fix | Delete
var style = tokenLexer(stream, state);
[298] Fix | Delete
[299] Fix | Delete
if (style && style != "comment")
[300] Fix | Delete
state.lastToken = (style == "keyword" || style == "punctuation") ? stream.current() : style;
[301] Fix | Delete
if (style == "punctuation") style = null;
[302] Fix | Delete
[303] Fix | Delete
if (stream.eol() && state.lambda)
[304] Fix | Delete
state.lambda = false;
[305] Fix | Delete
return addErr ? style + " " + ERRORCLASS : style;
[306] Fix | Delete
},
[307] Fix | Delete
[308] Fix | Delete
indent: function(state, textAfter) {
[309] Fix | Delete
if (state.tokenize != tokenBase)
[310] Fix | Delete
return state.tokenize.isString ? CodeMirror.Pass : 0;
[311] Fix | Delete
[312] Fix | Delete
var scope = top(state), closing = scope.type == textAfter.charAt(0)
[313] Fix | Delete
if (scope.align != null)
[314] Fix | Delete
return scope.align - (closing ? 1 : 0)
[315] Fix | Delete
else
[316] Fix | Delete
return scope.offset - (closing ? hangingIndent : 0)
[317] Fix | Delete
},
[318] Fix | Delete
[319] Fix | Delete
electricInput: /^\s*[\}\]\)]$/,
[320] Fix | Delete
closeBrackets: {triples: "'\""},
[321] Fix | Delete
lineComment: "#",
[322] Fix | Delete
fold: "indent"
[323] Fix | Delete
};
[324] Fix | Delete
return external;
[325] Fix | Delete
});
[326] Fix | Delete
[327] Fix | Delete
CodeMirror.defineMIME("text/x-python", "python");
[328] Fix | Delete
[329] Fix | Delete
var words = function(str) { return str.split(" "); };
[330] Fix | Delete
[331] Fix | Delete
CodeMirror.defineMIME("text/x-cython", {
[332] Fix | Delete
name: "python",
[333] Fix | Delete
extra_keywords: words("by cdef cimport cpdef ctypedef enum except"+
[334] Fix | Delete
"extern gil include nogil property public"+
[335] Fix | Delete
"readonly struct union DEF IF ELIF ELSE")
[336] Fix | Delete
});
[337] Fix | Delete
[338] Fix | Delete
});
[339] Fix | Delete
[340] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function