2 * See LICENSE in this directory for the license under which this code
6 CodeMirror.defineMode("sieve", function(config) {
8 var obj = {}, words = str.split(" ");
9 for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
13 var keywords = words("if elsif else stop require");
14 var atoms = words("true false not");
15 var indentUnit = config.indentUnit;
17 function tokenBase(stream, state) {
19 var ch = stream.next();
20 if (ch == "/" && stream.eat("*")) {
21 state.tokenize = tokenCComment;
22 return tokenCComment(stream, state);
31 state.tokenize = tokenString(ch);
32 return state.tokenize(stream, state);
36 state._indent.push("(");
37 // add virtual angel wings so that editor behaves...
38 // ...more sane incase of broken brackets
39 state._indent.push("{");
44 state._indent.push("{");
65 if (/[{}\(\),;]/.test(ch))
68 // 1*DIGIT "K" / "M" / "G"
70 stream.eatWhile(/[\d]/);
71 stream.eat(/[KkMmGg]/);
75 // ":" (ALPHA / "_") *(ALPHA / DIGIT / "_")
77 stream.eatWhile(/[a-zA-Z_]/);
78 stream.eatWhile(/[a-zA-Z0-9_]/);
83 stream.eatWhile(/\w/);
84 var cur = stream.current();
86 // "text:" *(SP / HTAB) (hash-comment / CRLF)
87 // *(multiline-literal / multiline-dotstart)
89 if ((cur == "text") && stream.eat(":"))
91 state.tokenize = tokenMultiLineString;
95 if (keywords.propertyIsEnumerable(cur))
98 if (atoms.propertyIsEnumerable(cur))
104 function tokenMultiLineString(stream, state)
106 state._multiLineString = true;
107 // the first line is special it may contain a comment
111 if (stream.peek() == "#") {
120 if ((stream.next() == ".") && (stream.eol()))
122 state._multiLineString = false;
123 state.tokenize = tokenBase;
129 function tokenCComment(stream, state) {
130 var maybeEnd = false, ch;
131 while ((ch = stream.next()) != null) {
132 if (maybeEnd && ch == "/") {
133 state.tokenize = tokenBase;
136 maybeEnd = (ch == "*");
141 function tokenString(quote) {
142 return function(stream, state) {
143 var escaped = false, ch;
144 while ((ch = stream.next()) != null) {
145 if (ch == quote && !escaped)
147 escaped = !escaped && ch == "\\";
149 if (!escaped) state.tokenize = tokenBase;
155 startState: function(base) {
156 return {tokenize: tokenBase,
157 baseIndent: base || 0,
161 token: function(stream, state) {
162 if (stream.eatSpace())
165 return (state.tokenize || tokenBase)(stream, state);;
168 indent: function(state, _textAfter) {
169 var length = state._indent.length;
170 if (_textAfter && (_textAfter[0] == "}"))
176 return length * indentUnit;
183 CodeMirror.defineMIME("application/sieve", "sieve");