nix.js 1.5 KB

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