haskell.js 2.8 KB

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