-
Notifications
You must be signed in to change notification settings - Fork 73
Verify lossless parse + serialize (without transforms) #85
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
Comments
This is actually not easily possible at the moment. The reason is that all space information is discarded for the last token on a line, since the column |
Agreed. The roundtrip test doesn't need to care about spaces at EOF and tabs. We just verify that for each text t, s(p(e(t))) = e(t) with s() = serialize, p() = parse, e = strip spaces at EOF + convert tabs to spaces. |
I am not sure if I understand you correctly, but I think that is not easily possible. It is easily possible if we remove all spaces, which you probably don't mean, right? Since we add spaces after the token and not before it (that is actually why we need eol stripping as a transformer) but add new lines before it , applying no transformers and serialising back will not yield the input. If we wanted this to be possible, we had to use |
I'm fine if we can find a set of transformers that will allow us to test the roundtrip: for each text t, s(x(p(e(t)))) = e(t), with (in addition) x() = minimally sufficient set of transformers. I think the main reason why we strip spaces at all is that spaces between tokens that also have a newline aren't properly recognized: The parse data isn't different for a +
b and a + ~
b (substitute Let's think a bit more about testing the roundtrip, just remove the two |
I just tried: styler:::parse_transform_serialize("a <- 1", list())
#> Warning: Unknown or uninitialised column: 'lag_newlines'.
#> Warning: Unknown or uninitialised column: 'lag_newlines'.
#> Warning: Unknown or uninitialised column: 'lag_newlines'.
#> Warning: Unknown or uninitialised column: 'spaces'.
#> Warning: Unknown or uninitialised column: 'lag_newlines'.
#> Warning: Unknown or uninitialised column: 'indent'.
#> Error: Element 4 is not a vector (NULL) I think this should at least work without warnings or errors, ideally this would return the text unchanged in all cases. |
The problems seem to vanish when implementing #94. However, since we are working with named transformers now, some adaptions may still be required to make it work with an empty list (instead of a list with named objects that are empty). |
Might have gained relevance with #187. |
Now it's actually possible to run with an "empty" style guide. styler::style_text("1+1 + ((3))", style = styler:::create_style_guide)
#> 1+1 + ((3)) We'd still have to implement the roundtrip to make sure we don't have any parsing / serialization problems. Not sure about tabs? Should we not just convert them to spaces as we used to? I can open a separate issue |
Closed in favor of #140. |
Reference: #368. |
Uh oh!
There was an error while loading. Please reload this page.
A run without any transformers enabled should yield exactly the same results as the input, minus spaces at EOL and conversion of tabs to spaces. This should be tested separately on all input files, for easier isolation of parse/serialize problems from transformer problems during later refactorings.
Reference: #79 (comment)
The text was updated successfully, but these errors were encountered: