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("haskell", function(_config, modeConfig) {
16
function switchState(source, setState, f) {
18
return f(source, setState);
22
var smallRE = /[a-z_]/;
23
var largeRE = /[A-Z]/;
25
var hexitRE = /[0-9A-Fa-f]/;
26
var octitRE = /[0-7]/;
27
var idRE = /[a-z_A-Z0-9'\xa1-\uffff]/;
28
var symbolRE = /[-!#$%&*+.\/<=>?@\\^|~:]/;
29
var specialRE = /[(),;[\]`{}]/;
30
var whiteCharRE = /[ \t\v\f]/;
32
function normal(source, setState) {
33
if (source.eatWhile(whiteCharRE)) {
37
var ch = source.next();
38
if (specialRE.test(ch)) {
39
if (ch == '{' && source.eat('-')) {
41
if (source.eat('#')) {
44
return switchState(source, setState, ncomment(t, 1));
50
if (source.eat('\\')) {
56
if (source.eat('\'')) {
59
return "string error";
63
return switchState(source, setState, stringLiteral);
66
if (largeRE.test(ch)) {
67
source.eatWhile(idRE);
68
if (source.eat('.')) {
74
if (smallRE.test(ch)) {
75
source.eatWhile(idRE);
79
if (digitRE.test(ch)) {
81
if (source.eat(/[xX]/)) {
82
source.eatWhile(hexitRE);
85
if (source.eat(/[oO]/)) {
86
source.eatWhile(octitRE);
90
source.eatWhile(digitRE);
92
if (source.match(/^\.\d+/)) {
95
if (source.eat(/[eE]/)) {
98
source.eatWhile(digitRE);
103
if (ch == "." && source.eat("."))
106
if (symbolRE.test(ch)) {
107
if (ch == '-' && source.eat(/-/)) {
108
source.eatWhile(/-/);
109
if (!source.eat(symbolRE)) {
118
source.eatWhile(symbolRE);
125
function ncomment(type, nest) {
129
return function(source, setState) {
131
while (!source.eol()) {
132
var ch = source.next();
133
if (ch == '{' && source.eat('-')) {
136
else if (ch == '-' && source.eat('}')) {
144
setState(ncomment(type, currNest));
149
function stringLiteral(source, setState) {
150
while (!source.eol()) {
151
var ch = source.next();
157
if (source.eol() || source.eat(whiteCharRE)) {
161
if (source.eat('&')) {
169
return "string error";
172
function stringGap(source, setState) {
173
if (source.eat('\\')) {
174
return switchState(source, setState, stringLiteral);
182
var wellKnownWords = (function() {
184
function setType(t) {
186
for (var i = 0; i < arguments.length; i++)
187
wkw[arguments[i]] = t;
192
"case", "class", "data", "default", "deriving", "do", "else", "foreign",
193
"if", "import", "in", "infix", "infixl", "infixr", "instance", "let",
194
"module", "newtype", "of", "then", "type", "where", "_");
197
"\.\.", ":", "::", "=", "\\", "<-", "->", "@", "~", "=>");
200
"!!", "$!", "$", "&&", "+", "++", "-", ".", "/", "/=", "<", "<*", "<=",
201
"<$>", "<*>", "=<<", "==", ">", ">=", ">>", ">>=", "^", "^^", "||", "*",
205
"Applicative", "Bool", "Bounded", "Char", "Double", "EQ", "Either", "Enum",
206
"Eq", "False", "FilePath", "Float", "Floating", "Fractional", "Functor",
207
"GT", "IO", "IOError", "Int", "Integer", "Integral", "Just", "LT", "Left",
208
"Maybe", "Monad", "Nothing", "Num", "Ord", "Ordering", "Rational", "Read",
209
"ReadS", "Real", "RealFloat", "RealFrac", "Right", "Show", "ShowS",
213
"abs", "acos", "acosh", "all", "and", "any", "appendFile", "asTypeOf",
214
"asin", "asinh", "atan", "atan2", "atanh", "break", "catch", "ceiling",
215
"compare", "concat", "concatMap", "const", "cos", "cosh", "curry",
216
"cycle", "decodeFloat", "div", "divMod", "drop", "dropWhile", "either",
217
"elem", "encodeFloat", "enumFrom", "enumFromThen", "enumFromThenTo",
218
"enumFromTo", "error", "even", "exp", "exponent", "fail", "filter",
219
"flip", "floatDigits", "floatRadix", "floatRange", "floor", "fmap",
220
"foldl", "foldl1", "foldr", "foldr1", "fromEnum", "fromInteger",
221
"fromIntegral", "fromRational", "fst", "gcd", "getChar", "getContents",
222
"getLine", "head", "id", "init", "interact", "ioError", "isDenormalized",
223
"isIEEE", "isInfinite", "isNaN", "isNegativeZero", "iterate", "last",
224
"lcm", "length", "lex", "lines", "log", "logBase", "lookup", "map",
225
"mapM", "mapM_", "max", "maxBound", "maximum", "maybe", "min", "minBound",
226
"minimum", "mod", "negate", "not", "notElem", "null", "odd", "or",
227
"otherwise", "pi", "pred", "print", "product", "properFraction", "pure",
228
"putChar", "putStr", "putStrLn", "quot", "quotRem", "read", "readFile",
229
"readIO", "readList", "readLn", "readParen", "reads", "readsPrec",
230
"realToFrac", "recip", "rem", "repeat", "replicate", "return", "reverse",
231
"round", "scaleFloat", "scanl", "scanl1", "scanr", "scanr1", "seq",
232
"sequence", "sequence_", "show", "showChar", "showList", "showParen",
233
"showString", "shows", "showsPrec", "significand", "signum", "sin",
234
"sinh", "snd", "span", "splitAt", "sqrt", "subtract", "succ", "sum",
235
"tail", "take", "takeWhile", "tan", "tanh", "toEnum", "toInteger",
236
"toRational", "truncate", "uncurry", "undefined", "unlines", "until",
237
"unwords", "unzip", "unzip3", "userError", "words", "writeFile", "zip",
238
"zip3", "zipWith", "zipWith3");
240
var override = modeConfig.overrideKeywords;
241
if (override) for (var word in override) if (override.hasOwnProperty(word))
242
wkw[word] = override[word];
250
startState: function () { return { f: normal }; },
251
copyState: function (s) { return { f: s.f }; },
253
token: function(stream, state) {
254
var t = state.f(stream, function(s) { state.f = s; });
255
var w = stream.current();
256
return wellKnownWords.hasOwnProperty(w) ? wellKnownWords[w] : t;
259
blockCommentStart: "{-",
260
blockCommentEnd: "-}",
266
CodeMirror.defineMIME("text/x-haskell", "haskell");