module Language.Haskell.Exts.Annotated.Build (
name,
sym,
var,
op,
qvar,
pvar,
app,
infixApp,
appFun,
pApp,
tuple,
pTuple,
varTuple,
pvarTuple,
function,
strE,
charE,
intE,
strP,
charP,
intP,
doE,
lamE,
letE,
caseE,
alt,
altGW,
listE,
eList,
peList,
paren,
pParen,
qualStmt,
genStmt,
letStmt,
binds,
noBinds,
wildcard,
genNames,
sfun,
simpleFun,
patBind,
patBindWhere,
nameBind,
metaFunction,
metaConPat
) where
import Language.Haskell.Exts.Annotated.Syntax
name :: l -> String -> Name l
name = Ident
sym :: l -> String -> Name l
sym = Symbol
var :: l -> Name l -> Exp l
var l = Var l . UnQual l
op :: l -> Name l -> QOp l
op l = QVarOp l . UnQual l
qvar :: l -> ModuleName l -> Name l -> Exp l
qvar l m = Var l . Qual l m
pvar :: l -> Name l -> Pat l
pvar = PVar
app :: l -> Exp l -> Exp l -> Exp l
app = App
infixApp :: l -> Exp l -> QOp l -> Exp l -> Exp l
infixApp = InfixApp
appFun :: [l] -> Exp l -> [Exp l] -> Exp l
appFun _ f [] = f
appFun (l:ls) f (a:as) = appFun ls (app l f a) as
pApp :: l -> Name l -> [Pat l] -> Pat l
pApp l n = PApp l (UnQual l n)
tuple :: l -> [Exp l] -> Exp l
tuple l = Tuple l Boxed
pTuple :: l -> [Pat l] -> Pat l
pTuple l = PTuple l Boxed
varTuple :: l -> [Name l] -> Exp l
varTuple l ns = tuple l $ map (var l) ns
pvarTuple :: l -> [Name l] -> Pat l
pvarTuple l ns = pTuple l $ map (pvar l) ns
function :: l -> String -> Exp l
function l = var l . Ident l
strE :: l -> String -> Exp l
strE l s = Lit l $ String l s s
charE :: l -> Char -> Exp l
charE l c = Lit l $ Char l c [c]
intE :: l -> Integer -> Exp l
intE l i = Lit l $ Int l i (show i)
strP :: l -> String -> Pat l
strP l s = PLit l $ String l s s
charP :: l -> Char -> Pat l
charP l c = PLit l $ Char l c [c]
intP :: l -> Integer -> Pat l
intP l i = PLit l $ Int l i (show i)
doE :: l -> [Stmt l] -> Exp l
doE = Do
lamE :: l -> [Pat l] -> Exp l -> Exp l
lamE = Lambda
letE :: l -> [Decl l] -> Exp l -> Exp l
letE l ds e = Let l (binds l ds) e
caseE :: l -> Exp l -> [Alt l] -> Exp l
caseE = Case
alt :: l -> Pat l -> Exp l -> Alt l
alt l p e = Alt l p (unGAlt l e) Nothing
altGW :: l -> Pat l -> [Stmt l] -> Exp l -> Binds l -> Alt l
altGW l p gs e w = Alt l p (gAlt l gs e) (Just w)
unGAlt :: l -> Exp l -> GuardedAlts l
unGAlt = UnGuardedAlt
gAlts :: l -> [([Stmt l], Exp l)] -> GuardedAlts l
gAlts l as = GuardedAlts l $ map (\(gs,e) -> GuardedAlt l gs e) as
gAlt :: l -> [Stmt l] -> Exp l -> GuardedAlts l
gAlt l gs e = gAlts l [(gs,e)]
listE :: l -> [Exp l] -> Exp l
listE = List
eList :: l -> Exp l
eList l = List l []
peList :: l -> Pat l
peList l = PList l []
paren :: l -> Exp l -> Exp l
paren = Paren
pParen :: l -> Pat l -> Pat l
pParen = PParen
qualStmt :: l -> Exp l -> Stmt l
qualStmt = Qualifier
genStmt :: l -> Pat l -> Exp l -> Stmt l
genStmt = Generator
letStmt :: l -> [Decl l] -> Stmt l
letStmt l ds = LetStmt l $ binds l ds
binds :: l -> [Decl l] -> Binds l
binds = BDecls
noBinds :: l -> Binds l
noBinds l = binds l []
wildcard :: l -> Pat l
wildcard = PWildCard
genNames :: l -> String -> Int -> [Name l]
genNames l s k = [ Ident l $ s ++ show i | i <- [1..k] ]
sfun :: l -> Name l -> [Name l] -> Rhs l -> Maybe (Binds l) -> Decl l
sfun l f pvs rhs mbs = FunBind l [Match l f (map (pvar l) pvs) rhs mbs]
simpleFun :: l -> Name l -> Name l -> Exp l -> Decl l
simpleFun l f a e = let rhs = UnGuardedRhs l e
in sfun l f [a] rhs Nothing
patBind :: l -> Pat l -> Exp l -> Decl l
patBind l p e = let rhs = UnGuardedRhs l e
in PatBind l p Nothing rhs Nothing
patBindWhere :: l -> Pat l -> Exp l -> [Decl l] -> Decl l
patBindWhere l p e ds = let rhs = UnGuardedRhs l e
in PatBind l p Nothing rhs (Just $ binds l ds)
nameBind :: l -> Name l -> Exp l -> Decl l
nameBind l n e = patBind l (pvar l n) e
metaFunction :: l -> String -> [Exp l] -> Exp l
metaFunction l s es = mf l s (reverse es)
where mf l s [] = var l $ name l s
mf l s (e:es) = app l (mf l s es) e
metaConPat :: l -> String -> [Pat l] -> Pat l
metaConPat l s ps = pApp l (name l s) ps