Skip to content

Commit 7611d95

Browse files
committed
add null coalescing
1 parent 1278539 commit 7611d95

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

hscript/Interp.hx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ class Interp {
117117
binops.set("=",assign);
118118
binops.set("...",function(e1,e2) return new #if (haxe_211 || haxe3) IntIterator #else IntIter #end(me.expr(e1),me.expr(e2)));
119119
binops.set("is",function(e1,e2) return #if (haxe_ver >= 4.2) Std.isOfType #else Std.is #end (me.expr(e1), me.expr(e2)));
120+
binops.set("??",function(e1,e2) return me.expr(e1) ?? me.expr(e2));
120121
assignOp("+=",function(v1:Dynamic,v2:Dynamic) return v1 + v2);
121122
assignOp("-=",function(v1:Float,v2:Float) return v1 - v2);
122123
assignOp("*=",function(v1:Float,v2:Float) return v1 * v2);

hscript/Parser.hx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class Parser {
115115

116116
public function new() {
117117
line = 1;
118-
opChars = "+*/-=!><&|^%~";
118+
opChars = "+*/-=!><&|^%~?";
119119
identChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
120120
var priorities = [
121121
["%"],
@@ -127,6 +127,7 @@ class Parser {
127127
["..."],
128128
["&&"],
129129
["||"],
130+
["??"],
130131
["=","+=","-=","*=","/=","%=","<<=",">>=",">>>=","|=","&=","^=","=>"],
131132
["->"]
132133
];
@@ -140,7 +141,7 @@ class Parser {
140141
for( i in 0...priorities.length )
141142
for( x in priorities[i] ) {
142143
opPriority.set(x, i);
143-
if( i == 9 ) opRightAssoc.set(x, true);
144+
if( i == 10 ) opRightAssoc.set(x, true);
144145
}
145146
for( x in ["!", "++", "--", "~"] ) // unary "-" handled in parser directly!
146147
opPriority.set(x, x == "++" || x == "--" ? -1 : -2);
@@ -1508,6 +1509,8 @@ class Parser {
15081509
char = readChar();
15091510
if( char == ".".code )
15101511
return TQuestionDot;
1512+
if( char == "?".code )
1513+
return TOp("??");
15111514
this.char = char;
15121515
return TQuestion;
15131516
case ":".code: return TDoubleDot;

0 commit comments

Comments
 (0)