Edit File by line
/home/barbar84/www/wp-conte.../plugins/wp-file-.../lib/codemirr.../mode/groovy
File: groovy.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
CodeMirror.defineMode("groovy", function(config) {
[13] Fix | Delete
function words(str) {
[14] Fix | Delete
var obj = {}, words = str.split(" ");
[15] Fix | Delete
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
[16] Fix | Delete
return obj;
[17] Fix | Delete
}
[18] Fix | Delete
var keywords = words(
[19] Fix | Delete
"abstract as assert boolean break byte case catch char class const continue def default " +
[20] Fix | Delete
"do double else enum extends final finally float for goto if implements import in " +
[21] Fix | Delete
"instanceof int interface long native new package private protected public return " +
[22] Fix | Delete
"short static strictfp super switch synchronized threadsafe throw throws transient " +
[23] Fix | Delete
"try void volatile while");
[24] Fix | Delete
var blockKeywords = words("catch class do else finally for if switch try while enum interface def");
[25] Fix | Delete
var standaloneKeywords = words("return break continue");
[26] Fix | Delete
var atoms = words("null true false this");
[27] Fix | Delete
[28] Fix | Delete
var curPunc;
[29] Fix | Delete
function tokenBase(stream, state) {
[30] Fix | Delete
var ch = stream.next();
[31] Fix | Delete
if (ch == '"' || ch == "'") {
[32] Fix | Delete
return startString(ch, stream, state);
[33] Fix | Delete
}
[34] Fix | Delete
if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
[35] Fix | Delete
curPunc = ch;
[36] Fix | Delete
return null;
[37] Fix | Delete
}
[38] Fix | Delete
if (/\d/.test(ch)) {
[39] Fix | Delete
stream.eatWhile(/[\w\.]/);
[40] Fix | Delete
if (stream.eat(/eE/)) { stream.eat(/\+\-/); stream.eatWhile(/\d/); }
[41] Fix | Delete
return "number";
[42] Fix | Delete
}
[43] Fix | Delete
if (ch == "/") {
[44] Fix | Delete
if (stream.eat("*")) {
[45] Fix | Delete
state.tokenize.push(tokenComment);
[46] Fix | Delete
return tokenComment(stream, state);
[47] Fix | Delete
}
[48] Fix | Delete
if (stream.eat("/")) {
[49] Fix | Delete
stream.skipToEnd();
[50] Fix | Delete
return "comment";
[51] Fix | Delete
}
[52] Fix | Delete
if (expectExpression(state.lastToken, false)) {
[53] Fix | Delete
return startString(ch, stream, state);
[54] Fix | Delete
}
[55] Fix | Delete
}
[56] Fix | Delete
if (ch == "-" && stream.eat(">")) {
[57] Fix | Delete
curPunc = "->";
[58] Fix | Delete
return null;
[59] Fix | Delete
}
[60] Fix | Delete
if (/[+\-*&%=<>!?|\/~]/.test(ch)) {
[61] Fix | Delete
stream.eatWhile(/[+\-*&%=<>|~]/);
[62] Fix | Delete
return "operator";
[63] Fix | Delete
}
[64] Fix | Delete
stream.eatWhile(/[\w\$_]/);
[65] Fix | Delete
if (ch == "@") { stream.eatWhile(/[\w\$_\.]/); return "meta"; }
[66] Fix | Delete
if (state.lastToken == ".") return "property";
[67] Fix | Delete
if (stream.eat(":")) { curPunc = "proplabel"; return "property"; }
[68] Fix | Delete
var cur = stream.current();
[69] Fix | Delete
if (atoms.propertyIsEnumerable(cur)) { return "atom"; }
[70] Fix | Delete
if (keywords.propertyIsEnumerable(cur)) {
[71] Fix | Delete
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
[72] Fix | Delete
else if (standaloneKeywords.propertyIsEnumerable(cur)) curPunc = "standalone";
[73] Fix | Delete
return "keyword";
[74] Fix | Delete
}
[75] Fix | Delete
return "variable";
[76] Fix | Delete
}
[77] Fix | Delete
tokenBase.isBase = true;
[78] Fix | Delete
[79] Fix | Delete
function startString(quote, stream, state) {
[80] Fix | Delete
var tripleQuoted = false;
[81] Fix | Delete
if (quote != "/" && stream.eat(quote)) {
[82] Fix | Delete
if (stream.eat(quote)) tripleQuoted = true;
[83] Fix | Delete
else return "string";
[84] Fix | Delete
}
[85] Fix | Delete
function t(stream, state) {
[86] Fix | Delete
var escaped = false, next, end = !tripleQuoted;
[87] Fix | Delete
while ((next = stream.next()) != null) {
[88] Fix | Delete
if (next == quote && !escaped) {
[89] Fix | Delete
if (!tripleQuoted) { break; }
[90] Fix | Delete
if (stream.match(quote + quote)) { end = true; break; }
[91] Fix | Delete
}
[92] Fix | Delete
if (quote == '"' && next == "$" && !escaped && stream.eat("{")) {
[93] Fix | Delete
state.tokenize.push(tokenBaseUntilBrace());
[94] Fix | Delete
return "string";
[95] Fix | Delete
}
[96] Fix | Delete
escaped = !escaped && next == "\\";
[97] Fix | Delete
}
[98] Fix | Delete
if (end) state.tokenize.pop();
[99] Fix | Delete
return "string";
[100] Fix | Delete
}
[101] Fix | Delete
state.tokenize.push(t);
[102] Fix | Delete
return t(stream, state);
[103] Fix | Delete
}
[104] Fix | Delete
[105] Fix | Delete
function tokenBaseUntilBrace() {
[106] Fix | Delete
var depth = 1;
[107] Fix | Delete
function t(stream, state) {
[108] Fix | Delete
if (stream.peek() == "}") {
[109] Fix | Delete
depth--;
[110] Fix | Delete
if (depth == 0) {
[111] Fix | Delete
state.tokenize.pop();
[112] Fix | Delete
return state.tokenize[state.tokenize.length-1](stream, state);
[113] Fix | Delete
}
[114] Fix | Delete
} else if (stream.peek() == "{") {
[115] Fix | Delete
depth++;
[116] Fix | Delete
}
[117] Fix | Delete
return tokenBase(stream, state);
[118] Fix | Delete
}
[119] Fix | Delete
t.isBase = true;
[120] Fix | Delete
return t;
[121] Fix | Delete
}
[122] Fix | Delete
[123] Fix | Delete
function tokenComment(stream, state) {
[124] Fix | Delete
var maybeEnd = false, ch;
[125] Fix | Delete
while (ch = stream.next()) {
[126] Fix | Delete
if (ch == "/" && maybeEnd) {
[127] Fix | Delete
state.tokenize.pop();
[128] Fix | Delete
break;
[129] Fix | Delete
}
[130] Fix | Delete
maybeEnd = (ch == "*");
[131] Fix | Delete
}
[132] Fix | Delete
return "comment";
[133] Fix | Delete
}
[134] Fix | Delete
[135] Fix | Delete
function expectExpression(last, newline) {
[136] Fix | Delete
return !last || last == "operator" || last == "->" || /[\.\[\{\(,;:]/.test(last) ||
[137] Fix | Delete
last == "newstatement" || last == "keyword" || last == "proplabel" ||
[138] Fix | Delete
(last == "standalone" && !newline);
[139] Fix | Delete
}
[140] Fix | Delete
[141] Fix | Delete
function Context(indented, column, type, align, prev) {
[142] Fix | Delete
this.indented = indented;
[143] Fix | Delete
this.column = column;
[144] Fix | Delete
this.type = type;
[145] Fix | Delete
this.align = align;
[146] Fix | Delete
this.prev = prev;
[147] Fix | Delete
}
[148] Fix | Delete
function pushContext(state, col, type) {
[149] Fix | Delete
return state.context = new Context(state.indented, col, type, null, state.context);
[150] Fix | Delete
}
[151] Fix | Delete
function popContext(state) {
[152] Fix | Delete
var t = state.context.type;
[153] Fix | Delete
if (t == ")" || t == "]" || t == "}")
[154] Fix | Delete
state.indented = state.context.indented;
[155] Fix | Delete
return state.context = state.context.prev;
[156] Fix | Delete
}
[157] Fix | Delete
[158] Fix | Delete
// Interface
[159] Fix | Delete
[160] Fix | Delete
return {
[161] Fix | Delete
startState: function(basecolumn) {
[162] Fix | Delete
return {
[163] Fix | Delete
tokenize: [tokenBase],
[164] Fix | Delete
context: new Context((basecolumn || 0) - config.indentUnit, 0, "top", false),
[165] Fix | Delete
indented: 0,
[166] Fix | Delete
startOfLine: true,
[167] Fix | Delete
lastToken: null
[168] Fix | Delete
};
[169] Fix | Delete
},
[170] Fix | Delete
[171] Fix | Delete
token: function(stream, state) {
[172] Fix | Delete
var ctx = state.context;
[173] Fix | Delete
if (stream.sol()) {
[174] Fix | Delete
if (ctx.align == null) ctx.align = false;
[175] Fix | Delete
state.indented = stream.indentation();
[176] Fix | Delete
state.startOfLine = true;
[177] Fix | Delete
// Automatic semicolon insertion
[178] Fix | Delete
if (ctx.type == "statement" && !expectExpression(state.lastToken, true)) {
[179] Fix | Delete
popContext(state); ctx = state.context;
[180] Fix | Delete
}
[181] Fix | Delete
}
[182] Fix | Delete
if (stream.eatSpace()) return null;
[183] Fix | Delete
curPunc = null;
[184] Fix | Delete
var style = state.tokenize[state.tokenize.length-1](stream, state);
[185] Fix | Delete
if (style == "comment") return style;
[186] Fix | Delete
if (ctx.align == null) ctx.align = true;
[187] Fix | Delete
[188] Fix | Delete
if ((curPunc == ";" || curPunc == ":") && ctx.type == "statement") popContext(state);
[189] Fix | Delete
// Handle indentation for {x -> \n ... }
[190] Fix | Delete
else if (curPunc == "->" && ctx.type == "statement" && ctx.prev.type == "}") {
[191] Fix | Delete
popContext(state);
[192] Fix | Delete
state.context.align = false;
[193] Fix | Delete
}
[194] Fix | Delete
else if (curPunc == "{") pushContext(state, stream.column(), "}");
[195] Fix | Delete
else if (curPunc == "[") pushContext(state, stream.column(), "]");
[196] Fix | Delete
else if (curPunc == "(") pushContext(state, stream.column(), ")");
[197] Fix | Delete
else if (curPunc == "}") {
[198] Fix | Delete
while (ctx.type == "statement") ctx = popContext(state);
[199] Fix | Delete
if (ctx.type == "}") ctx = popContext(state);
[200] Fix | Delete
while (ctx.type == "statement") ctx = popContext(state);
[201] Fix | Delete
}
[202] Fix | Delete
else if (curPunc == ctx.type) popContext(state);
[203] Fix | Delete
else if (ctx.type == "}" || ctx.type == "top" || (ctx.type == "statement" && curPunc == "newstatement"))
[204] Fix | Delete
pushContext(state, stream.column(), "statement");
[205] Fix | Delete
state.startOfLine = false;
[206] Fix | Delete
state.lastToken = curPunc || style;
[207] Fix | Delete
return style;
[208] Fix | Delete
},
[209] Fix | Delete
[210] Fix | Delete
indent: function(state, textAfter) {
[211] Fix | Delete
if (!state.tokenize[state.tokenize.length-1].isBase) return 0;
[212] Fix | Delete
var firstChar = textAfter && textAfter.charAt(0), ctx = state.context;
[213] Fix | Delete
if (ctx.type == "statement" && !expectExpression(state.lastToken, true)) ctx = ctx.prev;
[214] Fix | Delete
var closing = firstChar == ctx.type;
[215] Fix | Delete
if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : config.indentUnit);
[216] Fix | Delete
else if (ctx.align) return ctx.column + (closing ? 0 : 1);
[217] Fix | Delete
else return ctx.indented + (closing ? 0 : config.indentUnit);
[218] Fix | Delete
},
[219] Fix | Delete
[220] Fix | Delete
electricChars: "{}",
[221] Fix | Delete
closeBrackets: {triples: "'\""},
[222] Fix | Delete
fold: "brace"
[223] Fix | Delete
};
[224] Fix | Delete
});
[225] Fix | Delete
[226] Fix | Delete
CodeMirror.defineMIME("text/x-groovy", "groovy");
[227] Fix | Delete
[228] Fix | Delete
});
[229] Fix | Delete
[230] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function