How am I meant to use @(tag=<string>)?

Hello, I am learning odin for fun at the moment, and the overview has this point, that caught my eye.

It says @(tag=<string>) is useful for metaprogramming, but there is no example on how it’s meant to be used. Based on the other tags, I’m guessing I have to put the attribute before a declaration, but how is it meant to be processed by user-level code?

I’ve searched the demo file and the list of examples, but nothing seems to use this tag specifically. When I google “odin metaprogramming” the results are either about macroes, code generation or zig’s comptime.

the tags aren’t visible/queryable at runtime directly, like C# attributes

they’re also not like rust’s procedural macros that can directly read the ast and output some arbitrary code

you need to do your own manual parsing in a separate compilation step to be able to get the info you marked up using the tags and then meaningfully use it for codegen or something similar

odin compiler ships with a parser that you can use ("core:odin/ast", "core:odin/parser", "core:odin/tokenizer")

2 Likes

I see, that clears it up. Thank you