protobuf.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. aliases: ['proto'],
  49. keywords: {
  50. keyword: KEYWORDS,
  51. type: TYPES,
  52. literal: [
  53. 'true',
  54. 'false'
  55. ]
  56. },
  57. contains: [
  58. hljs.QUOTE_STRING_MODE,
  59. hljs.NUMBER_MODE,
  60. hljs.C_LINE_COMMENT_MODE,
  61. hljs.C_BLOCK_COMMENT_MODE,
  62. CLASS_DEFINITION,
  63. {
  64. className: 'function',
  65. beginKeywords: 'rpc',
  66. end: /[{;]/,
  67. excludeEnd: true,
  68. keywords: 'rpc returns'
  69. },
  70. { // match enum items (relevance)
  71. // BLAH = ...;
  72. begin: /^\s*[A-Z_]+(?=\s*=[^\n]+;$)/ }
  73. ]
  74. };
  75. }
  76. export { protobuf as default };