nix_highlight_rules.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. define(function(require, exports, module) {
  2. "use strict";
  3. var oop = require("../lib/oop");
  4. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  5. var NixHighlightRules = function() {
  6. var constantLanguage = "true|false";
  7. var keywordControl = "with|import|if|else|then|inherit";
  8. var keywordDeclaration = "let|in|rec";
  9. var keywordMapper = this.createKeywordMapper({
  10. "constant.language.nix": constantLanguage,
  11. "keyword.control.nix": keywordControl,
  12. "keyword.declaration.nix": keywordDeclaration
  13. }, "identifier");
  14. this.$rules = {
  15. "start": [{
  16. token: "comment",
  17. regex: /#.*$/
  18. }, {
  19. token: "comment",
  20. regex: /\/\*/,
  21. next: "comment"
  22. }, {
  23. token: "constant",
  24. regex: "<[^>]+>"
  25. }, {
  26. regex: "(==|!=|<=?|>=?)",
  27. token: ["keyword.operator.comparison.nix"]
  28. }, {
  29. regex: "((?:[+*/%-]|\\~)=)",
  30. token: ["keyword.operator.assignment.arithmetic.nix"]
  31. }, {
  32. regex: "=",
  33. token: "keyword.operator.assignment.nix"
  34. }, {
  35. token: "string",
  36. regex: "''",
  37. next: "qqdoc"
  38. }, {
  39. token: "string",
  40. regex: "'",
  41. next: "qstring"
  42. }, {
  43. token: "string",
  44. regex: '"',
  45. push: "qqstring"
  46. }, {
  47. token: "constant.numeric", // hex
  48. regex: "0[xX][0-9a-fA-F]+\\b"
  49. }, {
  50. token: "constant.numeric", // float
  51. regex: "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
  52. }, {
  53. token: keywordMapper,
  54. regex: "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
  55. }, {
  56. regex: "}",
  57. token: function(val, start, stack) {
  58. return stack[1] && stack[1].charAt(0) == "q" ? "constant.language.escape" : "text";
  59. },
  60. next: "pop"
  61. }],
  62. "comment": [{
  63. token: "comment", // closing comment
  64. regex: ".*?\\*\\/",
  65. next: "start"
  66. }, {
  67. token: "comment", // comment spanning whole line
  68. regex: ".+"
  69. }],
  70. "qqdoc": [
  71. {
  72. token: "constant.language.escape",
  73. regex: /\$\{/,
  74. push: "start"
  75. }, {
  76. token: "string",
  77. regex: "''",
  78. next: "pop"
  79. }, {
  80. defaultToken: "string"
  81. }],
  82. "qqstring": [
  83. {
  84. token: "constant.language.escape",
  85. regex: /\$\{/,
  86. push: "start"
  87. }, {
  88. token: "string",
  89. regex: '"',
  90. next: "pop"
  91. }, {
  92. defaultToken: "string"
  93. }],
  94. "qstring": [
  95. {
  96. token: "constant.language.escape",
  97. regex: /\$\{/,
  98. push: "start"
  99. }, {
  100. token: "string",
  101. regex: "'",
  102. next: "pop"
  103. }, {
  104. defaultToken: "string"
  105. }]
  106. };
  107. this.normalizeRules();
  108. };
  109. oop.inherits(NixHighlightRules, TextHighlightRules);
  110. exports.NixHighlightRules = NixHighlightRules;
  111. });