Skip to content

Commit 649e51e

Browse files
Added support for Dhall (#2473)
1 parent 453079b commit 649e51e

16 files changed

+398
-1
lines changed

components.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components.json

+4
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,10 @@
275275
"title": "DAX",
276276
"owner": "peterbud"
277277
},
278+
"dhall": {
279+
"title": "Dhall",
280+
"owner": "RunDevelopment"
281+
},
278282
"diff": {
279283
"title": "Diff",
280284
"owner": "uranusjr"

components/prism-dhall.js

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// ABNF grammar:
2+
// https://github.com/dhall-lang/dhall-lang/blob/master/standard/dhall.abnf
3+
4+
Prism.languages.dhall = {
5+
// Multi-line comments can be nested. E.g. {- foo {- bar -} -}
6+
// The multi-line pattern is essentially this:
7+
// \{-(?:[^-{]|-(?!\})|\{(?!-)|<SELF>)*-\}
8+
'comment': /--.*|\{-(?:[^-{]|-(?!\})|\{(?!-)|\{-(?:[^-{]|-(?!\})|\{(?!-))*-\})*-\}/,
9+
'string': {
10+
pattern: /"(?:[^"\\]|\\.)*"|''(?:[^']|'(?!')|'''|''\$\{)*''(?!'|\$)/,
11+
greedy: true,
12+
inside: {
13+
'interpolation': {
14+
pattern: /\$\{[^{}]*\}/,
15+
inside: {
16+
'expression': {
17+
pattern: /(^\$\{)[\s\S]+(?=\}$)/,
18+
lookbehind: true,
19+
alias: 'language-dhall',
20+
inside: null // see blow
21+
},
22+
'punctuation': /\$\{|\}/
23+
}
24+
}
25+
}
26+
},
27+
'label': {
28+
pattern: /`[^`]*`/,
29+
greedy: true
30+
},
31+
'url': {
32+
// https://github.com/dhall-lang/dhall-lang/blob/5fde8ef1bead6fb4e999d3c1ffe7044cd019d63a/standard/dhall.abnf#L596
33+
pattern: /\bhttps?:\/\/[\w.:%!$&'*+;=@~-]+(?:\/[\w.:%!$&'*+;=@~-]*)*(?:\?[/?\w.:%!$&'*+;=@~-]*)?/,
34+
greedy: true
35+
},
36+
'env': {
37+
// https://github.com/dhall-lang/dhall-lang/blob/5fde8ef1bead6fb4e999d3c1ffe7044cd019d63a/standard/dhall.abnf#L661
38+
pattern: /\benv:(?:(?!\d)\w+|"(?:[^"\\=]|\\.)*")/,
39+
greedy: true,
40+
inside: {
41+
'function': /^env/,
42+
'operator': /^:/,
43+
'variable': /[\s\S]+/
44+
}
45+
},
46+
'hash': {
47+
// https://github.com/dhall-lang/dhall-lang/blob/5fde8ef1bead6fb4e999d3c1ffe7044cd019d63a/standard/dhall.abnf#L725
48+
pattern: /\bsha256:[\da-fA-F]{64}\b/,
49+
inside: {
50+
'function': /sha256/,
51+
'operator': /:/,
52+
'number': /[\da-fA-F]{64}/
53+
}
54+
},
55+
56+
// https://github.com/dhall-lang/dhall-lang/blob/5fde8ef1bead6fb4e999d3c1ffe7044cd019d63a/standard/dhall.abnf#L359
57+
'keyword': /\b(?:as|assert|else|forall|if|in|let|merge|missing|then|toMap|using|with)\b|\u2200/,
58+
'builtin': /\b(?:Some|None)\b/,
59+
60+
'boolean': /\b(?:False|True)\b/,
61+
'number': /\bNaN\b|-?\bInfinity\b|[+-]?\b(?:0x[\da-fA-F]+|\d+(?:\.\d+)?(?:e[+-]?\d+)?)\b/,
62+
'operator': /\/\\|\/\/\\\\|&&|\|\||[!=]=|===|\/\/|->|\+\+|::|[+*#@=:?<>|\\\u2227\u2a53\u2261\u2afd\u03bb\u2192]/,
63+
'punctuation': /\.\.|[{}\[\](),./]/,
64+
65+
// we'll just assume that every capital word left is a type name
66+
'class-name': /\b[A-Z]\w*\b/
67+
};
68+
69+
Prism.languages.dhall.string.inside.interpolation.inside.expression.inside = Prism.languages.dhall;

components/prism-dhall.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/prism-dhall.html

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<h2>Full example</h2>
2+
<pre><code>
3+
-- source: https://github.com/dhall-lang/dhall-lang/blob/master/Prelude/Optional/head.dhall
4+
5+
{-
6+
Returns the first non-empty `Optional` value in a `List`
7+
-}
8+
let head
9+
: ∀(a : Type) → List (Optional a) → Optional a
10+
= λ(a : Type) →
11+
λ(xs : List (Optional a)) →
12+
List/fold
13+
(Optional a)
14+
xs
15+
(Optional a)
16+
( λ(l : Optional a) →
17+
λ(r : Optional a) →
18+
merge { Some = λ(x : a) → Some x, None = r } l
19+
)
20+
(None a)
21+
22+
let example0 = assert : head Natural [ None Natural, Some 1, Some 2 ] ≡ Some 1
23+
24+
let example1 =
25+
assert : head Natural [ None Natural, None Natural ] ≡ None Natural
26+
27+
let example2 =
28+
assert : head Natural ([] : List (Optional Natural)) ≡ None Natural
29+
30+
in head</code></pre>
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
False
2+
True
3+
4+
----------------------------------------------------
5+
6+
[
7+
["boolean", "False"],
8+
["boolean", "True"]
9+
]
10+
11+
----------------------------------------------------
12+
13+
Checks for Bool literals.
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-- comment
2+
3+
{-
4+
comment
5+
{-
6+
nested comment
7+
-}
8+
-}
9+
10+
----------------------------------------------------
11+
12+
[
13+
["comment", "-- comment"],
14+
15+
["comment", "{-\n\tcomment\n\t{-\n\t\tnested comment\n\t-}\n-}"]
16+
]
17+
18+
----------------------------------------------------
19+
20+
Checks for comments.
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
env:DHALL_PRELUDE
2+
env:"Quotes variable"
3+
4+
----------------------------------------------------
5+
6+
[
7+
["env", [
8+
["function", "env"],
9+
["operator", ":"],
10+
["variable", "DHALL_PRELUDE"]
11+
]],
12+
["env", [
13+
["function", "env"],
14+
["operator", ":"],
15+
["variable", "\"Quotes variable\""]
16+
]]
17+
]
18+
19+
----------------------------------------------------
20+
21+
Checks for environment variables.
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
sha256:33f7f4c3aff62e5ecf4848f964363133452d420dcde045784518fb59fa970037
2+
3+
----------------------------------------------------
4+
5+
[
6+
["hash", [
7+
["function", "sha256"],
8+
["operator", ":"],
9+
["number", "33f7f4c3aff62e5ecf4848f964363133452d420dcde045784518fb59fa970037"]
10+
]]
11+
]
12+
13+
----------------------------------------------------
14+
15+
Checks for sha256 hashes.
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
as
2+
assert
3+
else
4+
forall
5+
if
6+
in
7+
let
8+
merge
9+
missing
10+
then
11+
toMap
12+
using
13+
with
14+
15+
16+
17+
----------------------------------------------------
18+
19+
[
20+
["keyword", "as"],
21+
["keyword", "assert"],
22+
["keyword", "else"],
23+
["keyword", "forall"],
24+
["keyword", "if"],
25+
["keyword", "in"],
26+
["keyword", "let"],
27+
["keyword", "merge"],
28+
["keyword", "missing"],
29+
["keyword", "then"],
30+
["keyword", "toMap"],
31+
["keyword", "using"],
32+
["keyword", "with"],
33+
34+
["keyword", "∀"]
35+
]
36+
37+
----------------------------------------------------
38+
39+
Checks for keywords.
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
`"foo"'s 123`
2+
3+
----------------------------------------------------
4+
5+
[
6+
["label", "`\"foo\"'s 123`"]
7+
]
8+
9+
----------------------------------------------------
10+
11+
Checks for escaped labels.
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
0
2+
123
3+
123e-5
4+
-123e+2
5+
123.456
6+
+123.456e-7
7+
0xFF
8+
-0xFF
9+
+0xFF
10+
11+
Infinity
12+
-Infinity
13+
NaN
14+
15+
----------------------------------------------------
16+
17+
[
18+
["number", "0"],
19+
["number", "123"],
20+
["number", "123e-5"],
21+
["number", "-123e+2"],
22+
["number", "123.456"],
23+
["number", "+123.456e-7"],
24+
["number", "0xFF"],
25+
["number", "-0xFF"],
26+
["number", "+0xFF"],
27+
28+
["number", "Infinity"],
29+
["number", "-Infinity"],
30+
["number", "NaN"]
31+
]
32+
33+
----------------------------------------------------
34+
35+
Checks for numeric literals.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/\ //\\ && || != == == // -> ++ ::
2+
3+
+ * # | = : ? < > | \
4+
5+
∧ ⩓ ≡ ⫽ λ →
6+
7+
----------------------------------------------------
8+
9+
[
10+
["operator", "/\\"],
11+
["operator", "//\\\\"],
12+
["operator", "&&"],
13+
["operator", "||"],
14+
["operator", "!="],
15+
["operator", "=="],
16+
["operator", "=="],
17+
["operator", "//"],
18+
["operator", "->"],
19+
["operator", "++"],
20+
["operator", "::"],
21+
22+
["operator", "+"],
23+
["operator", "*"],
24+
["operator", "#"],
25+
["operator", "|"],
26+
["operator", "="],
27+
["operator", ":"],
28+
["operator", "?"],
29+
["operator", "<"],
30+
["operator", ">"],
31+
["operator", "|"],
32+
["operator", "\\"],
33+
34+
["operator", "∧"],
35+
["operator", "⩓"],
36+
["operator", "≡"],
37+
["operator", "⫽"],
38+
["operator", "λ"],
39+
["operator", "→"]
40+
]
41+
42+
----------------------------------------------------
43+
44+
Checks for operators.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
. .. /
2+
3+
{ } [ ] ( ) ,
4+
5+
----------------------------------------------------
6+
7+
[
8+
["punctuation", "."],
9+
["punctuation", ".."],
10+
["punctuation", "/"],
11+
12+
["punctuation", "{"],
13+
["punctuation", "}"],
14+
["punctuation", "["],
15+
["punctuation", "]"],
16+
["punctuation", "("],
17+
["punctuation", ")"],
18+
["punctuation", ","]
19+
]
20+
21+
----------------------------------------------------
22+
23+
Checks for punctuation.

0 commit comments

Comments
 (0)