UNPKG

2.32 kBJavaScriptView Raw
1// ABNF grammar:
2// https://github.com/dhall-lang/dhall-lang/blob/master/standard/dhall.abnf
3
4Prism.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
69Prism.languages.dhall.string.inside.interpolation.inside.expression.inside = Prism.languages.dhall;