golang_highlight_rules.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. define(function(require, exports, module) {
  2. var oop = require("../lib/oop");
  3. var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
  4. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  5. var GolangHighlightRules = function() {
  6. var keywords = (
  7. "else|break|case|return|goto|if|const|select|" +
  8. "continue|struct|default|switch|for|range|" +
  9. "func|import|package|chan|defer|fallthrough|go|interface|map|range|" +
  10. "select|type|var"
  11. );
  12. var builtinTypes = (
  13. "string|uint8|uint16|uint32|uint64|int8|int16|int32|int64|float32|" +
  14. "float64|complex64|complex128|byte|rune|uint|int|uintptr|bool|error"
  15. );
  16. var builtinFunctions = (
  17. "make|close|new|panic|recover"
  18. );
  19. var builtinConstants = ("nil|true|false|iota");
  20. var keywordMapper = this.createKeywordMapper({
  21. "keyword": keywords,
  22. "constant.language": builtinConstants,
  23. "support.function": builtinFunctions,
  24. "support.type": builtinTypes
  25. }, "identifier");
  26. this.$rules = {
  27. "start" : [
  28. {
  29. token : "comment",
  30. regex : "\\/\\/.*$"
  31. },
  32. DocCommentHighlightRules.getStartRule("doc-start"),
  33. {
  34. token : "comment", // multi line comment
  35. regex : "\\/\\*",
  36. next : "comment"
  37. }, {
  38. token : "string", // single line
  39. regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
  40. }, {
  41. token : "string", // single line
  42. regex : '[`](?:[^`]*)[`]'
  43. }, {
  44. token : "string", // multi line string start
  45. merge : true,
  46. regex : '[`](?:[^`]*)$',
  47. next : "bqstring"
  48. }, {
  49. token : "constant.numeric", // rune
  50. regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))[']"
  51. }, {
  52. token : "constant.numeric", // hex
  53. regex : "0[xX][0-9a-fA-F]+\\b"
  54. }, {
  55. token : "constant.numeric", // float
  56. regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
  57. }, {
  58. token : keywordMapper,
  59. regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
  60. }, {
  61. token : "keyword.operator",
  62. regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|==|=|!=|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^="
  63. }, {
  64. token : "punctuation.operator",
  65. regex : "\\?|\\:|\\,|\\;|\\."
  66. }, {
  67. token : "paren.lparen",
  68. regex : "[[({]"
  69. }, {
  70. token : "paren.rparen",
  71. regex : "[\\])}]"
  72. }, {
  73. token : "text",
  74. regex : "\\s+"
  75. }
  76. ],
  77. "comment" : [
  78. {
  79. token : "comment", // closing comment
  80. regex : ".*?\\*\\/",
  81. next : "start"
  82. }, {
  83. token : "comment", // comment spanning whole line
  84. regex : ".+"
  85. }
  86. ],
  87. "bqstring" : [
  88. {
  89. token : "string",
  90. regex : '(?:[^`]*)`',
  91. next : "start"
  92. }, {
  93. token : "string",
  94. regex : '.+'
  95. }
  96. ]
  97. };
  98. this.embedRules(DocCommentHighlightRules, "doc-",
  99. [ DocCommentHighlightRules.getEndRule("start") ]);
  100. };
  101. oop.inherits(GolangHighlightRules, TextHighlightRules);
  102. exports.GolangHighlightRules = GolangHighlightRules;
  103. });