LaravelTest
195 строк · 5.6 Кб
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
14function wordRegexp(words) {15return new RegExp("^((" + words.join(")|(") + "))\\b");16};17
18var builtinArray = [19"Clamp",20"Constructor",21"EnforceRange",22"Exposed",23"ImplicitThis",24"Global", "PrimaryGlobal",25"LegacyArrayClass",26"LegacyUnenumerableNamedProperties",27"LenientThis",28"NamedConstructor",29"NewObject",30"NoInterfaceObject",31"OverrideBuiltins",32"PutForwards",33"Replaceable",34"SameObject",35"TreatNonObjectAsNull",36"TreatNullAs",37"EmptyString",38"Unforgeable",39"Unscopeable"40];41var builtins = wordRegexp(builtinArray);42
43var typeArray = [44"unsigned", "short", "long", // UnsignedIntegerType45"unrestricted", "float", "double", // UnrestrictedFloatType46"boolean", "byte", "octet", // Rest of PrimitiveType47"Promise", // PromiseType48"ArrayBuffer", "DataView", "Int8Array", "Int16Array", "Int32Array",49"Uint8Array", "Uint16Array", "Uint32Array", "Uint8ClampedArray",50"Float32Array", "Float64Array", // BufferRelatedType51"ByteString", "DOMString", "USVString", "sequence", "object", "RegExp",52"Error", "DOMException", "FrozenArray", // Rest of NonAnyType53"any", // Rest of SingleType54"void" // Rest of ReturnType55];56var types = wordRegexp(typeArray);57
58var keywordArray = [59"attribute", "callback", "const", "deleter", "dictionary", "enum", "getter",60"implements", "inherit", "interface", "iterable", "legacycaller", "maplike",61"partial", "required", "serializer", "setlike", "setter", "static",62"stringifier", "typedef", // ArgumentNameKeyword except63// "unrestricted"64"optional", "readonly", "or"65];66var keywords = wordRegexp(keywordArray);67
68var atomArray = [69"true", "false", // BooleanLiteral70"Infinity", "NaN", // FloatLiteral71"null" // Rest of ConstValue72];73var atoms = wordRegexp(atomArray);74
75CodeMirror.registerHelper("hintWords", "webidl",76builtinArray.concat(typeArray).concat(keywordArray).concat(atomArray));77
78var startDefArray = ["callback", "dictionary", "enum", "interface"];79var startDefs = wordRegexp(startDefArray);80
81var endDefArray = ["typedef"];82var endDefs = wordRegexp(endDefArray);83
84var singleOperators = /^[:<=>?]/;85var integers = /^-?([1-9][0-9]*|0[Xx][0-9A-Fa-f]+|0[0-7]*)/;86var floats = /^-?(([0-9]+\.[0-9]*|[0-9]*\.[0-9]+)([Ee][+-]?[0-9]+)?|[0-9]+[Ee][+-]?[0-9]+)/;87var identifiers = /^_?[A-Za-z][0-9A-Z_a-z-]*/;88var identifiersEnd = /^_?[A-Za-z][0-9A-Z_a-z-]*(?=\s*;)/;89var strings = /^"[^"]*"/;90var multilineComments = /^\/\*.*?\*\//;91var multilineCommentsStart = /^\/\*.*/;92var multilineCommentsEnd = /^.*?\*\//;93
94function readToken(stream, state) {95// whitespace96if (stream.eatSpace()) return null;97
98// comment99if (state.inComment) {100if (stream.match(multilineCommentsEnd)) {101state.inComment = false;102return "comment";103}104stream.skipToEnd();105return "comment";106}107if (stream.match("//")) {108stream.skipToEnd();109return "comment";110}111if (stream.match(multilineComments)) return "comment";112if (stream.match(multilineCommentsStart)) {113state.inComment = true;114return "comment";115}116
117// integer and float118if (stream.match(/^-?[0-9\.]/, false)) {119if (stream.match(integers) || stream.match(floats)) return "number";120}121
122// string123if (stream.match(strings)) return "string";124
125// identifier126if (state.startDef && stream.match(identifiers)) return "def";127
128if (state.endDef && stream.match(identifiersEnd)) {129state.endDef = false;130return "def";131}132
133if (stream.match(keywords)) return "keyword";134
135if (stream.match(types)) {136var lastToken = state.lastToken;137var nextToken = (stream.match(/^\s*(.+?)\b/, false) || [])[1];138
139if (lastToken === ":" || lastToken === "implements" ||140nextToken === "implements" || nextToken === "=") {141// Used as identifier142return "builtin";143} else {144// Used as type145return "variable-3";146}147}148
149if (stream.match(builtins)) return "builtin";150if (stream.match(atoms)) return "atom";151if (stream.match(identifiers)) return "variable";152
153// other154if (stream.match(singleOperators)) return "operator";155
156// unrecognized157stream.next();158return null;159};160
161CodeMirror.defineMode("webidl", function() {162return {163startState: function() {164return {165// Is in multiline comment166inComment: false,167// Last non-whitespace, matched token168lastToken: "",169// Next token is a definition170startDef: false,171// Last token of the statement is a definition172endDef: false173};174},175token: function(stream, state) {176var style = readToken(stream, state);177
178if (style) {179var cur = stream.current();180state.lastToken = cur;181if (style === "keyword") {182state.startDef = startDefs.test(cur);183state.endDef = state.endDef || endDefs.test(cur);184} else {185state.startDef = false;186}187}188
189return style;190}191};192});193
194CodeMirror.defineMIME("text/x-webidl", "webidl");195});196