nix.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. Language: Nix
  3. Author: Domen Kožar <domen@dev.si>
  4. Description: Nix functional language
  5. Website: http://nixos.org/nix
  6. Category: system
  7. */
  8. function nix(hljs) {
  9. const KEYWORDS = {
  10. keyword: [
  11. "rec",
  12. "with",
  13. "let",
  14. "in",
  15. "inherit",
  16. "assert",
  17. "if",
  18. "else",
  19. "then"
  20. ],
  21. literal: [
  22. "true",
  23. "false",
  24. "or",
  25. "and",
  26. "null"
  27. ],
  28. built_in: [
  29. "import",
  30. "abort",
  31. "baseNameOf",
  32. "dirOf",
  33. "isNull",
  34. "builtins",
  35. "map",
  36. "removeAttrs",
  37. "throw",
  38. "toString",
  39. "derivation"
  40. ]
  41. };
  42. const ANTIQUOTE = {
  43. className: 'subst',
  44. begin: /\$\{/,
  45. end: /\}/,
  46. keywords: KEYWORDS
  47. };
  48. const ESCAPED_DOLLAR = {
  49. className: 'char.escape',
  50. begin: /''\$/,
  51. };
  52. const ATTRS = {
  53. begin: /[a-zA-Z0-9-_]+(\s*=)/,
  54. returnBegin: true,
  55. relevance: 0,
  56. contains: [
  57. {
  58. className: 'attr',
  59. begin: /\S+/,
  60. relevance: 0.2
  61. }
  62. ]
  63. };
  64. const STRING = {
  65. className: 'string',
  66. contains: [ ESCAPED_DOLLAR, ANTIQUOTE ],
  67. variants: [
  68. {
  69. begin: "''",
  70. end: "''"
  71. },
  72. {
  73. begin: '"',
  74. end: '"'
  75. }
  76. ]
  77. };
  78. const EXPRESSIONS = [
  79. hljs.NUMBER_MODE,
  80. hljs.HASH_COMMENT_MODE,
  81. hljs.C_BLOCK_COMMENT_MODE,
  82. STRING,
  83. ATTRS
  84. ];
  85. ANTIQUOTE.contains = EXPRESSIONS;
  86. return {
  87. name: 'Nix',
  88. aliases: [ "nixos" ],
  89. keywords: KEYWORDS,
  90. contains: EXPRESSIONS
  91. };
  92. }
  93. export { nix as default };