Edit File by line
/home/barbar84/www/wp-conte.../plugins/wp-file-.../lib/codemirr.../mode/coffeesc...
File: coffeescript.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
/**
[3] Fix | Delete
* Link to the project's GitHub page:
[4] Fix | Delete
* https://github.com/pickhardt/coffeescript-codemirror-mode
[5] Fix | Delete
*/
[6] Fix | Delete
(function(mod) {
[7] Fix | Delete
if (typeof exports == "object" && typeof module == "object") // CommonJS
[8] Fix | Delete
mod(require("../../lib/codemirror"));
[9] Fix | Delete
else if (typeof define == "function" && define.amd) // AMD
[10] Fix | Delete
define(["../../lib/codemirror"], mod);
[11] Fix | Delete
else // Plain browser env
[12] Fix | Delete
mod(CodeMirror);
[13] Fix | Delete
})(function(CodeMirror) {
[14] Fix | Delete
"use strict";
[15] Fix | Delete
[16] Fix | Delete
CodeMirror.defineMode("coffeescript", function(conf, parserConf) {
[17] Fix | Delete
var ERRORCLASS = "error";
[18] Fix | Delete
[19] Fix | Delete
function wordRegexp(words) {
[20] Fix | Delete
return new RegExp("^((" + words.join(")|(") + "))\\b");
[21] Fix | Delete
}
[22] Fix | Delete
[23] Fix | Delete
var operators = /^(?:->|=>|\+[+=]?|-[\-=]?|\*[\*=]?|\/[\/=]?|[=!]=|<[><]?=?|>>?=?|%=?|&=?|\|=?|\^=?|\~|!|\?|(or|and|\|\||&&|\?)=)/;
[24] Fix | Delete
var delimiters = /^(?:[()\[\]{},:`=;]|\.\.?\.?)/;
[25] Fix | Delete
var identifiers = /^[_A-Za-z$][_A-Za-z$0-9]*/;
[26] Fix | Delete
var atProp = /^@[_A-Za-z$][_A-Za-z$0-9]*/;
[27] Fix | Delete
[28] Fix | Delete
var wordOperators = wordRegexp(["and", "or", "not",
[29] Fix | Delete
"is", "isnt", "in",
[30] Fix | Delete
"instanceof", "typeof"]);
[31] Fix | Delete
var indentKeywords = ["for", "while", "loop", "if", "unless", "else",
[32] Fix | Delete
"switch", "try", "catch", "finally", "class"];
[33] Fix | Delete
var commonKeywords = ["break", "by", "continue", "debugger", "delete",
[34] Fix | Delete
"do", "in", "of", "new", "return", "then",
[35] Fix | Delete
"this", "@", "throw", "when", "until", "extends"];
[36] Fix | Delete
[37] Fix | Delete
var keywords = wordRegexp(indentKeywords.concat(commonKeywords));
[38] Fix | Delete
[39] Fix | Delete
indentKeywords = wordRegexp(indentKeywords);
[40] Fix | Delete
[41] Fix | Delete
[42] Fix | Delete
var stringPrefixes = /^('{3}|\"{3}|['\"])/;
[43] Fix | Delete
var regexPrefixes = /^(\/{3}|\/)/;
[44] Fix | Delete
var commonConstants = ["Infinity", "NaN", "undefined", "null", "true", "false", "on", "off", "yes", "no"];
[45] Fix | Delete
var constants = wordRegexp(commonConstants);
[46] Fix | Delete
[47] Fix | Delete
// Tokenizers
[48] Fix | Delete
function tokenBase(stream, state) {
[49] Fix | Delete
// Handle scope changes
[50] Fix | Delete
if (stream.sol()) {
[51] Fix | Delete
if (state.scope.align === null) state.scope.align = false;
[52] Fix | Delete
var scopeOffset = state.scope.offset;
[53] Fix | Delete
if (stream.eatSpace()) {
[54] Fix | Delete
var lineOffset = stream.indentation();
[55] Fix | Delete
if (lineOffset > scopeOffset && state.scope.type == "coffee") {
[56] Fix | Delete
return "indent";
[57] Fix | Delete
} else if (lineOffset < scopeOffset) {
[58] Fix | Delete
return "dedent";
[59] Fix | Delete
}
[60] Fix | Delete
return null;
[61] Fix | Delete
} else {
[62] Fix | Delete
if (scopeOffset > 0) {
[63] Fix | Delete
dedent(stream, state);
[64] Fix | Delete
}
[65] Fix | Delete
}
[66] Fix | Delete
}
[67] Fix | Delete
if (stream.eatSpace()) {
[68] Fix | Delete
return null;
[69] Fix | Delete
}
[70] Fix | Delete
[71] Fix | Delete
var ch = stream.peek();
[72] Fix | Delete
[73] Fix | Delete
// Handle docco title comment (single line)
[74] Fix | Delete
if (stream.match("####")) {
[75] Fix | Delete
stream.skipToEnd();
[76] Fix | Delete
return "comment";
[77] Fix | Delete
}
[78] Fix | Delete
[79] Fix | Delete
// Handle multi line comments
[80] Fix | Delete
if (stream.match("###")) {
[81] Fix | Delete
state.tokenize = longComment;
[82] Fix | Delete
return state.tokenize(stream, state);
[83] Fix | Delete
}
[84] Fix | Delete
[85] Fix | Delete
// Single line comment
[86] Fix | Delete
if (ch === "#") {
[87] Fix | Delete
stream.skipToEnd();
[88] Fix | Delete
return "comment";
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
// Handle number literals
[92] Fix | Delete
if (stream.match(/^-?[0-9\.]/, false)) {
[93] Fix | Delete
var floatLiteral = false;
[94] Fix | Delete
// Floats
[95] Fix | Delete
if (stream.match(/^-?\d*\.\d+(e[\+\-]?\d+)?/i)) {
[96] Fix | Delete
floatLiteral = true;
[97] Fix | Delete
}
[98] Fix | Delete
if (stream.match(/^-?\d+\.\d*/)) {
[99] Fix | Delete
floatLiteral = true;
[100] Fix | Delete
}
[101] Fix | Delete
if (stream.match(/^-?\.\d+/)) {
[102] Fix | Delete
floatLiteral = true;
[103] Fix | Delete
}
[104] Fix | Delete
[105] Fix | Delete
if (floatLiteral) {
[106] Fix | Delete
// prevent from getting extra . on 1..
[107] Fix | Delete
if (stream.peek() == "."){
[108] Fix | Delete
stream.backUp(1);
[109] Fix | Delete
}
[110] Fix | Delete
return "number";
[111] Fix | Delete
}
[112] Fix | Delete
// Integers
[113] Fix | Delete
var intLiteral = false;
[114] Fix | Delete
// Hex
[115] Fix | Delete
if (stream.match(/^-?0x[0-9a-f]+/i)) {
[116] Fix | Delete
intLiteral = true;
[117] Fix | Delete
}
[118] Fix | Delete
// Decimal
[119] Fix | Delete
if (stream.match(/^-?[1-9]\d*(e[\+\-]?\d+)?/)) {
[120] Fix | Delete
intLiteral = true;
[121] Fix | Delete
}
[122] Fix | Delete
// Zero by itself with no other piece of number.
[123] Fix | Delete
if (stream.match(/^-?0(?![\dx])/i)) {
[124] Fix | Delete
intLiteral = true;
[125] Fix | Delete
}
[126] Fix | Delete
if (intLiteral) {
[127] Fix | Delete
return "number";
[128] Fix | Delete
}
[129] Fix | Delete
}
[130] Fix | Delete
[131] Fix | Delete
// Handle strings
[132] Fix | Delete
if (stream.match(stringPrefixes)) {
[133] Fix | Delete
state.tokenize = tokenFactory(stream.current(), false, "string");
[134] Fix | Delete
return state.tokenize(stream, state);
[135] Fix | Delete
}
[136] Fix | Delete
// Handle regex literals
[137] Fix | Delete
if (stream.match(regexPrefixes)) {
[138] Fix | Delete
if (stream.current() != "/" || stream.match(/^.*\//, false)) { // prevent highlight of division
[139] Fix | Delete
state.tokenize = tokenFactory(stream.current(), true, "string-2");
[140] Fix | Delete
return state.tokenize(stream, state);
[141] Fix | Delete
} else {
[142] Fix | Delete
stream.backUp(1);
[143] Fix | Delete
}
[144] Fix | Delete
}
[145] Fix | Delete
[146] Fix | Delete
[147] Fix | Delete
[148] Fix | Delete
// Handle operators and delimiters
[149] Fix | Delete
if (stream.match(operators) || stream.match(wordOperators)) {
[150] Fix | Delete
return "operator";
[151] Fix | Delete
}
[152] Fix | Delete
if (stream.match(delimiters)) {
[153] Fix | Delete
return "punctuation";
[154] Fix | Delete
}
[155] Fix | Delete
[156] Fix | Delete
if (stream.match(constants)) {
[157] Fix | Delete
return "atom";
[158] Fix | Delete
}
[159] Fix | Delete
[160] Fix | Delete
if (stream.match(atProp) || state.prop && stream.match(identifiers)) {
[161] Fix | Delete
return "property";
[162] Fix | Delete
}
[163] Fix | Delete
[164] Fix | Delete
if (stream.match(keywords)) {
[165] Fix | Delete
return "keyword";
[166] Fix | Delete
}
[167] Fix | Delete
[168] Fix | Delete
if (stream.match(identifiers)) {
[169] Fix | Delete
return "variable";
[170] Fix | Delete
}
[171] Fix | Delete
[172] Fix | Delete
// Handle non-detected items
[173] Fix | Delete
stream.next();
[174] Fix | Delete
return ERRORCLASS;
[175] Fix | Delete
}
[176] Fix | Delete
[177] Fix | Delete
function tokenFactory(delimiter, singleline, outclass) {
[178] Fix | Delete
return function(stream, state) {
[179] Fix | Delete
while (!stream.eol()) {
[180] Fix | Delete
stream.eatWhile(/[^'"\/\\]/);
[181] Fix | Delete
if (stream.eat("\\")) {
[182] Fix | Delete
stream.next();
[183] Fix | Delete
if (singleline && stream.eol()) {
[184] Fix | Delete
return outclass;
[185] Fix | Delete
}
[186] Fix | Delete
} else if (stream.match(delimiter)) {
[187] Fix | Delete
state.tokenize = tokenBase;
[188] Fix | Delete
return outclass;
[189] Fix | Delete
} else {
[190] Fix | Delete
stream.eat(/['"\/]/);
[191] Fix | Delete
}
[192] Fix | Delete
}
[193] Fix | Delete
if (singleline) {
[194] Fix | Delete
if (parserConf.singleLineStringErrors) {
[195] Fix | Delete
outclass = ERRORCLASS;
[196] Fix | Delete
} else {
[197] Fix | Delete
state.tokenize = tokenBase;
[198] Fix | Delete
}
[199] Fix | Delete
}
[200] Fix | Delete
return outclass;
[201] Fix | Delete
};
[202] Fix | Delete
}
[203] Fix | Delete
[204] Fix | Delete
function longComment(stream, state) {
[205] Fix | Delete
while (!stream.eol()) {
[206] Fix | Delete
stream.eatWhile(/[^#]/);
[207] Fix | Delete
if (stream.match("###")) {
[208] Fix | Delete
state.tokenize = tokenBase;
[209] Fix | Delete
break;
[210] Fix | Delete
}
[211] Fix | Delete
stream.eatWhile("#");
[212] Fix | Delete
}
[213] Fix | Delete
return "comment";
[214] Fix | Delete
}
[215] Fix | Delete
[216] Fix | Delete
function indent(stream, state, type) {
[217] Fix | Delete
type = type || "coffee";
[218] Fix | Delete
var offset = 0, align = false, alignOffset = null;
[219] Fix | Delete
for (var scope = state.scope; scope; scope = scope.prev) {
[220] Fix | Delete
if (scope.type === "coffee" || scope.type == "}") {
[221] Fix | Delete
offset = scope.offset + conf.indentUnit;
[222] Fix | Delete
break;
[223] Fix | Delete
}
[224] Fix | Delete
}
[225] Fix | Delete
if (type !== "coffee") {
[226] Fix | Delete
align = null;
[227] Fix | Delete
alignOffset = stream.column() + stream.current().length;
[228] Fix | Delete
} else if (state.scope.align) {
[229] Fix | Delete
state.scope.align = false;
[230] Fix | Delete
}
[231] Fix | Delete
state.scope = {
[232] Fix | Delete
offset: offset,
[233] Fix | Delete
type: type,
[234] Fix | Delete
prev: state.scope,
[235] Fix | Delete
align: align,
[236] Fix | Delete
alignOffset: alignOffset
[237] Fix | Delete
};
[238] Fix | Delete
}
[239] Fix | Delete
[240] Fix | Delete
function dedent(stream, state) {
[241] Fix | Delete
if (!state.scope.prev) return;
[242] Fix | Delete
if (state.scope.type === "coffee") {
[243] Fix | Delete
var _indent = stream.indentation();
[244] Fix | Delete
var matched = false;
[245] Fix | Delete
for (var scope = state.scope; scope; scope = scope.prev) {
[246] Fix | Delete
if (_indent === scope.offset) {
[247] Fix | Delete
matched = true;
[248] Fix | Delete
break;
[249] Fix | Delete
}
[250] Fix | Delete
}
[251] Fix | Delete
if (!matched) {
[252] Fix | Delete
return true;
[253] Fix | Delete
}
[254] Fix | Delete
while (state.scope.prev && state.scope.offset !== _indent) {
[255] Fix | Delete
state.scope = state.scope.prev;
[256] Fix | Delete
}
[257] Fix | Delete
return false;
[258] Fix | Delete
} else {
[259] Fix | Delete
state.scope = state.scope.prev;
[260] Fix | Delete
return false;
[261] Fix | Delete
}
[262] Fix | Delete
}
[263] Fix | Delete
[264] Fix | Delete
function tokenLexer(stream, state) {
[265] Fix | Delete
var style = state.tokenize(stream, state);
[266] Fix | Delete
var current = stream.current();
[267] Fix | Delete
[268] Fix | Delete
// Handle scope changes.
[269] Fix | Delete
if (current === "return") {
[270] Fix | Delete
state.dedent = true;
[271] Fix | Delete
}
[272] Fix | Delete
if (((current === "->" || current === "=>") && stream.eol())
[273] Fix | Delete
|| style === "indent") {
[274] Fix | Delete
indent(stream, state);
[275] Fix | Delete
}
[276] Fix | Delete
var delimiter_index = "[({".indexOf(current);
[277] Fix | Delete
if (delimiter_index !== -1) {
[278] Fix | Delete
indent(stream, state, "])}".slice(delimiter_index, delimiter_index+1));
[279] Fix | Delete
}
[280] Fix | Delete
if (indentKeywords.exec(current)){
[281] Fix | Delete
indent(stream, state);
[282] Fix | Delete
}
[283] Fix | Delete
if (current == "then"){
[284] Fix | Delete
dedent(stream, state);
[285] Fix | Delete
}
[286] Fix | Delete
[287] Fix | Delete
[288] Fix | Delete
if (style === "dedent") {
[289] Fix | Delete
if (dedent(stream, state)) {
[290] Fix | Delete
return ERRORCLASS;
[291] Fix | Delete
}
[292] Fix | Delete
}
[293] Fix | Delete
delimiter_index = "])}".indexOf(current);
[294] Fix | Delete
if (delimiter_index !== -1) {
[295] Fix | Delete
while (state.scope.type == "coffee" && state.scope.prev)
[296] Fix | Delete
state.scope = state.scope.prev;
[297] Fix | Delete
if (state.scope.type == current)
[298] Fix | Delete
state.scope = state.scope.prev;
[299] Fix | Delete
}
[300] Fix | Delete
if (state.dedent && stream.eol()) {
[301] Fix | Delete
if (state.scope.type == "coffee" && state.scope.prev)
[302] Fix | Delete
state.scope = state.scope.prev;
[303] Fix | Delete
state.dedent = false;
[304] Fix | Delete
}
[305] Fix | Delete
[306] Fix | Delete
return style;
[307] Fix | Delete
}
[308] Fix | Delete
[309] Fix | Delete
var external = {
[310] Fix | Delete
startState: function(basecolumn) {
[311] Fix | Delete
return {
[312] Fix | Delete
tokenize: tokenBase,
[313] Fix | Delete
scope: {offset:basecolumn || 0, type:"coffee", prev: null, align: false},
[314] Fix | Delete
prop: false,
[315] Fix | Delete
dedent: 0
[316] Fix | Delete
};
[317] Fix | Delete
},
[318] Fix | Delete
[319] Fix | Delete
token: function(stream, state) {
[320] Fix | Delete
var fillAlign = state.scope.align === null && state.scope;
[321] Fix | Delete
if (fillAlign && stream.sol()) fillAlign.align = false;
[322] Fix | Delete
[323] Fix | Delete
var style = tokenLexer(stream, state);
[324] Fix | Delete
if (style && style != "comment") {
[325] Fix | Delete
if (fillAlign) fillAlign.align = true;
[326] Fix | Delete
state.prop = style == "punctuation" && stream.current() == "."
[327] Fix | Delete
}
[328] Fix | Delete
[329] Fix | Delete
return style;
[330] Fix | Delete
},
[331] Fix | Delete
[332] Fix | Delete
indent: function(state, text) {
[333] Fix | Delete
if (state.tokenize != tokenBase) return 0;
[334] Fix | Delete
var scope = state.scope;
[335] Fix | Delete
var closer = text && "])}".indexOf(text.charAt(0)) > -1;
[336] Fix | Delete
if (closer) while (scope.type == "coffee" && scope.prev) scope = scope.prev;
[337] Fix | Delete
var closes = closer && scope.type === text.charAt(0);
[338] Fix | Delete
if (scope.align)
[339] Fix | Delete
return scope.alignOffset - (closes ? 1 : 0);
[340] Fix | Delete
else
[341] Fix | Delete
return (closes ? scope.prev : scope).offset;
[342] Fix | Delete
},
[343] Fix | Delete
[344] Fix | Delete
lineComment: "#",
[345] Fix | Delete
fold: "indent"
[346] Fix | Delete
};
[347] Fix | Delete
return external;
[348] Fix | Delete
});
[349] Fix | Delete
[350] Fix | Delete
CodeMirror.defineMIME("text/x-coffeescript", "coffeescript");
[351] Fix | Delete
CodeMirror.defineMIME("text/coffeescript", "coffeescript");
[352] Fix | Delete
[353] Fix | Delete
});
[354] Fix | Delete
[355] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function