module HsIdent where
import PrettyPrint
import MUtils(( # ))
data HsIdentI i
= HsVar i
| HsCon i
deriving (Eq, Ord, Show)
getHSName = accHsIdent id
mapHsIdent nf (HsVar n) = HsVar $ nf n
mapHsIdent nf (HsCon n) = HsCon $ nf n
accHsIdent nf (HsVar n) = nf n
accHsIdent nf (HsCon n) = nf n
accHsIdent2 vf cf (HsVar n) = vf n
accHsIdent2 vf cf (HsCon n) = cf n
seqHsIdent (HsVar i) = HsVar # i
seqHsIdent (HsCon i) = HsCon # i
isHsVar (HsVar _) = True
isHsVar _ = False
isHsCon (HsCon _) = True
isHsCon _ = False
hsVarName (HsVar v) = Just v
hsVarName _ = Nothing
hsConName (HsCon c) = Just c
hsConName _ = Nothing
--- Pretty printing ------------------------------------------------------------
class Printable a => PrintableOp a where
{- How to print operators "mod" and "+":
ppi should produce "mod" and "+".
wrap should produce "mod" and "(+)".
ppiOp should produce "`mod`" and "+". -}
ppiOp :: a -> Doc
instance Printable i => Printable (HsIdentI i) where
ppi = ppi . getHSName
wrap = wrap . getHSName
instance PrintableOp i => PrintableOp (HsIdentI i) where
ppiOp = ppiOp . getHSName