The enum std.builtin.Type.ContainerType
previously had fields with upper-case camcelCase. It’s currently defined as:
enum {
auto,
@"extern",
@"packed",
}
Because extern
and packed
are keywords, the use of @"..."
is necessary. To set the layout of a struct for @Type()
to packed, you have to escape the enum name:
return @Type({
.layout = .@"packed",
// ...
});
I was thinking, what if we allow keywords to be interpreted as identifiers whenever they come immediately after a .
? That would allow a less ugly syntax:
return @Type({
.layout = .packed,
// ...
});
And permit snake_case to be used for enum throughout the standard library. Currently, the naming convention allows uppercase camelCase when clashes with keywords occur. This sounds like a reasonable compromise but this exception is absolutely pervasive because we switch on @typeInfo()
all the time.
Allowing .struct
, .packed
, etc. should require only trivial changes to the lexer. Basically, immediately after a period we don’t perform keyword look-up. The fact that this hasn’t happened yet makes me wonder if there’s some reason not to do so that I’m overlooking.