Skip to content

Commit 939a17c

Browse files
Protobuf: Added support for RPC (#2414)
1 parent 937e269 commit 939a17c

File tree

4 files changed

+92
-9
lines changed

4 files changed

+92
-9
lines changed

components/prism-protobuf.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,23 @@
33
var builtinTypes = /\b(?:double|float|[su]?int(?:32|64)|s?fixed(?:32|64)|bool|string|bytes)\b/;
44

55
Prism.languages.protobuf = Prism.languages.extend('clike', {
6-
'class-name': {
7-
pattern: /(\b(?:enum|extend|message|service)\s+)[A-Za-z_]\w*(?=\s*\{)/,
8-
lookbehind: true
9-
},
10-
'keyword': /\b(?:enum|extend|extensions|import|message|oneof|option|optional|package|public|repeated|required|reserved|service|syntax|to)\b/
6+
'class-name': [
7+
{
8+
pattern: /(\b(?:enum|extend|message|service)\s+)[A-Za-z_]\w*(?=\s*\{)/,
9+
lookbehind: true
10+
},
11+
{
12+
pattern: /(\b(?:rpc\s+\w+|returns)\s*\(\s*(?:stream\s+)?)\.?[A-Za-z_]\w*(?:\.[A-Za-z_]\w*)*(?=\s*\))/,
13+
lookbehind: true
14+
}
15+
],
16+
'keyword': /\b(?:enum|extend|extensions|import|message|oneof|option|optional|package|public|repeated|required|reserved|returns|rpc(?=\s+\w)|service|stream|syntax|to)\b(?!\s*=\s*\d)/,
17+
'function': /[a-z_]\w*(?=\s*\()/i
1118
});
1219

1320
Prism.languages.insertBefore('protobuf', 'operator', {
1421
'map': {
15-
pattern: /\bmap<\s*[\w.]+\s*,\s*[\w.]+\s*>(?=\s+[A-Za-z_]\w*\s*[=;])/,
22+
pattern: /\bmap<\s*[\w.]+\s*,\s*[\w.]+\s*>(?=\s+[a-z_]\w*\s*[=;])/i,
1623
alias: 'class-name',
1724
inside: {
1825
'punctuation': /[<>.,]/,
@@ -21,14 +28,14 @@
2128
},
2229
'builtin': builtinTypes,
2330
'positional-class-name': {
24-
pattern: /(?:\b|\B\.)[A-Za-z_]\w*(?:\.[A-Za-z_]\w*)*(?=\s+[A-Za-z_]\w*\s*[=;])/,
31+
pattern: /(?:\b|\B\.)[a-z_]\w*(?:\.[a-z_]\w*)*(?=\s+[a-z_]\w*\s*[=;])/i,
2532
alias: 'class-name',
2633
inside: {
2734
'punctuation': /\./
2835
}
2936
},
3037
'annotation': {
31-
pattern: /(\[\s*)[A-Za-z_]\w*(?=\s*=)/,
38+
pattern: /(\[\s*)[a-z_]\w*(?=\s*=)/i,
3239
lookbehind: true
3340
}
3441
});

components/prism-protobuf.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/languages/protobuf/keyword_feature.test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ public
1111
repeated
1212
required
1313
reserved
14+
returns
15+
rpc LotsOfReplies(
1416
service
17+
stream
1518
syntax
1619
to
1720

@@ -31,7 +34,12 @@ to
3134
["keyword", "repeated"],
3235
["keyword", "required"],
3336
["keyword", "reserved"],
37+
["keyword", "returns"],
38+
["keyword", "rpc"],
39+
["function", "LotsOfReplies"],
40+
["punctuation", "("],
3441
["keyword", "service"],
42+
["keyword", "stream"],
3543
["keyword", "syntax"],
3644
["keyword", "to"]
3745
]
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
rpc LotsOfReplies(HelloRequest) returns (stream HelloResponse);
2+
rpc BidiHello(stream HelloRequest) returns (stream HelloResponse);
3+
rpc CancelOperation(CancelOperationRequest) returns (google.protobuf.Empty) {
4+
option (google.api.http) = { post: "/v1/{name=operations/**}:cancel" body: "*" };
5+
}
6+
7+
----------------------------------------------------
8+
9+
[
10+
["keyword", "rpc"],
11+
["function", "LotsOfReplies"],
12+
["punctuation", "("],
13+
["class-name", "HelloRequest"],
14+
["punctuation", ")"],
15+
["keyword", "returns"],
16+
["punctuation", "("],
17+
["keyword", "stream"],
18+
["class-name", "HelloResponse"],
19+
["punctuation", ")"],
20+
["punctuation", ";"],
21+
22+
["keyword", "rpc"],
23+
["function", "BidiHello"],
24+
["punctuation", "("],
25+
["keyword", "stream"],
26+
["class-name", "HelloRequest"],
27+
["punctuation", ")"],
28+
["keyword", "returns"],
29+
["punctuation", "("],
30+
["keyword", "stream"],
31+
["class-name", "HelloResponse"],
32+
["punctuation", ")"],
33+
["punctuation", ";"],
34+
35+
["keyword", "rpc"],
36+
["function", "CancelOperation"],
37+
["punctuation", "("],
38+
["class-name", "CancelOperationRequest"],
39+
["punctuation", ")"],
40+
["keyword", "returns"],
41+
["punctuation", "("],
42+
["class-name", "google.protobuf.Empty"],
43+
["punctuation", ")"],
44+
["punctuation", "{"],
45+
["keyword", "option"],
46+
["punctuation", "("],
47+
"google",
48+
["punctuation", "."],
49+
"api",
50+
["punctuation", "."],
51+
"http",
52+
["punctuation", ")"],
53+
["operator", "="],
54+
["punctuation", "{"],
55+
" post",
56+
["punctuation", ":"],
57+
["string", "\"/v1/{name=operations/**}:cancel\""],
58+
" body",
59+
["punctuation", ":"],
60+
["string", "\"*\""],
61+
["punctuation", "}"],
62+
["punctuation", ";"],
63+
["punctuation", "}"]
64+
]
65+
66+
----------------------------------------------------
67+
68+
Check for RPC definitions.

0 commit comments

Comments
 (0)