Binary_Op_Subscript_Equals = 37,
Binary_Op_Ptr_Subscript = 38,
+ Binary_Op_Coalesce = 39,
+
Binary_Op_Count
} BinaryOp;
Token_Type_Dot_Dot,
Token_Type_Tilde_Tilde,
+ Token_Type_Question_Question,
Token_Type_Symbol,
Token_Type_Literal_String,
"|>", "..", "->",
"[]", "[]=", "^[]",
+
+ "??"
};
const char* entity_state_strings[Entity_State_Count] = {
case '~':
LITERAL_TOKEN("~~", 0, Token_Type_Tilde_Tilde);
break;
+
+ case '?':
+ LITERAL_TOKEN("??", 0, Token_Type_Question_Question);
+ break;
}
// Symbols
case Binary_Op_Method_Call: return 10;
+ case Binary_Op_Coalesce: return 11;
+
default: return -1;
}
}
case Token_Type_Dot_Dot: return Binary_Op_Range;
case '[': return Binary_Op_Subscript;
case Token_Type_Right_Arrow: return Binary_Op_Method_Call;
+ case Token_Type_Question_Question: return Binary_Op_Coalesce;
default: return Binary_Op_Count;
}
}
return #from_enclosing .{};
}
+ catch :: macro (o: ?$T, body: Code) -> T {
+ value := o;
+ if value.has_value do return value.value;
+
+ #unquote body;
+ }
+
hash :: (o: ?$T/core.hash.Hashable) -> u32 {
if !o.has_value do return 0;
return core.hash.to_u32(o.value);
return o1.value == o2.value;
}
+#operator ?? macro (opt: ?$T, catch: Code) -> T {
+ value := opt;
+ if value do return value.value;
+
+ #unquote catch;
+}
+
+#operator ?? macro (opt: ?$T, default: T) -> T {
+ value := opt;
+ if value do return value.value;
+
+ return default;
+}
+
+
#overload
__implicit_bool_cast :: macro (o: ?$T) => o.has_value;