From 1abb4b96ff98b49e0b55c8cf55f2fdf1a35299e1 Mon Sep 17 00:00:00 2001 From: David Waern Date: Thu, 22 Jan 2009 19:48:09 +0000 Subject: Add test for quasi quotation. No reference output yet. --- tests/tests/QuasiExpr.hs | 36 ++++++++++++++++++++++++++++++++++++ tests/tests/QuasiQuote.hs | 9 +++++++++ 2 files changed, 45 insertions(+) create mode 100644 tests/tests/QuasiExpr.hs create mode 100644 tests/tests/QuasiQuote.hs diff --git a/tests/tests/QuasiExpr.hs b/tests/tests/QuasiExpr.hs new file mode 100644 index 00000000..6fc00a72 --- /dev/null +++ b/tests/tests/QuasiExpr.hs @@ -0,0 +1,36 @@ +{-# LANGUAGE TemplateHaskell #-} + +-- Used by QuasiQuote. Example taken from the GHC documentation. +module QuasiExpr where + +import Language.Haskell.TH +import Language.Haskell.TH.Quote +import Data.Typeable +import Data.Generics + +data Expr = IntExpr Integer + | AntiIntExpr String + | BinopExpr BinOp Expr Expr + | AntiExpr String + deriving(Show, Typeable, Data) + +data BinOp = AddOp + | SubOp + | MulOp + | DivOp + deriving(Show, Typeable, Data) + +eval :: Expr -> Integer +eval (IntExpr n) = n +eval (BinopExpr op x y) = (opToFun op) (eval x) (eval y) + where + opToFun AddOp = (+) + opToFun SubOp = (-) + opToFun MulOp = (*) + opToFun DivOp = div + +expr = QuasiQuoter parseExprExp undefined + +-- cheating... +parseExprExp :: String -> Q Exp +parseExprExp _ = [| BinopExpr AddOp (IntExpr 1) (IntExpr 2) |] diff --git a/tests/tests/QuasiQuote.hs b/tests/tests/QuasiQuote.hs new file mode 100644 index 00000000..a1aa7256 --- /dev/null +++ b/tests/tests/QuasiQuote.hs @@ -0,0 +1,9 @@ +{-# LANGUAGE TemplateHaskell, QuasiQuotes #-} + +-- example taken from the GHC documentation +module QuasiQuote where + +import QuasiExpr + +run :: IO () +run = do { print $ eval [$expr|1 + 2|] } -- cgit v1.2.3