LaravelTest
223 строки · 7.5 Кб
1// CodeMirror, copyright (c) by Marijn Haverbeke and others
2// Distributed under an MIT license: https://codemirror.net/LICENSE
3
4(function(mod) {5if (typeof exports == "object" && typeof module == "object") // CommonJS6mod(require("../../lib/codemirror"));7else if (typeof define == "function" && define.amd) // AMD8define(["../../lib/codemirror"], mod);9else // Plain browser env10mod(CodeMirror);11})(function(CodeMirror) {12"use strict";13
14CodeMirror.defineMode("d", function(config, parserConfig) {15var indentUnit = config.indentUnit,16statementIndentUnit = parserConfig.statementIndentUnit || indentUnit,17keywords = parserConfig.keywords || {},18builtin = parserConfig.builtin || {},19blockKeywords = parserConfig.blockKeywords || {},20atoms = parserConfig.atoms || {},21hooks = parserConfig.hooks || {},22multiLineStrings = parserConfig.multiLineStrings;23var isOperatorChar = /[+\-*&%=<>!?|\/]/;24
25var curPunc;26
27function tokenBase(stream, state) {28var ch = stream.next();29if (hooks[ch]) {30var result = hooks[ch](stream, state);31if (result !== false) return result;32}33if (ch == '"' || ch == "'" || ch == "`") {34state.tokenize = tokenString(ch);35return state.tokenize(stream, state);36}37if (/[\[\]{}\(\),;\:\.]/.test(ch)) {38curPunc = ch;39return null;40}41if (/\d/.test(ch)) {42stream.eatWhile(/[\w\.]/);43return "number";44}45if (ch == "/") {46if (stream.eat("+")) {47state.tokenize = tokenNestedComment;48return tokenNestedComment(stream, state);49}50if (stream.eat("*")) {51state.tokenize = tokenComment;52return tokenComment(stream, state);53}54if (stream.eat("/")) {55stream.skipToEnd();56return "comment";57}58}59if (isOperatorChar.test(ch)) {60stream.eatWhile(isOperatorChar);61return "operator";62}63stream.eatWhile(/[\w\$_\xa1-\uffff]/);64var cur = stream.current();65if (keywords.propertyIsEnumerable(cur)) {66if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";67return "keyword";68}69if (builtin.propertyIsEnumerable(cur)) {70if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";71return "builtin";72}73if (atoms.propertyIsEnumerable(cur)) return "atom";74return "variable";75}76
77function tokenString(quote) {78return function(stream, state) {79var escaped = false, next, end = false;80while ((next = stream.next()) != null) {81if (next == quote && !escaped) {end = true; break;}82escaped = !escaped && next == "\\";83}84if (end || !(escaped || multiLineStrings))85state.tokenize = null;86return "string";87};88}89
90function tokenComment(stream, state) {91var maybeEnd = false, ch;92while (ch = stream.next()) {93if (ch == "/" && maybeEnd) {94state.tokenize = null;95break;96}97maybeEnd = (ch == "*");98}99return "comment";100}101
102function tokenNestedComment(stream, state) {103var maybeEnd = false, ch;104while (ch = stream.next()) {105if (ch == "/" && maybeEnd) {106state.tokenize = null;107break;108}109maybeEnd = (ch == "+");110}111return "comment";112}113
114function Context(indented, column, type, align, prev) {115this.indented = indented;116this.column = column;117this.type = type;118this.align = align;119this.prev = prev;120}121function pushContext(state, col, type) {122var indent = state.indented;123if (state.context && state.context.type == "statement")124indent = state.context.indented;125return state.context = new Context(indent, col, type, null, state.context);126}127function popContext(state) {128var t = state.context.type;129if (t == ")" || t == "]" || t == "}")130state.indented = state.context.indented;131return state.context = state.context.prev;132}133
134// Interface135
136return {137startState: function(basecolumn) {138return {139tokenize: null,140context: new Context((basecolumn || 0) - indentUnit, 0, "top", false),141indented: 0,142startOfLine: true143};144},145
146token: function(stream, state) {147var ctx = state.context;148if (stream.sol()) {149if (ctx.align == null) ctx.align = false;150state.indented = stream.indentation();151state.startOfLine = true;152}153if (stream.eatSpace()) return null;154curPunc = null;155var style = (state.tokenize || tokenBase)(stream, state);156if (style == "comment" || style == "meta") return style;157if (ctx.align == null) ctx.align = true;158
159if ((curPunc == ";" || curPunc == ":" || curPunc == ",") && ctx.type == "statement") popContext(state);160else if (curPunc == "{") pushContext(state, stream.column(), "}");161else if (curPunc == "[") pushContext(state, stream.column(), "]");162else if (curPunc == "(") pushContext(state, stream.column(), ")");163else if (curPunc == "}") {164while (ctx.type == "statement") ctx = popContext(state);165if (ctx.type == "}") ctx = popContext(state);166while (ctx.type == "statement") ctx = popContext(state);167}168else if (curPunc == ctx.type) popContext(state);169else if (((ctx.type == "}" || ctx.type == "top") && curPunc != ';') || (ctx.type == "statement" && curPunc == "newstatement"))170pushContext(state, stream.column(), "statement");171state.startOfLine = false;172return style;173},174
175indent: function(state, textAfter) {176if (state.tokenize != tokenBase && state.tokenize != null) return CodeMirror.Pass;177var ctx = state.context, firstChar = textAfter && textAfter.charAt(0);178if (ctx.type == "statement" && firstChar == "}") ctx = ctx.prev;179var closing = firstChar == ctx.type;180if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : statementIndentUnit);181else if (ctx.align) return ctx.column + (closing ? 0 : 1);182else return ctx.indented + (closing ? 0 : indentUnit);183},184
185electricChars: "{}",186blockCommentStart: "/*",187blockCommentEnd: "*/",188blockCommentContinue: " * ",189lineComment: "//",190fold: "brace"191};192});193
194function words(str) {195var obj = {}, words = str.split(" ");196for (var i = 0; i < words.length; ++i) obj[words[i]] = true;197return obj;198}199
200var blockKeywords = "body catch class do else enum for foreach foreach_reverse if in interface mixin " +201"out scope struct switch try union unittest version while with";202
203CodeMirror.defineMIME("text/x-d", {204name: "d",205keywords: words("abstract alias align asm assert auto break case cast cdouble cent cfloat const continue " +206"debug default delegate delete deprecated export extern final finally function goto immutable " +207"import inout invariant is lazy macro module new nothrow override package pragma private " +208"protected public pure ref return shared short static super synchronized template this " +209"throw typedef typeid typeof volatile __FILE__ __LINE__ __gshared __traits __vector __parameters " +210blockKeywords),211blockKeywords: words(blockKeywords),212builtin: words("bool byte char creal dchar double float idouble ifloat int ireal long real short ubyte " +213"ucent uint ulong ushort wchar wstring void size_t sizediff_t"),214atoms: words("exit failure success true false null"),215hooks: {216"@": function(stream, _state) {217stream.eatWhile(/[\w\$_]/);218return "meta";219}220}221});222
223});224