haskell-literate.js 1.4 KB

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