It’s not out yet, but in my project, I do a very primitive kind of parsing of zig and I have a StaticStringMap
of some identifiers. Here’s the part for the builtin types:
const map = std.StaticStringMap(TokenKind).initComptime(.{
// various things here
...
// various builtin types
.{ "anyerror", TokenKind.builtin_type },
.{ "anyframe", TokenKind.builtin_type },
.{ "anyopaque", TokenKind.builtin_type },
.{ "anytype", TokenKind.builtin_type }, // this isn't technically a type, but it makes sense for me
.{ "bool", TokenKind.builtin_type },
.{ "noreturn", TokenKind.builtin_type },
.{ "type", TokenKind.builtin_type },
.{ "void", TokenKind.builtin_type },
// builtin integers
.{ "c_char", TokenKind.builtin_type },
.{ "c_int", TokenKind.builtin_type },
.{ "c_long", TokenKind.builtin_type },
.{ "c_longlong", TokenKind.builtin_type },
.{ "c_short", TokenKind.builtin_type },
.{ "c_uint", TokenKind.builtin_type },
.{ "c_ulong", TokenKind.builtin_type },
.{ "c_ulonglong", TokenKind.builtin_type },
.{ "c_ushort", TokenKind.builtin_type },
.{ "comptime_int", TokenKind.builtin_type },
.{ "isize", TokenKind.builtin_type },
.{ "usize", TokenKind.builtin_type },
// builtin floating points
.{ "c_longdouble", TokenKind.builtin_type },
.{ "comptime_float", TokenKind.builtin_type },
.{ "f16", TokenKind.builtin_type },
.{ "f32", TokenKind.builtin_type },
.{ "f64", TokenKind.builtin_type },
.{ "f80", TokenKind.builtin_type },
.{ "f128", TokenKind.builtin_type },
// other various things here
...
});
Please note that these do not include all the integers types as you can go for arbitrary size \b(u|i)[0-9]+\b
. However they don’t go further than 65535, but I don’t know if it’s an edge case you care about.
Hope it helps.