Skip to content
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

Unexpected panic while rearranging macro arguments #71

Closed
Xaeroxe opened this issue Mar 20, 2024 · 3 comments · Fixed by #69 or #72 · May be fixed by #170
Closed

Unexpected panic while rearranging macro arguments #71

Xaeroxe opened this issue Mar 20, 2024 · 3 comments · Fixed by #69 or #72 · May be fixed by #170

Comments

@Xaeroxe
Copy link

Xaeroxe commented Mar 20, 2024

Invocation:

$ srgn --version
srgn 0.11.0

$ srgn --files '**/*.rs' --rust-query '((macro_invocation macro: (identifier) @name) @macro (#any-of? @name "error" "warn" "info" "debug" "trace" ))' '(?P<msg>.+);(?P<structure>.+)' '$structure,$msg'

Panic:

thread '<unnamed>' panicked at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/srgn-0.11.0/src/scoping/scope.rs:60:43:
begin <= end (23 <= 0) when slicing `error!( "server error"; "uuid" => %uuid, "error.user_msg" => %user_msg, src)`

Please let me know if more information is needed.

@alexpovel
Copy link
Owner

Thanks for your report! I can reproduce and will look into it.

Other than that, I'm sad to report replacement using named capture groups isn't supported ('$structure,$msg'). But that's a super useful and basic feature I've been wanting to implement anyway.

@alexpovel
Copy link
Owner

Hi! So the panic was simply a bug, which is fixed now. The syntax of '(?P<msg>.+);(?P<structure>.+)' '$structure,$msg' still doesn't work as intended yet, but as mentioned I'll be working on implementing that. In the meantime, to solve your immediate problem, perhaps ast-grep can help you?

@alexpovel
Copy link
Owner

alexpovel commented Jun 12, 2024

Hi @Xaeroxe !

Support for variables landed in main recently, at 7f6cfcb . That will make it into a release soon-ish (with the merge of #72 ). Then, an invocation like '(?P<msg>.+);(?P<structure>.+)' '$structure,$msg' will start working (see here for the docs). When building from main, it already works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants