prism-nix.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. Prism.languages.nix = {
  2. 'comment': /\/\*[\s\S]*?\*\/|#.*/,
  3. 'string': {
  4. pattern: /"(?:[^"\\]|\\[\s\S])*"|''(?:(?!'')[\s\S]|''(?:'|\\|\$\{))*''/,
  5. greedy: true,
  6. inside: {
  7. 'interpolation': {
  8. // The lookbehind ensures the ${} is not preceded by \ or ''
  9. pattern: /(^|(?:^|(?!'').)[^\\])\$\{(?:[^}]|\{[^}]*\})*}/,
  10. lookbehind: true,
  11. inside: {
  12. 'antiquotation': {
  13. pattern: /^\$(?=\{)/,
  14. alias: 'variable'
  15. }
  16. // See rest below
  17. }
  18. }
  19. }
  20. },
  21. 'url': [
  22. /\b(?:[a-z]{3,7}:\/\/)[\w\-+%~\/.:#=?&]+/,
  23. {
  24. pattern: /([^\/])(?:[\w\-+%~.:#=?&]*(?!\/\/)[\w\-+%~\/.:#=?&])?(?!\/\/)\/[\w\-+%~\/.:#=?&]*/,
  25. lookbehind: true
  26. }
  27. ],
  28. 'antiquotation': {
  29. pattern: /\$(?=\{)/,
  30. alias: 'variable'
  31. },
  32. 'number': /\b\d+\b/,
  33. 'keyword': /\b(?:assert|builtins|else|if|in|inherit|let|null|or|then|with)\b/,
  34. 'function': /\b(?:abort|add|all|any|attrNames|attrValues|baseNameOf|compareVersions|concatLists|currentSystem|deepSeq|derivation|dirOf|div|elem(?:At)?|fetch(?:url|Tarball)|filter(?:Source)?|fromJSON|genList|getAttr|getEnv|hasAttr|hashString|head|import|intersectAttrs|is(?:Attrs|Bool|Function|Int|List|Null|String)|length|lessThan|listToAttrs|map|mul|parseDrvName|pathExists|read(?:Dir|File)|removeAttrs|replaceStrings|seq|sort|stringLength|sub(?:string)?|tail|throw|to(?:File|JSON|Path|String|XML)|trace|typeOf)\b|\bfoldl'\B/,
  35. 'boolean': /\b(?:true|false)\b/,
  36. 'operator': /[=!<>]=?|\+\+?|\|\||&&|\/\/|->?|[?@]/,
  37. 'punctuation': /[{}()[\].,:;]/
  38. };
  39. Prism.languages.nix.string.inside.interpolation.inside.rest = Prism.languages.nix;