Skip to content

Commit c4b612d

Browse files
committed
Fix a problem with Razor less-than signs
Also add `do` to recognized blocks
1 parent f2b9634 commit c4b612d

2 files changed

Lines changed: 114 additions & 11 deletions

File tree

Razor/Razor.sublime-syntax

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ contexts:
105105
pop: true
106106
- match: '@@'
107107
scope: constant.character.escape.cs-razor
108-
- match: (@)(?=(?:if|switch|for|foreach|using|try|lock)\b)
108+
- match: (@)(?=(?:if|switch|for|foreach|using|try|lock|do)\b)
109109
captures:
110110
1: punctuation.section.embedded.cs-razor
111111
push:
@@ -147,13 +147,15 @@ contexts:
147147
push: razor-block
148148

149149
razor-block-prototype:
150-
- match: (?=[<&])
151-
embed: scope:text.html.basic
150+
- match: (?=&\w{1,8};|<[\w/!])
151+
embed: razor
152152
escape: (?=[@}]|$)
153153
- match: '@:'
154154
scope: punctuation.section.embedded.html.cs-razor
155155
embed: scope:text.html.basic
156156
escape: $
157+
- match: '@'
158+
scope: punctuation.section.embedded.line.cs-razor
157159

158160
eat-whitespace:
159161
- match: (?=\S)

Razor/tests/syntax_test_cshtml.cshtml

Lines changed: 109 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,17 @@
8282
<!-- ^^^^^^^^^^^^^^^^^^^^^^^ source.cs string.quoted.double - text.html -->
8383
<!-- ^ punctuation.section.embedded.end -->
8484
@Html.Raw("<span>Hello World</span>")
85-
<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call -->
86-
<!-- ^^^ variable.function -->
87-
<!-- <- punctuation.section.embedded.line -->
88-
<!-- ^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double -->
89-
<!-- ^ punctuation.section.group.end -->
85+
<!--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.cs.embedded.html -->
86+
<!--^ variable.language.this.razor -->
87+
<!-- ^ punctuation.accessor.dot.cs -->
88+
<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call.cs -->
89+
<!-- ^^^ variable.function.cs -->
90+
<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.cs -->
91+
<!-- ^ punctuation.section.group.begin.cs -->
92+
<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.cs string.quoted.double.cs -->
93+
<!-- ^ punctuation.definition.string.begin.cs -->
94+
<!-- ^ punctuation.definition.string.end.cs -->
95+
<!-- ^ punctuation.section.group.end.cs -->
9096

9197
@if (value % 2 == 0)
9298
<!-- ^ punctuation.section.embedded - source.cs -->
@@ -125,19 +131,103 @@ else
125131
<!-- ^^^^^ keyword.control.flow.break -->
126132
}
127133

