LaravelTest
193 строки · 4.2 Кб
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("sieve", function(config) {15function words(str) {16var obj = {}, words = str.split(" ");17for (var i = 0; i < words.length; ++i) obj[words[i]] = true;18return obj;19}20
21var keywords = words("if elsif else stop require");22var atoms = words("true false not");23var indentUnit = config.indentUnit;24
25function tokenBase(stream, state) {26
27var ch = stream.next();28if (ch == "/" && stream.eat("*")) {29state.tokenize = tokenCComment;30return tokenCComment(stream, state);31}32
33if (ch === '#') {34stream.skipToEnd();35return "comment";36}37
38if (ch == "\"") {39state.tokenize = tokenString(ch);40return state.tokenize(stream, state);41}42
43if (ch == "(") {44state._indent.push("(");45// add virtual angel wings so that editor behaves...46// ...more sane in case of broken brackets47state._indent.push("{");48return null;49}50
51if (ch === "{") {52state._indent.push("{");53return null;54}55
56if (ch == ")") {57state._indent.pop();58state._indent.pop();59}60
61if (ch === "}") {62state._indent.pop();63return null;64}65
66if (ch == ",")67return null;68
69if (ch == ";")70return null;71
72
73if (/[{}\(\),;]/.test(ch))74return null;75
76// 1*DIGIT "K" / "M" / "G"77if (/\d/.test(ch)) {78stream.eatWhile(/[\d]/);79stream.eat(/[KkMmGg]/);80return "number";81}82
83// ":" (ALPHA / "_") *(ALPHA / DIGIT / "_")84if (ch == ":") {85stream.eatWhile(/[a-zA-Z_]/);86stream.eatWhile(/[a-zA-Z0-9_]/);87
88return "operator";89}90
91stream.eatWhile(/\w/);92var cur = stream.current();93
94// "text:" *(SP / HTAB) (hash-comment / CRLF)95// *(multiline-literal / multiline-dotstart)96// "." CRLF97if ((cur == "text") && stream.eat(":"))98{99state.tokenize = tokenMultiLineString;100return "string";101}102
103if (keywords.propertyIsEnumerable(cur))104return "keyword";105
106if (atoms.propertyIsEnumerable(cur))107return "atom";108
109return null;110}111
112function tokenMultiLineString(stream, state)113{114state._multiLineString = true;115// the first line is special it may contain a comment116if (!stream.sol()) {117stream.eatSpace();118
119if (stream.peek() == "#") {120stream.skipToEnd();121return "comment";122}123
124stream.skipToEnd();125return "string";126}127
128if ((stream.next() == ".") && (stream.eol()))129{130state._multiLineString = false;131state.tokenize = tokenBase;132}133
134return "string";135}136
137function tokenCComment(stream, state) {138var maybeEnd = false, ch;139while ((ch = stream.next()) != null) {140if (maybeEnd && ch == "/") {141state.tokenize = tokenBase;142break;143}144maybeEnd = (ch == "*");145}146return "comment";147}148
149function tokenString(quote) {150return function(stream, state) {151var escaped = false, ch;152while ((ch = stream.next()) != null) {153if (ch == quote && !escaped)154break;155escaped = !escaped && ch == "\\";156}157if (!escaped) state.tokenize = tokenBase;158return "string";159};160}161
162return {163startState: function(base) {164return {tokenize: tokenBase,165baseIndent: base || 0,166_indent: []};167},168
169token: function(stream, state) {170if (stream.eatSpace())171return null;172
173return (state.tokenize || tokenBase)(stream, state);174},175
176indent: function(state, _textAfter) {177var length = state._indent.length;178if (_textAfter && (_textAfter[0] == "}"))179length--;180
181if (length <0)182length = 0;183
184return length * indentUnit;185},186
187electricChars: "}"188};189});190
191CodeMirror.defineMIME("application/sieve", "sieve");192
193});194