diff options
author | David Waern <david.waern@gmail.com> | 2009-01-22 19:48:09 +0000 |
---|---|---|
committer | David Waern <david.waern@gmail.com> | 2009-01-22 19:48:09 +0000 |
commit | 1abb4b96ff98b49e0b55c8cf55f2fdf1a35299e1 (patch) | |
tree | c8d963bb59d4fd81ef388eea0ea7762d8aa1b226 /tests | |
parent | 2ca9f33e5147bf1499e578dd559b927752fce0cc (diff) |
Add test for quasi quotation. No reference output yet.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/tests/QuasiExpr.hs | 36 | ||||
-rw-r--r-- | tests/tests/QuasiQuote.hs | 9 |
2 files changed, 45 insertions, 0 deletions
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|] } |