You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm calling for a partial reversal of a463dc7 which made it so that @"" is disallowed, everywhere.
My question is, how do I parse this valid JSON data using std.json.parse?
{
"": 123
}
This is no longer possible:
conststd=@import("std");
constjson=std.json;
constpayload=\\{\\ "": 123\\}
;
constConfig=struct {
@"": u8,
};
constconfig=x: {
varstream=json.TokenStream.init(payload);
constres=json.parse(Config, &stream, .{});
// Assert no error can occur since we are// parsing this JSON at comptime!break :xrescatchunreachable;
};
pubfnmain() !void {
std.log.info("\"\": {d}", .{config.@""});
}
x.zig:9:5: error: identifier cannot be empty
@"": u8,
^~~
x.zig:19:40: error: identifier cannot be empty
std.log.info("\"\": {d}", .{config.@""});
^~~
I'm facing a problem like this right now. Especially with Zig not having something like tags/attributes/annotations (#1099, #14656) for fields, the only thing I can think of is to come up with a special representation for empty fields without clashes. It can be kind of annoying especially because Zig should be able to handle @"" in a lot of places like these just fine.
Proposal
I think @"" should be allowed whenever it can be handled properly:
const @"" = 1 and var @"" = 1 should be perfectly fine
test "" should be fine. It may not look clean and may look weird if the name is interpolated into a string, but so does a test name with a single space or unprintable characters so I think an empty test name should be allowed too.
@"" as the field name in packed and normal structs
@"" for the name of a non-export function
But it should not be allowed in places such as:
extern const or export var
extern struct
export fn
Basically it shouldn't be allowed in anything that interfaces with the outside world as it may not be possible to handle there. For example I don't think C has some way of defining a field with an empty name (correct me if I'm wrong).
Things like @import("") should also stay disallowed, though.
Other Commentary
Another reason I have is that usually Zig avoids special cases like these where an empty string is not allowed so I find it odd that it is not allowed at all. Instead we should move the special cases over to mostly extern/export stuff where it simply cannot be represented properly.
Basically, I think it should be allowed everywhere where it is possible to properly handle an empty identifier.
Even JSON has the ability to represent null bytes in map keys.
JSON also has the ability for empty keys. So allowing @"" would benefit ZON too and bring it on the same level as JSON in this regard. I do think ZON is currently lacking here.
The text was updated successfully, but these errors were encountered:
Preface
I'm calling for a partial reversal of a463dc7 which made it so that
@""
is disallowed, everywhere.My question is, how do I parse this valid JSON data using
std.json.parse
?This is no longer possible:
I'm facing a problem like this right now. Especially with Zig not having something like tags/attributes/annotations (#1099, #14656) for fields, the only thing I can think of is to come up with a special representation for empty fields without clashes. It can be kind of annoying especially because Zig should be able to handle
@""
in a lot of places like these just fine.Proposal
I think
@""
should be allowed whenever it can be handled properly:const @"" = 1
andvar @"" = 1
should be perfectly finetest ""
should be fine. It may not look clean and may look weird if the name is interpolated into a string, but so does a test name with a single space or unprintable characters so I think an empty test name should be allowed too.@""
as the field name inpacked
and normalstruct
s@""
for the name of a non-export
functionBut it should not be allowed in places such as:
extern const
orexport var
extern struct
export fn
Basically it shouldn't be allowed in anything that interfaces with the outside world as it may not be possible to handle there. For example I don't think C has some way of defining a field with an empty name (correct me if I'm wrong).
Things like
@import("")
should also stay disallowed, though.Other Commentary
Another reason I have is that usually Zig avoids special cases like these where an empty string is not allowed so I find it odd that it is not allowed at all. Instead we should move the special cases over to mostly
extern
/export
stuff where it simply cannot be represented properly.Basically, I think it should be allowed everywhere where it is possible to properly handle an empty identifier.
Also, from #14534:
JSON also has the ability for empty keys. So allowing
@""
would benefit ZON too and bring it on the same level as JSON in this regard. I do think ZON is currently lacking here.The text was updated successfully, but these errors were encountered: