haskell.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. Language: Haskell
  3. Author: Jeremy Hull <[email protected]>
  4. Contributors: Zena Treep <[email protected]>
  5. Category: functional
  6. */
  7. function(hljs) {
  8. var COMMENT = {
  9. variants: [
  10. hljs.COMMENT('--', '$'),
  11. hljs.COMMENT(
  12. '{-',
  13. '-}',
  14. {
  15. contains: ['self']
  16. }
  17. )
  18. ]
  19. };
  20. var PRAGMA = {
  21. className: 'meta',
  22. begin: '{-#', end: '#-}'
  23. };
  24. var PREPROCESSOR = {
  25. className: 'meta',
  26. begin: '^#', end: '$'
  27. };
  28. var CONSTRUCTOR = {
  29. className: 'type',
  30. begin: '\\b[A-Z][\\w\']*', // TODO: other constructors (build-in, infix).
  31. relevance: 0
  32. };
  33. var LIST = {
  34. begin: '\\(', end: '\\)',
  35. illegal: '"',
  36. contains: [
  37. PRAGMA,
  38. PREPROCESSOR,
  39. {className: 'type', begin: '\\b[A-Z][\\w]*(\\((\\.\\.|,|\\w+)\\))?'},
  40. hljs.inherit(hljs.TITLE_MODE, {begin: '[_a-z][\\w\']*'}),
  41. COMMENT
  42. ]
  43. };
  44. var RECORD = {
  45. begin: '{', end: '}',
  46. contains: LIST.contains
  47. };
  48. return {
  49. aliases: ['hs'],
  50. keywords:
  51. 'let in if then else case of where do module import hiding ' +
  52. 'qualified type data newtype deriving class instance as default ' +
  53. 'infix infixl infixr foreign export ccall stdcall cplusplus ' +
  54. 'jvm dotnet safe unsafe family forall mdo proc rec',
  55. contains: [
  56. // Top-level constructions.
  57. {
  58. beginKeywords: 'module', end: 'where',
  59. keywords: 'module where',
  60. contains: [LIST, COMMENT],
  61. illegal: '\\W\\.|;'
  62. },
  63. {
  64. begin: '\\bimport\\b', end: '$',
  65. keywords: 'import qualified as hiding',
  66. contains: [LIST, COMMENT],
  67. illegal: '\\W\\.|;'
  68. },
  69. {
  70. className: 'class',
  71. begin: '^(\\s*)?(class|instance)\\b', end: 'where',
  72. keywords: 'class family instance where',
  73. contains: [CONSTRUCTOR, LIST, COMMENT]
  74. },
  75. {
  76. className: 'class',
  77. begin: '\\b(data|(new)?type)\\b', end: '$',
  78. keywords: 'data family type newtype deriving',
  79. contains: [PRAGMA, CONSTRUCTOR, LIST, RECORD, COMMENT]
  80. },
  81. {
  82. beginKeywords: 'default', end: '$',
  83. contains: [CONSTRUCTOR, LIST, COMMENT]
  84. },
  85. {
  86. beginKeywords: 'infix infixl infixr', end: '$',
  87. contains: [hljs.C_NUMBER_MODE, COMMENT]
  88. },
  89. {
  90. begin: '\\bforeign\\b', end: '$',
  91. keywords: 'foreign import export ccall stdcall cplusplus jvm ' +
  92. 'dotnet safe unsafe',
  93. contains: [CONSTRUCTOR, hljs.QUOTE_STRING_MODE, COMMENT]
  94. },
  95. {
  96. className: 'meta',
  97. begin: '#!\\/usr\\/bin\\/env\ runhaskell', end: '$'
  98. },
  99. // "Whitespaces".
  100. PRAGMA,
  101. PREPROCESSOR,
  102. // Literals and names.
  103. // TODO: characters.
  104. hljs.QUOTE_STRING_MODE,
  105. hljs.C_NUMBER_MODE,
  106. CONSTRUCTOR,
  107. hljs.inherit(hljs.TITLE_MODE, {begin: '^[_a-z][\\w\']*'}),
  108. COMMENT,
  109. {begin: '->|<-'} // No markup, relevance booster
  110. ]
  111. };
  112. }