prism-dhall.js 2.3 KB

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