Skip to content

Commit 27064cd

Browse files
deathaxeskyronic
authored andcommitted
Fix mustage template interpolation
This commit fixes implementation of mustage template tags {{...}}. Before this commit they tried to pop the `main` context off stack and caused `template-tag-content` to never have been popped off stack properly. With this commit the syntax distinguishes between embedded template tags and those which interpolate strings. The latter one remove `string` scope for better highlighting java code in `{{ ... }}`. It also does no longer push a dedicated `mustage-content` context on stack as this is the same content as the whole document. It's not required.
1 parent dbe9f0a commit 27064cd

File tree

4 files changed

+164
-62
lines changed

4 files changed

+164
-62
lines changed

Vue Component.sublime-syntax

Lines changed: 69 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -50,31 +50,54 @@ variables:
5050
)
5151
5252
contexts:
53+
54+
###[ HTML TAGS ]##############################################################
55+
56+
prototype:
57+
- meta_prepend: true
58+
- include: mustache-templates
59+
5360
main:
5461
- meta_prepend: true
5562
- include: template-tag
56-
- include: mustache-expression
57-
58-
mustache-expression:
59-
- match: (?={{)
60-
set:
61-
- meta_scope: meta.template.vue
62-
- match: '{{'
63-
scope: punctuation.definition.template.begin.html
64-
embed: scope:source.js
65-
embed_scope: source.js.embedded.vue
66-
escape: '}}'
67-
escape_captures:
68-
0: meta.template.vue punctuation.definition.template.end.html
69-
- match: ''
70-
pop: true
7163

7264
###[ TAG ATTRIBUTES ]#########################################################
7365

7466
tag-attributes:
7567
- meta_prepend: true
7668
- include: vue-directive
7769

70+
tag-attribute-value-content:
71+
- meta_prepend: true
72+
- include: mustache-interpolations
73+
74+
strings-common-content:
75+
- meta_prepend: true
76+
- include: mustache-interpolations
77+
78+
###[ MUSTAGE TEMPLATES ]######################################################
79+
80+
mustache-interpolations:
81+
- match: (?={{)
82+
push: mustache-interpolation-content
83+
84+
mustache-interpolation-content:
85+
- clear_scopes: 1
86+
- meta_scope: meta.interpolation.html
87+
- include: mustache-templates
88+
- include: immediately-pop
89+
90+
mustache-templates:
91+
- match: '{{'
92+
scope: meta.template.vue punctuation.definition.template.begin.html
93+
embed: scope:source.js
94+
embed_scope: meta.template.vue source.js.embedded.vue
95+
escape: '}}'
96+
escape_captures:
97+
0: meta.template.vue punctuation.definition.template.end.html
98+
99+
###[ VUE DIRECTIVES ]#########################################################
100+
78101
vue-directive:
79102
- match: (?=v-)
80103
push:
@@ -180,13 +203,13 @@ contexts:
180203
scope: punctuation.definition.tag.end.html
181204
set:
182205
- - include: style-close-tag
183-
- - embed_scope: source.sass.embedded.html
184-
escape_captures:
206+
- - escape_captures:
185207
1: source.sass.embedded.html
186208
2: comment.block.html punctuation.definition.comment.end.html
187209
3: source.sass.embedded.html
188210
4: comment.block.html punctuation.definition.comment.end.html
189211
match: '{{style_content_begin}}'
212+
embed_scope: source.sass.embedded.html
190213
captures:
191214
1: comment.block.html punctuation.definition.comment.begin.html
192215
pop: 1
@@ -202,13 +225,13 @@ contexts:
202225
scope: punctuation.definition.tag.end.html
203226
set:
204227
- - include: style-close-tag
205-
- - embed_scope: source.scss.embedded.html
206-
escape_captures:
228+
- - escape_captures:
207229
1: source.scss.embedded.html
208230
2: comment.block.html punctuation.definition.comment.end.html
209231
3: source.scss.embedded.html
210232
4: comment.block.html punctuation.definition.comment.end.html
211233
match: '{{style_content_begin}}'
234+
embed_scope: source.scss.embedded.html
212235
captures:
213236
1: comment.block.html punctuation.definition.comment.begin.html
214237
pop: 1
@@ -224,13 +247,13 @@ contexts:
224247
scope: punctuation.definition.tag.end.html
225248
set:
226249
- - include: style-close-tag
227-
- - embed_scope: source.stylus.embedded.html
228-
escape_captures:
250+
- - escape_captures:
229251
1: source.stylus.embedded.html
230252
2: comment.block.html punctuation.definition.comment.end.html
231253
3: source.stylus.embedded.html
232254
4: comment.block.html punctuation.definition.comment.end.html
233255
match: '{{style_content_begin}}'
256+
embed_scope: source.stylus.embedded.html
234257
captures:
235258
1: comment.block.html punctuation.definition.comment.begin.html
236259
pop: 1
@@ -246,13 +269,13 @@ contexts:
246269
scope: punctuation.definition.tag.end.html
247270
set:
248271
- - include: style-close-tag
249-
- - embed_scope: source.sss.embedded.html
250-
escape_captures:
272+
- - escape_captures:
251273
1: source.sss.embedded.html
252274
2: comment.block.html punctuation.definition.comment.end.html
253275
3: source.sss.embedded.html
254276
4: comment.block.html punctuation.definition.comment.end.html
255277
match: '{{style_content_begin}}'
278+
embed_scope: source.sss.embedded.html
256279
captures:
257280
1: comment.block.html punctuation.definition.comment.begin.html
258281
pop: 1
@@ -268,13 +291,13 @@ contexts:
268291
scope: punctuation.definition.tag.end.html
269292
set:
270293
- - include: style-close-tag
271-
- - embed_scope: source.postcss.embedded.html
272-
escape_captures:
294+
- - escape_captures:
273295
1: source.postcss.embedded.html
274296
2: comment.block.html punctuation.definition.comment.end.html
275297
3: source.postcss.embedded.html
276298
4: comment.block.html punctuation.definition.comment.end.html
277299
match: '{{style_content_begin}}'
300+
embed_scope: source.postcss.embedded.html
278301
captures:
279302
1: comment.block.html punctuation.definition.comment.begin.html
280303
pop: 1
@@ -290,13 +313,13 @@ contexts:
290313
scope: punctuation.definition.tag.end.html
291314
set:
292315
- - include: style-close-tag
293-
- - embed_scope: source.less.embedded.html
294-
escape_captures:
316+
- - escape_captures:
295317
1: source.less.embedded.html
296318
2: comment.block.html punctuation.definition.comment.end.html
297319
3: source.less.embedded.html
298320
4: comment.block.html punctuation.definition.comment.end.html
299321
match: '{{style_content_begin}}'
322+
embed_scope: source.less.embedded.html
300323
captures:
301324
1: comment.block.html punctuation.definition.comment.begin.html
302325
pop: 1
@@ -379,13 +402,13 @@ contexts:
379402
scope: punctuation.definition.tag.end.html
380403
set:
381404
- - include: script-close-tag
382-
- - embed_scope: source.coffee.embedded.html
383-
escape_captures:
405+
- - escape_captures:
384406
1: source.coffee.embedded.html
385407
2: comment.block.html punctuation.definition.comment.end.html
386408
3: source.coffee.embedded.html
387409
4: comment.block.html punctuation.definition.comment.end.html
388410
match: '{{script_content_begin}}'
411+
embed_scope: source.coffee.embedded.html
389412
captures:
390413
1: comment.block.html punctuation.definition.comment.begin.html
391414
pop: 1
@@ -401,13 +424,13 @@ contexts:
401424
scope: punctuation.definition.tag.end.html
402425
set:
403426
- - include: script-close-tag
404-
- - embed_scope: source.livescript.embedded.html
405-
escape_captures:
427+
- - escape_captures:
406428
1: source.livescript.embedded.html
407429
2: comment.block.html punctuation.definition.comment.end.html
408430
3: source.livescript.embedded.html
409431
4: comment.block.html punctuation.definition.comment.end.html
410432
match: '{{script_content_begin}}'
433+
embed_scope: source.livescript.embedded.html
411434
captures:
412435
1: comment.block.html punctuation.definition.comment.begin.html
413436
pop: 1
@@ -423,13 +446,13 @@ contexts:
423446
scope: punctuation.definition.tag.end.html
424447
set:
425448
- - include: script-close-tag
426-
- - embed_scope: source.ts.embedded.html
427-
escape_captures:
449+
- - escape_captures:
428450
1: source.ts.embedded.html
429451
2: comment.block.html punctuation.definition.comment.end.html
430452
3: source.ts.embedded.html
431453
4: comment.block.html punctuation.definition.comment.end.html
432454
match: '{{script_content_begin}}'
455+
embed_scope: source.ts.embedded.html
433456
captures:
434457
1: comment.block.html punctuation.definition.comment.begin.html
435458
pop: 1
@@ -451,6 +474,12 @@ contexts:
451474
1: punctuation.definition.tag.begin.html
452475
2: entity.name.tag.template.html
453476
push: template-mustache
477+
- match: (</)((?i:template))(>)
478+
scope: meta.tag.template.end.html
479+
captures:
480+
1: punctuation.definition.tag.begin.html
481+
2: entity.name.tag.template.html
482+
3: punctuation.definition.tag.end.html
454483

455484
template-close-tag:
456485
- match: (</)((?i:template))(>)
@@ -471,10 +500,7 @@ contexts:
471500
- include: template-common
472501
- match: '>'
473502
scope: punctuation.definition.tag.end.html
474-
set:
475-
- include: template-close-tag
476-
- match: ''
477-
push: main
503+
pop: 1
478504

479505
template-lang-attribute:
480506
- match: (?i:lang){{attribute_name_break}}
@@ -503,13 +529,13 @@ contexts:
503529
scope: punctuation.definition.tag.end.html
504530
set:
505531
- - include: template-close-tag
506-
- - embed_scope: text.jade.embedded.html
507-
escape_captures:
532+
- - escape_captures:
508533
1: text.jade.embedded.html
509534
2: comment.block.html punctuation.definition.comment.end.html
510535
3: text.jade.embedded.html
511536
4: comment.block.html punctuation.definition.comment.end.html
512537
match: '{{template_content_begin}}'
538+
embed_scope: text.jade.embedded.html
513539
captures:
514540
1: comment.block.html punctuation.definition.comment.begin.html
515541
pop: 1
@@ -525,13 +551,13 @@ contexts:
525551
scope: punctuation.definition.tag.end.html
526552
set:
527553
- - include: template-close-tag
528-
- - embed_scope: text.pug.embedded.html
529-
escape_captures:
554+
- - escape_captures:
530555
1: text.pug.embedded.html
531556
2: comment.block.html punctuation.definition.comment.end.html
532557
3: text.pug.embedded.html
533558
4: comment.block.html punctuation.definition.comment.end.html
534559
match: '{{template_content_begin}}'
560+
embed_scope: text.pug.embedded.html
535561
captures:
536562
1: comment.block.html punctuation.definition.comment.begin.html
537563
pop: 1
@@ -547,13 +573,13 @@ contexts:
547573
scope: punctuation.definition.tag.end.html
548574
set:
549575
- - include: template-close-tag
550-
- - embed_scope: text.slm.embedded.html
551-
escape_captures:
576+
- - escape_captures:
552577
1: text.slm.embedded.html
553578
2: comment.block.html punctuation.definition.comment.end.html
554579
3: text.slm.embedded.html
555580
4: comment.block.html punctuation.definition.comment.end.html
556581
match: '{{template_content_begin}}'
582+
embed_scope: text.slm.embedded.html
557583
captures:
558584
1: comment.block.html punctuation.definition.comment.begin.html
559585
pop: 1

Vue Component.sublime-syntax.yaml-macros

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,31 +51,54 @@ variables:
5151
)
5252

5353
contexts:
54+
55+
###[ HTML TAGS ]##############################################################
56+
57+
prototype:
58+
- meta_prepend: true
59+
- include: mustache-templates
60+
5461
main:
5562
- meta_prepend: true
5663
- include: template-tag
57-
- include: mustache-expression
58-
59-
mustache-expression:
60-
- match: '(?={{)'
61-
set:
62-
- meta_scope: meta.template.vue
63-
- match: '{{'
64-
scope: punctuation.definition.template.begin.html
65-
embed: scope:source.js
66-
embed_scope: source.js.embedded.vue
67-
escape: '}}'
68-
escape_captures:
69-
0: meta.template.vue punctuation.definition.template.end.html
70-
- match: ''
71-
pop: true
7264

7365
###[ TAG ATTRIBUTES ]#########################################################
7466

7567
tag-attributes:
7668
- meta_prepend: true
7769
- include: vue-directive
7870

71+
tag-attribute-value-content:
72+
- meta_prepend: true
73+
- include: mustache-interpolations
74+
75+
strings-common-content:
76+
- meta_prepend: true
77+
- include: mustache-interpolations
78+
79+
###[ MUSTAGE TEMPLATES ]######################################################
80+
81+
mustache-interpolations:
82+
- match: (?={{)
83+
push: mustache-interpolation-content
84+
85+
mustache-interpolation-content:
86+
- clear_scopes: 1
87+
- meta_scope: meta.interpolation.html
88+
- include: mustache-templates
89+
- include: immediately-pop
90+
91+
mustache-templates:
92+
- match: '{{'
93+
scope: meta.template.vue punctuation.definition.template.begin.html
94+
embed: scope:source.js
95+
embed_scope: meta.template.vue source.js.embedded.vue
96+
escape: '}}'
97+
escape_captures:
98+
0: meta.template.vue punctuation.definition.template.end.html
99+
100+
###[ VUE DIRECTIVES ]#########################################################
101+
79102
vue-directive:
80103
- match: (?=v-)
81104
push:
@@ -271,6 +294,12 @@ contexts:
271294
1: punctuation.definition.tag.begin.html
272295
2: entity.name.tag.template.html
273296
push: template-mustache
297+
- match: (</)((?i:template))(>)
298+
scope: meta.tag.template.end.html
299+
captures:
300+
1: punctuation.definition.tag.begin.html
301+
2: entity.name.tag.template.html
302+
3: punctuation.definition.tag.end.html
274303

275304
template-close-tag:
276305
- match: (</)((?i:template))(>)
@@ -291,10 +320,7 @@ contexts:
291320
- include: template-common
292321
- match: '>'
293322
scope: punctuation.definition.tag.end.html
294-
set:
295-
- include: template-close-tag
296-
- match: ''
297-
push: main
323+
pop: 1
298324

299325
template-lang-attribute:
300326
- match: (?i:lang){{attribute_name_break}}

tests/syntax_test_template.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
// SYNTAX TEST "Vue Component.sublime-syntax"
22

3+
<template>
4+
// <- text.html.vue - text text
5+
// ^^^^^^^^^^ meta.tag.template.begin.html
6+
7+
</template>
8+
// <- text.html.vue - text text
9+
// ^^^^^^^^^^^ meta.tag.template.end.html
10+
311

412
<template lang="jade"> foo </template>
513
// ^^^^^^^^^^^^^^^^^^^^^^ meta.tag - source

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy