nix.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. Language: Nix
  3. Author: Domen Kožar <domen@dev.si>
  4. Description: Nix functional language
  5. Website: http://nixos.org/nix
  6. */
  7. function nix(hljs) {
  8. const NIX_KEYWORDS = {
  9. keyword:
  10. 'rec with let in inherit assert if else then',
  11. literal:
  12. 'true false or and null',
  13. built_in:
  14. 'import abort baseNameOf dirOf isNull builtins map removeAttrs throw ' +
  15. 'toString derivation'
  16. };
  17. const ANTIQUOTE = {
  18. className: 'subst',
  19. begin: /\$\{/,
  20. end: /\}/,
  21. keywords: NIX_KEYWORDS
  22. };
  23. const ATTRS = {
  24. begin: /[a-zA-Z0-9-_]+(\s*=)/,
  25. returnBegin: true,
  26. relevance: 0,
  27. contains: [
  28. {
  29. className: 'attr',
  30. begin: /\S+/
  31. }
  32. ]
  33. };
  34. const STRING = {
  35. className: 'string',
  36. contains: [ ANTIQUOTE ],
  37. variants: [
  38. {
  39. begin: "''",
  40. end: "''"
  41. },
  42. {
  43. begin: '"',
  44. end: '"'
  45. }
  46. ]
  47. };
  48. const EXPRESSIONS = [
  49. hljs.NUMBER_MODE,
  50. hljs.HASH_COMMENT_MODE,
  51. hljs.C_BLOCK_COMMENT_MODE,
  52. STRING,
  53. ATTRS
  54. ];
  55. ANTIQUOTE.contains = EXPRESSIONS;
  56. return {
  57. name: 'Nix',
  58. aliases: [ "nixos" ],
  59. keywords: NIX_KEYWORDS,
  60. contains: EXPRESSIONS
  61. };
  62. }
  63. module.exports = nix;