From 3e1812416dd4906cb03820af27e42fa2c4bcef1d Mon Sep 17 00:00:00 2001 From: Michael Schmidt Date: Wed, 12 Jun 2019 15:28:44 +0200 Subject: [PATCH] Added more examples & small TOML improvement (#1917) This adds some of the missing examples and makes a small improvement to TOML. --- components/prism-toml.js | 2 +- components/prism-toml.min.js | 2 +- examples/prism-javadoc.html | 29 +++++++++++++++++++++++++ examples/prism-jsdoc.html | 21 ++++++++++++++++++ examples/prism-phpdoc.html | 15 +++++++++++++ examples/prism-t4-cs.html | 16 ++++++++++++++ examples/prism-t4-vb.html | 16 ++++++++++++++ examples/prism-toml.html | 28 ++++++++++++++++++++++++ tests/languages/toml/table_feature.test | 11 ++++++++++ 9 files changed, 138 insertions(+), 2 deletions(-) create mode 100644 examples/prism-javadoc.html create mode 100644 examples/prism-jsdoc.html create mode 100644 examples/prism-phpdoc.html create mode 100644 examples/prism-t4-cs.html create mode 100644 examples/prism-t4-vb.html create mode 100644 examples/prism-toml.html diff --git a/components/prism-toml.js b/components/prism-toml.js index 200fbdd0c3..e911d89ee3 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 2ce58e9f67..f0ffbd4c82 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 0000000000..4e809797bd --- /dev/null +++ b/examples/prism-javadoc.html @@ -0,0 +1,29 @@ +

Full example

+
/**
+ * Returns the value to which the specified key is mapped,
+ * or {@code null} if this map contains no mapping for the key.
+ *
+ * <p>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.)
+ *
+ * <p>If this map permits null values, then a return value of
+ * {@code null} does not <i>necessarily</i> 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
+ * (<a href="{@docRoot}/java/util/Collection.html#optional-restrictions">optional</a>)
+ * @throws NullPointerException if the specified key is null and this map
+ *         does not permit null keys
+ * (<a href="{@docRoot}/java/util/Collection.html#optional-restrictions">optional</a>)
+ */
+V get(Object key);
+
+// Source: Java 1.8, Map#get(Object)
diff --git a/examples/prism-jsdoc.html b/examples/prism-jsdoc.html new file mode 100644 index 0000000000..85a7442972 --- /dev/null +++ b/examples/prism-jsdoc.html @@ -0,0 +1,21 @@ +

Full example

+
/**
+ * @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();
+}
diff --git a/examples/prism-phpdoc.html b/examples/prism-phpdoc.html new file mode 100644 index 0000000000..5b2f9075fa --- /dev/null +++ b/examples/prism-phpdoc.html @@ -0,0 +1,15 @@ +

Full example

+
<?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) { ... }
diff --git a/examples/prism-t4-cs.html b/examples/prism-t4-cs.html new file mode 100644 index 0000000000..e3651c7708 --- /dev/null +++ b/examples/prism-t4-cs.html @@ -0,0 +1,16 @@ +

Full example

+
<#@ template hostspecific="false" language="C#" #>
+<#@ assembly name="System.Core.dll" #>
+<#@ output extension=".txt" #>
+<#
+    using System.Collections.Generic;
+
+    var numbers = new List<int> { 0, 1, 2, 3, 4, 5, 6, /* 7, */ 8, 9, 10  };
+
+    foreach (var i in numbers)
+    {
+#>
+The square of <#= i #> is <#= i * i #>
+<#
+    }
+#>
diff --git a/examples/prism-t4-vb.html b/examples/prism-t4-vb.html new file mode 100644 index 0000000000..04c999693d --- /dev/null +++ b/examples/prism-t4-vb.html @@ -0,0 +1,16 @@ +

Full example

+
<#@ template hostspecific="false" language="VB" #>
+<#@ assembly name="System.Core.dll" #>
+<#@ output extension=".txt" #>
+<#
+    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
+#>
+The square of <#= i #> is <#= i * i #>
+<#
+    Next
+#>
diff --git a/examples/prism-toml.html b/examples/prism-toml.html new file mode 100644 index 0000000000..7f68c8ef9b --- /dev/null +++ b/examples/prism-toml.html @@ -0,0 +1,28 @@ +

Full example

+
# 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" ]
diff --git a/tests/languages/toml/table_feature.test b/tests/languages/toml/table_feature.test index c0be8b7e0b..4fbce4e88a 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", "]"] ]