MyNixOS website logo
Description

A collection of GHC plugins to work with parsley.

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

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.

Metadata

Version

1.0.0.0

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows