Skip to content

Commit

Permalink
Added more examples & small TOML improvement (#1917)
Browse files Browse the repository at this point in the history
This adds some of the missing examples and makes a small improvement to TOML.
  • Loading branch information
RunDevelopment authored Jun 12, 2019
1 parent 4b6b6e8 commit 3e18124
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 2 deletions.
2 changes: 1 addition & 1 deletion components/prism-toml.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion components/prism-toml.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions examples/prism-javadoc.html
Original file line number Diff line number Diff line change
@@ -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>
21 changes: 21 additions & 0 deletions examples/prism-jsdoc.html
Original file line number Diff line number Diff line change
@@ -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>
15 changes: 15 additions & 0 deletions examples/prism-phpdoc.html
Original file line number Diff line number Diff line change
@@ -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>
16 changes: 16 additions & 0 deletions examples/prism-t4-cs.html
Original file line number Diff line number Diff line change
@@ -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>
16 changes: 16 additions & 0 deletions examples/prism-t4-vb.html
Original file line number Diff line number Diff line change
@@ -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>
28 changes: 28 additions & 0 deletions examples/prism-toml.html
Original file line number Diff line number Diff line change
@@ -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>
11 changes: 11 additions & 0 deletions tests/languages/toml/table_feature.test
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
[table]
[[array]]

# not a table
foo = [ "bar" ]

----------------------------------------------------

[
Expand All @@ -12,6 +15,14 @@
["punctuation", "["],
["table", "array"],
["punctuation", "]"],
["punctuation", "]"],

["comment", "# not a table"],

["key", "foo"],
["punctuation", "="],
["punctuation", "["],
["string", "\"bar\""],
["punctuation", "]"]
]

Expand Down

0 comments on commit 3e18124

Please sign in to comment.