-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathProtobufText.sublime-syntax
More file actions
187 lines (173 loc) · 5.49 KB
/
ProtobufText.sublime-syntax
File metadata and controls
187 lines (173 loc) · 5.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
%YAML 1.2
---
# Syntax for Protocol Buffer serialized as human readable text.
# Works with proto2 and proto3.
# See official Protobuff documentation at https://developers.google.com/protocol-buffers/docs/proto3
#
# Author: Raul Rangel & Guillaume Wenzek
#
# .sublime-syntax reference: http://www.sublimetext.com/docs/3/syntax.html
name: Protocol Buffer (TEXT)
file_extensions:
- pb.txt
- proto.text
- textpb
- pbtxt
- prototxt
- textproto
scope: text.prototxt
variables:
stringEscape: '(?:\\(?:[''"\\/abfnrtv?]|[0-9]{3}|(?i:u|x)[0-9A-Fa-f]+))'
field_name: '\b([A-Za-z][A-Za-z0-9_]*)\b'
integer: '(?:\+|-)?(?:0|[1-9]\d*)'
exp: '(?i:e(?:\+|-)?{{integer}})'
contexts:
prototype:
- include: comments
or_pop:
# Pop if nothing matched (whitespace are ignored).
- match: '(?=\S)'
pop: true
main:
- include: field
comments:
- match: '#'
scope: punctuation.definition.comment.begin.prototxt
push:
- meta_scope: comment.line.prototxt
- match: $\n?
pop: true
field:
- match: '{{field_name}}'
scope: variable.other.member.prototxt
push: field_sep_or_pop
- match: \[
scope: punctuation.definition.field_name.begin.prototxt
push:
- match: \]
set: field_sep_or_pop
scope: punctuation.definition.field_name.end.prototxt
- match: '{{field_name}}(\.)'
captures:
1: variable.other.namespace.prototxt
2: punctuation.accessor.prototxt
- match: '{{field_name}}'
scope: variable.other.member.prototxt
field_sep_or_pop:
- match: '(:)|(?=\{|<)'
scope: punctuation.separator.key-value.prototxt
set: [comma_or_pop, field_value_or_pop]
- include: or_pop
field_value_or_pop:
- match: '{'
scope: punctuation.definition.dictionary.begin.prototxt
set:
- meta_scope: meta.message.prototxt
- match: '}'
scope: punctuation.definition.dictionary.end.prototxt
pop: true
- include: field
- match: '<'
scope: punctuation.definition.dictionary.begin.prototxt
set:
- meta_scope: meta.message.prototxt
- match: '>'
scope: punctuation.definition.dictionary.end.prototxt
pop: true
- include: field
- include: constant
- include: string_double_multiline
- include: string_single_multiline
- include: enum_value
- include: number
- include: array
- include: or_pop
array:
- match: '\['
scope: punctuation.definition.array.begin.prototxt
set:
- match: '\]'
scope: punctuation.definition.array.end.prototxt
pop: true
- match: \,
scope: punctuation.separator.array.prototxt
- match: (?=\S)
push: field_value_or_pop
comma_or_pop:
- match: ','
scope: punctuation.separator.prototxt
pop: true
- include: or_pop
constant:
- match: \b(true|True|t|false|False|f)\b
scope: constant.language.prototxt
pop: true
- match: (\+|-)?\b(?i:inf|infinity)\b
scope: constant.language.prototxt
pop: true
- match: \b(?i:nan)\b
scope: constant.language.prototxt
pop: true
number:
- match: |-
(?xi:
{{integer}}?\.\d+{{exp}}?(f?) # literal with a dot: .3 .3e+4 1.3 1.3f
|{{integer}}(f) # literal with a 'f': 1f
|{{integer}}{{exp}}(f?) # literal with an exp: .3e+4 1e-3 1e3f
)\b
scope: constant.numeric.float.prototxt
captures:
1: punctuation.definition.numeric.float.prototxt
2: punctuation.definition.numeric.float.prototxt
3: punctuation.definition.numeric.float.prototxt
pop: true
- match: '{{integer}}\b'
scope: constant.numeric.integer.prototxt
pop: true
- match: '(0)[0-8]+\b'
scope: constant.numeric.octal.prototxt
captures:
1: punctuation.definition.numeric.octal.prototxt
pop: true
- match: '(0[xX])[0-9A-Fa-f]+\b'
scope: constant.numeric.hex.prototxt
captures:
1: punctuation.definition.numeric.hex.prototxt
pop: true
enum_value:
- match: '{{field_name}}'
scope: constant.numeric.enum.prototxt
pop: true
string_double_multiline:
- match: '"'
scope: punctuation.definition.string.begin.prototxt
set:
- meta_scope: string.quoted.double.prototxt
- meta_include_prototype: false
- match: '{{stringEscape}}'
scope: constant.character.escape.prototxt
- match: \\.
scope: invalid.illegal.unrecognized-string-escape.prototxt
- match: '"'
scope: punctuation.definition.string.end.prototxt
set:
- include: string_double_multiline
- include: or_pop
string_single_multiline:
- match: "'"
scope: punctuation.definition.string.quoted.single.begin.prototxt
set:
- meta_scope: string.quoted.single.prototxt
- meta_include_prototype: false
# Note that technically "bytes" field main don't respect escapes,
# but there is no way to know if the given string will be interpreted as
# "bytes".
- match: '{{stringEscape}}'
scope: constant.character.escape.prototxt
- match: \\.
scope: invalid.illegal.unrecognized-string-escape.prototxt
- match: "'"
scope: punctuation.definition.string.quoted.single.end.prototxt
set:
- include: string_single_multiline
- include: or_pop