jackfirth / rebellion

A collection of core libraries for Racket
https://pkgs.racket-lang.org/package/rebellion
Apache License 2.0
80 stars 16 forks source link

Draft of attempts at better multiline string literals #500

Closed jackfirth closed 3 years ago

jackfirth commented 3 years ago

This is an experimental attempt to figure out a better way to work with multiline string literals. There's two use cases: paragraphs and text blocks.

A paragraph is a string literal that spans multiple lines in the source code, but the actual written string is a one-line string. Use cases are long error messages that need to be split across multiple lines to stay under a reasonable column limit.

A text block is a string literal that spans multiple lines in the source code, where the total indentation of the the block doesn't matter but the relative indentation of each line does. Use cases are strings that contain multiple lines and have significant indentation and which are embedded in source code as expressions, such as the strings used in pretty printer test cases.

Approaches tried include @-expressions, here-strings, and a custom reader. Here-strings make it impossible to indent the whole string literal relative to the surrounding code, as the added indentation shows up in each line. @-expressions work great, except DrRacket wants to indent them like LaTeX-style macros within prose which breaks them. The custom reader approach is not finished, the idea is to have a meta-language which adds a new kind of string literal and an indenter that moves it around correctly.

I'm chucking this experiment into a closed pull request for now. I don't plan to put much more work into it (but I might anyway) and I just wanted a pull request to keep track of my thoughts and progress.