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