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

Rewriting to the same pattern differs in result #154

Open
jonathan-s opened this issue Apr 4, 2024 · 4 comments · May be fixed by #181
Open

Rewriting to the same pattern differs in result #154

jonathan-s opened this issue Apr 4, 2024 · 4 comments · May be fixed by #181
Assignees
Labels
bug Something isn't working python

Comments

@jonathan-s
Copy link

The following pattern

engine marzano(0.1)
language python

`def $method($args): $body` => `def $method($args): $body`

Should return the exact same thing, but that is not the case as you can see in the following example. https://app.grit.io/studio?key=m44jIoo2l3JuT1lcAXkEm

@morgante
Copy link
Contributor

morgante commented Apr 4, 2024

The example got wiped out, but this is likely a case of our whitespace manager not handling it correctly. We'll likely need to add a special rule of to restore the newline even though we didn't match on it.

Here's another example: https://app.grit.io/studio?key=I3RFrP0kLTyyenhAGihmq

@morgante morgante added bug Something isn't working python labels Apr 4, 2024
@ilevyor ilevyor self-assigned this Apr 4, 2024
@ilevyor ilevyor linked a pull request Apr 8, 2024 that will close this issue
@ilevyor
Copy link
Contributor

ilevyor commented Apr 8, 2024

Unfortunately I don't think this is a feasible thing to fix.
To get the desired behavior you'll have to insert the newline, and indent the desired amount in the snippet. Padding is implemented this way as the correct amount to pad is a function of the rewrite, not the source. For example

engine marzano(0.1)
language python

`def $method($args):
    while true:
        $body` => `def $method($args): $body`

should indent $body only once corresponding to the single function scope, but if we tried to calculate based on the source, we would indent for two scopes, first the function, and then the loop.

So in your example I would recommend:

engine marzano(0.1)
language python

`def $method($args): $body` => `def $method($args):
    $body`

@morgante
Copy link
Contributor

morgante commented Apr 8, 2024

I think we could implement this as a post-linearization "healing" stage. I'll do a quick PoC.

@morgante morgante assigned morgante and unassigned ilevyor Apr 10, 2024
@morgante
Copy link
Contributor

I did an attempt here (#194) but there's no obvious place to do this well.

For now I think stick to making output snippets valid-ish Python.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working python
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants