IMP_Ubiq()
-- friends:
-import HsLit ( HsLit )
+import HsBasic ( HsLit, Fixity )
IMPORT_DELOOPER(HsLoop) ( HsExpr )
-- others:
[InPat name]
| ConOpPatIn (InPat name)
name
+ Fixity -- c.f. OpApp in HsExpr
(InPat name)
+ | NPlusKPatIn name -- n+k pattern
+ HsLit
+
-- We preserve prefix negation and parenthesis for the precedence parser.
| NegPatIn (InPat name) -- negated pattern
(HsExpr tyvar uvar id (OutPat tyvar uvar id))
-- of type t -> Bool; detects match
+ | NPlusKPat id
+ HsLit -- Same reason as for LitPat
+ -- (This could be an Integer, but then
+ -- it's harder to partitionEqnsByLit
+ -- in the desugarer.)
+ (GenType tyvar uvar) -- Type of pattern, t
+ (HsExpr tyvar uvar id (OutPat tyvar uvar id)) -- Of type t -> Bool; detects match
+ (HsExpr tyvar uvar id (OutPat tyvar uvar id)) -- Of type t -> t; subtracts k
+
| DictPat -- Used when destructing Dictionaries with an explicit case
[id] -- superclass dicts
[id] -- methods
pprInPat :: (Outputable name, NamedThing name) => PprStyle -> InPat name -> Pretty
-pprInPat sty (WildPatIn) = ppStr "_"
-pprInPat sty (VarPatIn var) = pprNonSym sty var
+pprInPat sty (WildPatIn) = ppChar '_'
+pprInPat sty (VarPatIn var) = ppr sty var
pprInPat sty (LitPatIn s) = ppr sty s
pprInPat sty (LazyPatIn pat) = ppBeside (ppChar '~') (ppr sty pat)
pprInPat sty (AsPatIn name pat)
else
ppCat [ppr sty c, interppSP sty pats] -- ParPats put in the parens
-pprInPat sty (ConOpPatIn pat1 op pat2)
+pprInPat sty (ConOpPatIn pat1 op fixity pat2)
= ppCat [ppr sty pat1, ppr sty op, ppr sty pat2] -- ParPats put in parens
-- ToDo: use pprSym to print op (but this involves fiddling various
= ppBesides [ppLbrack, interpp'SP sty pats, ppRbrack]
pprInPat sty (TuplePatIn pats)
= ppParens (interpp'SP sty pats)
+pprInPat sty (NPlusKPatIn n k)
+ = ppBesides [ppLparen, ppr sty n, ppChar '+', ppr sty k, ppRparen]
pprInPat sty (RecPatIn con rpats)
- = ppBesides [ppr sty con, ppSP, ppChar '{', ppInterleave ppComma (map (pp_rpat sty) rpats), ppChar '}']
+ = ppCat [ppr sty con, ppCurlies (ppIntersperse pp'SP (map (pp_rpat sty) rpats))]
where
pp_rpat PprForUser (v, _, True) = ppr PprForUser v
- pp_rpat sty (v, p, _) = ppCat [ppr sty v, ppStr "=", ppr sty p]
+ pp_rpat sty (v, p, _) = ppCat [ppr sty v, ppChar '=', ppr sty p]
\end{code}
\begin{code}
-instance (Eq tyvar, Outputable tyvar, Eq uvar, Outputable uvar,
- NamedThing id, Outputable id)
+instance (Eq tyvar, Outputable tyvar, Eq uvar, Outputable uvar, Outputable id)
=> Outputable (OutPat tyvar uvar id) where
ppr = pprOutPat
\end{code}
\begin{code}
pprOutPat sty (WildPat ty) = ppChar '_'
-pprOutPat sty (VarPat var) = pprNonSym sty var
+pprOutPat sty (VarPat var) = ppr sty var
pprOutPat sty (LazyPat pat) = ppBesides [ppChar '~', ppr sty pat]
pprOutPat sty (AsPat name pat)
= ppBesides [ppLparen, ppr sty name, ppChar '@', ppr sty pat, ppRparen]
= ppParens (interpp'SP sty pats)
pprOutPat sty (RecPat con ty rpats)
- = ppBesides [ppr sty con, ppChar '{', ppInterleave ppComma (map (pp_rpat sty) rpats), ppChar '}']
+ = ppBesides [ppr sty con, ppCurlies (ppIntersperse pp'SP (map (pp_rpat sty) rpats))]
where
pp_rpat PprForUser (v, _, True) = ppr PprForUser v
- pp_rpat sty (v, p, _) = ppCat [ppr sty v, ppStr "=", ppr sty p]
+ pp_rpat sty (v, p, _) = ppCat [ppr sty v, ppChar '=', ppr sty p]
pprOutPat sty (LitPat l ty) = ppr sty l -- ToDo: print more
pprOutPat sty (NPat l ty e) = ppr sty l -- ToDo: print more
+pprOutPat sty (NPlusKPat n k ty e1 e2) -- ToDo: print more
+ = ppBesides [ppLparen, ppr sty n, ppChar '+', ppr sty k, ppRparen]
pprOutPat sty (DictPat dicts methods)
= ppSep [ppBesides [ppLparen, ppPStr SLIT("{-dict-}")],
patsAreAllLits :: [OutPat a b c] -> Bool
patsAreAllLits pat_list = all isLitPat pat_list
-isLitPat (AsPat _ pat) = isLitPat pat
-isLitPat (LitPat _ _) = True
-isLitPat (NPat _ _ _) = True
-isLitPat other = False
+isLitPat (AsPat _ pat) = isLitPat pat
+isLitPat (LitPat _ _) = True
+isLitPat (NPat _ _ _) = True
+isLitPat (NPlusKPat _ _ _ _ _) = True
+isLitPat other = False
\end{code}
This function @collectPatBinders@ works with the ``collectBinders''
\begin{code}
collectPatBinders :: InPat a -> [a]
-collectPatBinders WildPatIn = []
-collectPatBinders (VarPatIn var) = [var]
-collectPatBinders (LitPatIn _) = []
-collectPatBinders (LazyPatIn pat) = collectPatBinders pat
-collectPatBinders (AsPatIn a pat) = a : collectPatBinders pat
-collectPatBinders (ConPatIn c pats) = concat (map collectPatBinders pats)
-collectPatBinders (ConOpPatIn p1 c p2)= collectPatBinders p1 ++ collectPatBinders p2
-collectPatBinders (NegPatIn pat) = collectPatBinders pat
-collectPatBinders (ParPatIn pat) = collectPatBinders pat
-collectPatBinders (ListPatIn pats) = concat (map collectPatBinders pats)
-collectPatBinders (TuplePatIn pats) = concat (map collectPatBinders pats)
-collectPatBinders (RecPatIn c fields) = concat (map (\ (f,pat,_) -> collectPatBinders pat) fields)
+collectPatBinders WildPatIn = []
+collectPatBinders (VarPatIn var) = [var]
+collectPatBinders (LitPatIn _) = []
+collectPatBinders (LazyPatIn pat) = collectPatBinders pat
+collectPatBinders (AsPatIn a pat) = a : collectPatBinders pat
+collectPatBinders (NPlusKPatIn n _) = [n]
+collectPatBinders (ConPatIn c pats) = concat (map collectPatBinders pats)
+collectPatBinders (ConOpPatIn p1 c f p2) = collectPatBinders p1 ++ collectPatBinders p2
+collectPatBinders (NegPatIn pat) = collectPatBinders pat
+collectPatBinders (ParPatIn pat) = collectPatBinders pat
+collectPatBinders (ListPatIn pats) = concat (map collectPatBinders pats)
+collectPatBinders (TuplePatIn pats) = concat (map collectPatBinders pats)
+collectPatBinders (RecPatIn c fields) = concat (map (\ (f,pat,_) -> collectPatBinders pat) fields)
\end{code}