Commit 6679e735cb6cb580113aa49699efa3f7cedf9dc5

Golmote 2015-10-10T16:38:02

Add support for PARI/GP

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
diff --git a/components.js b/components.js
index ffa5683..184f3b7 100644
--- a/components.js
+++ b/components.js
@@ -317,6 +317,10 @@ var components = {
 			"title": "OCaml",
 			"owner": "Golmote"
 		},
+		"parigp": {
+			"title": "PARI/GP",
+			"owner": "Golmote"
+		},
 		"pascal": {
 			"title": "Pascal",
 			"owner": "Golmote"
diff --git a/components/prism-parigp.js b/components/prism-parigp.js
new file mode 100644
index 0000000..eec2293
--- /dev/null
+++ b/components/prism-parigp.js
@@ -0,0 +1,27 @@
+Prism.languages.parigp = {
+	'comment': /\/\*[\s\S]*?\*\/|\\\\.*/,
+	'string': /"(?:[^"\\]|\\.)*"/,
+	// PARI/GP does not care about white spaces at all
+	// so let's process the keywords to build an appropriate regexp
+	// (e.g. "b *r *e *a *k", etc.)
+	'keyword': (function () {
+		var keywords = [
+			'breakpoint', 'break', 'dbg_down', 'dbg_err', 'dbg_up', 'dbg_x',
+			'forcomposite', 'fordiv', 'forell', 'forpart', 'forprime',
+			'forstep', 'forsubgroup', 'forvec', 'for', 'iferr', 'if',
+			'local', 'my', 'next', 'return', 'until', 'while'
+		];
+		keywords = keywords.map(function (keyword) {
+			return keyword.split('').join(' *');
+		}).join('|');
+		return RegExp('\\b(?:' + keywords + ')\\b');
+	}()),
+	'function': /\w[\w ]*?(?= *\()/,
+	'number': {
+		// The lookbehind and the negative lookahead prevent from breaking the .. operator
+		pattern: /((?:\. *\. *)?)(?:\d(?: *\d)*(?: *(?!\. *\.)\.(?: *\d)*)?|\. *\d(?: *\d)*)(?: *e *[+-]? *\d(?: *\d)*)?/i,
+		lookbehind: true
+	},
+	'operator': /\. *\.|[*\/!](?: *=)?|%(?: *=|(?: *#)?(?: *')*)?|\+(?: *[+=])?|-(?: *[-=>])?|<(?:(?: *<)?(?: *=)?| *>)?|>(?: *>)?(?: *=)?|=(?: *=){0,2}|\\(?: *\/)?(?: *=)?|&(?: *&)?|\| *\||['#~^]/,
+	'punctuation': /[\[\]{}().,:;|]/
+};
\ No newline at end of file
diff --git a/components/prism-parigp.min.js b/components/prism-parigp.min.js
new file mode 100644
index 0000000..98bf20d
--- /dev/null
+++ b/components/prism-parigp.min.js
@@ -0,0 +1 @@
+Prism.languages.parigp={comment:/\/\*[\s\S]*?\*\/|\\\\.*/,string:/"(?:[^"\\]|\\.)*"/,keyword:function(){var r=["breakpoint","break","dbg_down","dbg_err","dbg_up","dbg_x","forcomposite","fordiv","forell","forpart","forprime","forstep","forsubgroup","forvec","for","iferr","if","local","my","next","return","until","while"];return r=r.map(function(r){return r.split("").join(" *")}).join("|"),RegExp("\\b(?:"+r+")\\b")}(),"function":/\w[\w ]*?(?= *\()/,number:{pattern:/((?:\. *\. *)?)(?:\d(?: *\d)*(?: *(?!\. *\.)\.(?: *\d)*)?|\. *\d(?: *\d)*)(?: *e *[+-]? *\d(?: *\d)*)?/i,lookbehind:!0},operator:/\. *\.|[*\/!](?: *=)?|%(?: *=|(?: *#)?(?: *')*)?|\+(?: *[+=])?|-(?: *[-=>])?|<(?:(?: *<)?(?: *=)?| *>)?|>(?: *>)?(?: *=)?|=(?: *=){0,2}|\\(?: *\/)?(?: *=)?|&(?: *&)?|\| *\||['#~^]/,punctuation:/[\[\]{}().,:;|]/};
\ No newline at end of file
diff --git a/examples/prism-parigp.html b/examples/prism-parigp.html
new file mode 100644
index 0000000..54c5fbb
--- /dev/null
+++ b/examples/prism-parigp.html
@@ -0,0 +1,33 @@
+<h1>PARI/GP</h1>
+<p>To use this language, use the class "language-parigp".</p>
+
+<h2>Comments</h2>
+<pre><code>\\ Single line comment
+/* Multi line
+comment */</code></pre>
+
+<h2>Strings</h2>
+<pre><code>""
+"Foo \"bar\" baz"</code></pre>
+
+<h2>Numbers</h2>
+<pre><code>0.
+42
+3 . 14 15 9
+5.2 E +12
+.89</code></pre>
+
+<h2>Ignored whitespaces</h2>
+<pre><code>p r i n t ("hello")
+if err(1/i, E, print (E))
+a + = b \ / c</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>"foo /* baz */" "foo \\ baz"</code></pre>
\ No newline at end of file
diff --git a/plugins/show-language/prism-show-language.js b/plugins/show-language/prism-show-language.js
index a221263..ddcfe89 100644
--- a/plugins/show-language/prism-show-language.js
+++ b/plugins/show-language/prism-show-language.js
@@ -5,7 +5,7 @@ if (typeof self === 'undefined' || !self.Prism || !self.document) {
 }
 
 // The languages map is built automatically with gulp
-var Languages = /*languages_placeholder[*/{"css":"CSS","clike":"C-like","javascript":"JavaScript","abap":"ABAP","actionscript":"ActionScript","apacheconf":"Apache Configuration","apl":"APL","applescript":"AppleScript","aspnet":"ASP.NET (C#)","autoit":"AutoIt","autohotkey":"AutoHotkey","basic":"BASIC","csharp":"C#","cpp":"C++","coffeescript":"CoffeeScript","css-extras":"CSS Extras","fsharp":"F#","glsl":"GLSL","http":"HTTP","inform7":"Inform 7","latex":"LaTeX","lolcode":"LOLCODE","matlab":"MATLAB","mel":"MEL","nasm":"NASM","nginx":"nginx","nsis":"NSIS","objectivec":"Objective-C","ocaml":"OCaml","php":"PHP","php-extras":"PHP Extras","powershell":"PowerShell","jsx":"React JSX","rest":"reST (reStructuredText)","sas":"SAS","sass":"Sass (Sass)","scss":"Sass (Scss)","sql":"SQL","typescript":"TypeScript","vhdl":"VHDL","vim":"vim","wiki":"Wiki markup","yaml":"YAML"}/*]*/;
+var Languages = /*languages_placeholder[*/{"css":"CSS","clike":"C-like","javascript":"JavaScript","abap":"ABAP","actionscript":"ActionScript","apacheconf":"Apache Configuration","apl":"APL","applescript":"AppleScript","aspnet":"ASP.NET (C#)","autoit":"AutoIt","autohotkey":"AutoHotkey","basic":"BASIC","csharp":"C#","cpp":"C++","coffeescript":"CoffeeScript","css-extras":"CSS Extras","fsharp":"F#","glsl":"GLSL","http":"HTTP","inform7":"Inform 7","latex":"LaTeX","lolcode":"LOLCODE","matlab":"MATLAB","mel":"MEL","nasm":"NASM","nginx":"nginx","nsis":"NSIS","objectivec":"Objective-C","ocaml":"OCaml","parigp":"PARI/GP","php":"PHP","php-extras":"PHP Extras","powershell":"PowerShell","jsx":"React JSX","rest":"reST (reStructuredText)","sas":"SAS","sass":"Sass (Sass)","scss":"Sass (Scss)","sql":"SQL","typescript":"TypeScript","vhdl":"VHDL","vim":"vim","wiki":"Wiki markup","yaml":"YAML"}/*]*/;
 Prism.hooks.add('before-highlight', function(env) {
 	var pre = env.element.parentNode;
 	if (!pre || !/pre/i.test(pre.nodeName)) {
diff --git a/plugins/show-language/prism-show-language.min.js b/plugins/show-language/prism-show-language.min.js
index 2969d91..2bc17a7 100644
--- a/plugins/show-language/prism-show-language.min.js
+++ b/plugins/show-language/prism-show-language.min.js
@@ -1 +1 @@
-!function(){if("undefined"!=typeof self&&self.Prism&&self.document){var e={css:"CSS",clike:"C-like",javascript:"JavaScript",abap:"ABAP",actionscript:"ActionScript",apacheconf:"Apache Configuration",apl:"APL",applescript:"AppleScript",aspnet:"ASP.NET (C#)",autoit:"AutoIt",autohotkey:"AutoHotkey",basic:"BASIC",csharp:"C#",cpp:"C++",coffeescript:"CoffeeScript","css-extras":"CSS Extras",fsharp:"F#",glsl:"GLSL",http:"HTTP",inform7:"Inform 7",latex:"LaTeX",lolcode:"LOLCODE",matlab:"MATLAB",mel:"MEL",nasm:"NASM",nginx:"nginx",nsis:"NSIS",objectivec:"Objective-C",ocaml:"OCaml",php:"PHP","php-extras":"PHP Extras",powershell:"PowerShell",jsx:"React JSX",rest:"reST (reStructuredText)",sas:"SAS",sass:"Sass (Sass)",scss:"Sass (Scss)",sql:"SQL",typescript:"TypeScript",vhdl:"VHDL",vim:"vim",wiki:"Wiki markup",yaml:"YAML"};Prism.hooks.add("before-highlight",function(a){var t=a.element.parentNode;if(t&&/pre/i.test(t.nodeName)){var s=e[a.language]||a.language.substring(0,1).toUpperCase()+a.language.substring(1);t.setAttribute("data-language",s);var i,r,l=t.previousSibling;l&&/\s*\bprism-show-language\b\s*/.test(l.className)&&l.firstChild&&/\s*\bprism-show-language-label\b\s*/.test(l.firstChild.className)?(r=l.firstChild,r.getAttribute("data-language")!==s&&(r.setAttribute("data-language",s),r.innerHTML=s)):(i=document.createElement("div"),r=document.createElement("div"),r.className="prism-show-language-label",r.setAttribute("data-language",s),r.innerHTML=s,i.className="prism-show-language",i.appendChild(r),t.parentNode.insertBefore(i,t))}})}}();
\ No newline at end of file
+!function(){if("undefined"!=typeof self&&self.Prism&&self.document){var e={css:"CSS",clike:"C-like",javascript:"JavaScript",abap:"ABAP",actionscript:"ActionScript",apacheconf:"Apache Configuration",apl:"APL",applescript:"AppleScript",aspnet:"ASP.NET (C#)",autoit:"AutoIt",autohotkey:"AutoHotkey",basic:"BASIC",csharp:"C#",cpp:"C++",coffeescript:"CoffeeScript","css-extras":"CSS Extras",fsharp:"F#",glsl:"GLSL",http:"HTTP",inform7:"Inform 7",latex:"LaTeX",lolcode:"LOLCODE",matlab:"MATLAB",mel:"MEL",nasm:"NASM",nginx:"nginx",nsis:"NSIS",objectivec:"Objective-C",ocaml:"OCaml",parigp:"PARI/GP",php:"PHP","php-extras":"PHP Extras",powershell:"PowerShell",jsx:"React JSX",rest:"reST (reStructuredText)",sas:"SAS",sass:"Sass (Sass)",scss:"Sass (Scss)",sql:"SQL",typescript:"TypeScript",vhdl:"VHDL",vim:"vim",wiki:"Wiki markup",yaml:"YAML"};Prism.hooks.add("before-highlight",function(a){var t=a.element.parentNode;if(t&&/pre/i.test(t.nodeName)){var s=e[a.language]||a.language.substring(0,1).toUpperCase()+a.language.substring(1);t.setAttribute("data-language",s);var i,r,l=t.previousSibling;l&&/\s*\bprism-show-language\b\s*/.test(l.className)&&l.firstChild&&/\s*\bprism-show-language-label\b\s*/.test(l.firstChild.className)?(r=l.firstChild,r.getAttribute("data-language")!==s&&(r.setAttribute("data-language",s),r.innerHTML=s)):(i=document.createElement("div"),r=document.createElement("div"),r.className="prism-show-language-label",r.setAttribute("data-language",s),r.innerHTML=s,i.className="prism-show-language",i.appendChild(r),t.parentNode.insertBefore(i,t))}})}}();
\ No newline at end of file
diff --git a/tests/languages/parigp/comment_feature.test b/tests/languages/parigp/comment_feature.test
new file mode 100644
index 0000000..6fd3e92
--- /dev/null
+++ b/tests/languages/parigp/comment_feature.test
@@ -0,0 +1,18 @@
+/**/
+/* foo
+bar */
+\\
+\\ foobar
+
+----------------------------------------------------
+
+[
+	["comment", "/**/"],
+	["comment", "/* foo\r\nbar */"],
+	["comment", "\\\\"],
+	["comment", "\\\\ foobar"]
+]
+
+----------------------------------------------------
+
+Checks for comments.
\ No newline at end of file
diff --git a/tests/languages/parigp/function_feature.test b/tests/languages/parigp/function_feature.test
new file mode 100644
index 0000000..e2ad9e4
--- /dev/null
+++ b/tests/languages/parigp/function_feature.test
@@ -0,0 +1,13 @@
+foo()
+f o o b a r ( )
+
+----------------------------------------------------
+
+[
+	["function", "foo"], ["punctuation", "("], ["punctuation", ")"],
+	["function", "f o o b a r"], ["punctuation", "("], ["punctuation", ")"]
+]
+
+----------------------------------------------------
+
+Checks for functions. Also checks that whitespaces are ignored.
\ No newline at end of file
diff --git a/tests/languages/parigp/keyword_feature.test b/tests/languages/parigp/keyword_feature.test
new file mode 100644
index 0000000..e210791
--- /dev/null
+++ b/tests/languages/parigp/keyword_feature.test
@@ -0,0 +1,103 @@
+break
+breakpoint
+dbg_down
+dbg_err
+dbg_up
+dbg_x
+for
+forcomposite
+fordiv
+forell
+forpart
+forprime
+forstep
+forsubgroup
+forvec
+if
+iferr
+local
+my
+next
+return
+until
+while
+
+br e ak
+break point
+d b g_down
+dbg_e r r
+dbg _ up
+db g _x
+f o r
+for composite
+for div
+for ell
+for part
+for prime
+for step
+for subgroup
+for vec
+i f
+if err
+l o c a l
+m y
+ne xt
+re tu rn
+u nti l
+whi le
+
+----------------------------------------------------
+
+[
+	["keyword", "break"],
+	["keyword", "breakpoint"],
+	["keyword", "dbg_down"],
+	["keyword", "dbg_err"],
+	["keyword", "dbg_up"],
+	["keyword", "dbg_x"],
+	["keyword", "for"],
+	["keyword", "forcomposite"],
+	["keyword", "fordiv"],
+	["keyword", "forell"],
+	["keyword", "forpart"],
+	["keyword", "forprime"],
+	["keyword", "forstep"],
+	["keyword", "forsubgroup"],
+	["keyword", "forvec"],
+	["keyword", "if"],
+	["keyword", "iferr"],
+	["keyword", "local"],
+	["keyword", "my"],
+	["keyword", "next"],
+	["keyword", "return"],
+	["keyword", "until"],
+	["keyword", "while"],
+
+	["keyword", "br e ak"],
+	["keyword", "break point"],
+	["keyword", "d b g_down"],
+	["keyword", "dbg_e r r"],
+	["keyword", "dbg _ up"],
+	["keyword", "db g _x"],
+	["keyword", "f o r"],
+	["keyword", "for composite"],
+	["keyword", "for div"],
+	["keyword", "for ell"],
+	["keyword", "for part"],
+	["keyword", "for prime"],
+	["keyword", "for step"],
+	["keyword", "for subgroup"],
+	["keyword", "for vec"],
+	["keyword", "i f"],
+	["keyword", "if err"],
+	["keyword", "l o c a l"],
+	["keyword", "m y"],
+	["keyword", "ne xt"],
+	["keyword", "re tu rn"],
+	["keyword", "u nti l"],
+	["keyword", "whi le"]
+]
+
+----------------------------------------------------
+
+Checks for all keywords. Also checks that whitespaces are ignored.
\ No newline at end of file
diff --git a/tests/languages/parigp/number_feature.test b/tests/languages/parigp/number_feature.test
new file mode 100644
index 0000000..63f27a6
--- /dev/null
+++ b/tests/languages/parigp/number_feature.test
@@ -0,0 +1,39 @@
+0
+42
+1 2 3 4 5
+4.
+4 .
+.5
+. 5
+3.14159
+3 . 14 15 9
+3E8
+3 E 8
+2.0e-7
+2 . 0 e - 7
+.28e+12
+. 2 8 e + 1 2
+
+----------------------------------------------------
+
+[
+	["number", "0"],
+	["number", "42"],
+	["number", "1 2 3 4 5"],
+	["number", "4."],
+	["number", "4 ."],
+	["number", ".5"],
+	["number", ". 5"],
+	["number", "3.14159"],
+	["number", "3 . 14 15 9"],
+	["number", "3E8"],
+	["number", "3 E 8"],
+	["number", "2.0e-7"],
+	["number", "2 . 0 e - 7"],
+	["number", ".28e+12"],
+	["number", ". 2 8 e + 1 2"]
+]
+
+----------------------------------------------------
+
+Checks for numbers. Also checks that whitespaces are ignored.
\ No newline at end of file
diff --git a/tests/languages/parigp/operator_feature.test b/tests/languages/parigp/operator_feature.test
new file mode 100644
index 0000000..ecb0f54
--- /dev/null
+++ b/tests/languages/parigp/operator_feature.test
@@ -0,0 +1,155 @@
+..
+. .
+*
+*=
+* =
+/
+/=
+/ =
+!
+!=
+! =
+%
+%=
+% =
+%#
+% #
+%'
+% '
+%#'
+% # '
+%'''''
+% '''''
+%#'''''
+% # '''''
++
+++
++ +
++=
++ =
+-
+--
+- -
+-=
+- =
+->
+- >
+<
+<<
+< <
+<=
+< =
+<<=
+< < =
+<>
+< >
+>
+>>
+> >
+>=
+> =
+>>=
+> > =
+=
+==
+= =
+===
+= = =
+\
+\/
+\ /
+\=
+\ =
+\/=
+\ / =
+&
+&&
+& &
+||
+| |
+'
+#
+~
+^
+
+----------------------------------------------------
+
+[
+	["operator", ".."],
+	["operator", ". ."],
+	["operator", "*"],
+	["operator", "*="],
+	["operator", "* ="],
+	["operator", "/"],
+	["operator", "/="],
+	["operator", "/ ="],
+	["operator", "!"],
+	["operator", "!="],
+	["operator", "! ="],
+	["operator", "%"],
+	["operator", "%="],
+	["operator", "% ="],
+	["operator", "%#"],
+	["operator", "% #"],
+	["operator", "%'"],
+	["operator", "% '"],
+	["operator", "%#'"],
+	["operator", "% # '"],
+	["operator", "%'''''"],
+	["operator", "% '''''"],
+	["operator", "%#'''''"],
+	["operator", "% # '''''"],
+	["operator", "+"],
+	["operator", "++"],
+	["operator", "+ +"],
+	["operator", "+="],
+	["operator", "+ ="],
+	["operator", "-"],
+	["operator", "--"],
+	["operator", "- -"],
+	["operator", "-="],
+	["operator", "- ="],
+	["operator", "->"],
+	["operator", "- >"],
+	["operator", "<"],
+	["operator", "<<"],
+	["operator", "< <"],
+	["operator", "<="],
+	["operator", "< ="],
+	["operator", "<<="],
+	["operator", "< < ="],
+	["operator", "<>"],
+	["operator", "< >"],
+	["operator", ">"],
+	["operator", ">>"],
+	["operator", "> >"],
+	["operator", ">="],
+	["operator", "> ="],
+	["operator", ">>="],
+	["operator", "> > ="],
+	["operator", "="],
+	["operator", "=="],
+	["operator", "= ="],
+	["operator", "==="],
+	["operator", "= = ="],
+	["operator", "\\"],
+	["operator", "\\/"],
+	["operator", "\\ /"],
+	["operator", "\\="],
+	["operator", "\\ ="],
+	["operator", "\\/="],
+	["operator", "\\ / ="],
+	["operator", "&"],
+	["operator", "&&"],
+	["operator", "& &"],
+	["operator", "||"],
+	["operator", "| |"],
+	["operator", "'"],
+	["operator", "#"],
+	["operator", "~"],
+	["operator", "^"]
+]
+
+----------------------------------------------------
+
+Checks for operators. Also checks that whitespaces are ignored.
\ No newline at end of file
diff --git a/tests/languages/parigp/string_feature.test b/tests/languages/parigp/string_feature.test
new file mode 100644
index 0000000..42c1913
--- /dev/null
+++ b/tests/languages/parigp/string_feature.test
@@ -0,0 +1,13 @@
+""
+"fo\"obar"
+
+----------------------------------------------------
+
+[
+	["string", "\"\""],
+	["string", "\"fo\\\"obar\""]
+]
+
+----------------------------------------------------
+
+Checks for strings.
\ No newline at end of file