source: node_modules/highlight.js/lib/languages/haskell.js@ e48199a

main
Last change on this file since e48199a was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

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