Skip to content

Conversation

avh4
Copy link
Contributor

@avh4 avh4 commented Mar 2, 2023

Fixes #191

This is a little bit tricky because the AST contains the string values in a format that is optimized for outputting the compiled javascript (it is a fully-assembled ByteArray# in UTF8 encoding, with javascript escape sequences, also with unicode escapes normalized to use only 4-digit hex codes). Perhaps a more ideal option would be to refactor the parser and AST to retain the String.Chunks that are currently used internally in Gren.String, but that seemed complicated to do. So instead this PR just has the formatter try to re-parse the string to recover the information needed to format it properly.

(elm-format hasn't had to deal with this yet, since it is still based on an older version of Elm's parser, so the AST there contains the actual string that is represented, instead of the javascript-escaped version.)

@robinheghan
Copy link
Member

Nice work!

@robinheghan
Copy link
Member

It's a little unfortunate that the parser is optimized for the codegen output, but fixing this in the formatter seems to be the most low-risk way of fixing this.

@robinheghan robinheghan merged commit 9c93957 into gren-lang:main Mar 2, 2023
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

Successfully merging this pull request may close these issues.

Formatting removes braces around unicode escapes
2 participants