1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
| /*
| Language: Haskell
| Author: Jeremy Hull <sourdrums@gmail.com>
| Contributors: Zena Treep <zena.treep@gmail.com>
| Website: https://www.haskell.org
| Category: functional
| */
|
| function haskell(hljs) {
| const COMMENT = {
| variants: [
| hljs.COMMENT('--', '$'),
| hljs.COMMENT(
| /\{-/,
| /-\}/,
| {
| contains: ['self']
| }
| )
| ]
| };
|
| const PRAGMA = {
| className: 'meta',
| begin: /\{-#/,
| end: /#-\}/
| };
|
| const PREPROCESSOR = {
| className: 'meta',
| begin: '^#',
| end: '$'
| };
|
| const CONSTRUCTOR = {
| className: 'type',
| begin: '\\b[A-Z][\\w\']*', // TODO: other constructors (build-in, infix).
| relevance: 0
| };
|
| const LIST = {
| begin: '\\(',
| end: '\\)',
| illegal: '"',
| contains: [
| PRAGMA,
| PREPROCESSOR,
| {
| className: 'type',
| begin: '\\b[A-Z][\\w]*(\\((\\.\\.|,|\\w+)\\))?'
| },
| hljs.inherit(hljs.TITLE_MODE, {
| begin: '[_a-z][\\w\']*'
| }),
| COMMENT
| ]
| };
|
| const RECORD = {
| begin: /\{/,
| end: /\}/,
| contains: LIST.contains
| };
|
| return {
| name: 'Haskell',
| aliases: ['hs'],
| keywords:
| 'let in if then else case of where do module import hiding ' +
| 'qualified type data newtype deriving class instance as default ' +
| 'infix infixl infixr foreign export ccall stdcall cplusplus ' +
| 'jvm dotnet safe unsafe family forall mdo proc rec',
| contains: [
| // Top-level constructions.
| {
| beginKeywords: 'module',
| end: 'where',
| keywords: 'module where',
| contains: [
| LIST,
| COMMENT
| ],
| illegal: '\\W\\.|;'
| },
| {
| begin: '\\bimport\\b',
| end: '$',
| keywords: 'import qualified as hiding',
| contains: [
| LIST,
| COMMENT
| ],
| illegal: '\\W\\.|;'
| },
| {
| className: 'class',
| begin: '^(\\s*)?(class|instance)\\b',
| end: 'where',
| keywords: 'class family instance where',
| contains: [
| CONSTRUCTOR,
| LIST,
| COMMENT
| ]
| },
| {
| className: 'class',
| begin: '\\b(data|(new)?type)\\b',
| end: '$',
| keywords: 'data family type newtype deriving',
| contains: [
| PRAGMA,
| CONSTRUCTOR,
| LIST,
| RECORD,
| COMMENT
| ]
| },
| {
| beginKeywords: 'default',
| end: '$',
| contains: [
| CONSTRUCTOR,
| LIST,
| COMMENT
| ]
| },
| {
| beginKeywords: 'infix infixl infixr',
| end: '$',
| contains: [
| hljs.C_NUMBER_MODE,
| COMMENT
| ]
| },
| {
| begin: '\\bforeign\\b',
| end: '$',
| keywords: 'foreign import export ccall stdcall cplusplus jvm ' +
| 'dotnet safe unsafe',
| contains: [
| CONSTRUCTOR,
| hljs.QUOTE_STRING_MODE,
| COMMENT
| ]
| },
| {
| className: 'meta',
| begin: '#!\\/usr\\/bin\\/env\ runhaskell',
| end: '$'
| },
| // "Whitespaces".
| PRAGMA,
| PREPROCESSOR,
|
| // Literals and names.
|
| // TODO: characters.
| hljs.QUOTE_STRING_MODE,
| hljs.C_NUMBER_MODE,
| CONSTRUCTOR,
| hljs.inherit(hljs.TITLE_MODE, {
| begin: '^[_a-z][\\w\']*'
| }),
| COMMENT,
| { // No markup, relevance booster
| begin: '->|<-'
| }
| ]
| };
| }
|
| module.exports = haskell;
|
|