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