New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make `regex` compatible w/ TH-less GHCs #70

Closed
hvr opened this Issue Mar 14, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@hvr
Contributor

hvr commented Mar 14, 2017

I think regex can be made to avoid relying on TemplateHaskell+QuasiQuotes for recent GHC versions which provide the TemplateHaskellQuotes extension, which would have the benefit that GHCs which don't have interpreter support would be able to compile regex, and also the TemplateHaskellQuotes extension is considered "safe" under SafeHaskell, whereas TemplateHaskell is "unsafe".

There are currently 3 modules which rely on TemplateHaskell,

  • Text/RE/Options.lhs
  • Text/RE/TDFA/RE.hs
  • Text/RE/Internal/NamedCaptures.lhs

The first two are trivial to make THQ-compatible; the 3rd one however makes use of heredocs, thereby actually executes TH code:

import           Text.Heredoc

scan :: String -> [Token]
scan = alex' match al oops
  where
    al :: [(Regex,Match String->Maybe Token)]
    al =
      [ mk [here|\$\{([^{}]+)\}\(|] $         ECap . Just . x_1
      , mk [here|\$\(|]             $ const $ ECap Nothing
      , mk [here|\(\?:|]            $ const   PGrp
      , mk [here|\(\?|]             $ const   PCap
      , mk [here|\(|]               $ const   Bra
      , mk [here|\\(.)|]            $         BS    . s2c . x_1
      , mk [here|(.)|]              $         Other . s2c . x_1
      ]

would it be possible to avoid using heredocs and thus avoid having to execute TH code?

@cdornan

This comment has been minimized.

Contributor

cdornan commented Mar 14, 2017

@hvr all looks quite do-able and expect it to be fixed in the next release (most likely over the weekend).

@hvr

This comment has been minimized.

Contributor

hvr commented Mar 15, 2017

@cdornan great; fyi, as this is a bit non-obvious, here's an example how this was done in another package: ekmett/reflection@d3c2d13 (by now Hackage does actually accept the HaskellTemplateQuotes token)

@cdornan cdornan added the up next label Mar 15, 2017

@cdornan cdornan self-assigned this Mar 15, 2017

@cdornan cdornan modified the milestone: v0.8.0.0 Mar 15, 2017

@cdornan cdornan added in progress and removed up next labels Mar 22, 2017

cdornan added a commit that referenced this issue Mar 25, 2017

0.9.0.0: Finish tidying up the API, add type-safe replacement templates
  * Flip the order of the arguments to replace (fixes #78)
  * Add type-safe replacement templates (fixes #60)
  * Finish tidying up the API (fixes #80)
  * Make `regex` compatible w/ TH-less GHCs (fixes #70)
  * Declare extensions the compiler must support (fixes #83)
  * Fix curl for AppVeyor build (fixes #79)
  * Fix AppVeyor badge (fixes #81)
  * Remove QQ from code coverage stats (fixes #82)
  * Rename Options, Context and Replace methods (fixes #84)

@cdornan cdornan closed this in #85 Mar 25, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment