feat: support chained member check fallbacks (a ? b ? c)#433
feat: support chained member check fallbacks (a ? b ? c)#433dyegoaurelio wants to merge 2 commits into
Conversation
25cddcf to
8699009
Compare
|
the nixpkgs diff was an improvement IMO diff --git a/nixos/modules/hardware/facter/camera/ipu6.nix b/nixos/modules/hardware/facter/camera/ipu6.nix
index 5319d8bf3d49f..799c221888245 100644
--- a/nixos/modules/hardware/facter/camera/ipu6.nix
+++ b/nixos/modules/hardware/facter/camera/ipu6.nix
@@ -66,7 +66,7 @@ let
in
bus_type.name == "PCI"
&& devices
- ? "${vendorHex}:${deviceHex}:${subVendorHex}:${subDeviceHex}/${baseClassHex}-${subClassHex}-${revisionHex}"
+ ? "${vendorHex}:${deviceHex}:${subVendorHex}:${subDeviceHex}/${baseClassHex}-${subClassHex}-${revisionHex}"
);
in
{the indentation also applies on |
8699009 to
be9a60a
Compare
jfly
left a comment
There was a problem hiding this comment.
Thanks! I haven't read the haskell diff closely (would prefer to do that in person, but it's totally OK if you get a shipit from someone else before then). The test cases look good, though.
I agree the nixpkgs diff is nice.
84ef425 to
6648956
Compare
Disabled regions should not be touched and usually shouldn't affect formatting on enabled regions. This documents some instances where a change in a disabled region would cause enabled regions to change.
Allow the ? operator to chain: a member check can now be followed by
further `? selector.path` fallbacks, e.g. `{} ? foo ? bar ? null`.
Previously the operator accepted a single selector path and a chain
was a parse error.
Note that this syntax is never useful in practice: nix parses
left-associatively as `(a ? b) ? c`, so the first check yields a
boolean and each further check tests an attribute on that boolean,
making any chain of two or more ? evaluate to constant false. It is
valid Nix syntax nonetheless, so the formatter handles it for
correctness.
MemberCheck now carries a non-empty list of (question mark, selector
path) pairs instead of a single pair. A chain stays on one line when
it fits; otherwise it breaks before every question mark, indented one
level past the subject:
```nix
aaaaaaaaaaaaaaaaaaaaaaaaaa
? bbbbbbbbbbbbbbbbbb
? cccccccccccccccccc
```
Like other operators, a comment trailing a question mark is moved onto
its own line above it, keeping the question mark attached to its
selector path.
6648956 to
54ebccd
Compare
MattSturgeon
left a comment
There was a problem hiding this comment.
SGTM, but I think we should be careful about calling ? chains a "fallback", as that is not what they represent even if that may be what users intended.
| _ | ||
| ) | ||
|
|
||
| # Chained fallbacks as default values |
There was a problem hiding this comment.
| # Chained fallbacks as default values | |
| # Chained presence checks as default values |
Terminology nit: to me, a fallback is what the or operator represents. The ? operator does not really have a fallback concept, and when chained it is just checking that the first Boolean contains an attribute.
Therefore I think we can avoid confusion by talking about attr-presence instead of fallbacks.
Allow the ? operator to chain: a member check can now be followed by further
? selector.pathfallbacks, e.g.{} ? foo ? bar ? null. Previously the operator accepted a single selector path and a chain was a parse error.Note that this syntax is never useful in practice: it parses left-associatively as
(a ? b) ? c, so the first check yields a boolean and each further check tests an attribute on that boolean, making any chain of two or more ? evaluate to constant false. It is valid Nix syntax nonetheless, so the formatter handles it for correctness.MemberCheck now carries a non-empty list of (question mark, selector path) pairs instead of a single pair. A chain stays on one line when it fits; otherwise it breaks before every question mark, indented one level past the subject:
Like other operators, a comment trailing a question mark is moved onto its own line above it, keeping the question mark attached to its selector path.
closes #359