-
Notifications
You must be signed in to change notification settings - Fork 594
/
Copy pathGit Config.sublime-syntax
238 lines (207 loc) · 7.46 KB
/
Git Config.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
%YAML 1.2
---
# Syntax based on documentation here:
# https://git-scm.com/docs/git-config#_syntax
name: Git Config
scope: text.git.config
version: 2
file_extensions:
- gitconfig # /etc/gitconfig
- .gitconfig # ~/.gitconfig
- .gitmodules # ~/.gitmodules
first_line_match: ^\[core\] # .git/config files always start with [core]
variables:
variable_name: '[a-zA-Z][\w-]*'
zero_to_255: 25[0-5]|2[0-4][0-9]|1\d\d|[1-9][0-9]|[0-9]
contexts:
prototype:
- include: Git Common.sublime-syntax#comments
main:
# We only want to match color values under these subsections:
# [color "branch"]
# [color "diff"]
# [color "interactive"]
# [color "status"]
# Note that this does not match [color] (without the subsection). This is
# because [color] doesn't actually take color values.
- match: ^\s*(?=\[\s*color\s+\")
push: [key-color-pair, section-header]
# section-other matches all sections except [color "subsection"].
- match: ^\s*(?=\[)
push: [key-value-pair, section-header]
##[ SECTION HEADERS ]##################################################
section-header:
- match: \[
scope: punctuation.definition.brackets.begin.git.config
set: [expect-line-end, section-header-end, section-name]
section-header-end:
- meta_scope: meta.brackets.git.config
- match: \]
scope: punctuation.definition.brackets.end.git.config
pop: 1
- include: illegal-line-end-pop
- match: \S
scope: invalid.illegal.header-end.git.config
section-name:
- match: '[\w-]+'
scope: entity.name.section.git.config
- match: \"
scope: punctuation.definition.string.begin.git.config
set: subsection-name-quoted
- match: \.
scope: punctuation.accessor.dot.git.config
set: subsection-name-unquoted
- match: (?=\])
pop: 1
- include: illegal-line-end-pop
- match: \S
scope: invalid.illegal.section-name.git.config
# [section "subsection"]
subsection-name-quoted:
- meta_include_prototype: false
- meta_scope: string.quoted.double.git.config
- match: \"
scope: punctuation.definition.string.end.git.config
pop: 1
- match: \\[\\"]
scope: constant.character.escape.git.config
# `\` is legal, but it can lead to confusion because escapes like `\t`
# are interpreted as `t` by the git config parser, not TAB or "\t"
# (two chars). Therefore, we discourage the use of `\`.
- match: \\
scope: invalid.unnecessary-escape.git.config
- include: illegal-line-end-pop
# [section.subsection]
subsection-name-unquoted:
- match: '[\w-]+'
scope: string.unquoted.git.config
- match: \.
scope: punctuation.accessor.dot.git.config
- match: (?=\])
pop: 1
- include: illegal-line-end-pop
- match: \S
scope: invalid.illegal.subsection-name.git.config
expect-section:
- match: (?=^\s*\[) # start of new section
pop: 1
- match: \]
scope: punctuation.definition.brackets.end.git.config invalid.illegal.stray-bracket.git.config
##[ SECTION BODY ]#####################################################
# changed = red
# untracked = bold green
key-color-pair:
- match: ^(\s*)({{variable_name}})(\s*(\=)\s*)
captures:
1: meta.mapping.git.config
2: meta.mapping.key.git.config variable.other.readwrite.git.config
3: meta.mapping.git.config
4: keyword.operator.assignment.git.config
push:
- meta_content_scope: meta.mapping.value.git.config
- include: color-value
- include: line-end
- include: expect-section
# key = val
key-value-pair:
- match: ^(\s*)({{variable_name}})(\s*(\=)\s*)
captures:
1: meta.mapping.git.config
2: meta.mapping.key.git.config variable.other.readwrite.git.config
3: meta.mapping.git.config
4: keyword.operator.assignment.git.config
push:
- meta_content_scope: meta.mapping.value.git.config
- include: other-value
- include: line-end
- include: expect-section
##[ VALUES ]###########################################################
color-value:
# example: bold, italic, underline
- match: \b(?:no-?)?(?:ul|strike|reverse|italic|dim|bold|blink)\b
scope: support.constant.color-attribute.git.config
- match: \b(?:normal|auto)\b
scope: support.constant.color.automatic.git.config
# example: red, blue, green
- match: \b(?:bright)?(?:yellow|white|red|magenta|green|cyan|blue|black)\b
scope: support.constant.color.git.config
# example: 0-255
- match: \b(?:{{zero_to_255}})\b
scope: constant.other.color.rgb-value.git.config
other-value:
- include: boolean
- include: shell-script
- include: string-quoted
- include: string-unquoted
boolean:
# 0 and 1 are omitted due to mismatches (e.g. "log -1", "HEAD~1"). They will
# be matched as unquoted strings instead.
- match: \b(?:yes|true|on|off|no|false)\b
scope: constant.language.git.config
shell-script:
- match: (\")(\!)
captures:
1: string.quoted.double.git.config punctuation.definition.string.begin.git.config
2: keyword.control.import.shell.git.config
escape: (?<!\\)\"(?=\s*(?:#.*)?$)
escape_captures:
0: meta.mapping.value.git.config string.quoted.double.git.config punctuation.definition.string.end.git.config
embed: scope:source.shell
- match: \!
scope: keyword.control.import.shell.git.config
escape: (?<!\\)\n
embed: scope:source.shell
string-quoted:
- match: \"
scope: punctuation.definition.string.begin.git.config
push:
- meta_include_prototype: false
- meta_scope: string.quoted.double.git.config
- match: \"
scope: punctuation.definition.string.end.git.config
set: expect-line-end
- include: line-continuation
- include: escape
- include: illegal-line-end # newlines only permitted after trailing \
- include: Git Common.sublime-syntax#pretty-formats-as-arg-minimal
string-unquoted:
- match: (?=\S)
push:
- meta_scope: string.unquoted.value.git.config
- include: line-continuation
- include: escape
- include: line-end
- include: Git Common.sublime-syntax#pretty-formats-as-arg-minimal
##[ PROTOTYPES ]#######################################################
# The only valid escapes: '\b', '\n', '\t', '\"', '\\'.
escape:
- match: \\[\\"bnt]
scope: constant.character.escape.git.config
- match: \\\S?
scope: invalid.illegal.escape.git.config
# 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.config
# make sure to resume parsing at next line
push:
- match: (?=\S|^\s*$)
pop: 1
line-end:
- match: $
pop: 1
expect-line-end:
- include: line-end
- match: \S
scope: invalid.illegal.expected.eol.git.config
##[ ILLEGAL ]##########################################################
illegal-line-end:
- match: $\n?
scope: invalid.illegal.unexpected.eol.git.config
illegal-line-end-pop:
- match: $\n?
scope: invalid.illegal.unexpected.eol.git.config
pop: 1