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

feat: update rnix

- Update rnix to its latest version.
- Since the AST changes significantly for select (a.b.c)
  and bin-ops (a + b + c), temporarily don't format those.
- Since |> is a bin-op, then this adds support for those operators.
This commit is contained in:
Kevin Amado 2025-02-23 17:17:53 -07:00
parent de80b8ee31
commit 24204cb3e1
21 changed files with 130 additions and 300 deletions

65
Cargo.lock generated
View file

@ -50,15 +50,6 @@ version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "cbitset"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29b6ad25ae296159fb0da12b970b2fe179b234584d7cd294c891e2bbb284466b"
dependencies = [
"num-traits",
]
[[package]]
name = "cc"
version = "1.1.34"
@ -115,9 +106,9 @@ dependencies = [
[[package]]
name = "countme"
version = "2.0.4"
version = "3.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "328b822bdcba4d4e402be8d9adb6eebf269f969f8eadef977a553ff3c4fbcb58"
checksum = "7704b5fdd17b18ae31c4c1da5a2e0305a2bf17b5249300a9ee9ed7b72114c636"
[[package]]
name = "diff"
@ -220,18 +211,18 @@ dependencies = [
"wasi",
]
[[package]]
name = "hashbrown"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04"
[[package]]
name = "hashbrown"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
[[package]]
name = "hashbrown"
version = "0.14.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
[[package]]
name = "hashbrown"
version = "0.15.2"
@ -301,15 +292,6 @@ version = "2.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
[[package]]
name = "memoffset"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce"
dependencies = [
"autocfg",
]
[[package]]
name = "mimalloc"
version = "0.1.43"
@ -319,15 +301,6 @@ dependencies = [
"libmimalloc-sys",
]
[[package]]
name = "num-traits"
version = "0.2.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
dependencies = [
"autocfg",
]
[[package]]
name = "num_cpus"
version = "1.16.0"
@ -434,24 +407,21 @@ dependencies = [
[[package]]
name = "rnix"
version = "0.10.2"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8024a523e8836f1a5d051203dc00d833357fee94e351b51348dfaeca5364daa9"
checksum = "6f15e00b0ab43abd70d50b6f8cd021290028f9b7fdd7cdfa6c35997173bc1ba9"
dependencies = [
"cbitset",
"rowan",
"smol_str",
]
[[package]]
name = "rowan"
version = "0.12.6"
version = "0.15.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1b36e449f3702f3b0c821411db1cbdf30fb451726a9456dce5dabcd44420043"
checksum = "0a542b0253fa46e632d27a1dc5cf7b930de4df8659dc6e720b647fc72147ae3d"
dependencies = [
"countme",
"hashbrown 0.9.1",
"memoffset",
"hashbrown 0.14.5",
"rustc-hash",
"text-size",
]
@ -515,15 +485,6 @@ dependencies = [
"autocfg",
]
[[package]]
name = "smol_str"
version = "0.1.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fad6c857cbab2627dcf01ec85a623ca4e7dcb5691cbaa3d7fb7653671f0d09c9"
dependencies = [
"serde",
]
[[package]]
name = "strsim"
version = "0.10.0"

View file

@ -1,7 +1,6 @@
[dependencies]
rnix = { version = "0.10.2", default-features = false, features = [] }
# rowan follows rnix
rowan = { version = "0.12.6", default-features = false, features = [] }
rnix = { version = "*", default-features = false, features = [] }
rowan = { version = "*", default-features = false, features = [] }
serde = { version = "*", default-features = false, features = ["derive"] }
[target.aarch64-unknown-linux-musl.dependencies.mimalloc]

View file

@ -145,15 +145,23 @@ fn format(
// a b
rnix::SyntaxKind::NODE_APPLY => crate::rules::apply::rule,
// assert a; b
rnix::SyntaxKind::NODE_ASSERT => crate::rules::scoped::rule,
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::bin_op::rule,
rnix::SyntaxKind::NODE_BIN_OP => crate::rules::default,
// ${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+ ;
@ -162,47 +170,35 @@ fn format(
rnix::SyntaxKind::NODE_INHERIT_FROM => {
crate::rules::paren::rule
}
rnix::SyntaxKind::NODE_KEY => crate::rules::default,
// a = b;
rnix::SyntaxKind::NODE_KEY_VALUE => {
crate::rules::key_value::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,
// let { }
rnix::SyntaxKind::NODE_LEGACY_LET => crate::rules::default,
// a or b
rnix::SyntaxKind::NODE_OR_DEFAULT => crate::rules::bin_op::rule,
// ( a )
rnix::SyntaxKind::NODE_PAREN => crate::rules::paren::rule,
// a | a ? b
rnix::SyntaxKind::NODE_PAT_BIND => crate::rules::pat_bind::rule,
// { NODE_PAT_ENTRY* }
rnix::SyntaxKind::NODE_PATTERN => crate::rules::pattern::rule,
// NODE_PAT_BIND | TOKEN_ELLIPSIS
rnix::SyntaxKind::NODE_PAT_ENTRY => {
crate::rules::pat_entry::rule
}
// /path/to/${a}
rnix::SyntaxKind::NODE_PATH_WITH_INTERPOL => {
crate::rules::default
}
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::select::rule,
rnix::SyntaxKind::NODE_SELECT => crate::rules::default,
// "..." || ''...''
rnix::SyntaxKind::NODE_STRING => crate::rules::string::rule,
// ${a}
rnix::SyntaxKind::NODE_STRING_INTERPOL => {
crate::rules::paren::rule
}
// !a
rnix::SyntaxKind::NODE_UNARY_OP => crate::rules::default,
// with a; b

View file

@ -62,7 +62,7 @@ impl Children {
| rnix::SyntaxKind::NODE_LIST
| rnix::SyntaxKind::NODE_LITERAL
| rnix::SyntaxKind::NODE_PAREN
| rnix::SyntaxKind::NODE_PATH_WITH_INTERPOL
| rnix::SyntaxKind::NODE_INTERPOL
| rnix::SyntaxKind::NODE_STRING
)
{

View file

@ -23,10 +23,10 @@ pub fn in_memory(
before: String,
config: Config,
) -> (Status, String) {
let tokens = rnix::tokenizer::Tokenizer::new(&before);
let ast = rnix::parser::parse(tokens);
let parsed = rnix::Root::parse(&before);
let errors = parsed.errors();
let errors = ast.errors();
if !errors.is_empty() {
return (Status::Error(errors[0].to_string()), before);
}
@ -41,9 +41,10 @@ pub fn in_memory(
vertical: true,
};
let after = crate::builder::build(&mut build_ctx, ast.node().into())
.unwrap()
.to_string();
let root = parsed.syntax();
let after =
crate::builder::build(&mut build_ctx, root.into()).unwrap().to_string();
if before == after {
(Status::Changed(false), after)

View file

@ -53,7 +53,7 @@ pub(crate) fn parse(
match child.kind() {
rnix::SyntaxKind::NODE_PAT_ENTRY
| rnix::SyntaxKind::TOKEN_CURLY_B_CLOSE
| rnix::SyntaxKind::TOKEN_R_BRACE
| rnix::SyntaxKind::TOKEN_ELLIPSIS => {
break;
}
@ -76,7 +76,7 @@ pub(crate) fn parse(
// item
let child = children.peek_next().unwrap();
match child.kind() {
rnix::SyntaxKind::TOKEN_CURLY_B_CLOSE => {
rnix::SyntaxKind::TOKEN_R_BRACE => {
pattern.comments_before_curly_b_close =
argument.comments_before;
break;
@ -96,7 +96,7 @@ pub(crate) fn parse(
match child.kind() {
rnix::SyntaxKind::NODE_PAT_ENTRY
| rnix::SyntaxKind::TOKEN_ELLIPSIS
| rnix::SyntaxKind::TOKEN_CURLY_B_CLOSE => {
| rnix::SyntaxKind::TOKEN_R_BRACE => {
break;
}
rnix::SyntaxKind::TOKEN_COMMA => {

View file

@ -8,16 +8,12 @@ pub(crate) fn rule(
let items_count = node
.children_with_tokens()
.skip_while(|element| {
element.kind() != rnix::SyntaxKind::TOKEN_CURLY_B_OPEN
})
.take_while(|element| {
element.kind() != rnix::SyntaxKind::TOKEN_CURLY_B_CLOSE
})
.skip_while(|element| element.kind() != rnix::SyntaxKind::TOKEN_L_BRACE)
.take_while(|element| element.kind() != rnix::SyntaxKind::TOKEN_R_BRACE)
.filter(|element| {
matches!(
element.kind(),
rnix::SyntaxKind::NODE_KEY_VALUE
rnix::SyntaxKind::NODE_ATTRPATH_VALUE
| rnix::SyntaxKind::NODE_INHERIT
| rnix::SyntaxKind::NODE_INHERIT_FROM
| rnix::SyntaxKind::TOKEN_COMMENT
@ -93,7 +89,7 @@ pub(crate) fn rule(
});
if let Some(child) = children.peek_next() {
if let rnix::SyntaxKind::TOKEN_CURLY_B_CLOSE = child.kind() {
if let rnix::SyntaxKind::TOKEN_R_BRACE = child.kind() {
break;
}

View file

@ -31,11 +31,7 @@ pub(crate) fn rule_with_configuration(
let kind = first.element.kind();
if (parent_kind == "bin_op_and_or_default"
&& matches!(
kind,
rnix::SyntaxKind::NODE_BIN_OP
| rnix::SyntaxKind::NODE_OR_DEFAULT
))
&& matches!(kind, rnix::SyntaxKind::NODE_BIN_OP))
|| (parent_kind == "select"
&& matches!(kind, rnix::SyntaxKind::NODE_SELECT))
{

View file

@ -11,7 +11,7 @@ pub(crate) fn rule(
.filter(|element| {
matches!(
element.kind(),
rnix::SyntaxKind::NODE_KEY_VALUE
rnix::SyntaxKind::NODE_ATTRPATH_VALUE
| rnix::SyntaxKind::NODE_INHERIT
| rnix::SyntaxKind::NODE_INHERIT_FROM
)

View file

@ -62,7 +62,7 @@ pub(crate) fn rule(
if let Some(child) = children.peek_next() {
let child_kind = child.kind();
if let rnix::SyntaxKind::TOKEN_SQUARE_B_CLOSE = child_kind {
if let rnix::SyntaxKind::TOKEN_R_BRACK = child_kind {
break;
}

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;
@ -14,7 +14,7 @@ pub(crate) mod pat_entry;
pub(crate) mod pattern;
pub(crate) mod root;
pub(crate) mod scoped;
pub(crate) mod select;
// pub(crate) mod select;
pub(crate) mod string;
pub(crate) fn default(

View file

@ -36,7 +36,6 @@ pub(crate) fn rule(
rnix::SyntaxKind::NODE_APPLY
| rnix::SyntaxKind::NODE_ASSERT
| rnix::SyntaxKind::NODE_BIN_OP
| rnix::SyntaxKind::NODE_OR_DEFAULT
| rnix::SyntaxKind::NODE_LAMBDA
| rnix::SyntaxKind::NODE_SELECT
| rnix::SyntaxKind::NODE_WITH

View file

@ -59,7 +59,7 @@ pub(crate) fn rule(
// {
steps.push_back(crate::builder::Step::Token(
rnix::SyntaxKind::TOKEN_CURLY_B_OPEN,
rnix::SyntaxKind::TOKEN_L_BRACE,
"{".to_string(),
));
if vertical {
@ -138,7 +138,7 @@ pub(crate) fn rule(
}
}
steps.push_back(crate::builder::Step::Token(
rnix::SyntaxKind::TOKEN_CURLY_B_OPEN,
rnix::SyntaxKind::TOKEN_R_BRACE,
"}".to_string(),
));

View file

@ -1,49 +1,10 @@
[
(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

@ -1,10 +1,8 @@
a
.${
a.${
/*
b
*/
c
.${
c.${
/*
d
*/

View file

@ -482,9 +482,8 @@
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
@ -508,8 +507,9 @@
"13" = "D";
"14" = "E";
"15" = "F";
}
.${toString d};
}.${
toString d
};
in
lib.concatMapStrings toHexDigit (toBaseDigits 16 i);

View file

@ -81,8 +81,7 @@ 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";
});
@ -245,8 +244,7 @@ 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"
@ -270,8 +268,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;
@ -339,8 +337,7 @@ 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,8 +81,7 @@ 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";
});
@ -245,8 +244,7 @@ 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"
@ -270,8 +268,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;
@ -339,8 +337,7 @@ 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,7 +60,10 @@ in {
type =
types.unspecified
// {
//
{
merge =
mergeEqualOption;
};
@ -77,8 +80,14 @@ in {
kernelPatches =
(originalArgs.kernelPatches
or [])
++ kernelPatches;
or
[])
++
kernelPatches;
features =
lib.recursiveUpdate

View file

@ -1,48 +1,14 @@
[
(a.b or c)
(a.b
or
/**/
c)
(a.b
/**/
or c)
(a.b
/**/
or
/**/
c)
(a.b
/**/
or
/**/
(a.b
/**/
or
/**/
(a.b
/**/
or
/**/
c)))
(a.b
/**/
or
/**/
(a.b
/**/
or
/**/
(a.b
/**/
or
/**/
c)))
(a.b or/**/c)
(a.b/**/or c)
(a.b/**/or/**/c)
(a.b/**/or/**/(a.b/**/or/**/(a.b/**/or/**/c)))
(a.b/**/or/**/(a.b/**/or/**/(a.b/**/or/**/c)))
(a.a or a.a or a.a or a.a or a.a or a.a or a.a or a.a or a.a or a.a or a.a or a.a or a.a or a.a or a.a or a.a or a.a or a.a or a.a)
(a.a
or a.a # test
(a.a or a.a # test
or a.a # test
or # test
a.a
or a.a or a.a or a.a or a.a or a.a or a.a or a.a or a.a or a.a or a.a or a.a or a.a or a.a or a.a or a.a or a.a)
a.a or
a.a or a.a or a.a or a.a or a.a or a.a or a.a or a.a or a.a or a.a or a.a or a.a or a.a or a.a or a.a or a.a)
]

View file

@ -1,55 +1,9 @@
[
(a . a)
(a
.
/**/
a)
(a
/**/
.a)
(a
/**/
.
/**/
a)
(a ./**/a)
(a/**/. a)
(a/**/./**/a)
(a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a)
(a
.a
.a
.a
.a
.a
.a
.a
.a
.a
.a
.a
.a
.a
.a
.a
.a
.a
.a
.a
.a
.a
.a
.a
.a
.a
.a
.a
.a
.a
.a
.a
.a
.a
.a
.a
.a
.a
.a)
(a.a
.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a)
]