| 141 | | asStr _ = return (cast "<sig>") -- XXX |
| 142 | | |
| 143 | | instance Pure Sig where {} |
| 144 | | |
| 145 | | |
| | 142 | asStr = return . cast . render . purePretty |
| | 143 | |
| | 144 | instance Pure Sig where |
| | 145 | purePretty s = colon <> (parens $ prettySig s) |
| | 146 | |
| | 147 | prettySig :: Sig -> Doc |
| | 148 | prettySig s@(SigMethSingle {}) = (prettyParam (s_invocant s) True True) <> colon `invSpace` (prettySubSig s) |
| | 149 | where |
| | 150 | invSpace :: Doc -> Doc -> Doc |
| | 151 | invSpace = if (isEmpty $ prettySubSig s) then (<>) else (<+>) |
| | 152 | prettySig s = prettySubSig s |
| | 153 | |
| | 154 | prettySubSig :: Sig -> Doc |
| | 155 | prettySubSig s = sep $ punctuate comma $ concat [posParams, namedParams] |
| | 156 | where |
| | 157 | posParams = [prettyParam p r True | p <- (s_positionalList s) | r <- (replicate (s_requiredPositionalCount s) True) ++ repeat False] |
| | 158 | namedParams = [prettyParam p (isReqNamed n) False | (n, p) <- Map.toList $ s_namedSet s] |
| | 159 | isReqNamed n = Set.member n $ s_requiredNames s |
| | 160 | |
| | 161 | prettyParam :: Param -> Bool -> Bool -> Doc |
| | 162 | prettyParam p isReq isPos = staticTypes <+> varName <> defaultHint <+> |
| | 163 | (if haveDefault then equals <+> text "..." else empty) <+> acc <+> ref <+> lazy <+> |
| | 164 | slots <+> constraints <+> debugDump |
| | 165 | where |
| | 166 | varName |
| | 167 | | isPos = text (cast $ p_variable p) |
| | 168 | | Buf.tail (cast $ p_variable p) == (cast $ p_label p) = text $ ":" ++ (cast $ p_variable p) |
| | 169 | | otherwise = text ":" <> text (cast p_label p) <> (parens $ text (cast p_variable p)) |
| | 170 | -- staticTypes = hsep $ map (text . (cast :: Types.Type -> String)) $ p_types p XXX: why is this wrong? |
| | 171 | staticTypes = hsep $ map (text . show) $ p_types p |
| | 172 | defaultHint = if not isReq && not haveDefault then text "?" else empty |
| | 173 | haveDefault = isJust $ unDefault $ p_default p |
| | 174 | acc = case p_hasAccess p of |
| | 175 | AccessRO -> empty |
| | 176 | AccessRW -> text "is rw" |
| | 177 | AccessCopy -> text "is copy" |
| | 178 | ref = if p_isRef p then text "is ref" else empty |
| | 179 | lazy = if p_isLazy p then text "is lazy" else empty |
| | 180 | -- slots = hsep [text ("is " ++ (cast aux)) <+> text "..." | (aux, val) <- Map.toList $ p_slots p] XXX: for when traits have args |
| | 181 | slots = hsep [text ("is " ++ (cast $ fst trait)) | trait <- Map.toList $ p_slots p] |
| | 182 | constraints = hsep $ replicate (length $ p_constraints p) (text "where {...}") |
| | 183 | debugDump = if True then empty else braces $ text $ show p -- XXX delme |