all repos — NoPaste @ 0c194823849d27c970ad8888f940f407bc7b4c0a

Resurrected - The PussTheCat.org fork of NoPaste

scripts/CodeMirror/mode/haskell-literate/haskell-literate.js (view raw)

 1// CodeMirror, copyright (c) by Marijn Haverbeke and others
 2// Distributed under an MIT license: https://codemirror.net/LICENSE
 3
 4(function (mod) {
 5  if (typeof exports == "object" && typeof module == "object") // CommonJS
 6    mod(require("../../lib/codemirror"), require("../haskell/haskell"))
 7  else if (typeof define == "function" && define.amd) // AMD
 8    define(["../../lib/codemirror", "../haskell/haskell"], mod)
 9  else // Plain browser env
10    mod(CodeMirror)
11})(function (CodeMirror) {
12  "use strict"
13
14  CodeMirror.defineMode("haskell-literate", function (config, parserConfig) {
15    var baseMode = CodeMirror.getMode(config, (parserConfig && parserConfig.base) || "haskell")
16
17    return {
18      startState: function () {
19        return {
20          inCode: false,
21          baseState: CodeMirror.startState(baseMode)
22        }
23      },
24      token: function (stream, state) {
25        if (stream.sol()) {
26          if (state.inCode = stream.eat(">"))
27            return "meta"
28        }
29        if (state.inCode) {
30          return baseMode.token(stream, state.baseState)
31        } else {
32          stream.skipToEnd()
33          return "comment"
34        }
35      },
36      innerMode: function (state) {
37        return state.inCode ? {state: state.baseState, mode: baseMode} : null
38      }
39    }
40  }, "haskell")
41
42  CodeMirror.defineMIME("text/x-literate-haskell", "haskell-literate")
43});