feat: Add support for starlark. #509

Merged
wetneb merged 7 commits from amartani/mergiraf:martani/add-starlark into main 2025-08-01 18:15:49 +02:00
Contributor

Add support for starlark (bazel's config language).

Add support for starlark ([bazel](https://bazel.build/)'s config language).
feat: Add support for starlark.
All checks were successful
/ test (pull_request) Successful in 1m34s
b0697d08d3
ada4a left a comment
Owner

Welcome, and thanks for the PR! The LangProfile looks thought out, and it's nice that you have multiple tests. After a bit of tweaking of simple_merge and an additional signature for list elements, I think this should be good to go!

Welcome, and thanks for the PR! The `LangProfile` looks thought out, and it's nice that you have multiple tests. After a bit of tweaking of `simple_merge` and an additional signature for list elements, I think this should be good to go!
@ -0,0 +1,12 @@
load("@rules_rust//rust:defs.bzl", "rust_library")
Owner

I think this conflict could've been resolved even with a default line-based merge algorithm, since the loads are only changed by the right side, and the deps only by the left side. To actually check that the commutativity works, one would need to try adding something from both sides. See cdb57b0744/examples/rust/working/use_statements for an example

I think this conflict could've been resolved even with a default line-based merge algorithm, since the `load`s are only changed by the right side, and the `deps` only by the left side. To actually check that the commutativity works, one would need to try adding something from _both_ sides. See https://codeberg.org/mergiraf/mergiraf/src/commit/cdb57b0744476e4248da70a26e427a55ada7ffe4/examples/rust/working/use_statements for an example
Author
Contributor

I added a new load_statement test case for that, thanks!

I added a new `load_statement` test case for that, thanks!
ada4a marked this conversation as resolved
@ -0,0 +5,4 @@
name = "lib",
srcs = ["src/lib.rs"],
deps = [
"@crates//:log",
Owner

One thing you'll probably want is to define a signature for the elements of a list, so that duplicates can be detected. Judging by the examples, it looks like they are all strings, which is a bit unfortunate but not that big of a problem I think. The list gets parsed as follows:

value: list
 ├[
 ├string
 │ ├string_start "
 │ ├string_content @crates//:log
 │ └string_end "
 ├,
 ├string
 │ ├string_start "
 │ ├string_content @crates//:serde
 │ └string_end "
 ├,
 └]

so I think the signature will need to be defined on string, and get its value from string_content (I don't think string_{start,end} can be meaningfully different, maybe become single-quotes at most)

One thing you'll probably want is to define a signature for the elements of a list, so that duplicates can be detected. Judging by the examples, it looks like they are all strings, which is a bit unfortunate but not that big of a problem I think. The list gets parsed as follows: ``` value: list ├[ ├string │ ├string_start " │ ├string_content @crates//:log │ └string_end " ├, ├string │ ├string_start " │ ├string_content @crates//:serde │ └string_end " ├, └] ``` so I think the signature will need to be defined on `string`, and get its value from `string_content` (I don't think `string_{start,end}` can be meaningfully different, maybe become single-quotes at most)
Author
Contributor

Not every list in starlark can be deduplicated, and they may not even be commutative... I added commutative rules for some of the cases where they are in a new commutative_lists test case; see if that makes sense.

Not every list in starlark can be deduplicated, and they may not even be commutative... I added commutative rules for some of the cases where they are in a new `commutative_lists` test case; see if that makes sense.
Rename simple_merge -> commutative_lists
All checks were successful
/ test (pull_request) Successful in 33s
ea1a2f8546
Author
Contributor

Thanks for the review! PTAL

Thanks for the review! PTAL
requested review from ada4a 2025-07-28 03:37:12 +02:00
@ -0,0 +12,4 @@
name = "python_lib",
srcs = ["python_lib.py"],
)
rust_library(
Author
Contributor

Question: Ideally, this merge would preserve a blank newline between each of the calls. I tried to do that by changing the CommutativeParent separator to be "\n\n", but that then causes a newline to be added between load() calls above as well, and since they are all expression_statement in the starlark tree-sitter library, it's not so easy to differentiate between them. Any suggestions on it? I think this is not a big deal, but it does mean that users will likely need to run a formatter after the merge resolution.

Question: Ideally, this merge would preserve a blank newline between each of the calls. I tried to do that by changing the CommutativeParent separator to be `"\n\n"`, but that then causes a newline to be added between `load()` calls above as well, and since they are all `expression_statement` in the starlark tree-sitter library, it's not so easy to differentiate between them. Any suggestions on it? I think this is not a big deal, but it does mean that users will likely need to run a formatter after the merge resolution.
Owner

This sounds like something that could be fixed by #373. Alternatively, as you say, the grammar could be changed to expose different node types at this level, which would make it possible to define children groups with different default separators.

This sounds like something that could be fixed by https://codeberg.org/mergiraf/mergiraf/issues/373. Alternatively, as you say, the grammar could be changed to expose different node types at this level, which would make it possible to define children groups with different default separators.
wetneb approved these changes 2025-07-28 23:51:34 +02:00
wetneb left a comment
Owner

Good to go as far as I am concerned. Thanks for the PR! :)

Good to go as far as I am concerned. Thanks for the PR! :)
@ -1102,0 +1129,4 @@
CommutativeParent::from_query(
r#"(call
function: (identifier) @func_name (#any-of? @func_name "exports_files" "glob")
arguments: (argument_list (list) @commutative))"#,
Owner

I love that you were able to use this new feature of defining commutative parents via tree-sitter queries! Congrats for that :)

I love that you were able to use this new feature of defining commutative parents via tree-sitter queries! Congrats for that :)
wetneb merged commit b235d8a78b into main 2025-08-01 18:15:49 +02:00
wetneb referenced this pull request from a commit 2025-08-01 18:15:51 +02:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: mergiraf/mergiraf#509
No description provided.