LaravelTest
352 строки · 9.9 Кб
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 forEach(arr, f) {15for (var i = 0; i < arr.length; i++) f(arr[i], i)16}
17function some(arr, f) {18for (var i = 0; i < arr.length; i++) if (f(arr[i], i)) return true19return false20}
21
22CodeMirror.defineMode("dylan", function(_config) {23// Words24var words = {25// Words that introduce unnamed definitions like "define interface"26unnamedDefinition: ["interface"],27
28// Words that introduce simple named definitions like "define library"29namedDefinition: ["module", "library", "macro",30"C-struct", "C-union",31"C-function", "C-callable-wrapper"32],33
34// Words that introduce type definitions like "define class".35// These are also parameterized like "define method" and are36// appended to otherParameterizedDefinitionWords37typeParameterizedDefinition: ["class", "C-subtype", "C-mapped-subtype"],38
39// Words that introduce trickier definitions like "define method".40// These require special definitions to be added to startExpressions41otherParameterizedDefinition: ["method", "function",42"C-variable", "C-address"43],44
45// Words that introduce module constant definitions.46// These must also be simple definitions and are47// appended to otherSimpleDefinitionWords48constantSimpleDefinition: ["constant"],49
50// Words that introduce module variable definitions.51// These must also be simple definitions and are52// appended to otherSimpleDefinitionWords53variableSimpleDefinition: ["variable"],54
55// Other words that introduce simple definitions56// (without implicit bodies).57otherSimpleDefinition: ["generic", "domain",58"C-pointer-type",59"table"60],61
62// Words that begin statements with implicit bodies.63statement: ["if", "block", "begin", "method", "case",64"for", "select", "when", "unless", "until",65"while", "iterate", "profiling", "dynamic-bind"66],67
68// Patterns that act as separators in compound statements.69// This may include any general pattern that must be indented70// specially.71separator: ["finally", "exception", "cleanup", "else",72"elseif", "afterwards"73],74
75// Keywords that do not require special indentation handling,76// but which should be highlighted77other: ["above", "below", "by", "from", "handler", "in",78"instance", "let", "local", "otherwise", "slot",79"subclass", "then", "to", "keyed-by", "virtual"80],81
82// Condition signaling function calls83signalingCalls: ["signal", "error", "cerror",84"break", "check-type", "abort"85]86};87
88words["otherDefinition"] =89words["unnamedDefinition"]90.concat(words["namedDefinition"])91.concat(words["otherParameterizedDefinition"]);92
93words["definition"] =94words["typeParameterizedDefinition"]95.concat(words["otherDefinition"]);96
97words["parameterizedDefinition"] =98words["typeParameterizedDefinition"]99.concat(words["otherParameterizedDefinition"]);100
101words["simpleDefinition"] =102words["constantSimpleDefinition"]103.concat(words["variableSimpleDefinition"])104.concat(words["otherSimpleDefinition"]);105
106words["keyword"] =107words["statement"]108.concat(words["separator"])109.concat(words["other"]);110
111// Patterns112var symbolPattern = "[-_a-zA-Z?!*@<>$%]+";113var symbol = new RegExp("^" + symbolPattern);114var patterns = {115// Symbols with special syntax116symbolKeyword: symbolPattern + ":",117symbolClass: "<" + symbolPattern + ">",118symbolGlobal: "\\*" + symbolPattern + "\\*",119symbolConstant: "\\$" + symbolPattern120};121var patternStyles = {122symbolKeyword: "atom",123symbolClass: "tag",124symbolGlobal: "variable-2",125symbolConstant: "variable-3"126};127
128// Compile all patterns to regular expressions129for (var patternName in patterns)130if (patterns.hasOwnProperty(patternName))131patterns[patternName] = new RegExp("^" + patterns[patternName]);132
133// Names beginning "with-" and "without-" are commonly134// used as statement macro135patterns["keyword"] = [/^with(?:out)?-[-_a-zA-Z?!*@<>$%]+/];136
137var styles = {};138styles["keyword"] = "keyword";139styles["definition"] = "def";140styles["simpleDefinition"] = "def";141styles["signalingCalls"] = "builtin";142
143// protected words lookup table144var wordLookup = {};145var styleLookup = {};146
147forEach([148"keyword",149"definition",150"simpleDefinition",151"signalingCalls"152], function(type) {153forEach(words[type], function(word) {154wordLookup[word] = type;155styleLookup[word] = styles[type];156});157});158
159
160function chain(stream, state, f) {161state.tokenize = f;162return f(stream, state);163}164
165function tokenBase(stream, state) {166// String167var ch = stream.peek();168if (ch == "'" || ch == '"') {169stream.next();170return chain(stream, state, tokenString(ch, "string"));171}172// Comment173else if (ch == "/") {174stream.next();175if (stream.eat("*")) {176return chain(stream, state, tokenComment);177} else if (stream.eat("/")) {178stream.skipToEnd();179return "comment";180}181stream.backUp(1);182}183// Decimal184else if (/[+\-\d\.]/.test(ch)) {185if (stream.match(/^[+-]?[0-9]*\.[0-9]*([esdx][+-]?[0-9]+)?/i) ||186stream.match(/^[+-]?[0-9]+([esdx][+-]?[0-9]+)/i) ||187stream.match(/^[+-]?\d+/)) {188return "number";189}190}191// Hash192else if (ch == "#") {193stream.next();194// Symbol with string syntax195ch = stream.peek();196if (ch == '"') {197stream.next();198return chain(stream, state, tokenString('"', "string"));199}200// Binary number201else if (ch == "b") {202stream.next();203stream.eatWhile(/[01]/);204return "number";205}206// Hex number207else if (ch == "x") {208stream.next();209stream.eatWhile(/[\da-f]/i);210return "number";211}212// Octal number213else if (ch == "o") {214stream.next();215stream.eatWhile(/[0-7]/);216return "number";217}218// Token concatenation in macros219else if (ch == '#') {220stream.next();221return "punctuation";222}223// Sequence literals224else if ((ch == '[') || (ch == '(')) {225stream.next();226return "bracket";227// Hash symbol228} else if (stream.match(/f|t|all-keys|include|key|next|rest/i)) {229return "atom";230} else {231stream.eatWhile(/[-a-zA-Z]/);232return "error";233}234} else if (ch == "~") {235stream.next();236ch = stream.peek();237if (ch == "=") {238stream.next();239ch = stream.peek();240if (ch == "=") {241stream.next();242return "operator";243}244return "operator";245}246return "operator";247} else if (ch == ":") {248stream.next();249ch = stream.peek();250if (ch == "=") {251stream.next();252return "operator";253} else if (ch == ":") {254stream.next();255return "punctuation";256}257} else if ("[](){}".indexOf(ch) != -1) {258stream.next();259return "bracket";260} else if (".,".indexOf(ch) != -1) {261stream.next();262return "punctuation";263} else if (stream.match("end")) {264return "keyword";265}266for (var name in patterns) {267if (patterns.hasOwnProperty(name)) {268var pattern = patterns[name];269if ((pattern instanceof Array && some(pattern, function(p) {270return stream.match(p);271})) || stream.match(pattern))272return patternStyles[name];273}274}275if (/[+\-*\/^=<>&|]/.test(ch)) {276stream.next();277return "operator";278}279if (stream.match("define")) {280return "def";281} else {282stream.eatWhile(/[\w\-]/);283// Keyword284if (wordLookup.hasOwnProperty(stream.current())) {285return styleLookup[stream.current()];286} else if (stream.current().match(symbol)) {287return "variable";288} else {289stream.next();290return "variable-2";291}292}293}294
295function tokenComment(stream, state) {296var maybeEnd = false, maybeNested = false, nestedCount = 0, ch;297while ((ch = stream.next())) {298if (ch == "/" && maybeEnd) {299if (nestedCount > 0) {300nestedCount--;301} else {302state.tokenize = tokenBase;303break;304}305} else if (ch == "*" && maybeNested) {306nestedCount++;307}308maybeEnd = (ch == "*");309maybeNested = (ch == "/");310}311return "comment";312}313
314function tokenString(quote, style) {315return function(stream, state) {316var escaped = false, next, end = false;317while ((next = stream.next()) != null) {318if (next == quote && !escaped) {319end = true;320break;321}322escaped = !escaped && next == "\\";323}324if (end || !escaped) {325state.tokenize = tokenBase;326}327return style;328};329}330
331// Interface332return {333startState: function() {334return {335tokenize: tokenBase,336currentIndent: 0337};338},339token: function(stream, state) {340if (stream.eatSpace())341return null;342var style = state.tokenize(stream, state);343return style;344},345blockCommentStart: "/*",346blockCommentEnd: "*/"347};348});349
350CodeMirror.defineMIME("text/x-dylan", "dylan");351
352});353