Commit 2032635b authored by thomie's avatar thomie
Browse files

Testsuite: fix qq005 and qq006 (#11279)

With 399a5b46, the old `[$foo| ... |]`
syntax for quasi-quotes is no longer allowed.
parent 2db18b81
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE FlexibleContexts #-}
module Expr where
import Data.Generics
import Data.Data
import Data.Typeable
import Language.Haskell.TH as TH
import Language.Haskell.TH.Quote
......@@ -29,6 +31,7 @@ eval (BinopExpr op x y) = (opToFun op) (eval x) (eval y)
opToFun MulOp = (*)
opToFun DivOp = (div)
small :: CharParser st Char
small = lower <|> char '_'
large = upper
idchar = small <|> large <|> digit <|> char '\''
......@@ -74,7 +77,8 @@ parseExpr (Loc {loc_filename = file, loc_start = (line,col)}) s =
eof
return e
expr = QuasiQuoter { quoteExp = parseExprExp, quotePat = parseExprPat }
expr = QuasiQuoter { quoteExp = parseExprExp, quotePat = parseExprPat,
quoteType = undefined, quoteDec = undefined }
parseExprExp :: String -> Q Exp
parseExprExp s = do loc <- location
......@@ -97,3 +101,15 @@ antiExprPat (AntiIntExpr v) = Just $ conP (mkName "IntExpr")
[varP (mkName v)]
antiExprPat (AntiExpr v) = Just $ varP (mkName v)
antiExprPat _ = Nothing
-- Copied from syb for the test
-- | Extend a generic query by a type-specific case
extQ :: ( Typeable a
, Typeable b
)
=> (a -> q)
-> (b -> q)
-> a
-> q
extQ f g a = maybe (f a) g (cast a)
......@@ -7,7 +7,7 @@ main :: IO ()
main = do print $ eval [expr|1 + 3 + 5|]
case [expr|2|] of
[expr|$n|] -> print n
_ -> return ()
case [$expr|1 + 2|] of
_ -> return ()
case [expr|1 + 2|] of
[expr|$x + $y|] -> putStrLn $ show x ++ " + " ++ show y
_ -> return ()
_ -> return ()
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE FlexibleContexts #-}
module Expr where
import Data.Generics
import Data.Data
import Data.Typeable
import Language.Haskell.TH as TH
import Language.Haskell.TH.Quote
......@@ -29,6 +31,7 @@ eval (BinopExpr op x y) = (opToFun op) (eval x) (eval y)
opToFun MulOp = (*)
opToFun DivOp = (div)
small :: CharParser st Char
small = lower <|> char '_'
large = upper
idchar = small <|> large <|> digit <|> char '\''
......@@ -74,7 +77,8 @@ parseExpr (Loc {loc_filename = file, loc_start = (line,col)}) s =
eof
return e
expr = QuasiQuoter { quoteExp = parseExprExp, quotePat = parseExprPat }
expr = QuasiQuoter { quoteExp = parseExprExp, quotePat = parseExprPat,
quoteType = undefined, quoteDec = undefined }
parseExprExp :: String -> Q Exp
parseExprExp s = do loc <- location
......@@ -97,3 +101,15 @@ antiExprPat (AntiIntExpr v) = Just $ conP (mkName "IntExpr")
[varP (mkName v)]
antiExprPat (AntiExpr v) = Just $ varP (mkName v)
antiExprPat _ = Nothing
-- Copied from syb for the test
-- | Extend a generic query by a type-specific case
extQ :: ( Typeable a
, Typeable b
)
=> (a -> q)
-> (b -> q)
-> a
-> q
extQ f g a = maybe (f a) g (cast a)
......@@ -4,6 +4,6 @@ module Main where
import Expr
main :: IO ()
main = do case [$expr|1 + 2|] of
[$expr|$x + $x|] -> print x
_ -> return ()
main = do case [expr|1 + 2|] of
[expr|$x + $x|] -> print x
_ -> return ()
Main.hs:8:20:
Conflicting definitions for `x'
In a case alternative
Main.hs:8:20: error:
• Conflicting definitions for ‘x’
Bound at: Main.hs:8:20-28
Main.hs:8:20-28
• In a case alternative
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment