-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathRazor.sublime-syntax
More file actions
333 lines (303 loc) · 11.4 KB
/
Razor.sublime-syntax
File metadata and controls
333 lines (303 loc) · 11.4 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
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
%YAML 1.2
---
# http://www.sublimetext.com/docs/syntax.html
name: HTML (C# Razor)
scope: text.html.cs.razor
version: 2
extends: Packages/HTML/HTML.sublime-syntax
file_extensions:
- cshtml
variables:
csharp_tag: '@{'
csharp_tag_end: '}'
csharp_tag_interpolation_paren: '@\('
csharp_tag_interpolation_bare: '@(?=\w)'
contexts:
prototype:
- meta_prepend: true
- include: comments
- include: csharp-embedded
main:
- meta_include_prototype: false
- match: ''
push: [razor, directives]
razor:
# This is the main Razor context.
# It includes `csharp-tags` which are allowed to be closed by } tags at any
# level of code-block on stack resuming with the next top-level @{ tag.
- meta_include_prototype: false
- include: csharp-tags
- include: html
comments:
- match: '@\*'
scope: punctuation.definition.comment.block.begin.cs-razor
push:
- meta_scope: comment.block.cs-razor
- match: '\*@'
scope: punctuation.definition.comment.block.end.cs-razor
pop: 1
###[ DIRECTIVES ]################################################################
directives:
- meta_include_prototype: false
- include: comments
- include: directive
- include: Packages/HTML/HTML (Plain).sublime-syntax#comment
- match: (?=\S)
pop: 1
directive:
- match: (@)(model)\b
captures:
1: punctuation.section.embedded.line.cs-razor
2: source.cs.embedded.html keyword.other.cs-razor
embed: scope:source.cs#type
embed_scope: source.cs.embedded.html
escape: $
- match: (@)(using)\b(?!\s*\()
captures:
1: punctuation.section.embedded.line.cs-razor
2: source.cs.embedded.html keyword.other.cs-razor
embed: scope:source.cs#line_of_code_in
embed_scope: source.cs.embedded.html
escape: $
###[ RAZOR CONSTRUCTS ]#######################################################
razor-constructs:
- match: (@)(section)\b(?:\s+(\w+))?
captures:
1: punctuation.section.embedded.line.cs-razor
2: source.cs.embedded.html keyword.other.cs-razor
3: entity.name.section.cs-razor
push:
- match: \{
scope: punctuation.section.block.begin.cs-razor
set:
- match: \}
scope: punctuation.section.block.end.cs-razor
pop: true
- include: razor
- match: (@)(functions)\b
captures:
1: punctuation.section.embedded.line.cs-razor
2: source.cs.embedded.html keyword.other.cs-razor
push:
- match: \{
scope: punctuation.section.block.begin.cs-razor
set:
- clear_scopes: 1
- meta_scope: source.cs.embedded.functions.cs-razor
- match: \}
scope: punctuation.section.block.end.cs-razor
pop: true
- include: Packages/HTML (C#)/Razor/C# (Razor).sublime-syntax#code_block_in
- match: \s*(?!\{)(?=\S)
scope: invalid.illegal.expected-block.cs-razor
pop: true
- match: '@@'
scope: constant.character.escape.cs-razor
- match: (@)(?=(?:if|switch|for|foreach|using|try|lock)\b)
captures:
1: punctuation.section.embedded.cs-razor
push:
- clear_scopes: 1
- meta_content_scope: source.cs.embedded.html
- include: Packages/HTML (C#)/Razor/C# (Razor).sublime-syntax#line_of_code
- match: ''
pop: true
with_prototype:
- include: razor-block-prototype
- match: '[\w-+]+@\w+' # ignore email addresses
- match: '@(?=(?:\w+\.)*\w+(?:[<\s]|$))'
scope: punctuation.section.embedded.line.cs-razor
embed: Packages/HTML (C#)/Razor/C# (Razor).sublime-syntax#line_of_code_in
embed_scope: source.cs.embedded.html
escape: $|(?=[<\s])
- match: '@(?=(?:\w+\.)*\w+\()'
scope: punctuation.section.embedded.line.cs-razor
push:
- meta_content_scope: source.cs.embedded.html
- match: (?=[<\s])
pop: true
- include: Packages/HTML (C#)/Razor/C# (Razor).sublime-syntax#line_of_code_in
- match: '@\('
scope: punctuation.section.embedded.begin.cs-razor
push:
- clear_scopes: 1
- meta_content_scope: source.cs.embedded.html
- match: \)
scope: punctuation.section.embedded.end.cs-razor
pop: true
- include: Packages/HTML (C#)/Razor/C# (Razor).sublime-syntax#line_of_code_in
#- match: '@(?=\w+(?:\.\w+)*)(?!\s*[+=|(])' # TODO: support a.b[2] etc.
# comment: property/variable access
# scope: punctuation.section.embedded.line.cs-razor
# #push: razor-block # TODO: stop at closing " etc.
- match: '@'
scope: punctuation.section.embedded.line.cs-razor
push: razor-block
razor-block-prototype:
- match: (?=[<&])
embed: scope:text.html.basic
escape: (?=[@}]|$)
- match: '@:'
scope: punctuation.section.embedded.html.cs-razor
embed: scope:text.html.basic
escape: $
eat-whitespace:
- match: (?=\S)
pop: true
razor-block:
- clear_scopes: 1
- meta_content_scope: source.cs.embedded.html
- match: (?=[<\s])
pop: true
- match: (?=\S)(?!@)
push:
- include: scope:source.cs#line_of_code
with_prototype:
- include: razor-block-prototype
###[ HTML CONTENT ]###########################################################
tag-html:
- meta_prepend: true
- include: razor-constructs
- include: csharp-interpolations
cdata-content:
- meta_prepend: true
- meta_include_prototype: false
- include: csharp-interpolations
script-javascript-content:
- meta_include_prototype: false
- match: \s*((<!\[)(CDATA)(\[))
captures:
1: meta.tag.sgml.cdata.html
2: punctuation.definition.tag.begin.html
3: keyword.declaration.cdata.html
4: punctuation.definition.tag.begin.html
pop: 1 # make sure to match only once
embed: scope:source.js.cs.razor
embed_scope: meta.tag.sgml.cdata.html source.js.embedded.html
escape: \]\]>
escape_captures:
0: meta.tag.sgml.cdata.html punctuation.definition.tag.end.html
- match: '{{script_content_begin}}'
captures:
1: comment.block.html punctuation.definition.comment.begin.html
pop: 1 # make sure to match only once
embed: scope:source.js.cs.razor
embed_scope: source.js.embedded.html
escape: '{{script_content_end}}'
escape_captures:
1: source.js.embedded.html
2: comment.block.html punctuation.definition.comment.end.html
3: source.js.embedded.html
4: comment.block.html punctuation.definition.comment.end.html
style-css-content:
- meta_include_prototype: false
- match: \s*((<!\[)(CDATA)(\[))
captures:
1: meta.tag.sgml.cdata.html
2: punctuation.definition.tag.begin.html
3: keyword.declaration.cdata.html
4: punctuation.definition.tag.begin.html
pop: 1 # make sure to match only once
embed: scope:source.css.cs.razor
embed_scope: meta.tag.sgml.cdata.html source.css.embedded.html
escape: \]\]>
escape_captures:
0: meta.tag.sgml.cdata.html punctuation.definition.tag.end.html
- match: '{{style_content_begin}}'
captures:
1: comment.block.html punctuation.definition.comment.begin.html
pop: 1 # make sure to match only once
embed: scope:source.css.cs.razor
embed_scope: source.css.embedded.html
escape: '{{style_content_end}}'
escape_captures:
1: source.css.embedded.html
2: comment.block.html punctuation.definition.comment.end.html
3: source.css.embedded.html
4: comment.block.html punctuation.definition.comment.end.html
tag-event-attribute-value:
- match: \"
scope: meta.string.html string.quoted.double.html punctuation.definition.string.begin.html
embed: scope:source.js.cs.razor
embed_scope: meta.string.html meta.interpolation.html source.js.embedded.html
escape: \"
escape_captures:
0: meta.string.html string.quoted.double.html punctuation.definition.string.end.html
- match: \'
scope: meta.string.html string.quoted.single.html punctuation.definition.string.begin.html
embed: scope:source.js.cs.razor
embed_scope: meta.string.html meta.interpolation.html source.js.embedded.html
escape: \'
escape_captures:
0: meta.string.html string.quoted.single.html punctuation.definition.string.end.html
- include: else-pop
tag-style-attribute-value:
- match: \"
scope: meta.string.html string.quoted.double.html punctuation.definition.string.begin.html
embed: scope:source.css.cs.razor#rule-list-body
embed_scope: meta.string.html meta.interpolation.html source.css.embedded.html
escape: \"
escape_captures:
0: meta.string.html string.quoted.double.html punctuation.definition.string.end.html
- match: \'
scope: meta.string.html string.quoted.single.html punctuation.definition.string.begin.html
embed: scope:source.css.cs.razor#rule-list-body
embed_scope: meta.string.html meta.interpolation.html source.css.embedded.html
escape: \'
escape_captures:
0: meta.string.html string.quoted.single.html punctuation.definition.string.end.html
- include: else-pop
tag-attribute-value-content:
- meta_prepend: true
- include: csharp-interpolations
tag-generic-attribute-value-content:
- meta_prepend: true
- include: csharp-interpolations
strings-common-content:
- meta_prepend: true
- include: csharp-interpolations
###[ C# TAGS ]###############################################################
csharp-tags:
# - include: php-tag-incomplete
- include: comments
- match: '{{csharp_tag}}'
scope: punctuation.section.embedded.begin.cs-razor
push: csharp-tag-content
csharp-tag-content:
- meta_include_prototype: false
- meta_scope: meta.embedded.cs
- meta_content_scope: source.cs.embedded.html
- match: ({{csharp_tag_end}})(\s*\n)?
captures:
1: punctuation.section.embedded.end.cs-razor
2: meta.html-newline-after-csharp.cs-razor # used by indentation rules
pop: 1
- include: Packages/HTML (C#)/Razor/C# (Razor).sublime-syntax
apply_prototype: true
csharp-interpolations:
- meta_include_prototype: false
- match: '@@'
scope: constant.character.escape.cs-razor
- match: '\B{{csharp_tag_interpolation_bare}}'
scope: punctuation.section.interpolation.begin.razor
push: Packages/HTML (C#)/Razor/embeddings/C# (for C# Razor HTML attribute).sublime-syntax#line_of_code_in
csharp-embedded:
- meta_include_prototype: false
- match: '{{csharp_tag_interpolation_bare}}'
scope: meta.embedded.cs punctuation.section.embedded.begin.cs-razor
embed: Packages/C#/C#.sublime-syntax
embed_scope: meta.embedded.cs source.cs.embedded.html
escape: ((?=")|\s*\n)?
escape_captures:
0: meta.embedded.cs
# 1: punctuation.section.embedded.end.cs-razor
1: meta.html-newline-after-csharp.cs-razor
- match: '{{csharp_tag_interpolation_paren}}'
scope: meta.embedded.cs punctuation.section.embedded.begin.cs-razor
embed: Packages/C#/C#.sublime-syntax
embed_scope: meta.embedded.cs source.cs.embedded.html
escape: (\))(\s*\n)?
escape_captures:
0: meta.embedded.cs
1: punctuation.section.embedded.end.cs-razor
2: meta.html-newline-after-csharp.cs-razor