Skip to content

Commit bfcd589

Browse files
committed
Add elvis operators.
1 parent 0ca634d commit bfcd589

31 files changed

+365
-215
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
Version 0.6.6
2+
=============
3+
4+
* Add the range operator `..`
5+
* Add elvis operators.
6+
7+
18
Version 0.6.5
29
=============
310

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"displayName": "Rhai Language Support",
55
"description": "Syntax highlighting for Rhai scripts",
66
"publisher": "rhaiscript",
7-
"version": "0.6.5",
7+
"version": "0.6.6",
88
"icon": "assets/icon.png",
99
"homepage": "https://rhai.rs",
1010
"bugs": {

syntax/rhai.JSON-tmLanguage

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Rhai",
3-
"version": "v0.6.3",
3+
"version": "v0.6.6",
44
"fileTypes": [
55
"rhai"
66
],
@@ -122,7 +122,7 @@
122122
"patterns": [
123123
{
124124
"name": "meta.group.braces.square",
125-
"begin": "\\[",
125+
"begin": "\\[|\\?\\[",
126126
"beginCaptures": {
127127
"0": {
128128
"name": "meta.brace.square.rhai"
@@ -477,7 +477,7 @@
477477
"patterns": [
478478
{
479479
"name": "meta.function-call.method.without-arguments.rhai",
480-
"match": "(?x) (?<=\\.)\n \\s*([_a-zA-Z]\\w*)\\s*\n (\\(\\s*\\))",
480+
"match": "(?x) (?<=(\\.|\\?\\.))\n \\s*([_a-zA-Z]\\w*)\\s*\n (\\(\\s*\\))",
481481
"captures": {
482482
"1": {
483483
"name": "entity.name.function.rhai"
@@ -489,7 +489,7 @@
489489
},
490490
{
491491
"name": "meta.function-call.method.with-arguments.rhai",
492-
"match": "(?x) (?<=\\.)\n \\s*([_a-zA-Z]\\w*)\\s*\n (?=\\()",
492+
"match": "(?x) (?<=(\\.|\\?\\.))\n \\s*([_a-zA-Z]\\w*)\\s*\n (?=\\()",
493493
"captures": {
494494
"1": {
495495
"name": "entity.name.function.rhai"
@@ -573,41 +573,49 @@
573573
"name": "keyword.operator.logical.rhai",
574574
"match": "(?x) !(?!=)| # logical-not right-to-left right\n && | # logical-and left-to-right both\n \\|\\| # logical-or left-to-right both"
575575
},
576+
{
577+
"name": "keyword.operator.coalesce.rhai",
578+
"match": "(?x) \\?\\? # null-coalesce left-to-right both"
579+
},
576580
{
577581
"name": "keyword.operator.assignment.rhai",
578-
"match": "(?x) =(?![=>]) # assignment right-to-left both"
582+
"match": "(?x) =(?![=>]) # assignment right-to-left both"
579583
},
580584
{
581585
"name": "keyword.operator.assignment.augmented.rhai",
582-
"match": "(?x) %= | # assignment right-to-left both\n &= | # assignment right-to-left both\n \\*\\*=| # assignment right-to-left both\n (?<!\\*)\\*= | # assignment right-to-left both\n \\+= | # assignment right-to-left both\n -= | # assignment right-to-left both\n /= | # assignment right-to-left both\n \\^= | # assignment right-to-left both\n \\|= | # assignment right-to-left both\n <<= | # assignment right-to-left both\n >>= # assignment right-to-left both"
586+
"match": "(?x) %= | # assignment right-to-left both\n &= | # assignment right-to-left both\n \\*\\*=| # assignment right-to-left both\n (?<!\\*)\\*= | # assignment right-to-left both\n \\+= | # assignment right-to-left both\n -= | # assignment right-to-left both\n /= | # assignment right-to-left both\n \\^= | # assignment right-to-left both\n \\|= | # assignment right-to-left both\n <<= | # assignment right-to-left both\n >>= # assignment right-to-left both"
583587
},
584588
{
585589
"name": "keyword.operator.bitwise.rhai",
586-
"match": "(?x) << | # bitwise-shift left-to-right both\n >> | # bitwise-shift left-to-right both\n & | # bitwise-and left-to-right both\n \\^ | # bitwise-xor left-to-right both\n \\| # bitwise-or left-to-right both"
590+
"match": "(?x) << | # bitwise-shift left-to-right both\n >> | # bitwise-shift left-to-right both\n & | # bitwise-and left-to-right both\n \\^ | # bitwise-xor left-to-right both\n \\| # bitwise-or left-to-right both"
587591
},
588592
{
589593
"name": "keyword.operator.relational.rhai",
590-
"match": "(?x) <= | # relational left-to-right both\n >= | # relational left-to-right both\n <(?!-) | # relational left-to-right both\n (?<!-)> # relational left-to-right both"
594+
"match": "(?x) <= | # relational ;eft-to-right both\n >= | # relational left-to-right both\n <(?!-) | # relational left-to-right both\n (?<!-)> # relational left-to-right both"
591595
},
592596
{
593597
"name": "keyword.operator.comparison.rhai",
594-
"match": "(?x) ==(?!=) | # equality left-to-right both\n !=(?!=) # equality left-to-right both"
598+
"match": "(?x) ==(?!=) | # equality left-to-right both\n !=(?!=) # equality left-to-right both"
595599
},
596600
{
597601
"name": "keyword.operator.arithmetic.rhai",
598602
"match": "(?x) / | # division left-to-right both\n % | # modulus left-to-right both\n \\*\\* | # power left-to-right both\n \\*(?!\\)) | # multiplication left-to-right both\n \\+(?!\\+) | # addition left-to-right both\n -(?![>-]) # subtraction left-to-right both"
599603
},
604+
{
605+
"name": "keyword.operator.range.rhai",
606+
"match": "\\.\\.(?!\\.)"
607+
},
600608
{
601609
"name": "keyword.operator.accessor.rhai punctuation.accessor.rhai",
602-
"match": "\\.(?!\\.)"
610+
"match": "\\.(?!\\.)|\\?\\."
603611
},
604612
{
605613
"name": "punctuation.separator.switch.case.rhai",
606614
"match": "=>"
607615
},
608616
{
609617
"name": "invalid.illegal.operator.rhai",
610-
"match": "(\\(\\*|\\*\\)|\\+\\+|--|\\.\\.+|~|#(?!{)|@|\\$(?!{)|->|<-|===|!==|\\:=|\\:\\:<)"
618+
"match": "(\\(\\*|\\*\\)|\\+\\+|--|\\.\\.\\.+|~|#(?!{)|@|\\?|\\$(?!{)|->|<-|===|!==|\\:=|\\:\\:<)"
611619
}
612620
]
613621
},
@@ -796,15 +804,15 @@
796804
"match": "[A-Z][_\\dA-Z]*\\b"
797805
},
798806
{
799-
"match": "(?<!\\.)\\s*([_a-zA-Z]\\w*)\\s*(?=\\.)",
807+
"match": "(?<!\\.)\\s*([_a-zA-Z]\\w*)\\s*(?=(\\.|\\?\\.))",
800808
"captures": {
801809
"1": {
802810
"name": "variable.other.object.rhai"
803811
}
804812
}
805813
},
806814
{
807-
"match": "(?<=\\.)\\s*([_a-zA-Z]\\w*)",
815+
"match": "(?<=(\\.|\\?\\.))\\s*([_a-zA-Z]\\w*)",
808816
"captures": {
809817
"1": {
810818
"name": "variable.other.property.rhai entity.name.property.rhai"

syntax/rhai.YAML-tmLanguage

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# This language definition is based upon https://github.com/Benvie/JavaScriptNext.tmLanguage
33
# Repo: https://github.com/rhaiscript
44
name: Rhai
5-
version: v0.6.3
5+
version: v0.6.6
66
fileTypes: [rhai]
77
uuid: 1e76f176-ee1c-4331-a781-eb21c0da77cf
88
scopeName: source.rhai
@@ -68,7 +68,7 @@ repository:
6868
square-brackets:
6969
patterns:
7070
- name: meta.group.braces.square
71-
begin: \[
71+
begin: \[|\?\[
7272
beginCaptures:
7373
'0': {name: meta.brace.square.rhai}
7474
end: \]
@@ -262,7 +262,7 @@ repository:
262262
- name: meta.function-call.method.without-arguments.rhai
263263
match: >-
264264
(?x)
265-
(?<=\.)
265+
(?<=(\.|\?\.))
266266
\s*([_a-zA-Z]\w*)\s*
267267
(\(\s*\))
268268
captures:
@@ -272,7 +272,7 @@ repository:
272272
- name: meta.function-call.method.with-arguments.rhai
273273
match: >-
274274
(?x)
275-
(?<=\.)
275+
(?<=(\.|\?\.))
276276
\s*([_a-zA-Z]\w*)\s*
277277
(?=\()
278278
captures:
@@ -328,44 +328,48 @@ repository:
328328
!(?!=)| # logical-not right-to-left right
329329
&& | # logical-and left-to-right both
330330
\|\| # logical-or left-to-right both
331+
- name: keyword.operator.coalesce.rhai
332+
match: >-
333+
(?x)
334+
\?\? # null-coalesce left-to-right both
331335
- name: keyword.operator.assignment.rhai
332336
match: >-
333337
(?x)
334-
=(?![=>]) # assignment right-to-left both
338+
=(?![=>]) # assignment right-to-left both
335339
- name: keyword.operator.assignment.augmented.rhai
336340
match: >-
337341
(?x)
338-
%= | # assignment right-to-left both
339-
&= | # assignment right-to-left both
340-
\*\*=| # assignment right-to-left both
341-
(?<!\*)\*= | # assignment right-to-left both
342-
\+= | # assignment right-to-left both
343-
-= | # assignment right-to-left both
344-
/= | # assignment right-to-left both
345-
\^= | # assignment right-to-left both
346-
\|= | # assignment right-to-left both
347-
<<= | # assignment right-to-left both
348-
>>= # assignment right-to-left both
342+
%= | # assignment right-to-left both
343+
&= | # assignment right-to-left both
344+
\*\*=| # assignment right-to-left both
345+
(?<!\*)\*= | # assignment right-to-left both
346+
\+= | # assignment right-to-left both
347+
-= | # assignment right-to-left both
348+
/= | # assignment right-to-left both
349+
\^= | # assignment right-to-left both
350+
\|= | # assignment right-to-left both
351+
<<= | # assignment right-to-left both
352+
>>= # assignment right-to-left both
349353
- name: keyword.operator.bitwise.rhai
350354
match: >-
351355
(?x)
352-
<< | # bitwise-shift left-to-right both
353-
>> | # bitwise-shift left-to-right both
354-
& | # bitwise-and left-to-right both
355-
\^ | # bitwise-xor left-to-right both
356-
\| # bitwise-or left-to-right both
356+
<< | # bitwise-shift left-to-right both
357+
>> | # bitwise-shift left-to-right both
358+
& | # bitwise-and left-to-right both
359+
\^ | # bitwise-xor left-to-right both
360+
\| # bitwise-or left-to-right both
357361
- name: keyword.operator.relational.rhai
358362
match: >-
359363
(?x)
360-
<= | # relational left-to-right both
361-
>= | # relational left-to-right both
362-
<(?!-) | # relational left-to-right both
363-
(?<!-)> # relational left-to-right both
364+
<= | # relational ;eft-to-right both
365+
>= | # relational left-to-right both
366+
<(?!-) | # relational left-to-right both
367+
(?<!-)> # relational left-to-right both
364368
- name: keyword.operator.comparison.rhai
365369
match: >-
366370
(?x)
367-
==(?!=) | # equality left-to-right both
368-
!=(?!=) # equality left-to-right both
371+
==(?!=) | # equality left-to-right both
372+
!=(?!=) # equality left-to-right both
369373
- name: keyword.operator.arithmetic.rhai
370374
match: >-
371375
(?x)
@@ -375,12 +379,14 @@ repository:
375379
\*(?!\)) | # multiplication left-to-right both
376380
\+(?!\+) | # addition left-to-right both
377381
-(?![>-]) # subtraction left-to-right both
382+
- name: keyword.operator.range.rhai
383+
match: \.\.(?!\.)
378384
- name: keyword.operator.accessor.rhai punctuation.accessor.rhai
379-
match: \.(?!\.)
385+
match: \.(?!\.)|\?\.
380386
- name: punctuation.separator.switch.case.rhai
381387
match: =>
382388
- name: invalid.illegal.operator.rhai
383-
match: (\(\*|\*\)|\+\+|--|\.\.+|~|#(?!{)|@|\$(?!{)|->|<-|===|!==|\:=|\:\:<)
389+
match: (\(\*|\*\)|\+\+|--|\.\.\.+|~|#(?!{)|@|\?|\$(?!{)|->|<-|===|!==|\:=|\:\:<)
384390

385391
literal-labels:
386392
patterns:
@@ -496,12 +502,12 @@ repository:
496502
match: '[A-Z][_\dA-Z]*\b'
497503

498504
# e.g. obj.property
499-
- match: (?<!\.)\s*([_a-zA-Z]\w*)\s*(?=\.)
505+
- match: (?<!\.)\s*([_a-zA-Z]\w*)\s*(?=(\.|\?\.))
500506
captures:
501507
'1': {name: variable.other.object.rhai}
502508

503509
# e.g. obj.property
504-
- match: (?<=\.)\s*([_a-zA-Z]\w*)
510+
- match: (?<=(\.|\?\.))\s*([_a-zA-Z]\w*)
505511
captures:
506512
'1': {name: variable.other.property.rhai entity.name.property.rhai}
507513

syntax/rhai.tmLanguage.json

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Rhai",
3-
"version": "v0.6.3",
3+
"version": "v0.6.6",
44
"fileTypes": [
55
"rhai"
66
],
@@ -122,7 +122,7 @@
122122
"patterns": [
123123
{
124124
"name": "meta.group.braces.square",
125-
"begin": "\\[",
125+
"begin": "\\[|\\?\\[",
126126
"beginCaptures": {
127127
"0": {
128128
"name": "meta.brace.square.rhai"
@@ -477,7 +477,7 @@
477477
"patterns": [
478478
{
479479
"name": "meta.function-call.method.without-arguments.rhai",
480-
"match": "(?x) (?<=\\.)\n \\s*([_a-zA-Z]\\w*)\\s*\n (\\(\\s*\\))",
480+
"match": "(?x) (?<=(\\.|\\?\\.))\n \\s*([_a-zA-Z]\\w*)\\s*\n (\\(\\s*\\))",
481481
"captures": {
482482
"1": {
483483
"name": "entity.name.function.rhai"
@@ -489,7 +489,7 @@
489489
},
490490
{
491491
"name": "meta.function-call.method.with-arguments.rhai",
492-
"match": "(?x) (?<=\\.)\n \\s*([_a-zA-Z]\\w*)\\s*\n (?=\\()",
492+
"match": "(?x) (?<=(\\.|\\?\\.))\n \\s*([_a-zA-Z]\\w*)\\s*\n (?=\\()",
493493
"captures": {
494494
"1": {
495495
"name": "entity.name.function.rhai"
@@ -573,41 +573,49 @@
573573
"name": "keyword.operator.logical.rhai",
574574
"match": "(?x) !(?!=)| # logical-not right-to-left right\n && | # logical-and left-to-right both\n \\|\\| # logical-or left-to-right both"
575575
},
576+
{
577+
"name": "keyword.operator.coalesce.rhai",
578+
"match": "(?x) \\?\\? # null-coalesce left-to-right both"
579+
},
576580
{
577581
"name": "keyword.operator.assignment.rhai",
578-
"match": "(?x) =(?![=>]) # assignment right-to-left both"
582+
"match": "(?x) =(?![=>]) # assignment right-to-left both"
579583
},
580584
{
581585
"name": "keyword.operator.assignment.augmented.rhai",
582-
"match": "(?x) %= | # assignment right-to-left both\n &= | # assignment right-to-left both\n \\*\\*=| # assignment right-to-left both\n (?<!\\*)\\*= | # assignment right-to-left both\n \\+= | # assignment right-to-left both\n -= | # assignment right-to-left both\n /= | # assignment right-to-left both\n \\^= | # assignment right-to-left both\n \\|= | # assignment right-to-left both\n <<= | # assignment right-to-left both\n >>= # assignment right-to-left both"
586+
"match": "(?x) %= | # assignment right-to-left both\n &= | # assignment right-to-left both\n \\*\\*=| # assignment right-to-left both\n (?<!\\*)\\*= | # assignment right-to-left both\n \\+= | # assignment right-to-left both\n -= | # assignment right-to-left both\n /= | # assignment right-to-left both\n \\^= | # assignment right-to-left both\n \\|= | # assignment right-to-left both\n <<= | # assignment right-to-left both\n >>= # assignment right-to-left both"
583587
},
584588
{
585589
"name": "keyword.operator.bitwise.rhai",
586-
"match": "(?x) << | # bitwise-shift left-to-right both\n >> | # bitwise-shift left-to-right both\n & | # bitwise-and left-to-right both\n \\^ | # bitwise-xor left-to-right both\n \\| # bitwise-or left-to-right both"
590+
"match": "(?x) << | # bitwise-shift left-to-right both\n >> | # bitwise-shift left-to-right both\n & | # bitwise-and left-to-right both\n \\^ | # bitwise-xor left-to-right both\n \\| # bitwise-or left-to-right both"
587591
},
588592
{
589593
"name": "keyword.operator.relational.rhai",
590-
"match": "(?x) <= | # relational left-to-right both\n >= | # relational left-to-right both\n <(?!-) | # relational left-to-right both\n (?<!-)> # relational left-to-right both"
594+
"match": "(?x) <= | # relational ;eft-to-right both\n >= | # relational left-to-right both\n <(?!-) | # relational left-to-right both\n (?<!-)> # relational left-to-right both"
591595
},
592596
{
593597
"name": "keyword.operator.comparison.rhai",
594-
"match": "(?x) ==(?!=) | # equality left-to-right both\n !=(?!=) # equality left-to-right both"
598+
"match": "(?x) ==(?!=) | # equality left-to-right both\n !=(?!=) # equality left-to-right both"
595599
},
596600
{
597601
"name": "keyword.operator.arithmetic.rhai",
598602
"match": "(?x) / | # division left-to-right both\n % | # modulus left-to-right both\n \\*\\* | # power left-to-right both\n \\*(?!\\)) | # multiplication left-to-right both\n \\+(?!\\+) | # addition left-to-right both\n -(?![>-]) # subtraction left-to-right both"
599603
},
604+
{
605+
"name": "keyword.operator.range.rhai",
606+
"match": "\\.\\.(?!\\.)"
607+
},
600608
{
601609
"name": "keyword.operator.accessor.rhai punctuation.accessor.rhai",
602-
"match": "\\.(?!\\.)"
610+
"match": "\\.(?!\\.)|\\?\\."
603611
},
604612
{
605613
"name": "punctuation.separator.switch.case.rhai",
606614
"match": "=>"
607615
},
608616
{
609617
"name": "invalid.illegal.operator.rhai",
610-
"match": "(\\(\\*|\\*\\)|\\+\\+|--|\\.\\.+|~|#(?!{)|@|\\$(?!{)|->|<-|===|!==|\\:=|\\:\\:<)"
618+
"match": "(\\(\\*|\\*\\)|\\+\\+|--|\\.\\.\\.+|~|#(?!{)|@|\\?|\\$(?!{)|->|<-|===|!==|\\:=|\\:\\:<)"
611619
}
612620
]
613621
},
@@ -796,15 +804,15 @@
796804
"match": "[A-Z][_\\dA-Z]*\\b"
797805
},
798806
{
799-
"match": "(?<!\\.)\\s*([_a-zA-Z]\\w*)\\s*(?=\\.)",
807+
"match": "(?<!\\.)\\s*([_a-zA-Z]\\w*)\\s*(?=(\\.|\\?\\.))",
800808
"captures": {
801809
"1": {
802810
"name": "variable.other.object.rhai"
803811
}
804812
}
805813
},
806814
{
807-
"match": "(?<=\\.)\\s*([_a-zA-Z]\\w*)",
815+
"match": "(?<=(\\.|\\?\\.))\\s*([_a-zA-Z]\\w*)",
808816
"captures": {
809817
"1": {
810818
"name": "variable.other.property.rhai entity.name.property.rhai"

test/array.rhai

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@ print(x[1]);
55

66
x[1] = 5;
77

8-
print("x[1] should be 5:");
9-
print(x[1]);
8+
print(`x[1] should be 5: ${x[1]}`);

test/assignment.rhai

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
print("x should be 78:");
1+
// This script contains a single assignment statement.
22

33
let x = 78;
4-
print(x);
4+
5+
print(`x should be 78: ${x}`);

0 commit comments

Comments
 (0)