1
Fork 0
mirror of https://github.com/RGBCube/alejandra synced 2025-07-30 12:07:46 +00:00

feat: support bin-op again

This commit is contained in:
Kevin Amado 2025-04-10 15:10:28 -06:00
parent f9d2a27751
commit 4afecdb5df
10 changed files with 115 additions and 54 deletions

View file

@ -144,63 +144,92 @@ fn format(
let rule = match kind {
// a b
rnix::SyntaxKind::NODE_APPLY => crate::rules::apply::rule,
// assert a; b
rnix::SyntaxKind::NODE_ASSERT => crate::rules::scoped::rule, /* a.b.c */
rnix::SyntaxKind::NODE_ASSERT => crate::rules::scoped::rule,
// a.b.c
rnix::SyntaxKind::NODE_ATTRPATH => crate::rules::default,
// a = b;
rnix::SyntaxKind::NODE_ATTRPATH_VALUE => {
crate::rules::key_value::rule
}
// { }
rnix::SyntaxKind::NODE_ATTR_SET => crate::rules::attr_set::rule,
// a $op b
rnix::SyntaxKind::NODE_BIN_OP => crate::rules::default,
rnix::SyntaxKind::NODE_BIN_OP => crate::rules::bin_op::rule,
// ${a} (interpolation but for NODE_SELECT)
rnix::SyntaxKind::NODE_DYNAMIC => crate::rules::dynamic::rule,
//
rnix::SyntaxKind::NODE_HAS_ATTR => crate::rules::default,
// $identifier
rnix::SyntaxKind::NODE_IDENT => crate::rules::default,
rnix::SyntaxKind::NODE_IDENT_PARAM => crate::rules::default,
// if a then b else c
rnix::SyntaxKind::NODE_IF_ELSE => crate::rules::if_else::rule,
// inherit NODE_INHERIT_FROM? b+ ;
rnix::SyntaxKind::NODE_INHERIT => crate::rules::inherit::rule,
// ( a )
rnix::SyntaxKind::NODE_INHERIT_FROM => {
crate::rules::paren::rule
}
// ${a}
rnix::SyntaxKind::NODE_INTERPOL => crate::rules::paren::rule,
// a: b
rnix::SyntaxKind::NODE_LAMBDA => crate::rules::lambda::rule,
// let { }
rnix::SyntaxKind::NODE_LEGACY_LET => crate::rules::default,
// let NODE_KEY_VALUE* in b;
rnix::SyntaxKind::NODE_LET_IN => crate::rules::let_in::rule,
// [ ... ]
rnix::SyntaxKind::NODE_LIST => crate::rules::list::rule,
// 1 | true | null
rnix::SyntaxKind::NODE_LITERAL => crate::rules::default,
// ( a )
rnix::SyntaxKind::NODE_PAREN => crate::rules::paren::rule,
// a | a ? b
rnix::SyntaxKind::NODE_PAT_BIND => crate::rules::pat_bind::rule,
// NODE_PAT_BIND | TOKEN_ELLIPSIS
rnix::SyntaxKind::NODE_PAT_ENTRY => {
crate::rules::pat_entry::rule
}
// /path/to/${a}
rnix::SyntaxKind::NODE_PATH => crate::rules::default,
// { NODE_PAT_ENTRY* }
rnix::SyntaxKind::NODE_PATTERN => crate::rules::pattern::rule,
// implementation detail of rowan
rnix::SyntaxKind::NODE_ROOT => crate::rules::root::rule,
// a.b | a.NODE_DYNAMIC
rnix::SyntaxKind::NODE_SELECT => crate::rules::default,
// "..." || ''...''
rnix::SyntaxKind::NODE_STRING => crate::rules::string::rule,
// !a
rnix::SyntaxKind::NODE_UNARY_OP => crate::rules::default,
// with a; b
rnix::SyntaxKind::NODE_WITH => crate::rules::scoped::rule,
kind => {

View file

@ -2,14 +2,7 @@ pub(crate) fn rule(
build_ctx: &crate::builder::BuildCtx,
node: &rnix::SyntaxNode,
) -> std::collections::LinkedList<crate::builder::Step> {
rule_with_configuration(build_ctx, node, "bin_op_and_or_default")
}
pub(crate) fn rule_with_configuration(
build_ctx: &crate::builder::BuildCtx,
node: &rnix::SyntaxNode,
parent_kind: &str,
) -> std::collections::LinkedList<crate::builder::Step> {
let mut steps = std::collections::LinkedList::new();
let mut children = crate::children2::new(build_ctx, node);
@ -30,11 +23,7 @@ pub(crate) fn rule_with_configuration(
if vertical {
let kind = first.element.kind();
if (parent_kind == "bin_op_and_or_default"
&& matches!(kind, rnix::SyntaxKind::NODE_BIN_OP))
|| (parent_kind == "select"
&& matches!(kind, rnix::SyntaxKind::NODE_SELECT))
{
if matches!(kind, rnix::SyntaxKind::NODE_BIN_OP) {
steps.push_back(crate::builder::Step::Format(first.element));
} else {
steps.push_back(crate::builder::Step::FormatWider(first.element));
@ -65,7 +54,7 @@ pub(crate) fn rule_with_configuration(
}
// second
if !vertical && parent_kind == "bin_op_and_or_default" {
if !vertical {
steps.push_back(crate::builder::Step::Whitespace);
}
steps.push_back(crate::builder::Step::Format(second.element));
@ -90,9 +79,7 @@ pub(crate) fn rule_with_configuration(
crate::children2::Trivia::Newlines => {}
}
}
} else if !second.has_inline_comment
&& parent_kind == "bin_op_and_or_default"
{
} else if !second.has_inline_comment {
steps.push_back(crate::builder::Step::Whitespace);
}

View file

@ -1,6 +1,6 @@
pub(crate) mod apply;
pub(crate) mod attr_set;
// pub(crate) mod bin_op;
pub(crate) mod bin_op;
pub(crate) mod dynamic;
pub(crate) mod if_else;
pub(crate) mod inherit;

View file

@ -1,10 +1,49 @@
[
(1 + 1)
(1 +/**/1)
(1/**/+ 1)
(1/**/+/**/1)
(1/**/+/**/(1/**/+/**/(1/**/+/**/1)))
(1
+
/**/
1)
(1
/**/
+ 1)
(1
/**/
+
/**/
1)
(1
/**/
+
/**/
(1
/**/
+
/**/
(1
/**/
+
/**/
1)))
(1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1)
(1
+ 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1)
+ 1
+ 1
+ 1
+ 1
+ 1
+ 1
+ 1
+ 1
+ 1
+ 1
+ 1
+ 1
+ 1
+ 1
+ 1
+ 1
+ 1
+ 1
+ 1)
]

View file

@ -482,8 +482,9 @@
Check whether something is a function or something
annotated with function args.
*/
isFunction = f: builtins.isFunction f ||
(f ? __functor && isFunction (f.__functor f));
isFunction = f:
builtins.isFunction f
|| (f ? __functor && isFunction (f.__functor f));
/*
Convert the given positive integer to a string of its hexadecimal

View file

@ -81,7 +81,8 @@ in {
};
boot.kernelParams = mkOption {
type = types.listOf (types.strMatching ''([^"[:space:]]|"[^"]*")+'' // {
type = types.listOf (types.strMatching ''([^"[:space:]]|"[^"]*")+''
// {
name = "kernelParam";
description = "string, with spaces inside double quotes";
});
@ -244,7 +245,8 @@ in {
"hid_logitech_hidpp"
"hid_logitech_dj"
"hid_microsoft"
] ++ optionals pkgs.stdenv.hostPlatform.isx86 [
]
++ optionals pkgs.stdenv.hostPlatform.isx86 [
# Misc. x86 keyboard stuff.
"pcips2"
"atkbd"
@ -268,8 +270,8 @@ in {
# Implement consoleLogLevel both in early boot and using sysctl
# (so you don't need to reboot to have changes take effect).
boot.kernelParams =
["loglevel=${toString config.boot.consoleLogLevel}"] ++
optionals config.boot.vesa ["vga=0x317" "nomodeset"];
["loglevel=${toString config.boot.consoleLogLevel}"]
++ optionals config.boot.vesa ["vga=0x317" "nomodeset"];
boot.kernel.sysctl."kernel.printk" = mkDefault config.boot.consoleLogLevel;
@ -337,7 +339,8 @@ in {
# !!! Should this really be needed?
(isYes "MODULES")
(isYes "BINFMT_ELF")
] ++ (optional (randstructSeed != "") (isYes "GCC_PLUGIN_RANDSTRUCT"));
]
++ (optional (randstructSeed != "") (isYes "GCC_PLUGIN_RANDSTRUCT"));
# nixpkgs kernels are assumed to have all required features
assertions =

View file

@ -81,7 +81,8 @@ in {
};
boot.kernelParams = mkOption {
type = types.listOf (types.strMatching ''([^"[:space:]]|"[^"]*")+'' // {
type = types.listOf (types.strMatching ''([^"[:space:]]|"[^"]*")+''
// {
name = "kernelParam";
description = "string, with spaces inside double quotes";
});
@ -244,7 +245,8 @@ in {
"hid_logitech_hidpp"
"hid_logitech_dj"
"hid_microsoft"
] ++ optionals pkgs.stdenv.hostPlatform.isx86 [
]
++ optionals pkgs.stdenv.hostPlatform.isx86 [
# Misc. x86 keyboard stuff.
"pcips2"
"atkbd"
@ -268,8 +270,8 @@ in {
# Implement consoleLogLevel both in early boot and using sysctl
# (so you don't need to reboot to have changes take effect).
boot.kernelParams =
["loglevel=${toString config.boot.consoleLogLevel}"] ++
optionals config.boot.vesa ["vga=0x317" "nomodeset"];
["loglevel=${toString config.boot.consoleLogLevel}"]
++ optionals config.boot.vesa ["vga=0x317" "nomodeset"];
boot.kernel.sysctl."kernel.printk" = mkDefault config.boot.consoleLogLevel;
@ -337,7 +339,8 @@ in {
# !!! Should this really be needed?
(isYes "MODULES")
(isYes "BINFMT_ELF")
] ++ (optional (randstructSeed != "") (isYes "GCC_PLUGIN_RANDSTRUCT"));
]
++ (optional (randstructSeed != "") (isYes "GCC_PLUGIN_RANDSTRUCT"));
# nixpkgs kernels are assumed to have all required features
assertions =

View file

@ -60,10 +60,7 @@ in {
type =
types.unspecified
//
{
// {
merge =
mergeEqualOption;
};
@ -84,10 +81,7 @@ in {
or
[])
++
kernelPatches;
++ kernelPatches;
features =
lib.recursiveUpdate

View file

@ -1,4 +1,6 @@
[
(1 |> builtins.add 2 |> builtins.mul 3)
(builtins.add 1 <| builtins.mul 2 <| 3)
(1 |> builtins.add 2 |>
builtins.mul 3)
]

View file

@ -1,4 +1,7 @@
[
(1 |> builtins.add 2 |> builtins.mul 3)
(builtins.add 1 <| builtins.mul 2 <| 3)
(1
|> builtins.add 2
|> builtins.mul 3)
]