thrift.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. Language: Thrift
  3. Author: Oleg Efimov <efimovov@gmail.com>
  4. Description: Thrift message definition format
  5. Website: https://thrift.apache.org
  6. Category: protocols
  7. */
  8. function thrift(hljs) {
  9. const TYPES = [
  10. "bool",
  11. "byte",
  12. "i16",
  13. "i32",
  14. "i64",
  15. "double",
  16. "string",
  17. "binary"
  18. ];
  19. const KEYWORDS = [
  20. "namespace",
  21. "const",
  22. "typedef",
  23. "struct",
  24. "enum",
  25. "service",
  26. "exception",
  27. "void",
  28. "oneway",
  29. "set",
  30. "list",
  31. "map",
  32. "required",
  33. "optional"
  34. ];
  35. return {
  36. name: 'Thrift',
  37. keywords: {
  38. keyword: KEYWORDS,
  39. type: TYPES,
  40. literal: 'true false'
  41. },
  42. contains: [
  43. hljs.QUOTE_STRING_MODE,
  44. hljs.NUMBER_MODE,
  45. hljs.C_LINE_COMMENT_MODE,
  46. hljs.C_BLOCK_COMMENT_MODE,
  47. {
  48. className: 'class',
  49. beginKeywords: 'struct enum service exception',
  50. end: /\{/,
  51. illegal: /\n/,
  52. contains: [
  53. hljs.inherit(hljs.TITLE_MODE, {
  54. // hack: eating everything after the first title
  55. starts: {
  56. endsWithParent: true,
  57. excludeEnd: true
  58. } })
  59. ]
  60. },
  61. {
  62. begin: '\\b(set|list|map)\\s*<',
  63. keywords: { type: [
  64. ...TYPES,
  65. "set",
  66. "list",
  67. "map"
  68. ] },
  69. end: '>',
  70. contains: [ 'self' ]
  71. }
  72. ]
  73. };
  74. }
  75. export { thrift as default };