LaravelTest
292 строки · 15.0 Кб
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("clojure", function (options) {15var atoms = ["false", "nil", "true"];16var specialForms = [".", "catch", "def", "do", "if", "monitor-enter",17"monitor-exit", "new", "quote", "recur", "set!", "throw", "try", "var"];18var coreSymbols = ["*", "*'", "*1", "*2", "*3", "*agent*",19"*allow-unresolved-vars*", "*assert*", "*clojure-version*",20"*command-line-args*", "*compile-files*", "*compile-path*",21"*compiler-options*", "*data-readers*", "*default-data-reader-fn*", "*e",22"*err*", "*file*", "*flush-on-newline*", "*fn-loader*", "*in*",23"*math-context*", "*ns*", "*out*", "*print-dup*", "*print-length*",24"*print-level*", "*print-meta*", "*print-namespace-maps*",25"*print-readably*", "*read-eval*", "*reader-resolver*", "*source-path*",26"*suppress-read*", "*unchecked-math*", "*use-context-classloader*",27"*verbose-defrecords*", "*warn-on-reflection*", "+", "+'", "-", "-'",28"->", "->>", "->ArrayChunk", "->Eduction", "->Vec", "->VecNode",29"->VecSeq", "-cache-protocol-fn", "-reset-methods", "..", "/", "<", "<=",30"=", "==", ">", ">=", "EMPTY-NODE", "Inst", "StackTraceElement->vec",31"Throwable->map", "accessor", "aclone", "add-classpath", "add-watch",32"agent", "agent-error", "agent-errors", "aget", "alength", "alias",33"all-ns", "alter", "alter-meta!", "alter-var-root", "amap", "ancestors",34"and", "any?", "apply", "areduce", "array-map", "as->", "aset",35"aset-boolean", "aset-byte", "aset-char", "aset-double", "aset-float",36"aset-int", "aset-long", "aset-short", "assert", "assoc", "assoc!",37"assoc-in", "associative?", "atom", "await", "await-for", "await1",38"bases", "bean", "bigdec", "bigint", "biginteger", "binding", "bit-and",39"bit-and-not", "bit-clear", "bit-flip", "bit-not", "bit-or", "bit-set",40"bit-shift-left", "bit-shift-right", "bit-test", "bit-xor", "boolean",41"boolean-array", "boolean?", "booleans", "bound-fn", "bound-fn*",42"bound?", "bounded-count", "butlast", "byte", "byte-array", "bytes",43"bytes?", "case", "cast", "cat", "char", "char-array",44"char-escape-string", "char-name-string", "char?", "chars", "chunk",45"chunk-append", "chunk-buffer", "chunk-cons", "chunk-first", "chunk-next",46"chunk-rest", "chunked-seq?", "class", "class?", "clear-agent-errors",47"clojure-version", "coll?", "comment", "commute", "comp", "comparator",48"compare", "compare-and-set!", "compile", "complement", "completing",49"concat", "cond", "cond->", "cond->>", "condp", "conj", "conj!", "cons",50"constantly", "construct-proxy", "contains?", "count", "counted?",51"create-ns", "create-struct", "cycle", "dec", "dec'", "decimal?",52"declare", "dedupe", "default-data-readers", "definline", "definterface",53"defmacro", "defmethod", "defmulti", "defn", "defn-", "defonce",54"defprotocol", "defrecord", "defstruct", "deftype", "delay", "delay?",55"deliver", "denominator", "deref", "derive", "descendants", "destructure",56"disj", "disj!", "dissoc", "dissoc!", "distinct", "distinct?", "doall",57"dorun", "doseq", "dosync", "dotimes", "doto", "double", "double-array",58"double?", "doubles", "drop", "drop-last", "drop-while", "eduction",59"empty", "empty?", "ensure", "ensure-reduced", "enumeration-seq",60"error-handler", "error-mode", "eval", "even?", "every-pred", "every?",61"ex-data", "ex-info", "extend", "extend-protocol", "extend-type",62"extenders", "extends?", "false?", "ffirst", "file-seq", "filter",63"filterv", "find", "find-keyword", "find-ns", "find-protocol-impl",64"find-protocol-method", "find-var", "first", "flatten", "float",65"float-array", "float?", "floats", "flush", "fn", "fn?", "fnext", "fnil",66"for", "force", "format", "frequencies", "future", "future-call",67"future-cancel", "future-cancelled?", "future-done?", "future?",68"gen-class", "gen-interface", "gensym", "get", "get-in", "get-method",69"get-proxy-class", "get-thread-bindings", "get-validator", "group-by",70"halt-when", "hash", "hash-combine", "hash-map", "hash-ordered-coll",71"hash-set", "hash-unordered-coll", "ident?", "identical?", "identity",72"if-let", "if-not", "if-some", "ifn?", "import", "in-ns", "inc", "inc'",73"indexed?", "init-proxy", "inst-ms", "inst-ms*", "inst?", "instance?",74"int", "int-array", "int?", "integer?", "interleave", "intern",75"interpose", "into", "into-array", "ints", "io!", "isa?", "iterate",76"iterator-seq", "juxt", "keep", "keep-indexed", "key", "keys", "keyword",77"keyword?", "last", "lazy-cat", "lazy-seq", "let", "letfn", "line-seq",78"list", "list*", "list?", "load", "load-file", "load-reader",79"load-string", "loaded-libs", "locking", "long", "long-array", "longs",80"loop", "macroexpand", "macroexpand-1", "make-array", "make-hierarchy",81"map", "map-entry?", "map-indexed", "map?", "mapcat", "mapv", "max",82"max-key", "memfn", "memoize", "merge", "merge-with", "meta",83"method-sig", "methods", "min", "min-key", "mix-collection-hash", "mod",84"munge", "name", "namespace", "namespace-munge", "nat-int?", "neg-int?",85"neg?", "newline", "next", "nfirst", "nil?", "nnext", "not", "not-any?",86"not-empty", "not-every?", "not=", "ns", "ns-aliases", "ns-imports",87"ns-interns", "ns-map", "ns-name", "ns-publics", "ns-refers",88"ns-resolve", "ns-unalias", "ns-unmap", "nth", "nthnext", "nthrest",89"num", "number?", "numerator", "object-array", "odd?", "or", "parents",90"partial", "partition", "partition-all", "partition-by", "pcalls", "peek",91"persistent!", "pmap", "pop", "pop!", "pop-thread-bindings", "pos-int?",92"pos?", "pr", "pr-str", "prefer-method", "prefers",93"primitives-classnames", "print", "print-ctor", "print-dup",94"print-method", "print-simple", "print-str", "printf", "println",95"println-str", "prn", "prn-str", "promise", "proxy",96"proxy-call-with-super", "proxy-mappings", "proxy-name", "proxy-super",97"push-thread-bindings", "pvalues", "qualified-ident?",98"qualified-keyword?", "qualified-symbol?", "quot", "rand", "rand-int",99"rand-nth", "random-sample", "range", "ratio?", "rational?",100"rationalize", "re-find", "re-groups", "re-matcher", "re-matches",101"re-pattern", "re-seq", "read", "read-line", "read-string",102"reader-conditional", "reader-conditional?", "realized?", "record?",103"reduce", "reduce-kv", "reduced", "reduced?", "reductions", "ref",104"ref-history-count", "ref-max-history", "ref-min-history", "ref-set",105"refer", "refer-clojure", "reify", "release-pending-sends", "rem",106"remove", "remove-all-methods", "remove-method", "remove-ns",107"remove-watch", "repeat", "repeatedly", "replace", "replicate", "require",108"reset!", "reset-meta!", "reset-vals!", "resolve", "rest",109"restart-agent", "resultset-seq", "reverse", "reversible?", "rseq",110"rsubseq", "run!", "satisfies?", "second", "select-keys", "send",111"send-off", "send-via", "seq", "seq?", "seqable?", "seque", "sequence",112"sequential?", "set", "set-agent-send-executor!",113"set-agent-send-off-executor!", "set-error-handler!", "set-error-mode!",114"set-validator!", "set?", "short", "short-array", "shorts", "shuffle",115"shutdown-agents", "simple-ident?", "simple-keyword?", "simple-symbol?",116"slurp", "some", "some->", "some->>", "some-fn", "some?", "sort",117"sort-by", "sorted-map", "sorted-map-by", "sorted-set", "sorted-set-by",118"sorted?", "special-symbol?", "spit", "split-at", "split-with", "str",119"string?", "struct", "struct-map", "subs", "subseq", "subvec", "supers",120"swap!", "swap-vals!", "symbol", "symbol?", "sync", "tagged-literal",121"tagged-literal?", "take", "take-last", "take-nth", "take-while", "test",122"the-ns", "thread-bound?", "time", "to-array", "to-array-2d",123"trampoline", "transduce", "transient", "tree-seq", "true?", "type",124"unchecked-add", "unchecked-add-int", "unchecked-byte", "unchecked-char",125"unchecked-dec", "unchecked-dec-int", "unchecked-divide-int",126"unchecked-double", "unchecked-float", "unchecked-inc",127"unchecked-inc-int", "unchecked-int", "unchecked-long",128"unchecked-multiply", "unchecked-multiply-int", "unchecked-negate",129"unchecked-negate-int", "unchecked-remainder-int", "unchecked-short",130"unchecked-subtract", "unchecked-subtract-int", "underive", "unquote",131"unquote-splicing", "unreduced", "unsigned-bit-shift-right", "update",132"update-in", "update-proxy", "uri?", "use", "uuid?", "val", "vals",133"var-get", "var-set", "var?", "vary-meta", "vec", "vector", "vector-of",134"vector?", "volatile!", "volatile?", "vreset!", "vswap!", "when",135"when-first", "when-let", "when-not", "when-some", "while",136"with-bindings", "with-bindings*", "with-in-str", "with-loading-context",137"with-local-vars", "with-meta", "with-open", "with-out-str",138"with-precision", "with-redefs", "with-redefs-fn", "xml-seq", "zero?",139"zipmap"];140var haveBodyParameter = [141"->", "->>", "as->", "binding", "bound-fn", "case", "catch", "comment",142"cond", "cond->", "cond->>", "condp", "def", "definterface", "defmethod",143"defn", "defmacro", "defprotocol", "defrecord", "defstruct", "deftype",144"do", "doseq", "dotimes", "doto", "extend", "extend-protocol",145"extend-type", "fn", "for", "future", "if", "if-let", "if-not", "if-some",146"let", "letfn", "locking", "loop", "ns", "proxy", "reify", "struct-map",147"some->", "some->>", "try", "when", "when-first", "when-let", "when-not",148"when-some", "while", "with-bindings", "with-bindings*", "with-in-str",149"with-loading-context", "with-local-vars", "with-meta", "with-open",150"with-out-str", "with-precision", "with-redefs", "with-redefs-fn"];151
152CodeMirror.registerHelper("hintWords", "clojure",153[].concat(atoms, specialForms, coreSymbols));154
155var atom = createLookupMap(atoms);156var specialForm = createLookupMap(specialForms);157var coreSymbol = createLookupMap(coreSymbols);158var hasBodyParameter = createLookupMap(haveBodyParameter);159var delimiter = /^(?:[\\\[\]\s"(),;@^`{}~]|$)/;160var numberLiteral = /^(?:[+\-]?\d+(?:(?:N|(?:[eE][+\-]?\d+))|(?:\.?\d*(?:M|(?:[eE][+\-]?\d+))?)|\/\d+|[xX][0-9a-fA-F]+|r[0-9a-zA-Z]+)?(?=[\\\[\]\s"#'(),;@^`{}~]|$))/;161var characterLiteral = /^(?:\\(?:backspace|formfeed|newline|return|space|tab|o[0-7]{3}|u[0-9A-Fa-f]{4}|x[0-9A-Fa-f]{4}|.)?(?=[\\\[\]\s"(),;@^`{}~]|$))/;162
163// simple-namespace := /^[^\\\/\[\]\d\s"#'(),;@^`{}~.][^\\\[\]\s"(),;@^`{}~.\/]*/164// simple-symbol := /^(?:\/|[^\\\/\[\]\d\s"#'(),;@^`{}~][^\\\[\]\s"(),;@^`{}~]*)/165// qualified-symbol := (<simple-namespace>(<.><simple-namespace>)*</>)?<simple-symbol>166var qualifiedSymbol = /^(?:(?:[^\\\/\[\]\d\s"#'(),;@^`{}~.][^\\\[\]\s"(),;@^`{}~.\/]*(?:\.[^\\\/\[\]\d\s"#'(),;@^`{}~.][^\\\[\]\s"(),;@^`{}~.\/]*)*\/)?(?:\/|[^\\\/\[\]\d\s"#'(),;@^`{}~][^\\\[\]\s"(),;@^`{}~]*)*(?=[\\\[\]\s"(),;@^`{}~]|$))/;167
168function base(stream, state) {169if (stream.eatSpace() || stream.eat(",")) return ["space", null];170if (stream.match(numberLiteral)) return [null, "number"];171if (stream.match(characterLiteral)) return [null, "string-2"];172if (stream.eat(/^"/)) return (state.tokenize = inString)(stream, state);173if (stream.eat(/^[(\[{]/)) return ["open", "bracket"];174if (stream.eat(/^[)\]}]/)) return ["close", "bracket"];175if (stream.eat(/^;/)) {stream.skipToEnd(); return ["space", "comment"];}176if (stream.eat(/^[#'@^`~]/)) return [null, "meta"];177
178var matches = stream.match(qualifiedSymbol);179var symbol = matches && matches[0];180
181if (!symbol) {182// advance stream by at least one character so we don't get stuck.183stream.next();184stream.eatWhile(function (c) {return !is(c, delimiter);});185return [null, "error"];186}187
188if (symbol === "comment" && state.lastToken === "(")189return (state.tokenize = inComment)(stream, state);190if (is(symbol, atom) || symbol.charAt(0) === ":") return ["symbol", "atom"];191if (is(symbol, specialForm) || is(symbol, coreSymbol)) return ["symbol", "keyword"];192if (state.lastToken === "(") return ["symbol", "builtin"]; // other operator193
194return ["symbol", "variable"];195}196
197function inString(stream, state) {198var escaped = false, next;199
200while (next = stream.next()) {201if (next === "\"" && !escaped) {state.tokenize = base; break;}202escaped = !escaped && next === "\\";203}204
205return [null, "string"];206}207
208function inComment(stream, state) {209var parenthesisCount = 1;210var next;211
212while (next = stream.next()) {213if (next === ")") parenthesisCount--;214if (next === "(") parenthesisCount++;215if (parenthesisCount === 0) {216stream.backUp(1);217state.tokenize = base;218break;219}220}221
222return ["space", "comment"];223}224
225function createLookupMap(words) {226var obj = {};227
228for (var i = 0; i < words.length; ++i) obj[words[i]] = true;229
230return obj;231}232
233function is(value, test) {234if (test instanceof RegExp) return test.test(value);235if (test instanceof Object) return test.propertyIsEnumerable(value);236}237
238return {239startState: function () {240return {241ctx: {prev: null, start: 0, indentTo: 0},242lastToken: null,243tokenize: base244};245},246
247token: function (stream, state) {248if (stream.sol() && (typeof state.ctx.indentTo !== "number"))249state.ctx.indentTo = state.ctx.start + 1;250
251var typeStylePair = state.tokenize(stream, state);252var type = typeStylePair[0];253var style = typeStylePair[1];254var current = stream.current();255
256if (type !== "space") {257if (state.lastToken === "(" && state.ctx.indentTo === null) {258if (type === "symbol" && is(current, hasBodyParameter))259state.ctx.indentTo = state.ctx.start + options.indentUnit;260else state.ctx.indentTo = "next";261} else if (state.ctx.indentTo === "next") {262state.ctx.indentTo = stream.column();263}264
265state.lastToken = current;266}267
268if (type === "open")269state.ctx = {prev: state.ctx, start: stream.column(), indentTo: null};270else if (type === "close") state.ctx = state.ctx.prev || state.ctx;271
272return style;273},274
275indent: function (state) {276var i = state.ctx.indentTo;277
278return (typeof i === "number") ?279i :280state.ctx.start + 1;281},282
283closeBrackets: {pairs: "()[]{}\"\""},284lineComment: ";;"285};286});287
288CodeMirror.defineMIME("text/x-clojure", "clojure");289CodeMirror.defineMIME("text/x-clojurescript", "clojure");290CodeMirror.defineMIME("application/edn", "clojure");291
292});293