# Determining if a string corresponds to a builtin type

**URL:** <https://ziggit.dev/t/determining-if-a-string-corresponds-to-a-builtin-type/6812>\
**Category:** Help\
**Tags:** language, standard-library\
**Created:** [November 11, 2024, 5:11pm UTC](https://ziggit.dev/t/determining-if-a-string-corresponds-to-a-builtin-type/6812 "2024-11-11T17:11:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![biosbob](https://ziggit.dev/user_avatar/ziggit.dev/biosbob/32/1987_2.png) [@biosbob](https://ziggit.dev/u/biosbob)\
**Post date:** [November 11, 2024, 5:11pm UTC](https://ziggit.dev/t/determining-if-a-string-corresponds-to-a-builtin-type/6812/1 "2024-11-11T17:11:09Z")

</div>

given strings such as `"bool"` or `"u8"` or `"short"`, is there a library function that tells me whether a particular string corresponds to a builtin type???

i’m already handling this in a textMate grammar using a regex, but i also need a local implementation in zig itself…

is it time for me to bite the bullet and start using a zig regex library???

---

<div class="post-metadata">

**Author:** ![Dok8tavo](https://ziggit.dev/user_avatar/ziggit.dev/dok8tavo/32/707_2.png) [@Dok8tavo](https://ziggit.dev/u/Dok8tavo)\
**Post date:** [November 11, 2024, 6:19pm UTC](https://ziggit.dev/t/determining-if-a-string-corresponds-to-a-builtin-type/6812/2 "2024-11-11T18:19:46Z")

</div>

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:

```zig
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.

---

<div class="post-metadata">

**Author:** ![biosbob](https://ziggit.dev/user_avatar/ziggit.dev/biosbob/32/1987_2.png) [@biosbob](https://ziggit.dev/u/biosbob)\
**Post date:** [November 11, 2024, 6:26pm UTC](https://ziggit.dev/t/determining-if-a-string-corresponds-to-a-builtin-type/6812/3 "2024-11-11T18:26:38Z")

</div>

unfortunately, i need the arbitrary-sized `u` and `i` types… i really **DO** need `\b(u|i)[0-9]+\b`

i’m seeing a lot of recent activity [here](https://ziggit.dev/t/minimum-viable-zig-regex/5160), so maybe that’s the way to go???

---

<div class="post-metadata">

**Author:** ![mnemnion](https://ziggit.dev/user_avatar/ziggit.dev/mnemnion/32/2478_2.png) [@mnemnion](https://ziggit.dev/u/mnemnion)\
**Post date:** [November 11, 2024, 6:33pm UTC](https://ziggit.dev/t/determining-if-a-string-corresponds-to-a-builtin-type/6812/4 "2024-11-11T18:33:20Z")

</div>

Mvzr should handle that regex just fine Bob. It isn’t full-featured but it covers the basics. I encourage you to give it a spin, and see if it meets your needs.

---

<div class="post-metadata">

**Author:** ![dimdin](https://ziggit.dev/user_avatar/ziggit.dev/dimdin/32/1457_2.png) [@dimdin](https://ziggit.dev/u/dimdin)\
**Post date:** [November 11, 2024, 7:38pm UTC](https://ziggit.dev/t/determining-if-a-string-corresponds-to-a-builtin-type/6812/5 "2024-11-11T19:38:31Z")

</div>

If that is the only reason to use regular expressions, perhaps [std.zig.isPrimitive](https://ziglang.org/documentation/master/std/#std.zig.primitives.isPrimitive) is suitable for your needs.
