1 // CodeMirror, copyright (c) by Marijn Haverbeke and others
2 // Distributed under an MIT license: http://codemirror.net/LICENSE
5 if (typeof exports == "object" && typeof module == "object") // CommonJS
6 mod(require("../../lib/codemirror"));
7 else if (typeof define == "function" && define.amd) // AMD
8 define(["../../lib/codemirror"], mod);
9 else // Plain browser env
11 })(function(CodeMirror) {
14 CodeMirror.defineMode("sieve", function(config) {
16 var obj = {}, words = str.split(" ");
17 for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
21 var keywords = words("if elsif else stop require");
22 var atoms = words("true false not");
23 var indentUnit = config.indentUnit;
25 function tokenBase(stream, state) {
27 var ch = stream.next();
28 if (ch == "/" && stream.eat("*")) {
29 state.tokenize = tokenCComment;
30 return tokenCComment(stream, state);
39 state.tokenize = tokenString(ch);
40 return state.tokenize(stream, state);
44 state._indent.push("(");
45 // add virtual angel wings so that editor behaves...
46 // ...more sane incase of broken brackets
47 state._indent.push("{");
52 state._indent.push("{");
73 if (/[{}\(\),;]/.test(ch))
76 // 1*DIGIT "K" / "M" / "G"
78 stream.eatWhile(/[\d]/);
79 stream.eat(/[KkMmGg]/);
83 // ":" (ALPHA / "_") *(ALPHA / DIGIT / "_")
85 stream.eatWhile(/[a-zA-Z_]/);
86 stream.eatWhile(/[a-zA-Z0-9_]/);
91 stream.eatWhile(/\w/);
92 var cur = stream.current();
94 // "text:" *(SP / HTAB) (hash-comment / CRLF)
95 // *(multiline-literal / multiline-dotstart)
97 if ((cur == "text") && stream.eat(":"))
99 state.tokenize = tokenMultiLineString;
103 if (keywords.propertyIsEnumerable(cur))
106 if (atoms.propertyIsEnumerable(cur))
112 function tokenMultiLineString(stream, state)
114 state._multiLineString = true;
115 // the first line is special it may contain a comment
119 if (stream.peek() == "#") {
128 if ((stream.next() == ".") && (stream.eol()))
130 state._multiLineString = false;
131 state.tokenize = tokenBase;
137 function tokenCComment(stream, state) {
138 var maybeEnd = false, ch;
139 while ((ch = stream.next()) != null) {
140 if (maybeEnd && ch == "/") {
141 state.tokenize = tokenBase;
144 maybeEnd = (ch == "*");
149 function tokenString(quote) {
150 return function(stream, state) {
151 var escaped = false, ch;
152 while ((ch = stream.next()) != null) {
153 if (ch == quote && !escaped)
155 escaped = !escaped && ch == "\\";
157 if (!escaped) state.tokenize = tokenBase;
163 startState: function(base) {
164 return {tokenize: tokenBase,
165 baseIndent: base || 0,
169 token: function(stream, state) {
170 if (stream.eatSpace())
173 return (state.tokenize || tokenBase)(stream, state);;
176 indent: function(state, _textAfter) {
177 var length = state._indent.length;
178 if (_textAfter && (_textAfter[0] == "}"))
184 return length * indentUnit;
191 CodeMirror.defineMIME("application/sieve", "sieve");