Created
March 2, 2020 17:09
-
-
Save guibou/e6ee12292ac80bd49fd3dc6c5213ecf1 to your computer and use it in GitHub Desktop.
How PyF can handle trimming whitespaces in front of multiline
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Solution 0, do nothing | |
| let foo = [fmt|\ | |
| this | |
| is | |
| a | |
| |] | |
| -- Will return " this\n is\n a\n " | |
| -- Solution 1, trim common alignement | |
| let foo = [fmt|\ | |
| this | |
| is | |
| a | |
| |] | |
| -- Will return "this\n is\na\n" after detecting that 4 spaces is common to all lines. | |
| -- Limitations: | |
| -- - Last line need to be indented | |
| -- - You cannot have lines starting with spaces | |
| -- Solution 2, trim based on the template haskell marker | |
| let foo = [fmt|\ | |
| this | |
| is | |
| a | |
| |] | |
| -- Will return "this\nis\na\n" after removing a fixed number of space based on the position of the | in the quasiquotation | |
| -- Limitations: | |
| -- - difficult to see | |
| -- Solution 3, add a marker: | |
| let foo = [fmt|\ | |
| |this | |
| | is | |
| |a | |
| |] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment