@@ -79,6 +79,15 @@ variables:
79
79
# functions and types.
80
80
ident : \b(?!{{keyword}})[[:alpha:]_][[:alnum:]_]*\b
81
81
82
+ # Directive comment key.
83
+ directive : \b[[:alpha:]_][[:alnum:]_]*\b
84
+
85
+ # Line directive comment key.
86
+ line_directive : (line) ([a-zA-Z0-9. :]*(?::[0-9]+){1,2})
87
+
88
+ # Cgo export and gccgo extern directive.
89
+ export_directive : (export|extern) ({{ident}})
90
+
82
91
# Single line only
83
92
inline_comment : /[*](?:[^*]|[*](?!/))*[*]/
84
93
@@ -118,12 +127,18 @@ contexts:
118
127
#
119
128
# //go:some_directive arg0 arg1 ...
120
129
#
130
+ # These have been adopted outside the gc compiler for use in linting
131
+ # directives and pragmas for other compiler suites where they take the
132
+ # more generalised form of:
133
+ #
134
+ # //namespace:some_directive ...
135
+ #
121
136
# They're not part of the language spec, may not be recognized by some Go
122
137
# compilers, and may stop working in future releases. Therefore,
123
138
# highlighting them as compiler pragmas could be misleading. We scope them
124
139
# as plain comments by default, and add some detailed meta scopes for
125
140
# enterprising users wishing to add more color.
126
- - match : (//)(go )(:)({{ident}})?
141
+ - match : (//)([a-z]+ )(:)({{directive}}(?:.*)){1,}
127
142
captures :
128
143
1 : punctuation.definition.comment.go
129
144
2 : meta.keyword.annotation.go
@@ -138,6 +153,54 @@ contexts:
138
153
- match : $
139
154
set : pop-line-comment
140
155
156
+ # Go also has line renumbering; line directives specify the source
157
+ # position for the character immediately following the comment as
158
+ # having come from the specified file, line and column. Both single
159
+ # line and block comment line directives are valid.
160
+ - match : (//){{line_directive}}$
161
+ captures :
162
+ 1 : punctuation.definition.comment.go
163
+ 2 : meta.keyword.annotation.go
164
+ 3 : meta.variable.function.go
165
+ push :
166
+ - meta_scope : meta.annotation.go comment.line.go
167
+ - match : \S+
168
+ scope : meta.variable.parameter.go
169
+ # End the annotation scope at EOL, but stretch the comment scope
170
+ # indefinitely to the right.
171
+ - match : $
172
+ set : pop-line-comment
173
+
174
+ - match : (/\*){{line_directive}}(\*/)
175
+ captures :
176
+ 1 : punctuation.definition.comment.go
177
+ 2 : meta.keyword.annotation.go
178
+ 3 : meta.variable.function.go
179
+ 4 : punctuation.definition.comment.go
180
+ push :
181
+ - meta_scope : meta.annotation.go comment.block.go
182
+ - match : \S+
183
+ scope : meta.variable.parameter.go
184
+ # End the annotation scope at EOL, but stretch the comment scope
185
+ # indefinitely to the right.
186
+ - match : $
187
+ set : pop-line-comment
188
+
189
+ # Finally, Cgo and gccgo have directives for exporting functions to C.
190
+ - match : (//){{export_directive}}$
191
+ captures :
192
+ 1 : punctuation.definition.comment.go
193
+ 2 : meta.keyword.annotation.go
194
+ 3 : meta.variable.function.go
195
+ push :
196
+ - meta_scope : meta.annotation.go comment.line.go
197
+ - match : \S+
198
+ scope : meta.variable.parameter.go
199
+ # End the annotation scope at EOL, but stretch the comment scope
200
+ # indefinitely to the right.
201
+ - match : $
202
+ set : pop-line-comment
203
+
141
204
# Line comment
142
205
- match : //
143
206
scope : punctuation.definition.comment.go
0 commit comments