128-
@*
134+
@do {
135+
<!--^^ meta.block.cs -->
136+
<!--^ punctuation.section.block.begin.cs -->
137+
<p>@foo</p>
138+
<!--^^^^^^^^^^^^ meta.block.cs -->
139+
<!--^^^ meta.tag.block.any.html -->
140+
<!--^ punctuation.definition.tag.begin.html -->
141+
<!-- ^ entity.name.tag.block.any.html -->
142+
<!-- ^ punctuation.definition.tag.end.html -->
143+
<!-- ^ punctuation.section.embedded.line.cs-razor -->
144+
<!-- ^^^ variable.other.cs -->
145+
<!-- ^^^^ meta.tag.block.any.html -->
146+
<!-- ^^ punctuation.definition.tag.begin.html -->
147+
<!-- ^ entity.name.tag.block.any.html -->
148+
<!-- ^ punctuation.definition.tag.end.html -->
149+
}
150+
while (foo <= 5)
151+
<!--^ keyword.control.loop.while.cs -->
152+
<!-- ^^^^^^^^^^ meta.group.cs -->
153+
<!-- ^ punctuation.section.group.begin.cs -->
154+
<!-- ^^^ variable.other.cs -->
155+
<!-- ^^ keyword.operator.comparison.cs -->
156+
<!-- ^ meta.number.integer.decimal.cs constant.numeric.value.cs -->
157+
<!-- ^ punctuation.section.group.end.cs -->
158+
159+
160+
<!-- TODO: Start the meta.group at the right place -->
129161
@for (var i = 0; i < people.Length; i++)
130-
<!-- <- comment.block - punctuation -->
162+
<!-- ^ punctuation.section.group.begin.cs -->
163+
<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.cs -->
164+
<!-- ^^^ storage.type.variable.cs -->
165+
<!-- ^ variable.other.cs -->
166+
<!-- ^ keyword.operator.assignment.cs -->
167+
<!-- ^ meta.number.integer.decimal.cs constant.numeric.value.cs -->
168+
<!-- ^ punctuation.terminator.statement.cs -->
169+
<!-- ^ variable.other.cs -->
170+
<!-- ^ keyword.operator.comparison.cs -->
171+
<!-- ^^^^^^ variable.other.cs -->
172+
<!-- ^ punctuation.accessor.dot.cs -->
173+
<!-- ^^^^^^ variable.other.cs -->
174+
<!-- ^ punctuation.terminator.statement.cs -->
175+
<!-- ^ variable.other.cs -->
176+
<!-- ^^ keyword.operator.arithmetic.cs -->
177+
<!-- ^ punctuation.section.group.end.cs -->
131178
{
132179
var person = people[i];
180+
<!--^^^^^^^^^^^^^^^^^^^^^^^^ meta.block.cs -->
181+
<!--^^^ storage.type.variable.cs -->
182+
<!-- ^^^^^^ variable.other.cs -->
183+
<!-- ^ keyword.operator.assignment.cs -->
184+
<!-- ^^^^^^ variable.other.cs -->
185+
<!-- ^^^ meta.brackets.cs -->
186+
<!-- ^ punctuation.section.brackets.begin.cs -->
187+
<!-- ^ variable.other.cs -->
188+
<!-- ^ punctuation.section.brackets.end.cs -->
189+
<!-- ^ punctuation.terminator.statement.cs -->
133190
<text>Name: @person.Name</text>
191+
<!--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.block.cs -->
192+
<!--^^^^^^ meta.tag.other.html -->
193+
<!--^ punctuation.definition.tag.begin.html -->
194+
<!-- ^^^^ entity.name.tag.other.html -->
195+
<!-- ^ punctuation.definition.tag.end.html -->
196+
<!-- ^ punctuation.section.embedded.line.cs-razor -->
197+
<!-- ^^^^^^ variable.other.cs -->
198+
<!-- ^ punctuation.accessor.dot.cs -->
199+
<!-- ^^^^ variable.other.cs -->
200+
<!-- ^^^^^^^ meta.tag.other.html -->
201+
<!-- ^^ punctuation.definition.tag.begin.html -->
202+
<!-- ^^^^ entity.name.tag.other.html -->
203+
<!-- ^ punctuation.definition.tag.end.html -->
134204
}
135205

206+
<!-- TODO: Start the meta.group at the right place -->
136207
@for (var i = 0; i < people.Length; i++)
208+
<!-- ^ punctuation.section.group.begin.cs -->
209+
<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.cs -->
210+
<!-- ^^^ storage.type.variable.cs -->
211+
<!-- ^ variable.other.cs -->
212+
<!-- ^ keyword.operator.assignment.cs -->
213+
<!-- ^ meta.number.integer.decimal.cs constant.numeric.value.cs -->
214+
<!-- ^ punctuation.terminator.statement.cs -->
215+
<!-- ^ variable.other.cs -->
216+
<!-- ^ keyword.operator.comparison.cs -->
217+
<!-- ^^^^^^ variable.other.cs -->
218+
<!-- ^ punctuation.accessor.dot.cs -->
219+
<!-- ^^^^^^ variable.other.cs -->
220+
<!-- ^ punctuation.terminator.statement.cs -->
221+
<!-- ^ variable.other.cs -->
222+
<!-- ^^ keyword.operator.arithmetic.cs -->
223+
<!-- ^ punctuation.section.group.end.cs -->
137224
{
138225
var person = people[i];
139226
@:Name: @person.Name
140-
} *@
227+
<!--^^^^^^^^^^^^^^^^^^^^^ meta.block.cs -->
228+
<!--^^ punctuation.section.embedded.html.cs-razor -->
229+
<!-- ^^^^^^^^^^^^^^^^^^ text.html.basic - punctuation -->
230+
}
141231

142232
@{ }
143233
<!--^^^^^^ meta.embedded.cs -->
@@ -384,7 +474,18 @@ finally
384474
</article>
385475

386476
@foreach (var item in Model)
477+
<!-- ^ punctuation.section.group.begin.cs -->
478+
<!-- ^^^^^^^^^^^^^^^^^^ meta.group.cs -->
479+
<!-- ^^^ storage.type.variable.cs -->
480+
<!-- ^^^^ variable.other.cs -->
481+
<!-- ^^ keyword.control.loop.in.cs -->
482+
<!-- ^^^^^ variable.language.this.razor -->
483+
<!-- ^ punctuation.section.group.end.cs -->
387484
{
485+
<p data-foo="@item.foo">
486+
<!-- TODO: scope at constructs in HTML attribute values correctly even when inside a razor code block -->
487+
</p>
488+
388489
if (item.ShouldBeDisplayed)
389490
{
390491
<article data-id="@item.ID">

0 commit comments

Comments
 (0)