Skip to content

Commit 367285f

Browse files
committed
??= operator
1 parent d60bb29 commit 367285f

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
];
@@ -1570,8 +1570,12 @@ class Parser {
15701570
char = readChar();
15711571
if( char == ".".code )
15721572
return TQuestionDot;
1573-
if( char == "?".code )
1573+
if( char == "?".code ) {
1574+
char = readChar();
1575+
if ( char == "=".code )
1576+
return TOp("??=");
15741577
return TOp("??");
1578+
}
15751579
this.char = char;
15761580
return TQuestion;
15771581
case ":".code: return TDoubleDot;

0 commit comments

Comments
 (0)