-
Notifications
You must be signed in to change notification settings - Fork 33
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
Patching ranged slice of struct literals #130
Comments
@mway I misread the patch. Try this: @@
var x identifier
@@
- for _, x := range []struct{ ... }{
+ foos := []struct { ... }{
...,
- } {
+ }
+ for _, x := range foos {
...
} It's a bit unreadable, but it appears to work on my local sample. For a more readable version, the @@
var x identifier
var fields, items dots // TODO: better name
@@
+foos := []struct{ fields }{ items }
-for _, x := range []struct{ fields }{ items } {
+for _, x := range foos {
...
} Which would eliminate all the bugginess with |
CC @lverma14 |
Thanks @abhinav, that worked. :) As a minor thing, it does end up with the following: foos := []struct{
// ...
}{
// ...
{ // last entry
// ...
}} instead of foos := []struct{
// ...
}{
// ...
{ // last entry
// ...
},
} (note the |
Yeah, my local experiment also showed the It's like that partly because |
Yeah, that's a reasonable workaround. Thanks for the help! |
I'm trying to write a patch to transform a ranged slice of (anonymous) struct literals. For example, I want to turn this:
into this:
I've tried minor variants of the following patch:
which returns the following error:
@abhinav suggested adding a trailing
;
to the elision, but that resulted in the same error.I'm not sure if this is technically the same thing as #4, but I think for this case it doesn't seem practical to do it in two stages (e.g., a second match on the trailing
} {
would be extremely ambiguous).Is this type of patch possible currently?
The text was updated successfully, but these errors were encountered: