capnproto.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. Language: Cap’n Proto
  3. Author: Oleg Efimov <efimovov@gmail.com>
  4. Description: Cap’n Proto message definition format
  5. Website: https://capnproto.org/capnp-tool.html
  6. Category: protocols
  7. */
  8. /** @type LanguageFn */
  9. function capnproto(hljs) {
  10. const KEYWORDS = [
  11. "struct",
  12. "enum",
  13. "interface",
  14. "union",
  15. "group",
  16. "import",
  17. "using",
  18. "const",
  19. "annotation",
  20. "extends",
  21. "in",
  22. "of",
  23. "on",
  24. "as",
  25. "with",
  26. "from",
  27. "fixed"
  28. ];
  29. const TYPES = [
  30. "Void",
  31. "Bool",
  32. "Int8",
  33. "Int16",
  34. "Int32",
  35. "Int64",
  36. "UInt8",
  37. "UInt16",
  38. "UInt32",
  39. "UInt64",
  40. "Float32",
  41. "Float64",
  42. "Text",
  43. "Data",
  44. "AnyPointer",
  45. "AnyStruct",
  46. "Capability",
  47. "List"
  48. ];
  49. const LITERALS = [
  50. "true",
  51. "false"
  52. ];
  53. const CLASS_DEFINITION = {
  54. variants: [
  55. { match: [
  56. /(struct|enum|interface)/,
  57. /\s+/,
  58. hljs.IDENT_RE
  59. ] },
  60. { match: [
  61. /extends/,
  62. /\s*\(/,
  63. hljs.IDENT_RE,
  64. /\s*\)/
  65. ] }
  66. ],
  67. scope: {
  68. 1: "keyword",
  69. 3: "title.class"
  70. }
  71. };
  72. return {
  73. name: 'Cap’n Proto',
  74. aliases: [ 'capnp' ],
  75. keywords: {
  76. keyword: KEYWORDS,
  77. type: TYPES,
  78. literal: LITERALS
  79. },
  80. contains: [
  81. hljs.QUOTE_STRING_MODE,
  82. hljs.NUMBER_MODE,
  83. hljs.HASH_COMMENT_MODE,
  84. {
  85. className: 'meta',
  86. begin: /@0x[\w\d]{16};/,
  87. illegal: /\n/
  88. },
  89. {
  90. className: 'symbol',
  91. begin: /@\d+\b/
  92. },
  93. CLASS_DEFINITION
  94. ]
  95. };
  96. }
  97. export { capnproto as default };