Skip to content

Commit cb8e7ce

Browse files
committed
Rewrite based on JavaScript template.
1 parent f09d514 commit cb8e7ce

File tree

3 files changed

+124
-99
lines changed

3 files changed

+124
-99
lines changed

syntax/rhai.YAML-tmLanguage

Lines changed: 52 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# This Rhai language definition is based upon https://github.com/Benvie/JavaScriptNext.tmLanguage
21
# Rhai is an enbedded scripting language and engine for Rust
2+
# This language definition is based upon https://github.com/Benvie/JavaScriptNext.tmLanguage
33
# Repo: https://github.com/rhaiscript
44
name: Rhai
55
version: v0.6.0
@@ -15,26 +15,23 @@ patterns:
1515

1616
repository:
1717
core:
18+
patterns:
19+
- include: '#expression'
20+
21+
expression:
1822
patterns:
1923
- include: '#literal-closure-labels'
2024

2125
- include: '#literal-labels'
2226
- include: '#literal-keywords'
2327
- include: '#literal-switch'
2428

25-
- include: '#expression'
26-
- include: '#literal-punctuation'
27-
28-
expression:
29-
patterns:
3029
- include: '#support'
3130
- include: '#literal-function'
3231
- include: '#literal-closure'
3332

34-
- include: '#literal-number'
33+
- include: '#literal-constant'
3534
- include: '#literal-template-string'
36-
- include: '#literal-string'
37-
- include: '#literal-language-constant'
3835
- include: '#literal-language-variable'
3936

4037
- include: '#literal-module'
@@ -49,6 +46,14 @@ repository:
4946
- include: '#literal-namespace'
5047
- include: '#literal-variable'
5148

49+
- include: '#literal-punctuation'
50+
51+
literal-constant:
52+
patterns:
53+
- include: '#literal-number'
54+
- include: '#literal-string'
55+
- include: '#literal-language-constant'
56+
5257
round-brackets:
5358
patterns:
5459
- name: meta.group.braces.round
@@ -105,19 +110,19 @@ repository:
105110
begin: /\*
106111
end: \*/
107112
captures:
108-
'0': {name: punctuation.definition.comment.rhai}
113+
'0': {name: punctuation.definition.comment.block.rhai}
109114
patterns:
110115
- include: '#comments'
111116

