Skip to content

Commit 5fe81c4

Browse files
author
deathaxe
committed
Refactor attributes
1. add dedicated `meta.directive` scopes (like in VueJS syntax) 2. use angular expression syntax in directive values instead of plain JavaScript
1 parent bb25c66 commit 5fe81c4

File tree

2 files changed

+374
-55
lines changed

2 files changed

+374
-55
lines changed

NgxHTML.sublime-syntax

+95-55
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,7 @@ contexts:
4040

4141
tag-attributes:
4242
- meta_prepend: true
43-
- include: tag-ng-template-attribute
44-
- include: tag-ng-reference-attribute
45-
- include: tag-ng-bind-attribute
46-
- include: tag-ng-on-attribute
47-
- include: tag-ng-bindon-attribute
43+
- include: ng-directives
4844

4945
###[ ANGULAR EXPRESSIONS ]#####################################################
5046

@@ -61,60 +57,91 @@ contexts:
6157
- include: ng-strings
6258
- include: ng-variables
6359

64-
###[ ANGULAR TAG ATTRIBUTES ]##################################################
60+
###[ ANGULAR DIRECTIVES ]######################################################
6561

66-
tag-ng-template-attribute:
67-
- match: (\*)([a-zA-Z]\w*)
68-
scope: meta.attribute-with-value.template.html
62+
ng-directives:
63+
# template
64+
- match: (\*)(?:(ngIf)|(ngFor)|(ngSwitch(?:Case|Default))|([a-zA-Z]\w*))
65+
scope: meta.directive.template.ngx
6966
captures:
70-
1: punctuation.definition.template.html
71-
2: entity.other.attribute-name.template.html
72-
push:
73-
- tag-event-attribute-meta
74-
- tag-event-attribute-assignment
75-
76-
tag-ng-reference-attribute:
67+
1: punctuation.definition.template.ngx
68+
2: keyword.control.conditional.if.ngx
69+
3: keyword.control.loop.for.ngx
70+
4: keyword.control.conditional.case.ngx
71+
5: entity.other.attribute-name.template.ngx
72+
push: ng-directive-assignment
73+
# reference
7774
- match: (\#)([a-zA-Z]\w*)
78-
scope: meta.attribute.reference.html
75+
scope: meta.directive.reference.ngx
7976
captures:
80-
1: punctuation.definition.reference.html
81-
2: entity.other.attribute-name.reference.html
82-
push:
83-
- tag-event-attribute-meta
84-
- tag-event-attribute-assignment
85-
86-
tag-ng-bind-attribute:
87-
- match: (\[)([a-zA-Z@][!\w.-]*)(\])
88-
scope: meta.attribute-with-value.bind.html
77+
1: punctuation.definition.reference.ngx
78+
2: entity.other.attribute-name.reference.ngx
79+
push: ng-directive-assignment
80+
# bind
81+
- match: (\[)(?:(ngSwitch)|([a-zA-Z@][!\w.-]*))(\])
82+
scope: meta.directive.bind.ngx
8983
captures:
90-
1: punctuation.section.bind.begin.html
91-
2: entity.other.attribute-name.bind.html
92-
3: punctuation.section.bind.end.html
93-
push:
94-
- tag-event-attribute-meta
95-
- tag-event-attribute-assignment
96-
97-
tag-ng-on-attribute:
84+
1: punctuation.definition.bind.begin.ngx
85+
2: keyword.control.conditional.switch.ngx
86+
3: entity.other.attribute-name.bind.ngx
87+
4: punctuation.definition.bind.end.ngx
88+
push: ng-directive-assignment
89+
# on
9890
- match: (\()([a-zA-Z@][\w:.]*)(\))
99-
scope: meta.attribute-with-value.on.html
91+
scope: meta.directive.on.ngx
10092
captures:
101-
1: punctuation.section.on.begin.html
102-
2: entity.other.attribute-name.on.html
103-
3: punctuation.section.on.end.html
104-
push:
105-
- tag-event-attribute-meta
106-
- tag-event-attribute-assignment
107-
108-
tag-ng-bindon-attribute:
93+
1: punctuation.definition.on.begin.ngx
94+
2: entity.other.attribute-name.on.ngx
95+
3: punctuation.definition.on.end.ngx
96+
push: ng-directive-assignment
97+
# bindon
10998
- match: (\[\()([a-zA-Z][\w.]*)(\)\])
110-
scope: meta.attribute-with-value.bindon.html
99+
scope: meta.directive.bindon.ngx
111100
captures:
112-
1: punctuation.section.bindon.begin.html
113-
2: entity.other.attribute-name.bindon.html
114-
3: punctuation.section.bindon.end.html
115-
push:
116-
- tag-event-attribute-meta
117-
- tag-event-attribute-assignment
101+
1: punctuation.definition.bindon.begin.ngx
102+
2: entity.other.attribute-name.bindon.ngx
103+
3: punctuation.definition.bindon.end.ngx
104+
push: ng-directive-assignment
105+
106+
ng-directive-assignment:
107+
- meta_include_prototype: false
108+
- meta_content_scope: meta.directive.ngx
109+
- match: =
110+
scope: meta.directive.ngx punctuation.separator.key-value.ngx
111+
set:
112+
- immediately-pop # workaround https://github.com/sublimehq/sublime_text/issues/4069
113+
- ng-directive-value
114+
- include: else-pop
115+
116+
ng-directive-value:
117+
- meta_content_scope: meta.directive.value.ngx
118+
- match: \"
119+
scope: meta.string.ngx string.quoted.double.ngx punctuation.definition.string.begin.ngx
120+
embed: ng-directive-expressions
121+
embed_scope: meta.directive.value.ngx meta.string.ngx meta.interpolation.ngx source.ngx.embedded.html
122+
escape: \"
123+
escape_captures:
124+
0: meta.string.ngx string.quoted.double.ngx punctuation.definition.string.end.ngx
125+
pop: 1
126+
- match: \'
127+
scope: meta.string.ngx string.quoted.single.ngx punctuation.definition.string.begin.ngx
128+
embed: ng-directive-expressions
129+
embed_scope: meta.directive.value.ngx meta.string.ngx meta.interpolation.ngx source.ngx.embedded.html
130+
escape: \'
131+
escape_captures:
132+
0: meta.string.ngx string.quoted.single.ngx punctuation.definition.string.end.ngx
133+
pop: 1
134+
- include: else-pop
135+
136+
ng-directive-expressions:
137+
- match: (trackBy)\s*(:)
138+
captures:
139+
1: keyword.control.flow.ngx
140+
2: punctuation.separator.key-value.ngx
141+
- include: ng-conditional-keywords
142+
- include: ng-defer-keywords
143+
- include: ng-for-keywords
144+
- include: ng-expressions
118145

119146
###[ ANGULAR DECLARATIONS ]####################################################
120147

@@ -240,9 +267,12 @@ contexts:
240267
- match: \)
241268
scope: punctuation.section.group.end.ngx
242269
pop: 1
270+
- include: ng-conditional-keywords
271+
- include: ng-expressions
272+
273+
ng-conditional-keywords:
243274
- match: as{{ident_break}}
244275
scope: keyword.operator.assignment.as.ngx
245-
- include: ng-expressions
246276

