-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathImba.sublime-syntax
811 lines (691 loc) · 19.2 KB
/
Imba.sublime-syntax
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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
%YAML 1.2
---
name: Imba
file_extensions: [imba,imba1,imba2]
scope: source.imba
first_line_match: ^#!/.*\bimba
variables:
ident: '[A-Za-z_\$](-?[A-Za-z\d\_\$]+)*([\!\?])?'
identifier: '[a-z_\$](-?[A-Za-z\d\_\$]+)*'
ivar: '\@\@?{{ident}}'
const: '[A-Z][A-Za-z\d\-\$]*'
private_field: '#[A-Za-z\_][\w\-]*'
tag_id: '#[A-Za-z\_][\w\-]*'
tag_class: '\.([A-Za-z\_][\w\-]*)'
contexts:
main:
- match: "### (less)( scoped)?"
scope: comment.block.imba
push: inline-less
- match: "### (css)( scoped)?"
scope: comment.block.imba
push: inline-css
- match: "### (sass)( scoped)?"
scope: keyword.control
push: inline-sass
- match: "### (stylus)( scoped)?"
scope: keyword.control
push: inline-stylus
- match: "### (scss)( scoped)?"
scope: keyword.control
push: inline-scss
- match: \b(import)\b
scope: keyword.control.imba
push: import
- include: css-block
- include: require
- match: \b(extern)\b
scope: keyword.control.imba
- include: def
- match: \b(export |export default )(var\s*|let\s*|const\s*)\b
captures:
1: keyword.control.imba
2: keyword.control.imba
push: vardef
- include: body
- match: \)
scope: invalid.illegal.stray-bracket-end
- match: \}
scope: invalid.illegal.stray-bracket-end
css-block:
- match: '(css)\s*(?=\{)'
scope: keyword.control.imba
push:
- match: \{
scope: keyword.control.imba
push: ImbaCSS.sublime-syntax
- match: \}
scope: keyword.control.imba
pop: true
pop-style:
- match: "###"
pop: true
scope: comment.block.imba
inline-css:
- meta_scope: source.imba.embedded.css
- include: pop-style
- match: (?=\S)
embed: scope:source.css
escape: (?i)(?=###)
inline-less:
- meta_scope: source.imba.embedded.css
- include: pop-style
- match: (?=\S)
embed: scope:source.less
embed_scope: source.imba.embedded.css
escape: (?i)(?=###)
inline-sass:
- meta_scope: source.imba.embedded.css
- include: pop-style
- match: (?=\S)
embed: scope:source.sass
embed_scope: source.imba.embedded.css
escape: (?i)(?=###)
inline-stylus:
- meta_scope: source.imba.embedded.css
- include: pop-style
- match: (?=\S)
embed: scope:source.stylus
embed_scope: source.imba.embedded.css
escape: (?i)(?=###)
inline-scss:
- meta_scope: source.imba.embedded.css
- include: pop-style
- match: (?=\S)
embed: scope:source.scss
embed_scope: source.imba.embedded.css
escape: (?i)(?=###)
symbol:
- match: (?<![\w\)\]\}])(\:[@$\w_][\w\-_$]*)
scope: string.symbol.imba
const:
- match: \b([A-Z][\w]*)\b
captures:
1: identifier.class.imba
decorator:
- match: '(@@)({{ident}})'
scope: storage.modifier.decorator
- match: '(\&)({{ident}})(\.{{ident}})*'
captures:
1: storage.modifier.decorator
# 2: keyword.control.imba
# scope: storage.modifier.decorator
ivar:
- match: '(@)({{ident}})'
captures:
1: variable.other.instance.imba
2: variable.other.instance.imba
svar:
- match: '(\$)({{ident}})'
captures:
1: variable.other.instance.imba
2: variable.other.instance.imba
argvar:
- match: '\$\d+'
scope: variable.special.imba
array:
- match: \[
push:
- meta_scope: array.imba
- match: \]
pop: true
- include: body
parens:
- match: \(
push:
- meta_scope: parens.imba
- match: \)
pop: true
- include: body
brackets:
- match: \{
push:
- meta_scope: brackets.imba
- match: \}
pop: true
- include: body
keyword:
- match: \b(if|else|elif|unless|for( own)?|while|return|until|switch|then|when|try|catch|finally|continue|break|throw|do|await|typeof|delete|static)\b(?![\:\-])
scope: keyword.control.imba
body:
- include: keyword
- include: def
- match: \b(var|let|const)(?=\s)
scope: keyword.control.imba
push: vardef
- match: \#\#\#
push: herecomment
- match: \)
scope: invalid.illegal.stray-bracket-end
- match: /\t\ /
scope: invalid.illegal.inconsistent-indentation
- include: class
- include: tagdef
- include: expr
alphanumerics:
- match: \b(true|yes)\b
scope: constant.language.boolean.true.imba
- match: \b(false|no)\b
scope: constant.language.boolean.false.imba
- match: \b(null|undefined)\b
scope: constant.language.boolean.null.imba
selector:
- match: (\$\$|\%\%|\$|\%)\(
push:
- meta_scope: meta.selector.all.imba
- include: selector_query
- match: \.
push: selector_class
- match: \)
pop: true
selector_query:
- include: interpolation
selector_class:
- meta_scope: meta.selector.class.imba
- match: (?=\))
pop: true
tag:
- match: '(<)([\w\-\:]+)'
captures:
1: punctuation.section.tag.open.imba
2: entity.name.tag.type.imba
# should not include these in the document?
push: tag_content
- match: '(<)(?=[a-z\#\.\{\@])'
scope: punctuation.section.tag.open.imba
push: tag_content
- match: '(<)([ ]*)(>)'
captures:
1: punctuation.section.tag.open.imba
2: entity.name.tag.type.imba
3: punctuation.section.tag.close.imba
scope: meta.tag.imba
tag_params:
- match: (\$[\$\w\.\-]+)
captures:
1: keyword.special.imba
- include: body
tag_content:
- meta_scope: entity.name.tag.imba
- match: '\.{'
push:
- meta_content_scope: meta.interpolation.imba
- include: expr
- match: '}'
pop: true
- match: '\@{'
scope: entity.name.tag.key.evaled.imba
push:
- meta_content_scope: meta.interpolation.imba
- include: expr
- match: '}'
scope: entity.name.tag.key.evaled.imba
pop: true
- match: '\#\{'
scope: entity.name.tag.id.evaled.imba
push:
- meta_content_scope: meta.interpolation.imba
- match: \}
scope: entity.name.tag.id.evaled.imba
pop: true
- include: expr
- match: '{'
push:
- meta_content_scope: meta.interpolation.imba
- include: expr
- match: '}'
pop: true
- match: (\@)(-*[a-zA-Z][\w\-]*)?
scope: entity.name.tag.ref.imba
- match: (\.)(-*[a-zA-Z][\w\-]*)?
scope: entity.name.tag.class.imba
- match: (\#)([a-zA-Z][\w\-]*)?
scope: entity.name.tag.id.imba
- match: (\:)(-*[a-zA-Z][\w\-]*)?
scope: entity.name.tag.event.imba
- match: \s+([@\:]?[a-zA-Z][\w\-])
scope: entity.name.tag.attribute.imba
- match: \=\s*
push:
- meta_scope: meta.tagobject.imba
- match: (?=(\s|[\-\=]?\>))
pop: true
- include: body
- match: \[
push:
- meta_scope: meta.tagobject.imba
- match: \]
pop: true
- include: body
- match: \(
push:
- meta_scope: meta.tagparams.imba
- match: \$[\w\.\-]+
scope: variable.special.imba
- match: \)
pop: true
- include: body
- match: ([ ]+)
scope: meta.whitespace.imba
- match: '>'
scope: punctuation.section.tag.close.imba
pop: true
- match: '->'
scope: punctuation.section.tag.close.imba
pop: true
- match: '=>'
scope: punctuation.section.tag.close.imba
pop: true
number:
- match: \b[0-9]+\.[0-9]+\b
scope: constant.numeric.float.imba
- match: \b[0-9]+\b
scope: constant.numeric.int.imba
- match: \b0x[0-9A-Fa-f]+\b
scope: constant.numeric.hex.imba
identifier:
- match: ({{ident}})
scope: identifier.basic.imba
special:
- match: \b(self)\b(\:)?(?![\-])
scope: variable.language.scope.self.imba
captures:
2: keyword.operator.accessor.imba
- match: \b(this)\b(\:)?(?![\-])
scope: variable.language.scope.this.imba
captures:
2: keyword.operator.accessor.imba
- match: \b(super)\b(\:)?(?![\-])
scope: keyword.special.imba
captures:
2: keyword.operator.accessor.imba
operator:
- match: <=>|<(?!<|=)|>(?!<|=|>)|<=|>=|\btypeof\b|===|==|\?=|=~|!=|!~\?|≤|≥|≡|≈|\||\!
scope: keyword.operator.comparison.imba
- match: \!?(is|isa|isnt|not|typeof)(?= )
scope: keyword.operator.comparison.imba
- match: \bnot\b|&&| and |\|\|| or | of | \!?in |\^|\s:\\s|\?\|{1,2}|\?\&{1,2}|[\?\&]\>|∩|∪|∈|∉|∋|∌
scope: keyword.operator.logical.imba
- match: \=|\?\=|\&\&?\=|\|=
scope: keyword.operator.assignment.imba
- match: (\?\.|\?\:)
scope: keyword.operator.accessor.imba
- match: (%|\*\*|\*|\+|\-|\/|×|÷|√|\+\+|\-\-)
scope: keyword.operator.arithmetic.imba
- match: (\>\>\>|&|\<\<|\>\>|\^|\~)
scope: keyword.operator.bitop.imba
- include: ternary
value:
- include: selector
- include: predefines
- include: number
- include: string
- include: symbol
- include: access
- include: richstring
- include: templatestring
- include: alphanumerics
- include: private_field
- include: special
- include: accessable
- include: assignable
- include: require
- include: tag
- include: heregex
punctuation:
- match: \.
scope: keyword.operator.accessor.imba
- match: ':'
scope: keyword.operator.accessor.raw.imba
key:
- match: ((\$|@|_)?[\w\-\$]+)[ \t]*(\:)
captures:
3: punctuation.keyset.imba
scope: identifier.key.imba
access:
- match: (\:)({{const}})
scope: accessor.access.const.imba
captures:
1: keyword.operator.accessor.imba
2: identifier.class.imba
- match: (\:)({{ivar}})
scope: accessor.access.ivar.imba
captures:
1: keyword.operator.accessor.imba
2: variable.instance.imba
- match: (\:)({{ident}})
scope: accessor.access.identifier.imba
captures:
1: keyword.operator.accessor.imba
2: identifier.basic.imba
accessor:
- match: (\.)(new|len)(?![\-\w])
scope: accessor.invocation.imba
captures:
# 1: punctuation.invoke.imba
1: keyword.operator.accessor.imba
2: keyword.special.imba
- match: (\.)({{ident}})
scope: accessor.invocation.imba
captures:
1: keyword.operator.accessor.imba
2: identifier.basic.imba
# 1: punctuation.invoke.imba
private_field:
- match: '(#)([A-Za-z\_][\w\-]*)'
captures:
1: variable.other.private.imba
2: variable.other.private.imba
accessable:
- include: const
- include: ivar
- include: svar
- include: identifier
assignable:
- include: const
- include: ivar
- include: svar
- include: array
- include: accessor
- include: identifier
expr:
- include: comment
- include: heregex
- include: literal-regexp
- include: expr_no_regex
expr_no_regex:
- include: tag
- include: require
- include: key
- include: keyword
- include: selector
- include: decorator
- include: operator
- include: argvar
- include: value
- include: brackets
- include: parens
- include: comment
- include: accessor
- include: identifier
- include: punctuation
unspaced_expr:
- include: tag
- include: selector
- include: operator
- include: value
- include: parens
- match: (?=\s)
pop: true
predefines:
- match: (\$\w+\$)
captures:
1: keyword.special.imba
ternary:
- match: '\?(?!\=)'
scope: keyword.operator.ternary.imba
push: in_ternary
in_ternary:
- include: special
- include: symbol
- include: access
- match: '\:'
scope: keyword.operator.ternary.imba
pop: true
- include: tag
- include: const
- include: ivar
- include: array
- include: accessor
- include: identifier
- include: value
- include: parens
- include: brackets
- include: punctuation
- include: operator
options:
- match: ([\w\-]+)[ \t]*(\:)
captures:
1: identifier.key.imba
2: identifier.key.imba
push:
- meta_scope: meta.option.imba
- meta_content_scope: meta.option.value.imba
- match: \,
pop: true
- match: (?=#[\t ]) # comment
pop: true
- match: (\n)
scope: meta.option.value.imba
pop: true
- include: value
vardef:
- meta_scope: vardef.imba
- include: expr
- match: \n
pop: true
string-content:
- match: \\\s*\n
scope: constant.character.escape.newline.js
- match: '\\(x[\da-fA-F]{2}|u[\da-fA-F]{4}|.)'
scope: constant.character.escape.js
richstring:
- match: '"'
push:
- meta_scope: string.quoted.double.imba
- include: interpolation
- match: '"'
pop: true
- include: string-content
templatestring:
- match: '`'
push:
- meta_scope: string.quoted.template.imba
- include: interpolation
- match: '`'
pop: true
- include: string-content
string:
- match: \'
push:
- meta_scope: string.quoted.single.imba
- match: "'"
pop: true
- include: string-content
# should rather insert the classname
class:
- match: ([\t ]*)(export |extend |export default )?(global )?(class|module)[ ](([\w\.]+)?( (\<) ([\w\.]+))?)([ ]*)
captures:
2: keyword.control.imba
3: keyword.control.imba
4: keyword.control.imba
5: entity.name.type.class.imba
8: keyword.control.imba
# 6: entity.name.type.class.imba
scope: scope.classdef.imba
push:
- meta_content_scope: scope.class.imba
- match: ^(?!(\1[\t ]+|\s*$))
pop: true
- include: class_body
# - match: \G[ ]+([A-Za-z\_][\w\#\.\-]*\=?)
class_head:
# - meta_scope: scope.classhead.imba
- match: (?=(\n|$))
pop: true
class_body:
- include: prop
- include: css-block
- include: body
tagdef:
- match: ([\t ]*)(export |export default |extend |global )?(tag)[ ]((#?[\w\:\-]+)?( (\<) (#?[\w\:\-]+))?)
captures:
2: keyword.control.imba
3: keyword.control.imba
# 4: entity.name.type.tag.imba
5: entity.name.type.tag.imba
7: keyword.control.imba
8: entity.name.tagdef.imba
# 6: entity.name.type.class.imba
scope: scope.tagdef.imba
push:
- meta_scope: scope.tag.imba
- match: ^(?!(\1[\t ]+|\s*$))
pop: true
- include: tagdef_body
tagdef_body:
- include: prop
- include: css-block
- include: body
def:
- match: ([\t ]*)(export |export default |global |static )?(var |let |const )?(def|get|set)(?=\s\#?[A-Za-z\_\[\$][\w\#\.\-\$]*)
captures:
2: keyword.control.imba
3: keyword.control.imba
4: keyword.control.imba
push:
- meta_content_scope: scope.method.imba
- match: ^(?!(\1[\t ]+|\s*$))
pop: true
- include: method_body
- match: \G[ ]\[
scope: entity.name.function.imba
push:
- meta_scope: entity.name.function.imba
- match: \]
scope: entity.name.function.imba
set: def_params
- include: body
- match: \G[ ](\#?[A-Za-z\_\$][\w\#\.\-\$]*[\=\!\?]?)
captures:
1: entity.name.function.imba
push: def_params
def_params:
- meta_scope: scope.methodparams.imba
- meta_content_scope: variable.parameter.function.imba
- match: (do)\b[ ]*
captures:
1: keyword.control.imba
pop: true
- match: (?=(\n|$))
pop: true
- include: expr
method_body:
- include: body
prop:
- match: ([\t\ ]*)(prop|attr)[ \t]+([A-Za-z_][\w\-]*)
captures:
2: keyword.control.imbac
3: entity.name.property.imba
# simply accepts a propname and pops otherwise
_propname:
- match: \G([A-Za-z_][\w\-]*)\s+
scope: entity.name.property.imba
pop: true
- match: (?=.|$)
pop: true
# could go over multiple lines(!)
_propconfig:
- match: \G([A-Za-z_][\w\-]*)
scope: entity.name.propertyoption.imba
- match: ($)
pop: true
interpolation:
- match: \{
push:
- meta_scope: meta.interpolation
- include: expr
- match: \}
pop: true
filepath:
- match: \(
push:
- meta_scope: parens.imba
- match: \)
pop: true
- include: filepath
- match: \"
push:
- meta_scope: string.quoted.filepath.double.imba
- meta_content_scope: meta.filepath.imba
- include: interpolation
- match: \"
pop: true
- match: \'
push:
- meta_scope: string.quoted.filepath.single.imba
- meta_content_scope: meta.filepath.imba
- match: \'
pop: true
- include: comment
- match: (?=(\n|\)))
pop: true
herecomment:
- meta_scope: comment.block.imba
- match: \#\#\#
pop: true
comment:
- match: \#([ \t].*)?$
scope: comment.line.imba
- match: \/\/([^\/].*)?$
scope: comment.line.imba
heregex:
- match: \/\/\/
push:
- meta_scope: string.regexp.multiline.imba
- match: \/\/\/
pop: true
regex:
- match: \/(?=.*\/[gimy]*[ ]*([\,\)\]\>\#]|and\b|or\b|if\b|unless\b|\|\||&|=|$))
push:
- meta_scope: string.regexp.simple.imba
- match: '\\\\'
scope: escaped.imba
- match: '\\\/'
scope: escaped.imba
- match: \/[gimy]*
pop: true
literal-regexp:
# Lookahead and prevent incorrect matches by finding a / following an
# identifier or number. Not perfect, but stops most incorrect matches
- match: '(?=({{identifier}}|0[xob]\d+|\d+|\d*\.\d*(e[-+]?\d+)?)\s*/[^/])'
push:
- include: comment
- match: '/'
scope: keyword.operator.arithmetic.imba
pop: true
- include: expr_no_regex
- match: '/(?=.+/[gimy]*(?!\s*[a-zA-Z0-9_$]))'
scope: punctuation.definition.string.begin.imba
push:
- meta_scope: string.regexp.imba
- match: "(/)([gimy]*)"
captures:
1: punctuation.definition.string.end.imba
2: keyword.other.imba
pop: true
- match: '(?=.|\n)'
with_prototype:
- match: '(?=/)'
pop: true
push: scope:source.regexp.js
# Consume a division operator to prevent incorrect highlighting as a regexp
prevent-incorrect-regexp:
- include: comment
- match: '/'
scope: keyword.operator.arithmetic.imba
- match: '(?=[\S\n])'
pop: true
forof:
- match: /(for) ([\w_][\-\w_]*)
import:
- match: \n
pop: true
- match: \b(from|as)\b
scope: keyword.control.imba
- include: filepath
- include: const
require:
- match: \b(require\s*)\b
scope: keyword.control.imba
push: filepath