From: Brendan Hansen Date: Wed, 14 Jun 2023 03:06:44 +0000 (-0500) Subject: added: parsing a `? T` with try to parse `T` X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=2ca1463e159f7c38efbf82bb587d547d36a9dcd4;p=onyx.git added: parsing a `? T` with try to parse `T` --- diff --git a/core/conv/parse.onyx b/core/conv/parse.onyx index a248b591..18dc22d0 100644 --- a/core/conv/parse.onyx +++ b/core/conv/parse.onyx @@ -4,6 +4,7 @@ use core.map use core.string use core.array use core.math +use core.memory use runtime #doc """ @@ -88,6 +89,15 @@ parse_any :: (target: rawptr, data_type: type_expr, to_parse: str, string_alloca d_info := cast(&Type_Info_Distinct) info; return parse_any(target, d_info.base_type, to_parse, string_allocator); } + + if info.kind == .Union && union_constructed_from(data_type, Optional) { + parsed_successful := parse_any(memory.ptr_add(target, info.alignment), info->as_union().variants[1].type, to_parse, string_allocator); + if !parsed_successful { + *cast(& u32) target = ~~ Optional(void).tag_enum.None; + } else { + *cast(& u32) target = ~~ Optional(void).tag_enum.Some; + } + } } }