Skip to content

Commit

Permalink
Added support for Dhall (#2473)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment authored Jul 27, 2020
1 parent 453079b commit 649e51e
Show file tree
Hide file tree
Showing 16 changed files with 398 additions and 1 deletion.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,10 @@
"title": "DAX",
"owner": "peterbud"
},
"dhall": {
"title": "Dhall",
"owner": "RunDevelopment"
},
"diff": {
"title": "Diff",
"owner": "uranusjr"
Expand Down
69 changes: 69 additions & 0 deletions components/prism-dhall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// ABNF grammar:
// https://github.com/dhall-lang/dhall-lang/blob/master/standard/dhall.abnf

Prism.languages.dhall = {
// Multi-line comments can be nested. E.g. {- foo {- bar -} -}
// The multi-line pattern is essentially this:
// \{-(?:[^-{]|-(?!\})|\{(?!-)|<SELF>)*-\}
'comment': /--.*|\{-(?:[^-{]|-(?!\})|\{(?!-)|\{-(?:[^-{]|-(?!\})|\{(?!-))*-\})*-\}/,
'string': {
pattern: /"(?:[^"\\]|\\.)*"|''(?:[^']|'(?!')|'''|''\$\{)*''(?!'|\$)/,
greedy: true,
inside: {
'interpolation': {
pattern: /\$\{[^{}]*\}/,
inside: {
'expression': {
pattern: /(^\$\{)[\s\S]+(?=\}$)/,
lookbehind: true,
alias: 'language-dhall',
inside: null // see blow
},
'punctuation': /\$\{|\}/
}
}
}
},
'label': {
pattern: /`[^`]*`/,
greedy: true
},
'url': {
// https://github.com/dhall-lang/dhall-lang/blob/5fde8ef1bead6fb4e999d3c1ffe7044cd019d63a/standard/dhall.abnf#L596
pattern: /\bhttps?:\/\/[\w.:%!$&'*+;=@~-]+(?:\/[\w.:%!$&'*+;=@~-]*)*(?:\?[/?\w.:%!$&'*+;=@~-]*)?/,
greedy: true
},
'env': {
// https://github.com/dhall-lang/dhall-lang/blob/5fde8ef1bead6fb4e999d3c1ffe7044cd019d63a/standard/dhall.abnf#L661
pattern: /\benv:(?:(?!\d)\w+|"(?:[^"\\=]|\\.)*")/,
greedy: true,
inside: {
'function': /^env/,
'operator': /^:/,
'variable': /[\s\S]+/
}
},
'hash': {
// https://github.com/dhall-lang/dhall-lang/blob/5fde8ef1bead6fb4e999d3c1ffe7044cd019d63a/standard/dhall.abnf#L725
pattern: /\bsha256:[\da-fA-F]{64}\b/,
inside: {
'function': /sha256/,
'operator': /:/,
'number': /[\da-fA-F]{64}/
}
},

// https://github.com/dhall-lang/dhall-lang/blob/5fde8ef1bead6fb4e999d3c1ffe7044cd019d63a/standard/dhall.abnf#L359
'keyword': /\b(?:as|assert|else|forall|if|in|let|merge|missing|then|toMap|using|with)\b|\u2200/,
'builtin': /\b(?:Some|None)\b/,

'boolean': /\b(?:False|True)\b/,
'number': /\bNaN\b|-?\bInfinity\b|[+-]?\b(?:0x[\da-fA-F]+|\d+(?:\.\d+)?(?:e[+-]?\d+)?)\b/,
'operator': /\/\\|\/\/\\\\|&&|\|\||[!=]=|===|\/\/|->|\+\+|::|[+*#@=:?<>|\\\u2227\u2a53\u2261\u2afd\u03bb\u2192]/,
'punctuation': /\.\.|[{}\[\](),./]/,

// we'll just assume that every capital word left is a type name
'class-name': /\b[A-Z]\w*\b/
};

Prism.languages.dhall.string.inside.interpolation.inside.expression.inside = Prism.languages.dhall;
1 change: 1 addition & 0 deletions components/prism-dhall.min.js

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

30 changes: 30 additions & 0 deletions examples/prism-dhall.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<h2>Full example</h2>
<pre><code>
-- source: https://github.com/dhall-lang/dhall-lang/blob/master/Prelude/Optional/head.dhall

{-
Returns the first non-empty `Optional` value in a `List`
-}
let head
: ∀(a : Type) → List (Optional a) → Optional a
= λ(a : Type) →
λ(xs : List (Optional a)) →
List/fold
(Optional a)
xs
(Optional a)
( λ(l : Optional a) →
λ(r : Optional a) →
merge { Some = λ(x : a) → Some x, None = r } l
)
(None a)

let example0 = assert : head Natural [ None Natural, Some 1, Some 2 ] ≡ Some 1

let example1 =
assert : head Natural [ None Natural, None Natural ] ≡ None Natural

let example2 =
assert : head Natural ([] : List (Optional Natural)) ≡ None Natural

in head</code></pre>
13 changes: 13 additions & 0 deletions tests/languages/dhall/boolean_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
False
True

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

[
["boolean", "False"],
["boolean", "True"]
]

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

Checks for Bool literals.
20 changes: 20 additions & 0 deletions tests/languages/dhall/comment_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-- comment

{-
comment
{-
nested comment
-}
-}

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

[
["comment", "-- comment"],

["comment", "{-\n\tcomment\n\t{-\n\t\tnested comment\n\t-}\n-}"]
]

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

Checks for comments.
21 changes: 21 additions & 0 deletions tests/languages/dhall/env_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
env:DHALL_PRELUDE
env:"Quotes variable"

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

[
["env", [
["function", "env"],
["operator", ":"],
["variable", "DHALL_PRELUDE"]
]],
["env", [
["function", "env"],
["operator", ":"],
["variable", "\"Quotes variable\""]
]]
]

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

Checks for environment variables.
15 changes: 15 additions & 0 deletions tests/languages/dhall/hash_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
sha256:33f7f4c3aff62e5ecf4848f964363133452d420dcde045784518fb59fa970037

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

[
["hash", [
["function", "sha256"],
["operator", ":"],
["number", "33f7f4c3aff62e5ecf4848f964363133452d420dcde045784518fb59fa970037"]
]]
]

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

Checks for sha256 hashes.
39 changes: 39 additions & 0 deletions tests/languages/dhall/keyword_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
as
assert
else
forall
if
in
let
merge
missing
then
toMap
using
with


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

[
["keyword", "as"],
["keyword", "assert"],
["keyword", "else"],
["keyword", "forall"],
["keyword", "if"],
["keyword", "in"],
["keyword", "let"],
["keyword", "merge"],
["keyword", "missing"],
["keyword", "then"],
["keyword", "toMap"],
["keyword", "using"],
["keyword", "with"],

["keyword", "∀"]
]

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

Checks for keywords.
11 changes: 11 additions & 0 deletions tests/languages/dhall/label_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
`"foo"'s 123`

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

[
["label", "`\"foo\"'s 123`"]
]

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

Checks for escaped labels.
35 changes: 35 additions & 0 deletions tests/languages/dhall/number_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
0
123
123e-5
-123e+2
123.456
+123.456e-7
0xFF
-0xFF
+0xFF

Infinity
-Infinity
NaN

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

[
["number", "0"],
["number", "123"],
["number", "123e-5"],
["number", "-123e+2"],
["number", "123.456"],
["number", "+123.456e-7"],
["number", "0xFF"],
["number", "-0xFF"],
["number", "+0xFF"],

["number", "Infinity"],
["number", "-Infinity"],
["number", "NaN"]
]

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

Checks for numeric literals.
44 changes: 44 additions & 0 deletions tests/languages/dhall/operator_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/\ //\\ && || != == == // -> ++ ::

+ * # | = : ? < > | \

∧ ⩓ ≡ ⫽ λ →

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

[
["operator", "/\\"],
["operator", "//\\\\"],
["operator", "&&"],
["operator", "||"],
["operator", "!="],
["operator", "=="],
["operator", "=="],
["operator", "//"],
["operator", "->"],
["operator", "++"],
["operator", "::"],

["operator", "+"],
["operator", "*"],
["operator", "#"],
["operator", "|"],
["operator", "="],
["operator", ":"],
["operator", "?"],
["operator", "<"],
["operator", ">"],
["operator", "|"],
["operator", "\\"],

["operator", "∧"],
["operator", "⩓"],
["operator", "≡"],
["operator", "⫽"],
["operator", "λ"],
["operator", "→"]
]

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

Checks for operators.
23 changes: 23 additions & 0 deletions tests/languages/dhall/punctuation_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
. .. /

{ } [ ] ( ) ,

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

[
["punctuation", "."],
["punctuation", ".."],
["punctuation", "/"],

["punctuation", "{"],
["punctuation", "}"],
["punctuation", "["],
["punctuation", "]"],
["punctuation", "("],
["punctuation", ")"],
["punctuation", ","]
]

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

Checks for punctuation.
Loading

0 comments on commit 649e51e

Please sign in to comment.