protobuf.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. Language: Protocol Buffers
  3. Author: Dan Tao <daniel.tao@gmail.com>
  4. Description: Protocol buffer message definition format
  5. Website: https://developers.google.com/protocol-buffers/docs/proto3
  6. Category: protocols
  7. */
  8. function protobuf(hljs) {
  9. const KEYWORDS = [
  10. "package",
  11. "import",
  12. "option",
  13. "optional",
  14. "required",
  15. "repeated",
  16. "group",
  17. "oneof"
  18. ];
  19. const TYPES = [
  20. "double",
  21. "float",
  22. "int32",
  23. "int64",
  24. "uint32",
  25. "uint64",
  26. "sint32",
  27. "sint64",
  28. "fixed32",
  29. "fixed64",
  30. "sfixed32",
  31. "sfixed64",
  32. "bool",
  33. "string",
  34. "bytes"
  35. ];
  36. const CLASS_DEFINITION = {
  37. match: [
  38. /(message|enum|service)\s+/,
  39. hljs.IDENT_RE
  40. ],
  41. scope: {
  42. 1: "keyword",
  43. 2: "title.class"
  44. }
  45. };
  46. return {
  47. name: 'Protocol Buffers',
  48. keywords: {
  49. keyword: KEYWORDS,
  50. type: TYPES,
  51. literal: [
  52. 'true',
  53. 'false'
  54. ]
  55. },
  56. contains: [
  57. hljs.QUOTE_STRING_MODE,
  58. hljs.NUMBER_MODE,
  59. hljs.C_LINE_COMMENT_MODE,
  60. hljs.C_BLOCK_COMMENT_MODE,
  61. CLASS_DEFINITION,
  62. {
  63. className: 'function',
  64. beginKeywords: 'rpc',
  65. end: /[{;]/,
  66. excludeEnd: true,
  67. keywords: 'rpc returns'
  68. },
  69. { // match enum items (relevance)
  70. // BLAH = ...;
  71. begin: /^\s*[A-Z_]+(?=\s*=[^\n]+;$)/ }
  72. ]
  73. };
  74. }
  75. module.exports = protobuf;