5
if (typeof exports == "object" && typeof module == "object")
6
mod(require("../../lib/codemirror"));
7
else if (typeof define == "function" && define.amd)
8
define(["../../lib/codemirror"], mod);
11
})(function(CodeMirror) {
14
CodeMirror.defineMode("elm", function() {
16
function switchState(source, setState, f)
19
return f(source, setState);
22
var lowerRE = /[a-z]/;
23
var upperRE = /[A-Z]/;
24
var innerRE = /[a-zA-Z0-9_]/;
26
var digitRE = /[0-9]/;
27
var hexRE = /[0-9A-Fa-f]/;
28
var symbolRE = /[-&*+.\\/<>=?^|:]/;
29
var specialRE = /[(),[\]{}]/;
30
var spacesRE = /[ \v\f]/;
34
return function(source, setState)
36
if (source.eatWhile(spacesRE))
41
var char = source.next();
43
if (specialRE.test(char))
45
return (char === '{' && source.eat('-'))
46
? switchState(source, setState, chompMultiComment(1))
47
: (char === '[' && source.match('glsl|'))
48
? switchState(source, setState, chompGlsl)
54
return switchState(source, setState, chompChar);
59
return source.eat('"')
61
? switchState(source, setState, chompMultiString)
63
: switchState(source, setState, chompSingleString);
66
if (upperRE.test(char))
68
source.eatWhile(innerRE);
72
if (lowerRE.test(char))
74
var isDef = source.pos === 1;
75
source.eatWhile(innerRE);
76
return isDef ? "def" : "variable";
79
if (digitRE.test(char))
83
if (source.eat(/[xX]/))
85
source.eatWhile(hexRE);
91
source.eatWhile(digitRE);
95
source.eatWhile(digitRE);
97
if (source.eat(/[eE]/))
100
source.eatWhile(digitRE);
105
if (symbolRE.test(char))
107
if (char === '-' && source.eat('-'))
112
source.eatWhile(symbolRE);
125
function chompMultiComment(nest)
131
return function(source, setState)
133
while (!source.eol())
135
var char = source.next();
136
if (char == '{' && source.eat('-'))
140
else if (char == '-' && source.eat('}'))
150
setState(chompMultiComment(nest));
155
function chompMultiString(source, setState)
157
while (!source.eol())
159
var char = source.next();
160
if (char === '"' && source.eat('"') && source.eat('"'))
169
function chompSingleString(source, setState)
171
while (source.skipTo('\\"')) { source.next(); source.next(); }
172
if (source.skipTo('"'))
183
function chompChar(source, setState)
185
while (source.skipTo("\\'")) { source.next(); source.next(); }
186
if (source.skipTo("'"))
197
function chompGlsl(source, setState)
199
while (!source.eol())
201
var char = source.next();
202
if (char === '|' && source.eat(']'))
211
var wellKnownWords = {
230
startState: function () { return { f: normal() }; },
231
copyState: function (s) { return { f: s.f }; },
233
token: function(stream, state) {
234
var type = state.f(stream, function(s) { state.f = s; });
235
var word = stream.current();
236
return (wellKnownWords.hasOwnProperty(word)) ? 'keyword' : type;
242
CodeMirror.defineMIME("text/x-elm", "elm");