Skip to content

Commit

Permalink
Add elvis operators.
Browse files Browse the repository at this point in the history
  • Loading branch information
schungx committed Jun 12, 2022
1 parent 0ca634d commit bfcd589
Show file tree
Hide file tree
Showing 31 changed files with 365 additions and 215 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Version 0.6.6
=============

* Add the range operator `..`
* Add elvis operators.


Version 0.6.5
=============

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"displayName": "Rhai Language Support",
"description": "Syntax highlighting for Rhai scripts",
"publisher": "rhaiscript",
"version": "0.6.5",
"version": "0.6.6",
"icon": "assets/icon.png",
"homepage": "https://rhai.rs",
"bugs": {
Expand Down
34 changes: 21 additions & 13 deletions syntax/rhai.JSON-tmLanguage
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Rhai",
"version": "v0.6.3",
"version": "v0.6.6",
"fileTypes": [
"rhai"
],
Expand Down Expand Up @@ -122,7 +122,7 @@
"patterns": [
{
"name": "meta.group.braces.square",
"begin": "\\[",
"begin": "\\[|\\?\\[",
"beginCaptures": {
"0": {
"name": "meta.brace.square.rhai"
Expand Down Expand Up @@ -477,7 +477,7 @@
"patterns": [
{
"name": "meta.function-call.method.without-arguments.rhai",
"match": "(?x) (?<=\\.)\n \\s*([_a-zA-Z]\\w*)\\s*\n (\\(\\s*\\))",
"match": "(?x) (?<=(\\.|\\?\\.))\n \\s*([_a-zA-Z]\\w*)\\s*\n (\\(\\s*\\))",
"captures": {
"1": {
"name": "entity.name.function.rhai"
Expand All @@ -489,7 +489,7 @@
},
{
"name": "meta.function-call.method.with-arguments.rhai",
"match": "(?x) (?<=\\.)\n \\s*([_a-zA-Z]\\w*)\\s*\n (?=\\()",
"match": "(?x) (?<=(\\.|\\?\\.))\n \\s*([_a-zA-Z]\\w*)\\s*\n (?=\\()",
"captures": {
"1": {
"name": "entity.name.function.rhai"
Expand Down Expand Up @@ -573,41 +573,49 @@
"name": "keyword.operator.logical.rhai",
"match": "(?x) !(?!=)| # logical-not right-to-left right\n && | # logical-and left-to-right both\n \\|\\| # logical-or left-to-right both"
},
{
"name": "keyword.operator.coalesce.rhai",
"match": "(?x) \\?\\? # null-coalesce left-to-right both"
},
{
"name": "keyword.operator.assignment.rhai",
"match": "(?x) =(?![=>]) # assignment right-to-left both"
"match": "(?x) =(?![=>]) # assignment right-to-left both"
},
{
"name": "keyword.operator.assignment.augmented.rhai",
"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"
"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"
},
{
"name": "keyword.operator.bitwise.rhai",
"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"
"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"
},
{
"name": "keyword.operator.relational.rhai",
"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"
"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"
},
{
"name": "keyword.operator.comparison.rhai",
"match": "(?x) ==(?!=) | # equality left-to-right both\n !=(?!=) # equality left-to-right both"
"match": "(?x) ==(?!=) | # equality left-to-right both\n !=(?!=) # equality left-to-right both"
},
{
"name": "keyword.operator.arithmetic.rhai",
"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"
},
{
"name": "keyword.operator.range.rhai",
"match": "\\.\\.(?!\\.)"
},
{
"name": "keyword.operator.accessor.rhai punctuation.accessor.rhai",
"match": "\\.(?!\\.)"
"match": "\\.(?!\\.)|\\?\\."
},
{
"name": "punctuation.separator.switch.case.rhai",
"match": "=>"
},
{
"name": "invalid.illegal.operator.rhai",
"match": "(\\(\\*|\\*\\)|\\+\\+|--|\\.\\.+|~|#(?!{)|@|\\$(?!{)|->|<-|===|!==|\\:=|\\:\\:<)"
"match": "(\\(\\*|\\*\\)|\\+\\+|--|\\.\\.\\.+|~|#(?!{)|@|\\?|\\$(?!{)|->|<-|===|!==|\\:=|\\:\\:<)"
}
]
},
Expand Down Expand Up @@ -796,15 +804,15 @@
"match": "[A-Z][_\\dA-Z]*\\b"
},
{
"match": "(?<!\\.)\\s*([_a-zA-Z]\\w*)\\s*(?=\\.)",
"match": "(?<!\\.)\\s*([_a-zA-Z]\\w*)\\s*(?=(\\.|\\?\\.))",
"captures": {
"1": {
"name": "variable.other.object.rhai"
}
}
},
{
"match": "(?<=\\.)\\s*([_a-zA-Z]\\w*)",
"match": "(?<=(\\.|\\?\\.))\\s*([_a-zA-Z]\\w*)",
"captures": {
"1": {
"name": "variable.other.property.rhai entity.name.property.rhai"
Expand Down
68 changes: 37 additions & 31 deletions syntax/rhai.YAML-tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This language definition is based upon https://github.com/Benvie/JavaScriptNext.tmLanguage
# Repo: https://github.com/rhaiscript
name: Rhai
version: v0.6.3
version: v0.6.6
fileTypes: [rhai]
uuid: 1e76f176-ee1c-4331-a781-eb21c0da77cf
scopeName: source.rhai
Expand Down Expand Up @@ -68,7 +68,7 @@ repository:
square-brackets:
patterns:
- name: meta.group.braces.square
begin: \[
begin: \[|\?\[
beginCaptures:
'0': {name: meta.brace.square.rhai}
end: \]
Expand Down Expand Up @@ -262,7 +262,7 @@ repository:
- name: meta.function-call.method.without-arguments.rhai
match: >-
(?x)
(?<=\.)
(?<=(\.|\?\.))
\s*([_a-zA-Z]\w*)\s*
(\(\s*\))
captures:
Expand All @@ -272,7 +272,7 @@ repository:
- name: meta.function-call.method.with-arguments.rhai
match: >-
(?x)
(?<=\.)
(?<=(\.|\?\.))
\s*([_a-zA-Z]\w*)\s*
(?=\()
captures:
Expand Down Expand Up @@ -328,44 +328,48 @@ repository:
!(?!=)| # logical-not right-to-left right
&& | # logical-and left-to-right both
\|\| # logical-or left-to-right both
- name: keyword.operator.coalesce.rhai
match: >-
(?x)
\?\? # null-coalesce left-to-right both
- name: keyword.operator.assignment.rhai
match: >-
(?x)
=(?![=>]) # assignment right-to-left both
=(?![=>]) # assignment right-to-left both
- name: keyword.operator.assignment.augmented.rhai
match: >-
(?x)
%= | # assignment right-to-left both
&= | # assignment right-to-left both
\*\*=| # assignment right-to-left both
(?<!\*)\*= | # assignment right-to-left both
\+= | # assignment right-to-left both
-= | # assignment right-to-left both
/= | # assignment right-to-left both
\^= | # assignment right-to-left both
\|= | # assignment right-to-left both
<<= | # assignment right-to-left both
>>= # assignment right-to-left both
%= | # assignment right-to-left both
&= | # assignment right-to-left both
\*\*=| # assignment right-to-left both
(?<!\*)\*= | # assignment right-to-left both
\+= | # assignment right-to-left both
-= | # assignment right-to-left both
/= | # assignment right-to-left both
\^= | # assignment right-to-left both
\|= | # assignment right-to-left both
<<= | # assignment right-to-left both
>>= # assignment right-to-left both
- name: keyword.operator.bitwise.rhai
match: >-
(?x)
<< | # bitwise-shift left-to-right both
>> | # bitwise-shift left-to-right both
& | # bitwise-and left-to-right both
\^ | # bitwise-xor left-to-right both
\| # bitwise-or left-to-right both
<< | # bitwise-shift left-to-right both
>> | # bitwise-shift left-to-right both
& | # bitwise-and left-to-right both
\^ | # bitwise-xor left-to-right both
\| # bitwise-or left-to-right both
- name: keyword.operator.relational.rhai
match: >-
(?x)
<= | # relational left-to-right both
>= | # relational left-to-right both
<(?!-) | # relational left-to-right both
(?<!-)> # relational left-to-right both
<= | # relational ;eft-to-right both
>= | # relational left-to-right both
<(?!-) | # relational left-to-right both
(?<!-)> # relational left-to-right both
- name: keyword.operator.comparison.rhai
match: >-
(?x)
==(?!=) | # equality left-to-right both
!=(?!=) # equality left-to-right both
==(?!=) | # equality left-to-right both
!=(?!=) # equality left-to-right both
- name: keyword.operator.arithmetic.rhai
match: >-
(?x)
Expand All @@ -375,12 +379,14 @@ repository:
\*(?!\)) | # multiplication left-to-right both
\+(?!\+) | # addition left-to-right both
-(?![>-]) # subtraction left-to-right both
- name: keyword.operator.range.rhai
match: \.\.(?!\.)
- name: keyword.operator.accessor.rhai punctuation.accessor.rhai
match: \.(?!\.)
match: \.(?!\.)|\?\.
- name: punctuation.separator.switch.case.rhai
match: =>
- name: invalid.illegal.operator.rhai
match: (\(\*|\*\)|\+\+|--|\.\.+|~|#(?!{)|@|\$(?!{)|->|<-|===|!==|\:=|\:\:<)
match: (\(\*|\*\)|\+\+|--|\.\.\.+|~|#(?!{)|@|\?|\$(?!{)|->|<-|===|!==|\:=|\:\:<)

literal-labels:
patterns:
Expand Down Expand Up @@ -496,12 +502,12 @@ repository:
match: '[A-Z][_\dA-Z]*\b'

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

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

Expand Down
34 changes: 21 additions & 13 deletions syntax/rhai.tmLanguage.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Rhai",
"version": "v0.6.3",
"version": "v0.6.6",
"fileTypes": [
"rhai"
],
Expand Down Expand Up @@ -122,7 +122,7 @@
"patterns": [
{
"name": "meta.group.braces.square",
"begin": "\\[",
"begin": "\\[|\\?\\[",
"beginCaptures": {
"0": {
"name": "meta.brace.square.rhai"
Expand Down Expand Up @@ -477,7 +477,7 @@
"patterns": [
{
"name": "meta.function-call.method.without-arguments.rhai",
"match": "(?x) (?<=\\.)\n \\s*([_a-zA-Z]\\w*)\\s*\n (\\(\\s*\\))",
"match": "(?x) (?<=(\\.|\\?\\.))\n \\s*([_a-zA-Z]\\w*)\\s*\n (\\(\\s*\\))",
"captures": {
"1": {
"name": "entity.name.function.rhai"
Expand All @@ -489,7 +489,7 @@
},
{
"name": "meta.function-call.method.with-arguments.rhai",
"match": "(?x) (?<=\\.)\n \\s*([_a-zA-Z]\\w*)\\s*\n (?=\\()",
"match": "(?x) (?<=(\\.|\\?\\.))\n \\s*([_a-zA-Z]\\w*)\\s*\n (?=\\()",
"captures": {
"1": {
"name": "entity.name.function.rhai"
Expand Down Expand Up @@ -573,41 +573,49 @@
"name": "keyword.operator.logical.rhai",
"match": "(?x) !(?!=)| # logical-not right-to-left right\n && | # logical-and left-to-right both\n \\|\\| # logical-or left-to-right both"
},
{
"name": "keyword.operator.coalesce.rhai",
"match": "(?x) \\?\\? # null-coalesce left-to-right both"
},
{
"name": "keyword.operator.assignment.rhai",
"match": "(?x) =(?![=>]) # assignment right-to-left both"
"match": "(?x) =(?![=>]) # assignment right-to-left both"
},
{
"name": "keyword.operator.assignment.augmented.rhai",
"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"
"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"
},
{
"name": "keyword.operator.bitwise.rhai",
"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"
"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"
},
{
"name": "keyword.operator.relational.rhai",
"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"
"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"
},
{
"name": "keyword.operator.comparison.rhai",
"match": "(?x) ==(?!=) | # equality left-to-right both\n !=(?!=) # equality left-to-right both"
"match": "(?x) ==(?!=) | # equality left-to-right both\n !=(?!=) # equality left-to-right both"
},
{
"name": "keyword.operator.arithmetic.rhai",
"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"
},
{
"name": "keyword.operator.range.rhai",
"match": "\\.\\.(?!\\.)"
},
{
"name": "keyword.operator.accessor.rhai punctuation.accessor.rhai",
"match": "\\.(?!\\.)"
"match": "\\.(?!\\.)|\\?\\."
},
{
"name": "punctuation.separator.switch.case.rhai",
"match": "=>"
},
{
"name": "invalid.illegal.operator.rhai",
"match": "(\\(\\*|\\*\\)|\\+\\+|--|\\.\\.+|~|#(?!{)|@|\\$(?!{)|->|<-|===|!==|\\:=|\\:\\:<)"
"match": "(\\(\\*|\\*\\)|\\+\\+|--|\\.\\.\\.+|~|#(?!{)|@|\\?|\\$(?!{)|->|<-|===|!==|\\:=|\\:\\:<)"
}
]
},
Expand Down Expand Up @@ -796,15 +804,15 @@
"match": "[A-Z][_\\dA-Z]*\\b"
},
{
"match": "(?<!\\.)\\s*([_a-zA-Z]\\w*)\\s*(?=\\.)",
"match": "(?<!\\.)\\s*([_a-zA-Z]\\w*)\\s*(?=(\\.|\\?\\.))",
"captures": {
"1": {
"name": "variable.other.object.rhai"
}
}
},
{
"match": "(?<=\\.)\\s*([_a-zA-Z]\\w*)",
"match": "(?<=(\\.|\\?\\.))\\s*([_a-zA-Z]\\w*)",
"captures": {
"1": {
"name": "variable.other.property.rhai entity.name.property.rhai"
Expand Down
3 changes: 1 addition & 2 deletions test/array.rhai
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ print(x[1]);

x[1] = 5;

print("x[1] should be 5:");
print(x[1]);
print(`x[1] should be 5: ${x[1]}`);
5 changes: 3 additions & 2 deletions test/assignment.rhai
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
print("x should be 78:");
// This script contains a single assignment statement.

let x = 78;
print(x);

print(`x should be 78: ${x}`);
Loading

0 comments on commit bfcd589

Please sign in to comment.