Commit 3e1812416dd4906cb03820af27e42fa2c4bcef1d

Michael Schmidt 2019-06-12T15:28:44

Added more examples & small TOML improvement (#1917) This adds some of the missing examples and makes a small improvement to TOML.

diff --git a/components/prism-toml.js b/components/prism-toml.js
index 200fbdd..e911d89 100644
--- a/components/prism-toml.js
+++ b/components/prism-toml.js
@@ -9,7 +9,7 @@
 			greedy: true
 		},
 		'table': {
-			pattern: RegExp("(\\[\\s*)" + key + "(?:\\s*\\.\\s*" + key + ")*(?=\\s*\\])"),
+			pattern: RegExp("(^\\s*\\[\\s*(?:\\[\\s*)?)" + key + "(?:\\s*\\.\\s*" + key + ")*(?=\\s*\\])", "m"),
 			lookbehind: true,
 			greedy: true,
 			alias: 'class-name'
diff --git a/components/prism-toml.min.js b/components/prism-toml.min.js
index 2ce58e9..f0ffbd4 100644
--- a/components/prism-toml.min.js
+++ b/components/prism-toml.min.js
@@ -1 +1 @@
-!function(e){var d="(?:[\\w-]+|'[^'\n\r]*'|\"(?:\\.|[^\\\\\"\r\n])*\")";Prism.languages.toml={comment:{pattern:/#.*/,greedy:!0},table:{pattern:RegExp("(\\[\\s*)"+d+"(?:\\s*\\.\\s*"+d+")*(?=\\s*\\])"),lookbehind:!0,greedy:!0,alias:"class-name"},key:{pattern:RegExp("(^\\s*|[{,]\\s*)"+d+"(?:\\s*\\.\\s*"+d+")*(?=\\s*=)","m"),lookbehind:!0,greedy:!0,alias:"property"},string:{pattern:/"""(?:\\[\s\S]|[^\\])*?"""|'''[\s\S]*?'''|'[^'\n\r]*'|"(?:\\.|[^\\"\r\n])*"/,greedy:!0},date:[{pattern:/\d{4}-\d{2}-\d{2}(?:[T\s]\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})?)?/i,alias:"number"},{pattern:/\d{2}:\d{2}:\d{2}(?:\.\d+)?/i,alias:"number"}],number:/(?:\b0(?:x[\da-zA-Z]+(?:_[\da-zA-Z]+)*|o[0-7]+(?:_[0-7]+)*|b[10]+(?:_[10]+)*))\b|[-+]?\d+(?:_\d+)*(?:\.\d+(?:_\d+)*)?(?:[eE][+-]?\d+(?:_\d+)*)?\b|[-+]?(?:inf|nan)\b/,boolean:/\b(?:true|false)\b/,punctuation:/[.,=[\]{}]/}}();
\ No newline at end of file
+!function(e){var d="(?:[\\w-]+|'[^'\n\r]*'|\"(?:\\.|[^\\\\\"\r\n])*\")";Prism.languages.toml={comment:{pattern:/#.*/,greedy:!0},table:{pattern:RegExp("(^\\s*\\[\\s*(?:\\[\\s*)?)"+d+"(?:\\s*\\.\\s*"+d+")*(?=\\s*\\])","m"),lookbehind:!0,greedy:!0,alias:"class-name"},key:{pattern:RegExp("(^\\s*|[{,]\\s*)"+d+"(?:\\s*\\.\\s*"+d+")*(?=\\s*=)","m"),lookbehind:!0,greedy:!0,alias:"property"},string:{pattern:/"""(?:\\[\s\S]|[^\\])*?"""|'''[\s\S]*?'''|'[^'\n\r]*'|"(?:\\.|[^\\"\r\n])*"/,greedy:!0},date:[{pattern:/\d{4}-\d{2}-\d{2}(?:[T\s]\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})?)?/i,alias:"number"},{pattern:/\d{2}:\d{2}:\d{2}(?:\.\d+)?/i,alias:"number"}],number:/(?:\b0(?:x[\da-zA-Z]+(?:_[\da-zA-Z]+)*|o[0-7]+(?:_[0-7]+)*|b[10]+(?:_[10]+)*))\b|[-+]?\d+(?:_\d+)*(?:\.\d+(?:_\d+)*)?(?:[eE][+-]?\d+(?:_\d+)*)?\b|[-+]?(?:inf|nan)\b/,boolean:/\b(?:true|false)\b/,punctuation:/[.,=[\]{}]/}}();
\ No newline at end of file
diff --git a/examples/prism-javadoc.html b/examples/prism-javadoc.html
new file mode 100644
index 0000000..4e80979
--- /dev/null
+++ b/examples/prism-javadoc.html
@@ -0,0 +1,29 @@
+<h2>Full example</h2>
+<pre><code class="language-java">/**
+ * Returns the value to which the specified key is mapped,
+ * or {@code null} if this map contains no mapping for the key.
+ *
+ * &lt;p&gt;More formally, if this map contains a mapping from a key
+ * {@code k} to a value {@code v} such that {@code (key==null ? k==null :
+ * key.equals(k))}, then this method returns {@code v}; otherwise
+ * it returns {@code null}.  (There can be at most one such mapping.)
+ *
+ * &lt;p&gt;If this map permits null values, then a return value of
+ * {@code null} does not &lt;i&gt;necessarily&lt;/i&gt; indicate that the map
+ * contains no mapping for the key; it's also possible that the map
+ * explicitly maps the key to {@code null}.  The {@link #containsKey
+ * containsKey} operation may be used to distinguish these two cases.
+ *
+ * @param key the key whose associated value is to be returned
+ * @return the value to which the specified key is mapped, or
+ *         {@code null} if this map contains no mapping for the key
+ * @throws ClassCastException if the key is of an inappropriate type for
+ *         this map
+ * (&lt;a href="{@docRoot}/java/util/Collection.html#optional-restrictions"&gt;optional&lt;/a&gt;)
+ * @throws NullPointerException if the specified key is null and this map
+ *         does not permit null keys
+ * (&lt;a href="{@docRoot}/java/util/Collection.html#optional-restrictions"&gt;optional&lt;/a&gt;)
+ */
+V get(Object key);
+
+// Source: Java 1.8, Map#get(Object)</code></pre>
diff --git a/examples/prism-jsdoc.html b/examples/prism-jsdoc.html
new file mode 100644
index 0000000..85a7442
--- /dev/null
+++ b/examples/prism-jsdoc.html
@@ -0,0 +1,21 @@
+<h2>Full example</h2>
+<pre><code class="language-javascript">/**
+ * @typedef {object} Foo
+ * @property {string} bar
+ * @memberof Baz
+ */
+
+/**
+ * Trims the given string.
+ *
+ * @param {string} [str=""] the string.
+ * @returns {string} the trimmed string.
+ * @throws {TypeError} if the argument is not a string.
+ * @example trim(" hello ")
+ */
+function trim(str = "") {
+	if (typeof str != "string") {
+		throw new TypeError("str has to be a string");
+	}
+	return str.trim();
+}</code></pre>
diff --git a/examples/prism-phpdoc.html b/examples/prism-phpdoc.html
new file mode 100644
index 0000000..5b2f907
--- /dev/null
+++ b/examples/prism-phpdoc.html
@@ -0,0 +1,15 @@
+<h2>Full example</h2>
+<pre><code class="language-php">&lt;?php
+
+/** @var \DateTime[] An array of DateTime objects. */
+/** @var string[] An array of string objects. */
+/** @var callable[] An array of with callable functions or methods. */
+
+/** @var \ArrayObject|\DateTime[] */
+$dates = array()
+
+/**
+ * @param bool|\DateTime $foo the first argument
+ * @return string|null
+ */
+function bar($foo) { ... }</code></pre>
diff --git a/examples/prism-t4-cs.html b/examples/prism-t4-cs.html
new file mode 100644
index 0000000..e3651c7
--- /dev/null
+++ b/examples/prism-t4-cs.html
@@ -0,0 +1,16 @@
+<h2>Full example</h2>
+<pre><code>&lt;#@ template hostspecific="false" language="C#" #&gt;
+&lt;#@ assembly name="System.Core.dll" #&gt;
+&lt;#@ output extension=".txt" #&gt;
+&lt;#
+    using System.Collections.Generic;
+
+    var numbers = new List&lt;int&gt; { 0, 1, 2, 3, 4, 5, 6, /* 7, */ 8, 9, 10  };
+
+    foreach (var i in numbers)
+    {
+#&gt;
+The square of &lt;#= i #&gt; is &lt;#= i * i #&gt;
+&lt;#
+    }
+#&gt;</code></pre>
diff --git a/examples/prism-t4-vb.html b/examples/prism-t4-vb.html
new file mode 100644
index 0000000..04c9996
--- /dev/null
+++ b/examples/prism-t4-vb.html
@@ -0,0 +1,16 @@
+<h2>Full example</h2>
+<pre><code>&lt;#@ template hostspecific="false" language="VB" #&gt;
+&lt;#@ assembly name="System.Core.dll" #&gt;
+&lt;#@ output extension=".txt" #&gt;
+&lt;#
+    Imports System.Collections.Generic
+
+    Dim numbers() As Integer = { 0, 1, 2, 3, 4, 5, 6, 8, 9, 10  }
+    ' not including 7
+
+    For Each i In numbers
+#&gt;
+The square of &lt;#= i #&gt; is &lt;#= i * i #&gt;
+&lt;#
+    Next
+#&gt;</code></pre>
diff --git a/examples/prism-toml.html b/examples/prism-toml.html
new file mode 100644
index 0000000..7f68c8e
--- /dev/null
+++ b/examples/prism-toml.html
@@ -0,0 +1,28 @@
+<h2>Full example</h2>
+<pre><code># This is a comment
+
+key = "value"
+paths.home = 'c:\foo\'
+
+[database.prod]
+server = "192.168.1.1"
+ports = [ 8001, 8001, 8002 ]
+connection_max = 5000
+enabled = true
+
+
+[[users]]
+name = "John"
+bday = 1995-09-22
+bio = ""
+interests = [ "biking", "fishing" ]
+
+[[users]]
+name = "Jane"
+bday = 1989-05-09
+bio = """\
+Hi!
+
+I love programming!\
+"""
+interests = [ "programming" ]</code></pre>
diff --git a/tests/languages/toml/table_feature.test b/tests/languages/toml/table_feature.test
index c0be8b7..4fbce4e 100644
--- a/tests/languages/toml/table_feature.test
+++ b/tests/languages/toml/table_feature.test
@@ -1,6 +1,9 @@
 [table]
 [[array]]
 
+# not a table
+foo = [ "bar" ]
+
 ----------------------------------------------------
 
 [
@@ -12,6 +15,14 @@
 	["punctuation", "["],
 	["table", "array"],
 	["punctuation", "]"],
+	["punctuation", "]"],
+
+	["comment", "# not a table"],
+
+	["key", "foo"],
+	["punctuation", "="],
+	["punctuation", "["],
+	["string", "\"bar\""],
 	["punctuation", "]"]
 ]