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

Only first match is located #361

Open
Nikoraito opened this issue Mar 30, 2023 · 1 comment
Open

Only first match is located #361

Nikoraito opened this issue Mar 30, 2023 · 1 comment

Comments

@Nikoraito
Copy link

Describe the bug
When searching for a hole in an environment, only the first match will be found, even if multiple passes would detect multiple holes in the context.

Reproducing
the config below locates XYZ(); within brackets and moves it to the end of the brackets.

[XYZtoTheEnd]
match="{
      :[before]
      XYZ(:[params]);
      :[after]
}"
rewrite="{
      :[before]
      :[after]
      XYZ(:[params]);
}"

Expected behavior
Given the following method, I would like to find all matches and move them to the end.

public void foo(){
    XYZ(a);
    XYZ(b);
    int a=0, b=3, c=4;
    XYZ(a,b,c);
}

My expected result would be

public void foo(){
    int a=0, b=3, c=4;
    XYZ(a);
    XYZ(b);
    XYZ(a,b,c);
}

however I end up with the following, because the brackets are no longer inspected once a match is found.

public void foo(){
    XYZ(b);
    int a=0, b=3, c=4;
    XYZ(a,b,c);
    XYZ(a);
}

Additional context
It seems uncertain to me whether this is a bug or the expected behavior; if it isn't a bug, I'm curious how one would achieve the result I'm looking for. The reason brackets are necessary is that there are multiple methods in the file which need to be arranged in this way, rather than collecting all the matches in one place.

@markrian
Copy link

@Nikoraito This gets you a bit closer to what you want. I think the whitespace before and after :[before] isn't getting matched in your example code.

match="""{
    :[before]XYZ(:[params]);
    :[after]
}"""

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

No branches or pull requests

2 participants