Skip to content

Commit 48cd28a

Browse files
committed
Use syntaxes from #344
1 parent 320d08a commit 48cd28a

File tree

6 files changed

+339
-384
lines changed

6 files changed

+339
-384
lines changed

package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,22 @@
136136
"Protobuf"
137137
],
138138
"configuration": "./protobuf-language-configuration.json"
139+
},
140+
{
141+
"//": "This is a special language used by the 'declaration' part of hover inlays in Markdown.",
142+
"id": "proto-decl"
139143
}
140144
],
141145
"grammars": [
142146
{
143147
"language": "proto",
144148
"scopeName": "source.proto",
145-
"path": "./syntaxes/proto.tmLanguage.json"
149+
"path": "./syntaxes/proto.json"
150+
},
151+
{
152+
"language": "proto-decl",
153+
"scopeName": "source.proto-decl",
154+
"path": "./syntaxes/proto-decl.json"
146155
}
147156
],
148157
"commands": [

syntaxes/proto-decl.json

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
{
2+
"//": [
3+
"See https://protobuf.com/docs/language-spec",
4+
"Comments in this file are stored in // keys."
5+
],
6+
"scopeName": "source.proto-decl",
7+
"patterns": [
8+
{
9+
"name": "comment.line.double-slash.proto-decl",
10+
"begin": "//",
11+
"end": "$\\N?"
12+
},
13+
{
14+
"name": "comment.line.block.proto-decl",
15+
"begin": "/\\*",
16+
"end": "\\*/"
17+
},
18+
{
19+
"name": "string.quoted.double.proto-decl",
20+
"begin": "\"",
21+
"end": "(?<!\\\\)(\\\\\\\\)*\"|$",
22+
"patterns": [
23+
{
24+
"include": "#escapes"
25+
},
26+
{
27+
"include": "#bad_escapes"
28+
}
29+
],
30+
"captures": {
31+
"1": {
32+
"name": "constant.character.escape.proto-decl"
33+
}
34+
}
35+
},
36+
{
37+
"name": "string.quoted.single.proto-decl",
38+
"begin": "'",
39+
"end": "(?<!\\\\)(\\\\\\\\)*'|$",
40+
"patterns": [
41+
{
42+
"include": "#escapes"
43+
},
44+
45+
{
46+
"include": "#bad_escapes"
47+
}
48+
],
49+
"captures": {
50+
"1": {
51+
"name": "constant.character.escape.proto-decl"
52+
}
53+
}
54+
},
55+
{
56+
"//": "Declarations that name a type",
57+
"match": "(builtin|message|group|enum|service) ((?:[^\\s]+\\.)*[^\\s]+)$",
58+
"captures": {
59+
"1": {
60+
"name": "keyword.control.proto-decl"
61+
},
62+
"2": {
63+
"name": "entity.name.type.proto-decl"
64+
}
65+
}
66+
},
67+
68+
{
69+
"//": "Declarations that name a variable",
70+
"match": "(field|extension|oneof|const) ((?:[^\\s]+\\.)(?:[^\\s]+))\\.([^\\s]+)$",
71+
"captures": {
72+
"1": {
73+
"name": "keyword.control.proto-decl"
74+
},
75+
"2": {
76+
"name": "entity.name.type.proto-decl"
77+
},
78+
"3": {
79+
"name": "variable.other.proto-decl"
80+
}
81+
}
82+
},
83+
84+
{
85+
"//": "Declarations that name a variable",
86+
"match": "(rpc) ((?:[^\\s]+\\.)(?:[^\\s]+))\\.([^\\s]+)$",
87+
"captures": {
88+
"1": {
89+
"name": "keyword.control.proto-decl"
90+
},
91+
"2": {
92+
"name": "entity.name.type.proto-decl"
93+
},
94+
"3": {
95+
"name": "entity.name.function.proto-decl"
96+
}
97+
}
98+
},
99+
{
100+
"name": "constant.numeric.proto-decl",
101+
"match": "(\\.|\\b)[0-9](\\.|([eE][-+]?)|\\w)*"
102+
},
103+
{
104+
"//": "Declarations that name a function",
105+
"match": "(rpc) ((:?[^\\s]+\\.)+)([^\\s]+)",
106+
"captures": {
107+
"1": {
108+
"name": "keyword.control.proto-decl"
109+
},
110+
"2": {
111+
"name": "entity.name.type.proto-decl"
112+
},
113+
"3": {
114+
"name": "entity.name.function.proto-decl"
115+
}
116+
}
117+
},
118+
{
119+
"name": "keyword.other.proto-decl",
120+
"match": "\\b(weak|public|group|map|extensions|reserved|stream|returns|to|optional|required|repeated)\\b"
121+
},
122+
{
123+
"name": "constant.language.proto-decl",
124+
"match": "\\b(inf|nan|true|false|max)\\b"
125+
},
126+
{
127+
"//": [
128+
"This picks up any loose identifiers/numbers that aren't otherwise highlighted.",
129+
"The pattern is VERY generous: it matches all kinds of Unicode characters."
130+
],
131+
"name": "variable.other.proto-decl",
132+
"match": "\\b\\w+\\b"
133+
}
134+
],
135+
"repository": {
136+
"escapes": {
137+
"name": "constant.character.escape.proto-decl",
138+
"//": [
139+
"This pattern will match all possible escape sequences, so they can be highlighted as such.",
140+
"They are as follows, without regex escaping applied:",
141+
"simple_escape_seq: \\[abfnrtv\\'\"?]",
142+
"hex_escape_seq: \\[xX][a-fA-F0-9]{1,2}",
143+
"octal_escape_seq: \\[0-7]{1,3}",
144+
"unicode_escape_seq: \\u[a-fA-F0-9]{4}",
145+
"unicode_escape_seq: \\U[a-fA-F0-9]{8}"
146+
],
147+
"match": "(\\\\[abfnrtv\\\\'\"\\?])|(\\\\[xX][a-fA-F0-9]{1,2})|(\\\\[0-7]{1,3})|(\\\\u[a-fA-F0-9]{4})|(\\\\U[a-fA-F0-9]{8})"
148+
},
149+
"bad_escapes": {
150+
"name": "invalid.error",
151+
"//": "This pattern picks up all invalid variants of the above. For example, this will highlight \\xxx, not just the \\x.",
152+
"match": "(\\\\[xX][^'\"\\\\]{1,2})|(\\\\u[^'\"\\\\]{1,4})|(\\\\U[^'\"\\\\]{0,8})|(\\\\.)"
153+
}
154+
}
155+
}

syntaxes/proto.json

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
{
2+
"//": [
3+
"See https://protobuf.com/docs/language-spec",
4+
"Comments in this file are stored in // keys."
5+
],
6+
"scopeName": "source.proto",
7+
"fileTypes": ["proto"],
8+
"foldingStartMarker": "(\\{|/\\*\\*?)\\s*$",
9+
"foldingStopMarker": "^\\s*(\\}|\\*/)",
10+
"patterns": [
11+
{
12+
"name": "comment.line.double-slash.proto",
13+
"begin": "//",
14+
"end": "$\\N?"
15+
},
16+
{
17+
"name": "comment.line.block.proto",
18+
"begin": "/\\*",
19+
"end": "\\*/"
20+
},
21+
{
22+
"name": "string.quoted.double.proto",
23+
"begin": "\"",
24+
"end": "(?<!\\\\)(\\\\\\\\)*\"|$",
25+
"patterns": [
26+
{
27+
"include": "#escapes"
28+
},
29+
{
30+
"include": "#bad_escapes"
31+
}
32+
],
33+
"captures": {
34+
"1": {
35+
"name": "constant.character.escape.proto"
36+
}
37+
}
38+
},
39+
{
40+
"name": "string.quoted.single.proto",
41+
"begin": "'",
42+
"end": "(?<!\\\\)(\\\\\\\\)*'|$",
43+
"patterns": [
44+
{
45+
"include": "#escapes"
46+
},
47+
{
48+
"include": "#bad_escapes"
49+
}
50+
],
51+
"captures": {
52+
"1": {
53+
"name": "constant.character.escape.proto"
54+
}
55+
}
56+
},
57+
{
58+
"name": "constant.numeric.proto",
59+
"match": "(\\b|\\.)[0-9](\\.|([eE][-+]?)|\\w)*"
60+
},
61+
{
62+
"//": "Protobuf does not have control flow, so we repurpose it for 'definition' keywords.",
63+
"name": "keyword.control.proto",
64+
"match": "\\b(syntax|edition|import|package|option|message|enum|service|extend|oneof|group|rpc)\\b"
65+
},
66+
{
67+
"name": "keyword.other.proto",
68+
"match": "\\b(weak|public|group|map|extensions|reserved|stream|returns|to|optional|required|repeated)\\b"
69+
},
70+
{
71+
"name": "constant.language.proto",
72+
"match": "\\b(inf|nan|true|false|max)\\b"
73+
}
74+
],
75+
"repository": {
76+
"escapes": {
77+
"name": "constant.character.escape.proto",
78+
"//": [
79+
"This pattern will match all possible escape sequences, so they can be highlighted as such.",
80+
"They are as follows, without regex escaping applied:",
81+
"simple_escape_seq: \\[abfnrtv\\'\"?]",
82+
"hex_escape_seq: \\[xX][a-fA-F0-9]{1,2}",
83+
"octal_escape_seq: \\[0-7]{1,3}",
84+
"unicode_escape_seq: \\u[a-fA-F0-9]{4}",
85+
"unicode_escape_seq: \\U[a-fA-F0-9]{8}"
86+
],
87+
"match": "(\\\\[abfnrtv\\\\'\"\\?])|(\\\\[xX][a-fA-F0-9]{1,2})|(\\\\[0-7]{1,3})|(\\\\u[a-fA-F0-9]{4})|(\\\\U[a-fA-F0-9]{8})"
88+
},
89+
"bad_escapes": {
90+
"name": "invalid.error",
91+
"//": "This pattern picks up all invalid variants of the above. For example, this will highlight \\xxx, not just the \\x.",
92+
"match": "(\\\\[xX][^'\"\\\\]{1,2})|(\\\\u[^'\"\\\\]{1,4})|(\\\\U[^'\"\\\\]{0,8})|(\\\\.)"
93+
}
94+
}
95+
}

syntaxes/proto.tmLanguage.LICENSE

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)