-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ability to @import
.zon files
#14531
Comments
"Zig source files are implicitly structs" ziglang.org. Why is this philosophy not followed in the zon ones too? Given the following snippet with an const data = @import("foo.zon");
comptime {
assert(std.mem.eql(u8, data.bar, "hello"));
} my expectation for a .bar = "hello", and not .{
.bar = "hello",
} |
This was actually my first thought as well. But then, .bar = "hello", likely wouldn't work. It'd have to be written as: const bar = "hello"; But now we're just writing code in the ZON file, which defeats the purpose of an object notation. As presented so far, it seems like the ZON format is intended to be parsed at compile time for resolving package dependencies. Is runtime parsing in application code also going to be allowed? That would allow ZON files to be used to specify app configs (replace a |
Hello, i'm also interested in runtime parsing of zon files! |
This seems to be the only issue I could find in which there is any description of what is allowed in zon files, so I'll ask these questions here: Zon files are allowed to be, or to contain, zig literals: what about expressions that evaluate to the equivalent of these literals? E.g. is (Similar to the first question) Should Do multi-line string literals fall under "string literal"? In the case of a value being |
Right now, |
The runtime zon file benefits the most, so I second it. :D Another question is, can a zon file be empty? If yes, what would it be? An undefined? 🤔 |
Looking at the parsing code, it doesn't seem to allow that, as |
The "retrieve version from |
Extracted from #14523.
Given a foo.zon file:
it should be possible to
@import
it as a comptime-known value:One motivating use case in particular is, inside build.zig, one should be able to
@import("build.zig.zon")
and access those values.Note that the top level expression of a zon file is not necessarily an anonymous struct literal. It can be:
The text was updated successfully, but these errors were encountered: