Closed AlexTMjugador closed 1 year ago
Thanks for the review!
I didn't know that the pretty
crate was a thing. In hindsight, it probably would have been a good idea to refactor the transpiler to use it, since it allows a greater degree of abstraction over low-level formatting details, as you've said. But I'm glad that this PR was able to cobble together a better transpiler without resorting to that crate, at least for now :wink:
While the current GLSL transpiler output format is quite customizable, I needed to further extend its customizability to better support outputting GLSL in both pretty and minified formats. To that end, these changes overhaul the transpiler's formatting logic and implement some minor format changes and fixes. The fixes included are complementary to those in https://github.com/vtavernier/glsl-lang/pull/19.
I considered splitting this PR into several smaller ones, but decided against it because the changes are so closely related that doing so would make them harder to review. Please let me know your thoughts on this!
The full list of changes, in no particular order, is as follows:
else
keyword, after the list separator and for separator tokens (comma and semicolon, respectively), around the initializer list expression braces, and around the parentheses that are part of some statements, such as selection, jump, or switch statements.write_str
of a single char withwrite_char
.write_binary_op
so that the value of the corresponding format option is applied more consistently.return
keyword when no expression follows, which is better for both minified and prettified output.FormattingSettings::minifying
factory method to get formatting settings that minify the generated GLSL output, which is more convenient than setting each option to the most space-saving value.