247277
ng-defer-group:
248278
- meta_include_prototype: false
@@ -256,15 +286,22 @@ contexts:
256286
- match: \)
257287
scope: punctuation.section.group.end.ngx
258288
pop: 1
259-
- match: (?:idle|viewport|interaction|hover|immediatetimer){{ident_break}}
260-
scope: constant.language.event.ngx
289+
- include: ng-defer-keywords
290+
- include: ng-expressions
291+
292+
ng-defer-keywords:
261293
- match: (?:prefetch on|on|prefetch when|when){{ident_break}}
262294
scope: keyword.control.flow.ngx
295+
push: ng-defer-event
263296
- match: (minimum|after)(\?)
264297
captures:
265298
1: keyword.operator.word.ngx
266299
2: keyword.control.question.ngx
267-
- include: ng-expressions
300+
301+
ng-defer-event:
302+
- match: (?:idle|viewport|interaction|hover|immediatetimer){{ident_break}}
303+
scope: constant.language.event.ngx
304+
- include: else-pop
268305

269306
ng-for-group:
270307
- meta_include_prototype: false
@@ -278,13 +315,16 @@ contexts:
278315
- match: \)
279316
scope: punctuation.section.group.end.ngx
280317
pop: 1
318+
- include: ng-for-keywords
319+
- include: ng-expressions
320+
321+
ng-for-keywords:
281322
- match: track{{ident_break}}
282323
scope: keyword.control.flow.ngx
283324
- match: let{{ident_break}}
284325
scope: keyword.declation.variable.ngx
285326
- match: of{{ident_break}}
286327
scope: keyword.operator.iteration.ngx
287-
- include: ng-expressions
288328

289329
###[ ANGULAR INTERPOLATIONS ]##################################################
290330

0 commit comments

Comments
 (0)