forked from sublimehq/Packages
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Git Common.sublime-syntax
404 lines (364 loc) · 14.1 KB
/
Git Common.sublime-syntax
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
%YAML 1.2
---
# This file is some kind of internal library which is used to store
# common rules which are used by the visible syntax files.
name: Git Common
scope: text.git.common
version: 2
hidden: true
variables:
comment_char: '[#;]'
hash: \b\h{7,}\b
repository_ref: |-
(?x:
[\w-]+ (/) [\w-]+ # user / repo
| [\w-]{2,} # user with a heuristic to exclude C#7, F#7, ...
)
pretty_formats_builtins: oneline|short|medium|fuller|full|email|raw|reference
pretty_formats_empty_value_modifiers: '[-+ ]?'
contexts:
main:
- include: references
##[ PROTOTYPES ]#######################################################
# Trailing slashes can be used to break up long lines. '\' is only legal at
# the end of a line, or in an escape such as '\"'. Anywhere else it will cause
# a fatal parser error. Comments are not permitted after a trailing slash.
line-continuation:
- match: (\\)\s*$\n?
captures:
1: punctuation.separator.continuation.line.git
# make sure to resume parsing at next line
push:
- match: (?=\S|^\s*$)
pop: 1
eol-pop:
- include: line-continuation
- match: $
pop: 1
illegal-eol-pop:
- include: line-continuation
- match: $\n?
scope: invalid.illegal.unexpected.eol.git
pop: 1
##[ COMMENTS ]#########################################################
comments:
# comment which may start in the middle of a line
- match: ({{comment_char}}).*\n?
scope: comment.line.git
captures:
1: punctuation.definition.comment.git
comments-line:
# comment which must start at the beginning of a line
- match: ^\s*({{comment_char}}).*\n?
scope: comment.line.git
captures:
1: punctuation.definition.comment.git
##[ REFERENCES ]#######################################################
references:
# all github references
- include: issue
- include: email
- include: username
- include: commit
- include: urls
issue:
# issue reference
# https://help.github.com/articles/closing-issues-using-keywords
- match: |-
(?x)
# optional closing keyword
(?i:
( (?:close|fixe|resolve)[ds]? | fix ) # keyword
\s* (:)? \s* # optional colon separator
)? # keyword is optional
# user/repo#issue
(
(?: {{repository_ref}} | \B )
(\#)[0-9]+ # issue number
)\b
scope: meta.reference.issue.git
captures:
1: keyword.other.resolved-issue.git
2: punctuation.separator.key-value.resolved-issue.git
3: constant.other.reference.issue.git
4: punctuation.separator.reference.issue.git # (inside repository_ref)
5: punctuation.definition.reference.issue.git
email:
# email reference
- match: <(?=\S+?@\S+?\.\S+?>)
scope: punctuation.definition.reference.email.begin.git
push: [email-meta, email-name]
email-meta:
- meta_include_prototype: false
- meta_scope: meta.reference.email.git
- match: ''
pop: 1
email-name:
- meta_content_scope: entity.name.reference.email.git
- match: '@'
scope: entity.name.reference.email.git punctuation.separator.email.git
set: email-domain
- include: email-end
email-domain:
- meta_content_scope: entity.name.reference.email.git
- match: \.
scope: punctuation.separator.domain.git
- include: email-end
email-end:
- match: '>'
scope: punctuation.definition.reference.email.end.git
pop: 1
- match: (?=\s)
pop: 1
username:
# user reference
- match: (\@)[-\w]+\b
scope: meta.reference.username.git entity.name.reference.username.git
captures:
1: punctuation.definition.reference.username.git
commit:
- match: (?:{{repository_ref}}(@))?{{hash}}
scope: constant.other.hash.git
captures:
1: punctuation.separator.reference.commit.git # (inside repository_ref)
2: punctuation.separator.reference.commit.git
urls:
- match: |-
(?x)
\b(?:
https?://(?:(?:[\w\d\-]+(?:\.[\w\d\-.]+)+)|localhost) # http://
| www\.[\w\d\-]+(?:\.[\w\d\-.]+)+ # www.
)
/?[\w\d\-.?,!'(){}\[\]/+&@%$#=:"|~;]* # url path and query string
[\w\d\-~:/#@$*+=] # allowed end chars
scope: markup.underline.link.git
##[ FNMATCH ]##########################################################
# The first characters of a path pattern may have special meaning and
# must therefore be treated differently. This scope finally pops off
# if no more match is found. It must therefore be used as multi-push.
fnmatch-start:
# windows drive letter and separator
- match: '[A-Za-z](:)(?=/)'
captures:
1: punctuation.separator.drive.fnmatch.git
pop: 1
# homedir tilde operator
- match: ~(?=/)
scope: variable.language.environment.home.fnmatch.git
pop: 1
# any other directory pattern
- include: fnmatch-dir-pattern
# In order to use fnmatch by other syntaxes, it is importand to use
# fnmatch-body as include in a scope, which defines the desired meta
# and the required bail-out scopes as they might be different and
# therefore are not part of the following section.
fnmatch-body:
- include: fnmatch-char-classes
- include: fnmatch-common
fnmatch-common:
- match: '/' # path separators
scope: punctuation.separator.path.fnmatch.git
push: fnmatch-dir-pattern
- match: \.(?!.*[./]) # the last dot not followed by path sep
scope: punctuation.separator.path.extension.fnmatch.git
- match: '[*?]' # unescapable operators
scope: keyword.operator.path.asterisk.fnmatch.git
- match: '\\[^$*?]' # backslash escapes nearly everything
scope: constant.character.escape.path.fnmatch.git
- match: \$\w+
scope: variable.language.environment.other.fnmatch.git
- match: ':' # drive separators
scope: invalid.illegal.separator.drive.fnmatch.git
- match: '\\(?=\s)' # single backslash is invalid
scope: invalid.illegal.escape.path.fnmatch.git
fnmatch-dir-pattern:
- match: \.\.(?=/)
scope: constant.language.path.parent.fnmatch.git
pop: 1
- match: \.(?=/)
scope: constant.language.path.self.fnmatch.git
pop: 1
- match: ''
pop: 1
fnmatch-char-classes:
- match: \[ # shell style character class
scope: keyword.control.char-class.begin.fnmatch.git
push:
- fnmatch-char-class-body
- fnmatch-char-class-start
- fnmatch-char-class-operator
fnmatch-char-class-operator:
- match: '[!^]?' # optional pattern negation
scope: keyword.operator.logical.fnmatch.git
pop: 1
fnmatch-char-class-start:
- match: \]? # first unescaped ']' is matched as normal char
scope: constant.character.char-class.fnmatch.git
pop: 1
fnmatch-char-class-body:
- meta_scope: meta.char-class.fnmatch.git
- match: \]
scope: keyword.control.char-class.end.fnmatch.git
pop: 1
- match: $\n? # class must end before end of line
scope: invalid.illegal.unexpected.eol.fnmatch.git
pop: 1
- match: '\\\]' # backslash escapes only ']'
scope: constant.character.escape.char-class.fnmatch.git
- match: '[*?]' # asterisk is ignored by fnmatch
scope: invalid.illegal.unexpected.char-class.fnmatch.git
- match: \S
scope: constant.character.char-class.fnmatch.git
##[ PRETTY FORMATS ]###################################################
# https://git-scm.com/docs/pretty-formats
# Link this from contexts where command line options are highlighted
pretty-formats-as-arg:
- match: (--)(pretty|format)(=)({{pretty_formats_builtins}})?(?:(t?format)(:))?
captures:
1: punctuation.definition.parameter.shell
2: variable.parameter.option.shell
3: keyword.operator.assignment.option.shell
4: constant.language.pretty-formats.git
5: keyword.declaration.pretty-formats.git
6: keyword.operator.assignment.option.pretty-formats.git
push: include-pretty-formats
# Link this from contexts where command line options are not highlighted
pretty-formats-as-arg-minimal:
- match: (--)(pretty|format)(=)({{pretty_formats_builtins}})?(?:(t?format)(:))?
captures:
# 1: punctuation.definition.parameter.shell
# 2: variable.parameter.option.shell
# 3: keyword.operator.assignment.option.shell
4: constant.language.pretty-formats.git
5: keyword.declaration.pretty-formats.git
6: keyword.operator.assignment.option.pretty-formats.git
push: include-pretty-formats
include-pretty-formats:
- meta_content_scope: meta.pretty-formats.git
- match: (?!\S)
pop: 1
- match: (\')(?:(t?format)(:))?
captures:
1: punctuation.definition.string.begin.shell
2: keyword.declaration.pretty-formats.git
3: keyword.operator.assignment.option.pretty-formats.git
push:
- meta_scope: string.quoted.single.shell
- match: \'
scope: punctuation.definition.string.end.shell
pop: 1
- include: illegal-eol-pop
- include: pretty-formats
- match: \"(?:(t?format)(:))?
captures:
1: punctuation.definition.string.begin.shell
2: keyword.declaration.pretty-formats.git
3: keyword.operator.assignment.option.pretty-formats.git
push:
- meta_scope: string.quoted.double.shell
- match: \"
scope: punctuation.definition.string.end.shell
pop: 1
- include: illegal-eol-pop
- include: pretty-formats
- include: pretty-formats
pretty-formats:
- match: '%%'
scope: constant.character.escape.pretty-formats.git
- match: '%x\d\d'
scope: constant.character.byte.pretty-formats.git
- match: |
(?x)
%{{pretty_formats_empty_value_modifiers}}
(?:
[HhTtPpdDesSfbBNmn]| # single-char
[ac][nNeElLdDsrtiI]| # author and committer
G[G?DKFP]| # GPG
g[dnNeEs] # reflog
)
scope: constant.other.placeholder.pretty-formats.git
- include: pretty-formats-colors
- include: pretty-formats-wrap-formatting
- include: pretty-formats-string-formatting
- include: pretty-formats-trailers
pretty-formats-wrap-formatting:
- match: '(%{{pretty_formats_empty_value_modifiers}}w)(\()'
captures:
1: meta.function-call.pretty-formats.git variable.function.pretty-formats.git
2: meta.function-call.arguments.pretty-formats.git punctuation.section.parens.begin.pretty-formats.git
push:
- meta_content_scope: meta.function-call.arguments.pretty-formats.git
- match: '\)'
scope: meta.function-call.arguments.pretty-formats.git punctuation.section.parens.end.pretty-formats.git
pop: 1
- match: \d+
scope: meta.number.integer.decimal.git constant.numeric.value.git
- match: ',,'
scope: invalid.illegal.pretty-formats.git
- match: ','
scope: punctuation.separator.parameters.pretty-formats.git
- match: \S
scope: invalid.illegal.pretty-formats.git
pretty-formats-string-formatting:
- match: |
(?x)
(%{{pretty_formats_empty_value_modifiers}}
(?:<\|?|>>?\|?|><\|?) # alignment directions
)
((\()
(\d+) # space reserved
(?:(,)([lm]?trunc))? # truncation directions
(\)))
captures:
1: meta.function-call.pretty-formats.git variable.function.pretty-formats.git
2: meta.function-call.arguments.pretty-formats.git
3: punctuation.section.parens.begin.pretty-formats.git
4: meta.number.integer.decimal.git constant.numeric.value.git
5: punctuation.separator.parameters.pretty-formats.git
6: support.constant.truncation.pretty-formats.git
7: punctuation.section.parens.end.pretty-formats.git
pretty-formats-colors:
- match: '(%{{pretty_formats_empty_value_modifiers}}C)((red|green|blue)|(reset))'
captures:
1: meta.function-call.pretty-formats.git variable.function.pretty-formats.git
2: meta.function-call.arguments.pretty-formats.git
3: support.constant.color.git.config
4: support.constant.color-reset.git.config
- match: '(%{{pretty_formats_empty_value_modifiers}}C)(\()'
captures:
1: meta.function-call.pretty-formats.git variable.function.pretty-formats.git
2: meta.function-call.arguments.pretty-formats.git punctuation.section.parens.begin.pretty-formats.git
push:
- meta_content_scope: meta.function-call.arguments.pretty-formats.git
- match: \)
scope: meta.function-call.arguments.pretty-formats.git punctuation.section.parens.end.pretty-formats.git
pop: 1
- include: Git Config.sublime-syntax#color-value
- match: reset
scope: support.constant.color-reset.git.config
pretty-formats-trailers:
- match: '(%\()(trailers)'
captures:
1: punctuation.section.parens.begin.pretty-formats.git
2: keyword.other.trailers.pretty-formats.git
push:
- meta_scope: meta.trailers.pretty-formats.git
- include: illegal-eol-pop
- match: \)
scope: punctuation.section.parens.end.pretty-formats.git
pop: 1
- match: ':'
scope: keyword.operator.assignment.option.pretty-formats.git
push:
- include: eol-pop
- match: (?=\))
pop: 1
- match: ',,|:'
scope: invalid.illegal.pretty-formats.git
- match: ','
scope: punctuation.separator.parameters.pretty-formats.git
# Unclear from https://git-scm.com/docs/git-interpret-trailers what other values are valid here
- match: \b(only|unfold)\b
scope: support.constant.trailer.git.config
- match: \b\w+\b
scope: constant.other.trailer.pretty-formats.git