112117
- name: comment.line.documentation.rhai
113118
match: (///)[^/].*$\n?
114119
captures:
115-
'1': {name: punctuation.definition.comment.rhai}
120+
'1': {name: punctuation.definition.comment.documentation.rhai}
116121

117122
- name: comment.line.double-slash.rhai
118123
match: (//).*$\n?
119124
captures:
120-
'1': {name: punctuation.definition.comment.rhai}
125+
'1': {name: punctuation.definition.comment.double-slash.rhai}
121126

122127
- name: comment.line.shebang.rhai
123128
match: ^(#!).*$\n?
@@ -141,7 +146,7 @@ repository:
141146

142147
literal-module:
143148
patterns:
144-
- name: keyword.operator.module.rhai keyword.control.import.rhai
149+
- name: keyword.control.import.rhai
145150
match: \b(import|export|as)\b
146151

147152
literal-function:
@@ -154,8 +159,8 @@ repository:
154159
\s*(fn)
155160
\s*([_a-zA-Z]\w*)\s*
156161
beginCaptures:
157-
'1': {name: storage.type.rhai storage.modifier.rhai}
158-
'2': {name: storage.type.function.rhai keyword.declaration.function.rhai}
162+
'1': {name: storage.modifier.rhai}
163+
'2': {name: storage.type.function.rhai}
159164
'3': {name: entity.name.function.rhai}
160165
end: (?<=\))
161166
patterns:
@@ -232,7 +237,7 @@ repository:
232237
([_a-zA-Z]\w*)(!)?\s*
233238
(\(\s*\))
234239
captures:
235-
'1': {name: variable.function.rhai}
240+
'1': {name: entity.name.function.rhai}
236241
'2': {name: punctuation.function-call.capture.rhai}
237242
'3': {name: meta.group.braces.round.function.arguments.rhai}
238243

@@ -242,7 +247,7 @@ repository:
242247
([_a-zA-Z]\w*)(!)?\s*
243248
(?=\()
244249
captures:
245-
'1': {name: variable.function.rhai}
250+
'1': {name: entity.name.function.rhai}
246251
'2': {name: punctuation.function-call.capture.rhai}
247252

248253
literal-method-call:
@@ -254,7 +259,7 @@ repository:
254259
([_a-zA-Z]\w*)\s*
255260
(\(\s*\))
256261
captures:
257-
'1': {name: variable.function.rhai}
262+
'1': {name: entity.name.function.rhai}
258263
'2': {name: meta.group.braces.round.function.arguments.rhai}
259264

260265
- name: meta.function-call.method.with-arguments.rhai
@@ -264,7 +269,7 @@ repository:
264269
([_a-zA-Z]\w*)\s*
265270
(?=\()
266271
captures:
267-
'1': {name: variable.function.rhai}
272+
'1': {name: entity.name.function.rhai}
268273

269274
literal-language-variable:
270275
patterns:
@@ -310,19 +315,20 @@ repository:
310315
endCaptures:
311316
'0': {name: meta.brace.curly.rhai}
312317
patterns:
313-
- include: '#round-brackets'
318+
- include: '#expression'
314319
- begin: \{
315320
beginCaptures:
316321
'0': {name: meta.brace.curly.rhai}
317322
end: (?=})
318323
patterns:
319-
- begin: \b(case|_)\b
324+
- begin: (?<([\{,\}]|\(\)))
320325
beginCaptures:
321-
'1': {name: keyword.control.switch.rhai}
326+
'1': {name: keyword.control.switch.case.rhai}
322327
end: (?==>)
323328
patterns:
324-
- include: '#expression'
325-
- match: _
329+
- include: '#literal-constant'
330+
- name: name: keyword.control.switch.default.rhai
331+
match: \_
326332
- include: $self
327333

328334
literal-operators:
@@ -336,7 +342,7 @@ repository:
336342
- name: keyword.operator.assignment.rhai
337343
match: >-
338344
(?x)
339-
=(?!=) # assignment right-to-left both
345+
=(?![=>]) # assignment right-to-left both
340346
- name: keyword.operator.assignment.augmented.rhai
341347
match: >-
342348
(?x)
@@ -365,7 +371,7 @@ repository:
365371
<= | # relational left-to-right both
366372
>= | # relational left-to-right both
367373
< | # relational left-to-right both
368-
> # relational left-to-right both
374+
(?<!=)> # relational left-to-right both
369375
- name: keyword.operator.comparison.rhai
370376
match: >-
371377
(?x)
@@ -377,7 +383,7 @@ repository:
377383
/ | # division left-to-right both
378384
% | # modulus left-to-right both
379385
\*\* | # power left-to-right both
380-
(?<!\*)\* | # multiplication left-to-right both
386+
\*(?!\*) | # multiplication left-to-right both
381387
\+ | # addition left-to-right both
382388
- # subtraction left-to-right both
383389
- name: keyword.operator.accessor.rhai punctuation.accessor.rhai
@@ -388,14 +394,14 @@ repository:
388394
- begin: >-
389395
(?x)
390396
(?<!\?)(?<!\?\s)
391-
(?=((")((?:[^"]|\\")*)("))\s*:)
397+
(?=((")((?:[^\:"]|\\")*)("))\s*:)
392398
end: ':'
393399
endCaptures:
394400
'0': {name: punctuation.separator.key-value.rhai}
395401
patterns:
396402
- include: '#literal-string'
397403
- name: constant.other.object.key.rhai
398-
match: (?<!\.|\?|\?\s)([_a-zA-Z]\w*)\s*(:)
404+
match: (?<!\.|\?|\?\s)([_a-zA-Z]\w*)\s*(:)(?!\:)
399405
captures:
400406
'1': {name: string.unquoted.label.rhai}
401407
'2': {name: punctuation.separator.key-value.rhai}
@@ -426,7 +432,7 @@ repository:
426432

427433
literal-template-string:
428434
patterns:
429-
- name: string.template-string.rhai
435+
- name: string.interpolated.rhai
430436
begin: '`'
431437
beginCaptures:
432438
'0': {name: punctuation.definition.string.begin.rhai}
@@ -435,14 +441,13 @@ repository:
435441
'0': {name: punctuation.definition.string.end.rhai}
436442
patterns:
437443
- include: '#string-content'
438-
- name: entity.template-string.element.rhai meta.interpolation.rhai
444+
- name: meta.interpolation.rhai
439445
begin: \${
440446
beginCaptures:
441447
'0': {name: punctuation.section.interpolation.begin.rhai}
442448
end: '}'
443449
endCaptures:
444450
'0': {name: punctuation.section.interpolation.end.rhai}
445-
clear_scope: string.*
446451
patterns:
447452
- include: '#expression'
448453

@@ -477,13 +482,18 @@ repository:
477482

478483
literal-namespace:
479484
patterns:
480-
- name: meta.path
481-
match: ((?:([_a-zA-Z]\w*)\s*(\:\:)\s*)+)([_a-zA-Z]\w*)
485+
# e.g. ns::var
486+
- name: meta.path.rhai
487+
match: ([_a-zA-Z]\w*)\s*(\:\:)
488+
captures:
489+
'1': {name: entity.name.namespace.rhai}
490+
'2': {name: punctuation.separator.namespace.rhai}
491+
492+
# e.g. ns::var
493+
- match: (?<=\:\:)(\s*([_a-zA-Z]\w*))\s*(?!\:\:)
482494
captures:
483-
'1': {name: meta.namespace.rhai}
484-
'2': {name: entity.name.namespace.rhai}
485-
'3': {name: punctuation.separator.namespace.rhai}
486-
'4': {name: variable.other.readwrite.rhai}
495+
'1': {name: meta.path.rhai}
496+
'2': {name: variable.other.constant.rhai}
487497

488498
literal-variable:
489499
patterns:
@@ -492,16 +502,14 @@ repository:
492502
match: '[A-Z][_\dA-Z]*\b'
493503

494504
# e.g. obj.property
495-
- name: variable.other.object.rhai
496-
match: (?<!\.)[_a-zA-Z]\w*\s*(?=[\[\.])
505+
- match: (?<!\.)([_a-zA-Z]\w*)\s*(?=\.)
497506
captures:
498507
'1': {name: variable.other.object.rhai}
499508

500509
# e.g. obj.property
501-
- name: meta.property.object.rhai
502-
match: (?<=\.)\s*[_a-zA-Z]\w*
510+
- match: (?<=\.)\s*([_a-zA-Z]\w*)
503511
captures:
504-
'2': {name: variable.other.property.rhai}
512+
'1': {name: variable.other.property.rhai entity.name.property.rhai}
505513

506514
- name: variable.other.readwrite.rhai
507515
match: '[_a-zA-Z]\w*'
@@ -510,5 +518,5 @@ repository:
510518
# built-ins
511519
- name: support.function.rhai
512520
match: \b(print|debug|call|curry|eval|type_of|is_def_var|is_def_fn|is_shared)\b
513-
- name: invalid.illegal.rhai
521+
- name: invalid.illegal.keyword.rhai
514522
match: \b(var|static|begin|end|shared|each|then|goto|exit|unless|match|case|public|protected|new|use|with|module|package|super|thread|spawn|go|await|async|sync|yield|default|void|null|nil)\b

0 commit comments

Comments
 (0)