Commit 0b539136c3abb715c6b5efedba1955d57267540c

Michael Schmidt 2020-01-06T14:39:45

Added checks for examples (#2128) This adds a check to `premerge` to detect missing and lone examples. All currently missing examples were added with some exceptions.

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
diff --git a/examples/prism-antlr4.html b/examples/prism-antlr4.html
new file mode 100644
index 0000000..2a4753e
--- /dev/null
+++ b/examples/prism-antlr4.html
@@ -0,0 +1,75 @@
+<h2>Full example</h2>
+<pre><code>// Source: https://github.com/antlr/grammars-v4/blob/master/json/JSON.g4
+
+/** Taken from "The Definitive ANTLR 4 Reference" by Terence Parr */
+
+// Derived from http://json.org
+grammar JSON;
+
+json
+   : value
+   ;
+
+obj
+   : '{' pair (',' pair)* '}'
+   | '{' '}'
+   ;
+
+pair
+   : STRING ':' value
+   ;
+
+array
+   : '[' value (',' value)* ']'
+   | '[' ']'
+   ;
+
+value
+   : STRING
+   | NUMBER
+   | obj
+   | array
+   | 'true'
+   | 'false'
+   | 'null'
+   ;
+
+
+STRING
+   : '"' (ESC | SAFECODEPOINT)* '"'
+   ;
+
+
+fragment ESC
+   : '\\' (["\\/bfnrt] | UNICODE)
+   ;
+fragment UNICODE
+   : 'u' HEX HEX HEX HEX
+   ;
+fragment HEX
+   : [0-9a-fA-F]
+   ;
+fragment SAFECODEPOINT
+   : ~ ["\\\u0000-\u001F]
+   ;
+
+
+NUMBER
+   : '-'? INT ('.' [0-9] +)? EXP?
+   ;
+
+fragment INT
+   : '0' | [1-9] [0-9]*
+   ;
+
+// no leading zeros
+
+fragment EXP
+   : [Ee] [+\-]? INT
+   ;
+
+// \- since - means "range" inside [...]
+
+WS
+   : [ \t\n\r] + -> skip
+   ;</code></pre>
diff --git a/examples/prism-cil.html b/examples/prism-cil.html
new file mode 100644
index 0000000..0d228d3
--- /dev/null
+++ b/examples/prism-cil.html
@@ -0,0 +1,49 @@
+<h2>Full example</h2>
+<pre><code>// Metadata version: v4.0.30319
+.assembly extern mscorlib
+{
+  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                         // .z\V.4..
+  .ver 4:0:0:0
+}
+.assembly i1ohgbkl
+{
+  .hash algorithm 0x00008004
+  .ver 0:0:0:0
+}
+.module i1ohgbkl.dll
+// MVID: {AC981AA1-16FE-413D-BBED-D83AE719F45C}
+.imagebase 0x10000000
+.file alignment 0x00000200
+.stackreserve 0x00100000
+.subsystem 0x0003       // WINDOWS_CUI
+.corflags 0x00000001    //  ILONLY
+// Image base: 0x017C0000
+​
+​
+// =============== CLASS MEMBERS DECLARATION ===================
+​
+.class public auto ansi beforefieldinit Program
+       extends [mscorlib]System.Object
+{
+  .method public hidebysig static void  Main() cil managed
+  {
+    //
+    .maxstack  8
+    IL_0000:  nop
+    IL_0001:  ldstr      "Hello World"
+    IL_0006:  call       void [mscorlib]System.Console::WriteLine(string)
+    IL_000b:  nop
+    IL_000c:  ret
+  } // end of method Program::Main
+​
+  .method public hidebysig specialname rtspecialname
+          instance void  .ctor() cil managed
+  {
+    //
+    .maxstack  8
+    IL_0000:  ldarg.0
+    IL_0001:  call       instance void [mscorlib]System.Object::.ctor()
+    IL_0006:  ret
+  } // end of method Program::.ctor
+​
+} // end of class Program</code></pre>
diff --git a/examples/prism-css-extras.html b/examples/prism-css-extras.html
new file mode 100644
index 0000000..c780d93
--- /dev/null
+++ b/examples/prism-css-extras.html
@@ -0,0 +1,28 @@
+<h2>Selectors</h2>
+<pre><code class="language-css">a#id.class:hover {}
+li:nth-child(2n+1) {}
+span::before {}
+a[title], a[href$=".pdf"] {}, a[href$=".jpg" i] {}
+</code></pre>
+
+<p>Some of added tokens aren't supported by Prism's default themes.</p>
+
+<h2>Variables</h2>
+<pre><code class="language-css">:root {
+	--foo: 12px;
+}
+a {
+	font-size: var(--foo);
+	padding: calc(var(--foo) + .5em);
+}
+</code></pre>
+
+<h2>Colors</h2>
+<pre><code class="language-css">span {
+	background: rgba(0, 128, 255, .4);
+	color: red;
+	color: green;
+	color: blue;
+	border: 1px solid #FFF;
+}
+</code></pre>
diff --git a/examples/prism-js-extras.html b/examples/prism-js-extras.html
new file mode 100644
index 0000000..fa3ea9b
--- /dev/null
+++ b/examples/prism-js-extras.html
@@ -0,0 +1,20 @@
+<h2>Support built-in JS classes</h2>
+<pre><code class="language-javascript">Math.sin();
+Number.isNaN();
+Object.keys();
+
+// and many more</code></pre>
+
+<h2>DOM variables</h2>
+<pre><code class="language-javascript">document.querySelectorAll();
+window.parent;
+location.href;
+performance.now();
+
+// and many more</code></pre>
+
+<h2>console</h2>
+<pre><code class="language-javascript">console.log();</code></pre>
+
+<h2>Invisible changes</h2>
+<p>The goal of JS Extras is to make the tokenization of JavaScript more granular to allow for more customization in your themes. To to do this, JS Extras adds many new tokens and given existing tokens new aliases. These new tokens and aliases can be used by your theme but aren't supported by Prism's default themes and therefore invisible.</p>
diff --git a/examples/prism-latte.html b/examples/prism-latte.html
new file mode 100644
index 0000000..684a693
--- /dev/null
+++ b/examples/prism-latte.html
@@ -0,0 +1,16 @@
+<h2>Full example</h2>
+<pre><code>&lt;!DOCTYPE html>
+&lt;html>
+	&lt;head>
+		&lt;title>{$title|upper}&lt;/title>
+	&lt;/head>
+	&lt;body>
+		{if count($menu) > 1}
+			&lt;ul class="menu">
+				{foreach $menu as $item}
+				&lt;li>&lt;a href="{$item->href}">{$item->caption}&lt;/a>&lt;/li>
+				{/foreach}
+			&lt;/ul>
+		{/if}
+	&lt;/body>
+&lt;/html></code></pre>
diff --git a/examples/prism-lilypond.html b/examples/prism-lilypond.html
new file mode 100644
index 0000000..d61d94a
--- /dev/null
+++ b/examples/prism-lilypond.html
@@ -0,0 +1,60 @@
+<h2>Full example</h2>
+<pre><code>\version "2.16.0"
+\include "example-header.ily"
+
+#(ly:set-option 'point-and-click #f)
+#(set-global-staff-size 24)
+
+global = {
+    \time 4/4
+    \numericTimeSignature
+    \key c \major
+}
+
+cf = \relative c {
+  \clef bass
+  \global
+  c4 c' b a |
+  g a f d |
+  e f g g, |
+  c1
+}
+
+upper = \relative c'' {
+  \global
+  r4 s4 s2 |
+  s1*2 |
+  s2 s4 s
+  \bar "||"
+}
+
+bassFigures = \figuremode {
+  s1*2 | s4 &lt;6> &lt;6 4> &lt;7> | s1
+}
+
+\markup { "Exercise 3: Write 8th notes against the given bass line." }
+
+\score {
+  \new PianoStaff &lt;&lt;
+    \new Staff {
+      \context Voice = "added voice" \with {
+        \consists "Balloon_engraver"
+      }
+      \upper
+    }
+
+    \new Staff = lower {
+      &lt;&lt;
+%      \context Voice = "cantus firmus" \with {
+%        \consists "Balloon_engraver"
+%      }
+        \context Staff = lower \cf
+        \new FiguredBass \bassFigures
+      >>
+    }
+  >>
+  \layout {}
+  %{\midi {
+    \tempo 4 = 120
+  }%}
+}</code></pre>
diff --git a/examples/prism-neon.html b/examples/prism-neon.html
new file mode 100644
index 0000000..831697a
--- /dev/null
+++ b/examples/prism-neon.html
@@ -0,0 +1,16 @@
+<h2>Full example</h2>
+<pre><code># my web application config
+
+php:
+	date.timezone: Europe/Prague
+	zlib.output_compression: true  # use gzip
+
+database:
+	driver: mysql
+	username: root
+	password: beruska92
+
+users:
+	- Dave
+	- Kryten
+	- Rimmer</code></pre>
diff --git a/examples/prism-php-extras.html b/examples/prism-php-extras.html
new file mode 100644
index 0000000..cfe1214
--- /dev/null
+++ b/examples/prism-php-extras.html
@@ -0,0 +1,14 @@
+<h2>General</h2>
+<p>This adds new tokens to the PHP language to allow more customization in your theme.</p>
+<p>Prism's default themes do not support the new tokens, so there will be no visible changes in the following examples.</p>
+
+<h2>$this</h2>
+<pre><code class="language-php">$this->foo = 2;</code></pre>
+
+<h2>Global variables</h2>
+<pre><code class="language-php">$_SERVER;
+$_GET;
+$_POST;
+$argc; $argv;
+
+// and many more</code></pre>
diff --git a/examples/prism-tap.html b/examples/prism-tap.html
new file mode 100644
index 0000000..4ed15fa
--- /dev/null
+++ b/examples/prism-tap.html
@@ -0,0 +1,7 @@
+<h2>Full example</h2>
+<pre></code>1..48
+ok 1 Description # Directive
+# Diagnostic
+....
+ok 47 Description
+ok 48 Description</code></pre>
diff --git a/gulpfile.js/premerge.js b/gulpfile.js/premerge.js
index a78c21b..d674b2c 100644
--- a/gulpfile.js/premerge.js
+++ b/gulpfile.js/premerge.js
@@ -1,8 +1,15 @@
 "use strict";
 
+const { parallel } = require('gulp');
+const fs = require('fs');
 const git = require('simple-git/promise')(__dirname);
+// use the JSON file because this file is less susceptible to merge conflicts
+const { languages } = require('../components.json');
 
 
+/**
+ * Checks that no files have been modified by the build process.
+ */
 function gitChanges() {
 	return git.status().then(res => {
 		if (res.files.length > 0) {
@@ -12,7 +19,46 @@ function gitChanges() {
 	});
 }
 
+/**
+ * Checks that all languages have and example.
+ */
+async function hasExample() {
+	const exampleFiles = new Set(fs.readdirSync(__dirname + '/../examples'));
+	const ignore = new Set([
+		// these are libraries and not languages
+		'markup-templating',
+		't4-templating',
+		// this does alter some languages but it's mainly a library
+		'javadoclike',
+		// Regex doesn't have any classes supported by our themes and mainly extends other languages
+		'regex'
+	]);
+
+	/** @type {string[]} */
+	const missing = [];
+	for (const lang in languages) {
+		if (lang === 'meta') {
+			continue;
+		}
+
+		if (!exampleFiles.delete(`prism-${lang}.html`)) {
+			if (!ignore.has(lang)) {
+				missing.push(lang);
+			}
+		}
+	}
+
+	const errors = missing.map(id => `Missing example for ${id}.`);
+	for (const file of exampleFiles) {
+		errors.push(`The examples file "${file}" has no language associated with it.`);
+	}
+
+	if (errors.length) {
+		throw new Error(errors.join('\n'));
+	}
+}
+
 
 module.exports = {
-	premerge: gitChanges
+	premerge: parallel(gitChanges, hasExample)
 };