Skip to content

Commit 1790d83

Browse files
Merge pull request #2 from lemz1/feature/null-coalescing
[FEATURE] ??= Operator
2 parents 0005c0b + 367285f commit 1790d83

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

hscript/Interp.hx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ class Interp {
110110
assignOp("<<=",function(v1,v2) return v1 << v2);
111111
assignOp(">>=",function(v1,v2) return v1 >> v2);
112112
assignOp(">>>=",function(v1,v2) return v1 >>> v2);
113+
assignOp("??=",function(v1,v2) return v1 ?? v2);
113114
}
114115

115116
function setVar( name : String, v : Dynamic ) {

hscript/Parser.hx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class Parser {
118118
["&&"],
119119
["||"],
120120
["??"],
121-
["=","+=","-=","*=","/=","%=","<<=",">>=",">>>=","|=","&=","^=","=>"],
121+
["=","+=","-=","*=","/=","%=","<<=",">>=",">>>=","??=","|=","&=","^=","=>"],
122122
["->"],
123123
["in","is"]
124124
];
@@ -1610,8 +1610,12 @@ class Parser {
16101610
char = readChar();
16111611
if( char == ".".code )
16121612
return TQuestionDot;
1613-
if( char == "?".code )
1613+
if( char == "?".code ) {
1614+
char = readChar();
1615+
if ( char == "=".code )
1616+
return TOp("??=");
16141617
return TOp("??");
1618+
}
16151619
this.char = char;
16161620
return TQuestion;
16171621
case ":".code: return TDoubleDot;

0 commit comments

Comments
 (0)