UNPKG

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