protobuf_highlight_rules.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 ProtobufHighlightRules = function() {
  6. var builtinTypes = "double|float|int32|int64|uint32|uint64|sint32|" +
  7. "sint64|fixed32|fixed64|sfixed32|sfixed64|bool|" +
  8. "string|bytes";
  9. var keywordDeclaration = "message|required|optional|repeated|package|" +
  10. "import|option|enum";
  11. var keywordMapper = this.createKeywordMapper({
  12. "keyword.declaration.protobuf": keywordDeclaration,
  13. "support.type": builtinTypes
  14. }, "identifier");
  15. this.$rules = {
  16. "start": [{
  17. token: "comment",
  18. regex: /\/\/.*$/
  19. }, {
  20. token: "comment",
  21. regex: /\/\*/,
  22. next: "comment"
  23. }, {
  24. token: "constant",
  25. regex: "<[^>]+>"
  26. }, {
  27. regex: "=",
  28. token: "keyword.operator.assignment.protobuf"
  29. }, {
  30. token : "string", // single line
  31. regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
  32. }, {
  33. token : "string", // single line
  34. regex : '[\'](?:(?:\\\\.)|(?:[^\'\\\\]))*?[\']'
  35. }, {
  36. token: "constant.numeric", // hex
  37. regex: "0[xX][0-9a-fA-F]+\\b"
  38. }, {
  39. token: "constant.numeric", // float
  40. regex: "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
  41. }, {
  42. token: keywordMapper,
  43. regex: "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
  44. }],
  45. "comment": [{
  46. token: "comment", // closing comment
  47. regex: ".*?\\*\\/",
  48. next: "start"
  49. }, {
  50. token: "comment", // comment spanning whole line
  51. regex: ".+"
  52. }]
  53. };
  54. this.normalizeRules();
  55. };
  56. oop.inherits(ProtobufHighlightRules, TextHighlightRules);
  57. exports.ProtobufHighlightRules = ProtobufHighlightRules;
  58. });