Path: blob/master/web-gui/buildyourownbotnet/assets/js/codemirror/mode/d/d.js
1294 views
CodeMirror.defineMode("d", function(config, parserConfig) {1var indentUnit = config.indentUnit,2statementIndentUnit = parserConfig.statementIndentUnit || indentUnit,3keywords = parserConfig.keywords || {},4builtin = parserConfig.builtin || {},5blockKeywords = parserConfig.blockKeywords || {},6atoms = parserConfig.atoms || {},7hooks = parserConfig.hooks || {},8multiLineStrings = parserConfig.multiLineStrings;9var isOperatorChar = /[+\-*&%=<>!?|\/]/;1011var curPunc;1213function tokenBase(stream, state) {14var ch = stream.next();15if (hooks[ch]) {16var result = hooks[ch](stream, state);17if (result !== false) return result;18}19if (ch == '"' || ch == "'" || ch == "`") {20state.tokenize = tokenString(ch);21return state.tokenize(stream, state);22}23if (/[\[\]{}\(\),;\:\.]/.test(ch)) {24curPunc = ch;25return null;26}27if (/\d/.test(ch)) {28stream.eatWhile(/[\w\.]/);29return "number";30}31if (ch == "/") {32if (stream.eat("+")) {33state.tokenize = tokenComment;34return tokenNestedComment(stream, state);35}36if (stream.eat("*")) {37state.tokenize = tokenComment;38return tokenComment(stream, state);39}40if (stream.eat("/")) {41stream.skipToEnd();42return "comment";43}44}45if (isOperatorChar.test(ch)) {46stream.eatWhile(isOperatorChar);47return "operator";48}49stream.eatWhile(/[\w\$_]/);50var cur = stream.current();51if (keywords.propertyIsEnumerable(cur)) {52if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";53return "keyword";54}55if (builtin.propertyIsEnumerable(cur)) {56if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";57return "builtin";58}59if (atoms.propertyIsEnumerable(cur)) return "atom";60return "variable";61}6263function tokenString(quote) {64return function(stream, state) {65var escaped = false, next, end = false;66while ((next = stream.next()) != null) {67if (next == quote && !escaped) {end = true; break;}68escaped = !escaped && next == "\\";69}70if (end || !(escaped || multiLineStrings))71state.tokenize = null;72return "string";73};74}7576function tokenComment(stream, state) {77var maybeEnd = false, ch;78while (ch = stream.next()) {79if (ch == "/" && maybeEnd) {80state.tokenize = null;81break;82}83maybeEnd = (ch == "*");84}85return "comment";86}8788function tokenNestedComment(stream, state) {89var maybeEnd = false, ch;90while (ch = stream.next()) {91if (ch == "/" && maybeEnd) {92state.tokenize = null;93break;94}95maybeEnd = (ch == "+");96}97return "comment";98}99100function Context(indented, column, type, align, prev) {101this.indented = indented;102this.column = column;103this.type = type;104this.align = align;105this.prev = prev;106}107function pushContext(state, col, type) {108var indent = state.indented;109if (state.context && state.context.type == "statement")110indent = state.context.indented;111return state.context = new Context(indent, col, type, null, state.context);112}113function popContext(state) {114var t = state.context.type;115if (t == ")" || t == "]" || t == "}")116state.indented = state.context.indented;117return state.context = state.context.prev;118}119120// Interface121122return {123startState: function(basecolumn) {124return {125tokenize: null,126context: new Context((basecolumn || 0) - indentUnit, 0, "top", false),127indented: 0,128startOfLine: true129};130},131132token: function(stream, state) {133var ctx = state.context;134if (stream.sol()) {135if (ctx.align == null) ctx.align = false;136state.indented = stream.indentation();137state.startOfLine = true;138}139if (stream.eatSpace()) return null;140curPunc = null;141var style = (state.tokenize || tokenBase)(stream, state);142if (style == "comment" || style == "meta") return style;143if (ctx.align == null) ctx.align = true;144145if ((curPunc == ";" || curPunc == ":" || curPunc == ",") && ctx.type == "statement") popContext(state);146else if (curPunc == "{") pushContext(state, stream.column(), "}");147else if (curPunc == "[") pushContext(state, stream.column(), "]");148else if (curPunc == "(") pushContext(state, stream.column(), ")");149else if (curPunc == "}") {150while (ctx.type == "statement") ctx = popContext(state);151if (ctx.type == "}") ctx = popContext(state);152while (ctx.type == "statement") ctx = popContext(state);153}154else if (curPunc == ctx.type) popContext(state);155else if (((ctx.type == "}" || ctx.type == "top") && curPunc != ';') || (ctx.type == "statement" && curPunc == "newstatement"))156pushContext(state, stream.column(), "statement");157state.startOfLine = false;158return style;159},160161indent: function(state, textAfter) {162if (state.tokenize != tokenBase && state.tokenize != null) return CodeMirror.Pass;163var ctx = state.context, firstChar = textAfter && textAfter.charAt(0);164if (ctx.type == "statement" && firstChar == "}") ctx = ctx.prev;165var closing = firstChar == ctx.type;166if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : statementIndentUnit);167else if (ctx.align) return ctx.column + (closing ? 0 : 1);168else return ctx.indented + (closing ? 0 : indentUnit);169},170171electricChars: "{}"172};173});174175(function() {176function words(str) {177var obj = {}, words = str.split(" ");178for (var i = 0; i < words.length; ++i) obj[words[i]] = true;179return obj;180}181182var blockKeywords = "body catch class do else enum for foreach foreach_reverse if in interface mixin " +183"out scope struct switch try union unittest version while with";184185CodeMirror.defineMIME("text/x-d", {186name: "d",187keywords: words("abstract alias align asm assert auto break case cast cdouble cent cfloat const continue " +188"debug default delegate delete deprecated export extern final finally function goto immutable " +189"import inout invariant is lazy macro module new nothrow override package pragma private " +190"protected public pure ref return shared short static super synchronized template this " +191"throw typedef typeid typeof volatile __FILE__ __LINE__ __gshared __traits __vector __parameters " +192blockKeywords),193blockKeywords: words(blockKeywords),194builtin: words("bool byte char creal dchar double float idouble ifloat int ireal long real short ubyte " +195"ucent uint ulong ushort wchar wstring void size_t sizediff_t"),196atoms: words("exit failure success true false null"),197hooks: {198"@": function(stream, _state) {199stream.eatWhile(/[\w\$_]/);200return "meta";201}202}203});204}());205206207