haskell-literate.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  2. // Distributed under an MIT license: https://codemirror.net/LICENSE
  3. ;(function (mod) {
  4. if (typeof exports == 'object' && typeof module == 'object')
  5. // CommonJS
  6. mod(require('../../lib/codemirror'), require('../haskell/haskell'))
  7. else if (typeof define == 'function' && define.amd)
  8. // AMD
  9. define(['../../lib/codemirror', '../haskell/haskell'], mod)
  10. // Plain browser env
  11. else mod(CodeMirror)
  12. })(function (CodeMirror) {
  13. 'use strict'
  14. CodeMirror.defineMode(
  15. 'haskell-literate',
  16. function (config, parserConfig) {
  17. var baseMode = CodeMirror.getMode(config, (parserConfig && parserConfig.base) || 'haskell')
  18. return {
  19. startState: function () {
  20. return {
  21. inCode: false,
  22. baseState: CodeMirror.startState(baseMode),
  23. }
  24. },
  25. token: function (stream, state) {
  26. if (stream.sol()) {
  27. if ((state.inCode = stream.eat('>'))) 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. },
  41. 'haskell'
  42. )
  43. CodeMirror.defineMIME('text/x-literate-haskell', 'haskell-literate')
  44. })