guibou / PyF

Haskell QuasiQuoter for String Formatting

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

haskell expression containing `:` are fragile

guibou opened this issue · comments

If the haskell expression contains :, it will fail with an unprecise error.

{-# LANGUAGE QuasiQuotes #-}

import PyF

f = ([fmt|{":"}|] :: String)
[1 of 2] Compiling Main             ( P.hs, interpreted )

P.hs:5:78: error:
    • lexical error in string/character literal at end of input in haskell expression
    • In the quasi-quotation:
        [fmtTrim|{if length currentJobsList == 0 then "- Countdown until autostop: " <> show countdown else ""}|]
  |
5 | f = ([fmtTrim|{if length currentJobsList == 0 then "- Countdown until autostop: " <> show countdown else ""}|] :: String)
  |                                                                              ^
Failed, no modules loaded.

--

f = ([fmt|{show (:[])}|] :: String)

[1 of 2] Compiling Main ( P.hs, interpreted )

P.hs:5:17: error:
• parse error (possibly incorrect indentation or mismatched brackets) in haskell expression
• In the quasi-quotation: [fmt|{show (:[])}|]
|
5 | f = ([fmt|{show (:[])}|] :: String)
| ^
Failed, no modules loaded.

ghci> [fmtTrim|{1:[]}|]

<interactive>:16:14: error:
    • 
unexpected "]"
expecting "<", ">", "^" or "="
    • In the quasi-quotation: [fmtTrim|{1:[]}|]

Some ambiguity cannot be resolved, and leads to really surprisng results.

ghci> let s = [1,2,3] in [fmtTrim|{1:s}|]
"1"

Other ambiguities, could be solved by typing, but are still leading to surprising errors

ghci> let s = [1,2,3] in [fmtTrim|{1:s:s}|]

<interactive>:18:33: error:
    • 
unexpected ":"
expecting "}"
    • In the quasi-quotation: [fmtTrim|{1:s:s}|]