Skip to content

Instantly share code, notes, and snippets.

@guibou
Created March 2, 2020 17:09
Show Gist options
  • Select an option

  • Save guibou/e6ee12292ac80bd49fd3dc6c5213ecf1 to your computer and use it in GitHub Desktop.

Select an option

Save guibou/e6ee12292ac80bd49fd3dc6c5213ecf1 to your computer and use it in GitHub Desktop.
How PyF can handle trimming whitespaces in front of multiline
-- 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