Skip to content

Commit f7d2350

Browse files
committed
Lots of work on Directives
1 parent d4ffd30 commit f7d2350

5 files changed

Lines changed: 195 additions & 16 deletions

File tree

HTML-C#.sublime-syntax

Lines changed: 130 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,50 +13,165 @@ contexts:
1313
main:
1414
- include: html
1515

16+
directive-generic-attribute:
17+
- match: '\b(\w+)\s*(?:(=)\s*((")[^"]*("))?)?\s*'
18+
captures:
19+
1: entity.other.attribute-name.cshtml
20+
2: punctuation.separator.key-value.cshtml
21+
3: string.quoted.double.cshtml
22+
4: punctuation.definition.string.begin.cshtml
23+
5: punctuation.definition.string.end.cshtml
24+
25+
directive-end:
26+
- match: '%>'
27+
scope: punctuation.section.embedded.end.cshtml
28+
pop: true
29+
1630
directive:
17-
- match: '<%@' # https://msdn.microsoft.com/en-us/library/xz702w3e(v=vs.100).aspx
31+
# https://msdn.microsoft.com/en-us/library/xz702w3e(v=vs.100).aspx
32+
- match: '<%@'
1833
scope: punctuation.section.embedded.begin.cshtml
19-
push:
20-
- match: '\b(\w+)\s*(=)\s*((")[^"]*("))\s*'
34+
set:
35+
- meta_scope: meta.block.processing-directive.cshtml
36+
- include: directive-type
37+
- include: directive-import
38+
- include: directive-implements
39+
- include: directive-reference
40+
- include: directive-outputcache
41+
- include: directive-other
42+
# Blank directives are considered to be "Page" or "Control" by .Net
43+
- include: directive-generic-attribute
44+
- include: directive-end
45+
46+
directive-type:
47+
# https://msdn.microsoft.com/en-us/library/xz702w3e(v=vs.100).aspx
48+
- match: '\b(?i:Application|Page|Control|Master)\b'
49+
scope: constant.language.processing-directive.cshtml entity.name.class.cs
50+
set:
51+
- meta_scope: meta.block.processing-directive.contents.type.cshtml
52+
- include: directive-generic-attribute
53+
- include: directive-end
54+
55+
directive-import:
56+
# https://msdn.microsoft.com/en-us/library/eb44kack(v=vs.100).aspx
57+
- match: '\b(?i:Import)\b'
58+
scope: constant.language.processing-directive.cshtml
59+
set:
60+
- meta_scope: meta.block.processing-directive.contents.import.cshtml
61+
- match: '\b(?i:(Namespace))\s*(=)\s*((")([^"]*)("))'
2162
captures:
2263
1: entity.other.attribute-name.cshtml
2364
2: punctuation.separator.key-value.cshtml
2465
3: string.quoted.double.cshtml
2566
4: punctuation.definition.string.begin.cshtml
26-
5: punctuation.definition.string.end.cshtml
27-
- match: '\s*(Application|Page|Control|Import|Implements|Register|Assembly|OutputCache|Reference|Master|PreviousPageType|MasterType|WebHandler)\b(?:(=)"([^"]+)")?'
67+
5: meta.path.cs
68+
6: punctuation.definition.string.end.cshtml
69+
- include: directive-end
70+
71+
directive-implements:
72+
# https://msdn.microsoft.com/en-us/library/cbsf6k72(v=vs.100).aspx
73+
- match: '\b(?i:(Implements))\b'
74+
scope: constant.language.processing-directive.cshtml
75+
set:
76+
- meta_scope: meta.block.processing-directive.contents.implements.cshtml
77+
- match: '\b(?i:(Interface))\s*(=)\s*((")([^"]*)("))'
2878
captures:
29-
1: constant.language.processing-directive.cshtml
79+
1: entity.other.attribute-name.cshtml
3080
2: punctuation.separator.key-value.cshtml
3181
3: string.quoted.double.cshtml
32-
- match: '%>'
33-
scope: punctuation.section.embedded.end.cshtml
34-
pop: true
82+
4: punctuation.definition.string.begin.cshtml
83+
5: entity.other.inherited-class.cs
84+
6: punctuation.definition.string.end.cshtml
85+
- include: directive-end
86+
87+
directive-reference:
88+
# https://msdn.microsoft.com/en-us/library/w70c655a(v=vs.100).aspx
89+
- match: '\b(?i:(Reference))\b'
90+
scope: constant.language.processing-directive.reference.cshtml
91+
set:
92+
- meta_scope: meta.block.processing-directive.contents.reference.cshtml
93+
- match: '\b(?i:(Page|Control|VirtualPath))\s*(=)\s*((")([^"]*)("))'
94+
captures:
95+
1: entity.other.attribute-name.cshtml
96+
2: punctuation.separator.key-value.cshtml
97+
3: string.quoted.double.cshtml
98+
4: punctuation.definition.string.begin.cshtml
99+
5: meta.path.cs
100+
6: punctuation.definition.string.end.cshtml
101+
- include: directive-end
102+
103+
directive-outputcache:
104+
# https://msdn.microsoft.com/en-us/library/hdxfb6cy(v=vs.100).aspx
105+
- match: '\b(?i:(OutputCache))\b'
106+
scope: constant.language.processing-directive.caching.cshtml
107+
set:
108+
- meta_scope: meta.block.processing-directive.contents.outputcache.cshtml
109+
- match: '\b(?i:(Duration))\s*(=)\s*((")(?:(\d+)|[^"]*)("))'
110+
captures:
111+
1: entity.other.attribute-name.cshtml
112+
2: punctuation.separator.key-value.cshtml
113+
3: string.quoted.double.cshtml
114+
4: punctuation.definition.string.begin.cshtml
115+
5: constant.numeric.integer.cshtml
116+
6: punctuation.definition.string.end.cshtml
117+
- match: '\b(?i:(NoStore|Shared))\s*(=)\s*((")(?i:(true|false)|[^"]*)("))'
118+
captures:
119+
1: entity.other.attribute-name.cshtml
120+
2: punctuation.separator.key-value.cshtml
121+
3: string.quoted.double.cshtml
122+
4: punctuation.definition.string.begin.cshtml
123+
5: constant.language.boolean.cshtml
124+
6: punctuation.definition.string.end.cshtml
125+
- match: '\b(?i:(Location))\s*(=)\s*((")(?i:(Any|Client|Downstream|Server|None|ServerAndClient)|[^"]*)("))'
126+
captures:
127+
1: entity.other.attribute-name.cshtml
128+
2: punctuation.separator.key-value.cshtml
129+
3: string.quoted.double.cshtml
130+
4: punctuation.definition.string.begin.cshtml
131+
5: meta.enum.cache-location.cshtml
132+
6: punctuation.definition.string.end.cshtml
133+
- match: '\b(?i:(CacheProfile|SqlDependency|ProviderName|VaryBy(?:Control|Custom|Header|Param|ContentEncoding)))\s*(=)\s*((")([^"]*)("))'
134+
captures:
135+
1: entity.other.attribute-name.cshtml
136+
2: punctuation.separator.key-value.cshtml
137+
3: string.quoted.double.cshtml
138+
4: punctuation.definition.string.begin.cshtml
139+
5: meta.path.cs
140+
6: punctuation.definition.string.end.cshtml
141+
- include: directive-end
142+
143+
directive-other:
144+
# https://msdn.microsoft.com/en-us/library/xz702w3e(v=vs.100).aspx
145+
- match: '\b(Register|Assembly|PreviousPageType|MasterType)\b'
146+
scope: constant.language.processing-directive.cshtml
147+
set:
148+
- include: directive-generic-attribute
149+
- include: directive-end
35150
36151
html:
37152
- match: ''
38153
set: scope:text.html.basic
39154
with_prototype:
40155
- include: comments
41-
- include: script_tag_cs
156+
- include: script-tag-cs
42157
- include: directive
43-
- include: block_cs
158+
- include: block-cs
44159
45-
block_cs:
160+
block-cs:
46161
- match: '<%[=#:$]?'
47162
scope: punctuation.section.embedded.begin.cshtml
48-
embed: inside_block_cs
163+
embed: inside-block-cs
49164
embed_scope: source.cs.embedded.html
50165
escape: '%>'
51166
escape_captures:
52167
0: punctuation.section.embedded.end.cshtml
53168

54-
inside_block_cs:
169+
inside-block-cs:
55170
- match: '}'
56171
scope: punctuation.section.block.end.cs
57172
- include: scope:source.cs
58173

59-
script_tag_cs:
174+
script-tag-cs:
60175
- match: (?i)(<)(script)[^>]+(runat)(=)(?:((')server('))|((")server(")))
61176
captures:
62177
1: punctuation.definition.tag.begin.html
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
// https://msdn.microsoft.com/en-us/library/hdxfb6cy(v=vs.100).aspx
3+
"scope": "text.html.cshtml meta.block.processing-directive.contents.outputcache",
4+
"completions": [
5+
{ "trigger": "Duration\tOutputCache", "contents": "Duration=\"${1:120}\" " },
6+
{ "trigger": "Location\tOutputCache", "contents": "Location=\"${1:Any | Client | Downstream | Server | None | ServerAndClient}\" " },
7+
{ "trigger": "Shared\tOutputCache", "contents": "Shared=\"${1:true}\" " },
8+
{ "trigger": "VaryByControl\tOutputCache", "contents": "VaryByControl=\"${1:ControlName}\" " },
9+
{ "trigger": "VaryByCustom\tOutputCache", "contents": "VaryByCustom=\"${1:Method}\" " },
10+
{ "trigger": "VaryByHeader\tOutputCache", "contents": "VaryByHeader=\"${1:Header1${2:;Header2}}\" " },
11+
{ "trigger": "VaryByParam\tOutputCache", "contents": "VaryByParam=\"${1:Param1${2:;Param2}}\" " },
12+
{ "trigger": "VaryByContentEncoding\tOutputCache", "contents": "VaryByContentEncoding=\"${1:Encoding}\" " },
13+
{ "trigger": "CacheProfile\tOutputCache", "contents": "CacheProfile=\"${1:CacheProfileName}\" " },
14+
{ "trigger": "NoStore\tOutputCache", "contents": "NoStore=\"${1:true}\" " },
15+
{ "trigger": "SqlDependency\tOutputCache", "contents": "SqlDependency=\"${1:${2:DatabaseName}:${2:TableName}\" " },
16+
{ "trigger": "ProviderName\tOutputCache", "contents": "ProviderName=\"${1:ProviderName}\" " },
17+
]
18+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
// https://msdn.microsoft.com/en-us/library/xz702w3e(v=vs.100).aspx
3+
"scope": "text.html.cshtml meta.block.processing-directive - meta.block.processing-directive.contents",
4+
"completions": [
5+
{ "trigger": "Application\tDirective", "contents": "Application" },
6+
{ "trigger": "Page\tDirective", "contents": "Page" },
7+
{ "trigger": "Control\tDirective", "contents": "Control" },
8+
{ "trigger": "Import\tDirective", "contents": "Import Namespace=\"${1:System.Net}\" " },
9+
{ "trigger": "Implements\tDirective", "contents": "Implements Interface=\"${1:IFoo}\" " },
10+
{ "trigger": "Register\tDirective", "contents": "Register" },
11+
{ "trigger": "Assembly\tDirective", "contents": "Assembly" },
12+
{ "trigger": "OutputCache\tDirective", "contents": "OutputCache Duration=\"${1:120}\" " },
13+
{ "trigger": "Reference\tDirective", "contents": "Reference" },
14+
{ "trigger": "Master\tDirective", "contents": "Master" },
15+
{ "trigger": "PreviousPageType\tDirective", "contents": "PreviousPageType" },
16+
{ "trigger": "MasterType\tDirective", "contents": "MasterType" },
17+
// { "trigger": "WebHandler\tDirective", "contents": "WebHandler" },
18+
]
19+
}
Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<%@ Page Debug="true" Title="" AutoEventWireup="true" Inherits="System.Web.UI.Page" %>
44
// <- punctuation.section.embedded.begin.cshtml
5-
// ^^^^ constant.language.processing-directive.cshtml
5+
// ^^^^ constant.language.processing-directive.cshtml entity.name.class.cs
66
// ^^^^^ entity.other.attribute-name.cshtml
77
// ^ punctuation.separator.key-value.cshtml
88
// ^^^^^^ string.quoted.double.cshtml
@@ -13,12 +13,39 @@
1313
// ^^ string.quoted.double.cshtml
1414
// ^ punctuation.definition.string.begin.cshtml
1515
// ^ punctuation.definition.string.end.cshtml
16+
17+
<%@ Import Namespace="System.Net" %>
18+
// <- punctuation.section.embedded.begin.cshtml
19+
// ^^^^^^ constant.language.processing-directive.cshtml
20+
// ^^^^^^^^^ entity.other.attribute-name.cshtml
21+
// ^ punctuation.separator.key-value.cshtml
22+
// ^^^^^^^^^^^^ string.quoted.double.cshtml
23+
// ^ punctuation.definition.string.begin.cshtml
24+
// ^^^^^^^^^^ meta.path.cs
25+
// ^ punctuation.definition.string.end.cshtml
26+
// ^^ punctuation.section.embedded.end.cshtml
27+
1628
<%@ Register TagPrefix="my" Namespace="Foo.Bar" Assembly="Solution.LinkLibrary" %>
1729
// <- punctuation.section.embedded.begin.cshtml
1830
// ^^^^^^^^ constant.language.processing-directive.cshtml
1931
// ^^^^^^^^ entity.other.attribute-name.cshtml - constant.language.processing-directive.cshtml
2032
// ^^^^ string.quoted.double.cshtml
2133

34+
<%@ Implements Interface="IFooPage" %>
35+
// ^^^^^^^^^^ constant.language.processing-directive.cshtml
36+
// ^^^^^^^^^ entity.other.attribute-name.cshtml
37+
// ^^^^^^^^ entity.other.inherited-class.cs
38+
39+
<%@ OutputCache Duration="120" VaryByControl="ControlName" NoStore="true" %>
40+
// ^^^^^^^^^^^ constant.language.processing-directive.caching.cshtml
41+
// ^^^^^^^^ entity.other.attribute-name.cshtml
42+
// ^^^ constant.numeric.integer.cshtml
43+
// ^^^^ constant.language.boolean.cshtml
44+
45+
<%@ Foo="bar" %>
46+
// ^^^ entity.other.attribute-name.cshtml
47+
// ^^^ string.quoted.double.cshtml
48+
2249
<script runat="server" language="C#">
2350
// ^^^^ entity.name.tag.script.html - source.cs.embedded.html
2451
// ^^^^^ constant.language.processing-directive.cshtml

0 commit comments

Comments
 (0)