-
Notifications
You must be signed in to change notification settings - Fork 447
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
shorthand for deep field overrides #227
Comments
Yeah this has come up a few times. I agree it would be nice. You need a way to be able to compute the fields too, perhaps like this:
presumably self in each of those expressions bind the same way it would if there were syntax sugar, although there are no explicit { } there to guide the eye. Then there's the question of avoiding duplicates:
|
Perhaps it is OK to force the user to collect the c and b modification into a single mixin there? |
Here's the design I came up with after some thinking and trying to figure C++ and parsers. Shorthand-dot operator suggestionCurrently, the I suggest to extend the case of IDENTIFIER initially to allow DOT to follow it. In that case, the remainder is parsed recursively as either IDENTIFIER+DOT pairs, or the usual This makes the following:
equal to
which is, supposedly, one of the most used cases. The duplicates resolution must be updated to consider duplicates only of the leaves of DOT-chains, otherwise Version 2To cover additional cases, STRING_DOUBLE, STRING_SINGLE or STRING_BLOCK should be allowed in the syntax (I don't think STRING_BLOCK would actually be any useful, but there's no good reason to exclude it). Version 3Allow indexing expressions of single elements of paths via Note that I ignore the computational part of the dot-paths on purpose. The whole idea for them is to allow quick overrides in deep-nested objects (those are very common in kubernetes definitions) to make them more human-readable. |
I think you mean:
is equal to
whereas
is equal to
For the duplicates resolution, I suppose you could just say that:
Must be expressed as:
I.e., so there are no additional smarts needed in that code. |
I think this is fine to leave this feature as syntax sugar, and don't introduce any special runtime handling: { a.b.c[a].z: 1, a.b.c[a].x: 1 }
# =>
{
a+: {
b+: {
c+: {
[a]+: {
z: 1,
},
[a]+: {
x: 1,
},
},
},
},
} Nix does it same way:
|
Has this feature been implemented? |
Not in version v0.20.0 Is this planned? It really does not seem like that big of a feature |
It would be really cool if the above (or something along those lines) worked and evaluated to:
To achieve the same in today's jsonnet you would have to write:
I don't know how difficult and/or sane this would be to implement, but there is a similar construct in Nix that is quite useful :)
The text was updated successfully, but these errors were encountered: