Skip to content

Commit 27c86f9

Browse files
Merge branch 'lemz1-null-coalescing' into funkin-dev
2 parents 2cd322e + 7611d95 commit 27c86f9

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
@@ -98,6 +98,7 @@ class Interp {
9898
binops.set("=",assign);
9999
binops.set("...",function(e1,e2) return new IntIterator(me.expr(e1),me.expr(e2)));
100100
binops.set("is",function(e1,e2) return #if (haxe_ver >= 4.2) Std.isOfType #else Std.is #end (me.expr(e1), me.expr(e2)));
101+
binops.set("??",function(e1,e2) return me.expr(e1) ?? me.expr(e2));
101102
assignOp("+=",function(v1:Dynamic,v2:Dynamic) return v1 + v2);
102103
assignOp("-=",function(v1:Float,v2:Float) return v1 - v2);
103104
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
@@ -105,7 +105,7 @@ class Parser {
105105

106106
public function new() {
107107
line = 1;
108-
opChars = "+*/-=!><&|^%~";
108+
opChars = "+*/-=!><&|^%~?";
109109
identChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
110110
var priorities = [
111111
["%"],
@@ -117,6 +117,7 @@ class Parser {
117117
["..."],
118118
["&&"],
119119
["||"],
120+
["??"],
120121
["=","+=","-=","*=","/=","%=","<<=",">>=",">>>=","|=","&=","^=","=>"],
121122
["->"]
122123
];
@@ -125,7 +126,7 @@ class Parser {
125126
for( i in 0...priorities.length )
126127
for( x in priorities[i] ) {
127128
opPriority.set(x, i);
128-
if( i == 9 ) opRightAssoc.set(x, true);
129+
if( i == 10 ) opRightAssoc.set(x, true);
129130
}
130131
for( x in ["!", "++", "--", "~"] ) // unary "-" handled in parser directly!
131132
opPriority.set(x, x == "++" || x == "--" ? -1 : -2);
@@ -1478,6 +1479,8 @@ class Parser {
14781479
char = readChar();
14791480
if( char == ".".code )
14801481
return TQuestionDot;
1482+
if( char == "?".code )
1483+
return TOp("??");
14811484
this.char = char;
14821485
return TQuestion;
14831486
case ":".code: return TDoubleDot;

0 commit comments

Comments
 (0)