parsley-garnish: A collection of GHC plugins to work with parsley

[ bsd3, library, plugin ] [ Propose Tags ] [ Report a vulnerability ]

This package contains a collection (for now one) to help remove boilerplate when writing parsers using parsley.


[Skip to Readme]

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.1.0.1, 1.0.0.0
Change log ChangeLog.md
Dependencies base (>=4.10 && <5), ghc (>=8.6 && <9.2), ghc-tcplugins-extra (>=0.3 && <0.5), parsley-core (>=1 && <3), syb (>=0.7 && <0.8), template-haskell (>=2.14 && <3) [details]
Tested with ghc ==8.6.5, ghc ==8.8.4, ghc ==8.10.5, ghc ==9.0.1
License BSD-3-Clause
Author Jamie Willis, Garnish Contributors
Maintainer Jamie Willis <j.willis19@imperial.ac.uk>
Revised Revision 1 made by j_mie6 at 2021-10-28T22:46:36Z
Category Plugin
Home page https://github.com/j-mie6/parsley-garnish
Bug tracker https://github.com/j-mie6/parsley-garnish/issues
Source repo head: git clone https://github.com/j-mie6/parsley-garnish
Uploaded by j_mie6 at 2021-06-12T14:58:21Z
Distributions
Downloads 686 total (1 in the last 30 days)
Rating 2.25 (votes: 2) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2021-06-12 [all 1 reports]

Readme for parsley-garnish-1.0.0.0

[back to package description]

Parsley Garnish GitHub release GitHub license GitHub commits since latest release (by SemVer) Hackage Version Dependent repos (via libraries.io)

This repo houses the parsley-specific GHC plugins to help make writing parsers with parsley take less boilerplate.

Each plugin here will in some way interact to produce values of either type Parsley.WQ or Parsley.Defunctionalized.Defunc. These datatypes are how parsley's API interacts with user-land functions.

By default, the user can produce values of these types by using the makeQ function:

makeQ :: Quapplicative q => a -> Code a -> q a

Where both WQ and Defunc are instances of Quapplicative. However, this can be tedious to do by hand.

OverloadedQuotes

The first plugin found in the garnish hijacks the regular Haskell syntax for Untyped Template Haskell (UTH). Since parsley uses Typed Template Haskell (TTH), it is unlikely that a user of the library will need to be using UTH in the same file (with the possible exception of top-level splices, or quotes other than the basic [|x|]). This plugin will transform every UTH quote in a file so that it represents a value of Quapplicative q => q a. This transformation is as follows:

qsucc :: Quapplicative q => q Int -> q Int
qsucc qx = [|$(qx) + 1|]
-- goes to:
qsucc qx = makeQ (_val qx + 1) [||$$(_code qx) + 1||]

Values of Defunc can also be spliced in directly:

diffcons :: Defunc a -> Defunc ([a] -> [a]) -> Defunc ([a] -> [a])
diffcons qx qdxs = [| $(COMPOSE) ($(CONS) $(qx)) $(qdxs) |]

And lambda abstraction works too (along with any other syntax):

diffcons' :: Defunc (a -> ([a] -> [a]) -> [a] -> [a])
diffcons' = [|\x dxs -> $(diffcons [|x|] [|dxs|])|]

The disadvantage to this plugin currently is that it does not make any attempt to leverage the specialised parts of Defunc to improve the code generation and inspectibility. The user would be left to use this manually.