guibou / PyF

Haskell QuasiQuoter for String Formatting
BSD 3-Clause "New" or "Revised" License
66 stars 13 forks source link

Better missing variable error #106

Closed guibou closed 2 years ago

guibou commented 2 years ago

Close #102.

The following quote, where name is not defined:

f = [fmt|Hello {name}|]

was previously failing with just a simple error message, variable not found: name and the error context was a span covering the complete quote.

Now it gives a detailled location for the missing variable:

image

Code is not perfect and could be cleaned / refactored, but as long as test are passing, we'll clean later.

The difficult part in this MR is that code which introduces new names, such as [fmt|hello {(\x -> x) name}|] will fail because x will be considered as an undefined variable.

I'm sure nobody is using PyF this way (with case and lambda in the formatting expression), but well, it should not fail.

Hence I had to introduce a mecanism which detects which variables are new binding and which are free variables.

TODO: do also the check in width and precision field, which can also contain haskell expression.

guibou commented 2 years ago

The problem with lambda is fixed. I observed that our support for pattern matching is rather limited in lambda.

I need to fix the build with different GHC, and we'll launch this in production.

guibou commented 2 years ago

Works with the different version of GHC we are supporting. I forgot to handle the width and precision fields, so let's fix that.

guibou commented 2 years ago

width and precision fields are now correctly handled.