Commit 198bc99a644fcd9afe2d0cdff036aa618a2597ba

Golmote 2015-10-07T00:28:30

Add support for Nix

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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
diff --git a/components.js b/components.js
index e236cd7..12970b1 100644
--- a/components.js
+++ b/components.js
@@ -304,6 +304,10 @@ var components = {
 			"title": "Nim",
 			"owner": "Golmote"
 		},
+		"nix": {
+			"title": "Nix",
+			"owner": "Golmote"
+		},
 		"nsis": {
 			"title": "NSIS",
 			"owner": "idleberg"
diff --git a/components/prism-nix.js b/components/prism-nix.js
new file mode 100644
index 0000000..7dee574
--- /dev/null
+++ b/components/prism-nix.js
@@ -0,0 +1,39 @@
+Prism.languages.nix = {
+	'comment': /\/\*[\s\S]*?\*\/|#.*/,
+	'string': {
+		pattern: /"(?:[^"\\]|\\[\s\S])*"|''(?:(?!'')[\s\S]|''(?:'|\\|\$\{))*''/,
+		inside: {
+			'interpolation': {
+				// The lookbehind ensures the ${} is not preceded by \ or ''
+				pattern: /(^|(?:^|(?!'').)[^\\])\$\{(?:[^}]|\{[^}]*\})*}/,
+				lookbehind: true,
+				inside: {
+					'antiquotation': {
+						pattern: /^\$(?=\{)/,
+						alias: 'variable'
+					}
+					// See rest below
+				}
+			}
+		}
+	},
+	'url': [
+		/\b(?:[a-z]{3,7}:\/\/)[\w\-+%~\/.:#=?&]+/,
+		{
+			pattern: /([^\/])(?:[\w\-+%~.:#=?&]*(?!\/\/)[\w\-+%~\/.:#=?&])?(?!\/\/)\/[\w\-+%~\/.:#=?&]*/,
+			lookbehind: true
+		}
+	],
+	'antiquotation': {
+		pattern: /\$(?=\{)/,
+		alias: 'variable'
+	},
+	'number': /\b\d+\b/,
+	'keyword': /\b(?:assert|builtins|else|if|in|inherit|let|null|or|then|with)\b/,
+	'function': /\b(?:abort|add|all|any|attrNames|attrValues|baseNameOf|compareVersions|concatLists|currentSystem|deepSeq|derivation|dirOf|div|elem(?:At)?|fetch(?:url|Tarball)|filter(?:Source)?|fromJSON|genList|getAttr|getEnv|hasAttr|hashString|head|import|intersectAttrs|is(?:Attrs|Bool|Function|Int|List|Null|String)|length|lessThan|listToAttrs|map|mul|parseDrvName|pathExists|read(?:Dir|File)|removeAttrs|replaceStrings|seq|sort|stringLength|sub(?:string)?|tail|throw|to(?:File|JSON|Path|String|XML)|trace|typeOf)\b|\bfoldl'\B/,
+	'boolean': /\b(?:true|false)\b/,
+	'operator': /[=!<>]=?|\+\+?|\|\||&&|\/\/|->?|[?@]/,
+	'punctuation': /[{}()[\].,:;]/
+};
+
+Prism.languages.nix.string.inside.interpolation.inside.rest = Prism.util.clone(Prism.languages.nix);
\ No newline at end of file
diff --git a/components/prism-nix.min.js b/components/prism-nix.min.js
new file mode 100644
index 0000000..fd9e076
--- /dev/null
+++ b/components/prism-nix.min.js
@@ -0,0 +1 @@
+Prism.languages.nix={comment:/\/\*[\s\S]*?\*\/|#.*/,string:{pattern:/"(?:[^"\\]|\\[\s\S])*"|''(?:(?!'')[\s\S]|''(?:'|\\|\$\{))*''/,inside:{interpolation:{pattern:/(^|(?:^|(?!'').)[^\\])\$\{(?:[^}]|\{[^}]*\})*}/,lookbehind:!0,inside:{antiquotation:{pattern:/^\$(?=\{)/,alias:"variable"}}}}},url:[/\b(?:[a-z]{3,7}:\/\/)[\w\-+%~\/.:#=?&]+/,{pattern:/([^\/])(?:[\w\-+%~.:#=?&]*(?!\/\/)[\w\-+%~\/.:#=?&])?(?!\/\/)\/[\w\-+%~\/.:#=?&]*/,lookbehind:!0}],antiquotation:{pattern:/\$(?=\{)/,alias:"variable"},number:/\b\d+\b/,keyword:/\b(?:assert|builtins|else|if|in|inherit|let|null|or|then|with)\b/,"function":/\b(?:abort|add|all|any|attrNames|attrValues|baseNameOf|compareVersions|concatLists|currentSystem|deepSeq|derivation|dirOf|div|elem(?:At)?|fetch(?:url|Tarball)|filter(?:Source)?|fromJSON|genList|getAttr|getEnv|hasAttr|hashString|head|import|intersectAttrs|is(?:Attrs|Bool|Function|Int|List|Null|String)|length|lessThan|listToAttrs|map|mul|parseDrvName|pathExists|read(?:Dir|File)|removeAttrs|replaceStrings|seq|sort|stringLength|sub(?:string)?|tail|throw|to(?:File|JSON|Path|String|XML)|trace|typeOf)\b|\bfoldl'\B/,"boolean":/\b(?:true|false)\b/,operator:/[=!<>]=?|\+\+?|\|\||&&|\/\/|->?|[?@]/,punctuation:/[{}()[\].,:;]/},Prism.languages.nix.string.inside.interpolation.inside.rest=Prism.util.clone(Prism.languages.nix);
\ No newline at end of file
diff --git a/examples/prism-nix.html b/examples/prism-nix.html
new file mode 100644
index 0000000..ee79b0d
--- /dev/null
+++ b/examples/prism-nix.html
@@ -0,0 +1,59 @@
+<h1>Nix</h1>
+<p>To use this language, use the class "language-nix".</p>
+
+<h2>Comments</h2>
+<pre><code>#
+# Single line comment
+/* Multi-line
+comment */</code></pre>
+
+<h2>String</h2>
+<pre><code>""
+"foo\"bar"
+"foo
+bar"
+
+''''
+''foo'''bar''
+''
+foo
+bar
+''</code></pre>
+
+<h2>String interpolation</h2>
+<pre><code>"foo${42}bar"
+"foo\${42}bar" # This is not interpolated
+''foo${42}bar''
+''foo''${42}bar'' # This is not interpolated</code></pre>
+
+<h2>URLs and paths</h2>
+<pre><code>ftp://ftp.nluug.nl/pub/gnu/hello/hello-2.1.1.tar.gz
+http://example.org/foo.tar.bz2
+/bin/sh
+./builder.sh
+~/foo.bar</code></pre>
+
+<h2>Integers, booleans and null</h2>
+<pre><code>0
+42
+
+true
+false
+
+null</code></pre>
+
+<h2>Builtin functions</h2>
+<pre><code>name = baseNameOf (toString url);
+imap =
+	if builtins ? genList then
+		f: list: genList (n: f (n + 1) (elemAt list n)) (length list)</code></pre>
+
+<h2>Known failures</h2>
+<p>There are certain edge cases where Prism will fail.
+	There are always such cases in every regex-based syntax highlighter.
+	However, Prism dares to be open and honest about them.
+	If a failure is listed here, it doesn’t mean it will never be fixed. This is more of a “known bugs” list, just with a certain type of bug.
+</p>
+
+<h3>Comment-like substrings</h3>
+<pre><code>"This # is a broken string"</code></pre>
\ No newline at end of file
diff --git a/tests/languages/nix/antiquotation_feature.test b/tests/languages/nix/antiquotation_feature.test
new file mode 100644
index 0000000..b0e6e51
--- /dev/null
+++ b/tests/languages/nix/antiquotation_feature.test
@@ -0,0 +1,14 @@
+${42}
+
+----------------------------------------------------
+
+[
+	["antiquotation", "$"],
+	["punctuation", "{"],
+	["number", "42"],
+	["punctuation", "}"]
+]
+
+----------------------------------------------------
+
+Checks for antiquotations outside of strings.
\ No newline at end of file
diff --git a/tests/languages/nix/boolean_feature.test b/tests/languages/nix/boolean_feature.test
new file mode 100644
index 0000000..4019c44
--- /dev/null
+++ b/tests/languages/nix/boolean_feature.test
@@ -0,0 +1,13 @@
+true
+false
+
+----------------------------------------------------
+
+[
+	["boolean", "true"],
+	["boolean", "false"]
+]
+
+----------------------------------------------------
+
+Checks for booleans.
\ No newline at end of file
diff --git a/tests/languages/nix/comment_feature.test b/tests/languages/nix/comment_feature.test
new file mode 100644
index 0000000..f44b3d4
--- /dev/null
+++ b/tests/languages/nix/comment_feature.test
@@ -0,0 +1,18 @@
+#
+# foobar
+/**/
+/* foo
+bar */
+
+----------------------------------------------------
+
+[
+	["comment", "#"],
+	["comment", "# foobar"],
+	["comment", "/**/"],
+	["comment", "/* foo\r\nbar */"]
+]
+
+----------------------------------------------------
+
+Checks for comments.
\ No newline at end of file
diff --git a/tests/languages/nix/function_feature.test b/tests/languages/nix/function_feature.test
new file mode 100644
index 0000000..1720b45
--- /dev/null
+++ b/tests/languages/nix/function_feature.test
@@ -0,0 +1,133 @@
+abort
+add
+all
+any
+attrNames
+attrValues
+baseNameOf
+compareVersions
+concatLists
+currentSystem
+deepSeq
+derivation
+dirOf
+div
+elem
+elemAt
+fetchurl
+fetchTarball
+filter
+filterSource
+fromJSON
+genList
+getAttr
+getEnv
+hasAttr
+hashString
+head
+import
+intersectAttrs
+isAttrs
+isBool
+isFunction
+isInt
+isList
+isNull
+isString
+length
+lessThan
+listToAttrs
+map
+mul
+parseDrvName
+pathExists
+readDir
+readFile
+removeAttrs
+replaceStrings
+seq
+sort
+stringLength
+sub
+substring
+tail
+throw
+toFile
+toJSON
+toPath
+toString
+toXML
+trace
+typeOf
+foldl'
+
+----------------------------------------------------
+
+[
+	["function", "abort"],
+	["function", "add"],
+	["function", "all"],
+	["function", "any"],
+	["function", "attrNames"],
+	["function", "attrValues"],
+	["function", "baseNameOf"],
+	["function", "compareVersions"],
+	["function", "concatLists"],
+	["function", "currentSystem"],
+	["function", "deepSeq"],
+	["function", "derivation"],
+	["function", "dirOf"],
+	["function", "div"],
+	["function", "elem"],
+	["function", "elemAt"],
+	["function", "fetchurl"],
+	["function", "fetchTarball"],
+	["function", "filter"],
+	["function", "filterSource"],
+	["function", "fromJSON"],
+	["function", "genList"],
+	["function", "getAttr"],
+	["function", "getEnv"],
+	["function", "hasAttr"],
+	["function", "hashString"],
+	["function", "head"],
+	["function", "import"],
+	["function", "intersectAttrs"],
+	["function", "isAttrs"],
+	["function", "isBool"],
+	["function", "isFunction"],
+	["function", "isInt"],
+	["function", "isList"],
+	["function", "isNull"],
+	["function", "isString"],
+	["function", "length"],
+	["function", "lessThan"],
+	["function", "listToAttrs"],
+	["function", "map"],
+	["function", "mul"],
+	["function", "parseDrvName"],
+	["function", "pathExists"],
+	["function", "readDir"],
+	["function", "readFile"],
+	["function", "removeAttrs"],
+	["function", "replaceStrings"],
+	["function", "seq"],
+	["function", "sort"],
+	["function", "stringLength"],
+	["function", "sub"],
+	["function", "substring"],
+	["function", "tail"],
+	["function", "throw"],
+	["function", "toFile"],
+	["function", "toJSON"],
+	["function", "toPath"],
+	["function", "toString"],
+	["function", "toXML"],
+	["function", "trace"],
+	["function", "typeOf"],
+	["function", "foldl'"]
+]
+
+----------------------------------------------------
+
+Checks for built-in functions.
\ No newline at end of file
diff --git a/tests/languages/nix/keyword_feature.test b/tests/languages/nix/keyword_feature.test
new file mode 100644
index 0000000..46fc443
--- /dev/null
+++ b/tests/languages/nix/keyword_feature.test
@@ -0,0 +1,15 @@
+assert builtins else if
+in inherit let null
+or then with
+
+----------------------------------------------------
+
+[
+	["keyword", "assert"], ["keyword", "builtins"], ["keyword", "else"], ["keyword", "if"],
+	["keyword", "in"], ["keyword", "inherit"], ["keyword", "let"], ["keyword", "null"],
+	["keyword", "or"], ["keyword", "then"], ["keyword", "with"]
+]
+
+----------------------------------------------------
+
+Checks for keywords.
\ No newline at end of file
diff --git a/tests/languages/nix/number_feature.test b/tests/languages/nix/number_feature.test
new file mode 100644
index 0000000..25fc031
--- /dev/null
+++ b/tests/languages/nix/number_feature.test
@@ -0,0 +1,15 @@
+0
+42
+120457
+
+----------------------------------------------------
+
+[
+	["number", "0"],
+	["number", "42"],
+	["number", "120457"]
+]
+
+----------------------------------------------------
+
+Checks for integers.
\ No newline at end of file
diff --git a/tests/languages/nix/operator_feature.test b/tests/languages/nix/operator_feature.test
new file mode 100644
index 0000000..461f1a2
--- /dev/null
+++ b/tests/languages/nix/operator_feature.test
@@ -0,0 +1,25 @@
+= ==
+! !=
+< <=
+> >=
++ ++
+- ->
+|| && //
+? @
+
+----------------------------------------------------
+
+[
+	["operator", "="], ["operator", "=="],
+	["operator", "!"], ["operator", "!="],
+	["operator", "<"], ["operator", "<="],
+	["operator", ">"], ["operator", ">="],
+	["operator", "+"], ["operator", "++"],
+	["operator", "-"], ["operator", "->"],
+	["operator", "||"], ["operator", "&&"], ["operator", "//"],
+	["operator", "?"], ["operator", "@"]
+]
+
+----------------------------------------------------
+
+Checks for operators.
\ No newline at end of file
diff --git a/tests/languages/nix/string_feature.test b/tests/languages/nix/string_feature.test
new file mode 100644
index 0000000..e8e7f35
--- /dev/null
+++ b/tests/languages/nix/string_feature.test
@@ -0,0 +1,56 @@
+""
+"foo\"b\\ar"
+"f''o'o'\"bar"
+"foo
+bar"
+"foo ${ 42 } baz"
+"foo \${ 42 } baz"
+
+''''
+''
+foo
+bar
+''
+''
+f'oo'''ba'r
+foo ${ 42 } baz
+foo ''${ 42 } baz
+''
+
+----------------------------------------------------
+
+[
+	["string", ["\"\""]],
+	["string", ["\"foo\\\"b\\\\ar\""]],
+	["string", ["\"f''o'o'\\\"bar\""]],
+	["string", ["\"foo\r\nbar\""]],
+	["string", [
+		"\"foo ",
+		["interpolation", [
+			["antiquotation", "$"],
+			["punctuation", "{"],
+			["number", "42"],
+			["punctuation", "}"]
+		]],
+		" baz\""
+	]],
+	["string", ["\"foo \\${ 42 } baz\""]],
+
+	["string", ["''''"]],
+	["string", ["''\r\nfoo\r\nbar\r\n''"]],
+	["string", [
+		"''\r\nf'oo'''ba'r\r\nfoo ",
+		["interpolation", [
+			["antiquotation", "$"],
+			["punctuation", "{"],
+			["number", "42"],
+			["punctuation", "}"]
+		]],
+		" baz\r\nfoo ''${ 42 } baz\r\n''"
+	]]
+]
+
+----------------------------------------------------
+
+Checks for strings and string interpolation.
+Also checks that escaped interpolations are not interpreted.
\ No newline at end of file
diff --git a/tests/languages/nix/url_feature.test b/tests/languages/nix/url_feature.test
new file mode 100644
index 0000000..9b69ee3
--- /dev/null
+++ b/tests/languages/nix/url_feature.test
@@ -0,0 +1,21 @@
+http://example.org/foo.tar.bz2
+ftp://ftp.nluug.nl/pub/gnu/hello/hello-2.1.1.tar.gz
+
+/bin/sh
+./builder.sh
+~/foo.bar
+
+----------------------------------------------------
+
+[
+	["url", "http://example.org/foo.tar.bz2"],
+	["url", "ftp://ftp.nluug.nl/pub/gnu/hello/hello-2.1.1.tar.gz"],
+
+	["url", "/bin/sh"],
+	["url", "./builder.sh"],
+	["url", "~/foo.bar"]
+]
+
+----------------------------------------------------
+
+Checks for URLs and paths.
\ No newline at end of file