From 0b539136c3abb715c6b5efedba1955d57267540c Mon Sep 17 00:00:00 2001 From: Michael Schmidt Date: Mon, 6 Jan 2020 14:39:45 +0100 Subject: [PATCH] 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. --- examples/prism-antlr4.html | 75 ++++++++++++++++++++++++++++++++++ examples/prism-cil.html | 49 ++++++++++++++++++++++ examples/prism-css-extras.html | 28 +++++++++++++ examples/prism-js-extras.html | 20 +++++++++ examples/prism-latte.html | 16 ++++++++ examples/prism-lilypond.html | 60 +++++++++++++++++++++++++++ examples/prism-neon.html | 16 ++++++++ examples/prism-php-extras.html | 14 +++++++ examples/prism-tap.html | 7 ++++ gulpfile.js/premerge.js | 48 +++++++++++++++++++++- 10 files changed, 332 insertions(+), 1 deletion(-) create mode 100644 examples/prism-antlr4.html create mode 100644 examples/prism-cil.html create mode 100644 examples/prism-css-extras.html create mode 100644 examples/prism-js-extras.html create mode 100644 examples/prism-latte.html create mode 100644 examples/prism-lilypond.html create mode 100644 examples/prism-neon.html create mode 100644 examples/prism-php-extras.html create mode 100644 examples/prism-tap.html diff --git a/examples/prism-antlr4.html b/examples/prism-antlr4.html new file mode 100644 index 0000000000..2a4753e85d --- /dev/null +++ b/examples/prism-antlr4.html @@ -0,0 +1,75 @@ +

Full example

+
// 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
+   ;
diff --git a/examples/prism-cil.html b/examples/prism-cil.html new file mode 100644 index 0000000000..0d228d363a --- /dev/null +++ b/examples/prism-cil.html @@ -0,0 +1,49 @@ +

Full example

+
// 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
diff --git a/examples/prism-css-extras.html b/examples/prism-css-extras.html new file mode 100644 index 0000000000..c780d93536 --- /dev/null +++ b/examples/prism-css-extras.html @@ -0,0 +1,28 @@ +

Selectors

+
a#id.class:hover {}
+li:nth-child(2n+1) {}
+span::before {}
+a[title], a[href$=".pdf"] {}, a[href$=".jpg" i] {}
+
+ +

Some of added tokens aren't supported by Prism's default themes.

+ +

Variables

+
:root {
+	--foo: 12px;
+}
+a {
+	font-size: var(--foo);
+	padding: calc(var(--foo) + .5em);
+}
+
+ +

Colors

+
span {
+	background: rgba(0, 128, 255, .4);
+	color: red;
+	color: green;
+	color: blue;
+	border: 1px solid #FFF;
+}
+
diff --git a/examples/prism-js-extras.html b/examples/prism-js-extras.html new file mode 100644 index 0000000000..fa3ea9b5a0 --- /dev/null +++ b/examples/prism-js-extras.html @@ -0,0 +1,20 @@ +

Support built-in JS classes

+
Math.sin();
+Number.isNaN();
+Object.keys();
+
+// and many more
+ +

DOM variables

+
document.querySelectorAll();
+window.parent;
+location.href;
+performance.now();
+
+// and many more
+ +

console

+
console.log();
+ +

Invisible changes

+

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.

diff --git a/examples/prism-latte.html b/examples/prism-latte.html new file mode 100644 index 0000000000..684a693274 --- /dev/null +++ b/examples/prism-latte.html @@ -0,0 +1,16 @@ +

Full example

+
<!DOCTYPE html>
+<html>
+	<head>
+		<title>{$title|upper}</title>
+	</head>
+	<body>
+		{if count($menu) > 1}
+			<ul class="menu">
+				{foreach $menu as $item}
+				<li><a href="{$item->href}">{$item->caption}</a></li>
+				{/foreach}
+			</ul>
+		{/if}
+	</body>
+</html>
diff --git a/examples/prism-lilypond.html b/examples/prism-lilypond.html new file mode 100644 index 0000000000..d61d94ad2d --- /dev/null +++ b/examples/prism-lilypond.html @@ -0,0 +1,60 @@ +

Full example

+
\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 <6> <6 4> <7> | s1
+}
+
+\markup { "Exercise 3: Write 8th notes against the given bass line." }
+
+\score {
+  \new PianoStaff <<
+    \new Staff {
+      \context Voice = "added voice" \with {
+        \consists "Balloon_engraver"
+      }
+      \upper
+    }
+
+    \new Staff = lower {
+      <<
+%      \context Voice = "cantus firmus" \with {
+%        \consists "Balloon_engraver"
+%      }
+        \context Staff = lower \cf
+        \new FiguredBass \bassFigures
+      >>
+    }
+  >>
+  \layout {}
+  %{\midi {
+    \tempo 4 = 120
+  }%}
+}
diff --git a/examples/prism-neon.html b/examples/prism-neon.html new file mode 100644 index 0000000000..831697abfe --- /dev/null +++ b/examples/prism-neon.html @@ -0,0 +1,16 @@ +

Full example

+
# 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
diff --git a/examples/prism-php-extras.html b/examples/prism-php-extras.html new file mode 100644 index 0000000000..cfe1214e32 --- /dev/null +++ b/examples/prism-php-extras.html @@ -0,0 +1,14 @@ +

General

+

This adds new tokens to the PHP language to allow more customization in your theme.

+

Prism's default themes do not support the new tokens, so there will be no visible changes in the following examples.

+ +

$this

+
$this->foo = 2;
+ +

Global variables

+
$_SERVER;
+$_GET;
+$_POST;
+$argc; $argv;
+
+// and many more
diff --git a/examples/prism-tap.html b/examples/prism-tap.html new file mode 100644 index 0000000000..4ed15fa754 --- /dev/null +++ b/examples/prism-tap.html @@ -0,0 +1,7 @@ +

Full example

+
1..48
+ok 1 Description # Directive
+# Diagnostic
+....
+ok 47 Description
+ok 48 Description
diff --git a/gulpfile.js/premerge.js b/gulpfile.js/premerge.js index a78c21b691..d674b2c5b2 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) };