my use-case has a zig program generating source-code artifacts (including other zig files)… most of these files are relatively small (<50 lines), but do require some amount of simple interpolation of values when writing the output…
i can certainly use print
from the std library, especially in combination with a comptime multi-line string that allows me to easily see the forest from the trees… i then pass this string as my fmt
to print
, along with my args
tuple… interpolation is handled with appropriate {...}
specifiers in the string…
the problem, of course, is that much of what i generate is source-code full of braces!!! to use print
i have to (tediously) use {{
and }}
as an escape… obviously i can live with this – though the compiler errors are quite strange when you forget!!!
before i even consider re-writing the fmt
string at comptime, adding the proper escapes, i thought i’d ask what others are doing in these sorts of situations…
i’ve seen some existing templating mechanisms (eg., mustache) used with zig, though i have no particular legacy use with any of these…
were i to attempt something, it would be along the line of “backtick” substitution used in javascript, the shell, etc… details aside, each instance of a “backticked” expression could be moved to the args
tuple, while replacing it with some appropriate {..}
format specifier…
to simply the problem, i’m fine if all interpolated values can work with {s}
… not sure if there is a “generic” specifier other than {any}
which does a reasonable job with scalars… i suppose i could assume my interpolated values are scalar, and then “json stringify” them as a first approximation…
whew!!! not looking to boil the ocean here, just warm-up my bathtub a little