diff options
Diffstat (limited to 'hypsrc-test/src')
| -rw-r--r-- | hypsrc-test/src/Quasiquoter.hs | 16 | ||||
| -rw-r--r-- | hypsrc-test/src/TemplateHaskellQuasiquotes.hs | 39 | ||||
| -rw-r--r-- | hypsrc-test/src/TemplateHaskellSplices.hs | 8 | ||||
| -rw-r--r-- | hypsrc-test/src/UsingQuasiquotes.hs | 9 | 
4 files changed, 72 insertions, 0 deletions
| diff --git a/hypsrc-test/src/Quasiquoter.hs b/hypsrc-test/src/Quasiquoter.hs new file mode 100644 index 00000000..d0a46c33 --- /dev/null +++ b/hypsrc-test/src/Quasiquoter.hs @@ -0,0 +1,16 @@ +module Quasiquoter ( string ) where + +import Language.Haskell.TH.Quote +import Language.Haskell.TH.Syntax + +-- | Quoter for constructing multiline string literals +string :: QuasiQuoter +string = QuasiQuoter +  { quoteExp = pure . LitE . StringL +  , quotePat = invalidDomain +  , quoteType = invalidDomain +  , quoteDec = invalidDomain +  } +  where +    invalidDomain :: String -> Q a +    invalidDomain _ = fail "stringQuoter: only valid in expression context" diff --git a/hypsrc-test/src/TemplateHaskellQuasiquotes.hs b/hypsrc-test/src/TemplateHaskellQuasiquotes.hs new file mode 100644 index 00000000..a1661895 --- /dev/null +++ b/hypsrc-test/src/TemplateHaskellQuasiquotes.hs @@ -0,0 +1,39 @@ +{-# LANGUAGE TemplateHaskell #-} + +module TemplateHaskellQuasiquotes where + +import Language.Haskell.TH + +aDecl :: DecsQ +aDecl = [d| +    bar :: $aType -> [ (Int, String) ] +    bar $aPattern = $anExpression +  |] + +aPattern :: PatQ +aPattern = [p| +    [ aCrazyLongVariableName +    , _unused +    , (y, z) +    , ( $aNumberPattern, "hello") +    ] +  |] + +aNumberPattern :: PatQ +aNumberPattern = [p| +    w @ v @ 4.5 +  |] + +anExpression, anExpression2 :: ExpQ +anExpression = [e| +    [ (1 + $anExpression2, "world") ] +  |] +anExpression2 = [| (1 + round pi) |] + +aType :: TypeQ +aType = [t| +    [ (Double, String) ] +  |] + + + diff --git a/hypsrc-test/src/TemplateHaskellSplices.hs b/hypsrc-test/src/TemplateHaskellSplices.hs new file mode 100644 index 00000000..bbd3948e --- /dev/null +++ b/hypsrc-test/src/TemplateHaskellSplices.hs @@ -0,0 +1,8 @@ +{-# LANGUAGE TemplateHaskell #-} +module TemplateHaskellSplices where + +import TemplateHaskellQuasiquotes + +$(aDecl) + +foo = id $(anExpression2) diff --git a/hypsrc-test/src/UsingQuasiquotes.hs b/hypsrc-test/src/UsingQuasiquotes.hs new file mode 100644 index 00000000..34872d4d --- /dev/null +++ b/hypsrc-test/src/UsingQuasiquotes.hs @@ -0,0 +1,9 @@ +{-# LANGUAGE QuasiQuotes #-} +module UsingQuasiquotes where + +import Quasiquoter + +baz  = [string| foo bar |] ++ [string| some +  mulitline +  quasiquote +|] | 
