diff options
author | Péter Diviánszky <divipp@gmail.com> | 2016-05-05 17:55:01 +0200 |
---|---|---|
committer | Péter Diviánszky <divipp@gmail.com> | 2016-05-05 17:55:01 +0200 |
commit | 9e232c77ee6d0948f7dd5727d3ec568bbedf4316 (patch) | |
tree | d9f64543cf48a964fd29e95b87b824f9b5c2a877 /src | |
parent | f24ab8bd8d5cb60a7a75e52655b567f916f73a53 (diff) |
improve pretty printing & try to fix local function handling
Diffstat (limited to 'src')
-rw-r--r-- | src/LambdaCube/Compiler/Core.hs | 18 | ||||
-rw-r--r-- | src/LambdaCube/Compiler/CoreToIR.hs | 23 | ||||
-rw-r--r-- | src/LambdaCube/Compiler/DesugaredSource.hs | 19 | ||||
-rw-r--r-- | src/LambdaCube/Compiler/Infer.hs | 22 | ||||
-rw-r--r-- | src/LambdaCube/Compiler/Pretty.hs | 48 |
5 files changed, 74 insertions, 56 deletions
diff --git a/src/LambdaCube/Compiler/Core.hs b/src/LambdaCube/Compiler/Core.hs index 5e2b4136..a75beb60 100644 --- a/src/LambdaCube/Compiler/Core.hs +++ b/src/LambdaCube/Compiler/Core.hs | |||
@@ -21,7 +21,7 @@ import Control.Arrow hiding ((<+>)) | |||
21 | --import LambdaCube.Compiler.Utils | 21 | --import LambdaCube.Compiler.Utils |
22 | import LambdaCube.Compiler.DeBruijn | 22 | import LambdaCube.Compiler.DeBruijn |
23 | import LambdaCube.Compiler.Pretty hiding (braces, parens) | 23 | import LambdaCube.Compiler.Pretty hiding (braces, parens) |
24 | import LambdaCube.Compiler.DesugaredSource hiding (getList) | 24 | import LambdaCube.Compiler.DesugaredSource |
25 | 25 | ||
26 | -------------------------------------------------------------------------------- De-Bruijn limit | 26 | -------------------------------------------------------------------------------- De-Bruijn limit |
27 | 27 | ||
@@ -509,8 +509,7 @@ instance MkDoc Exp where | |||
509 | Pi h TType b -> shLam_ (usedVar 0 b) (BPi h) Nothing (f b) | 509 | Pi h TType b -> shLam_ (usedVar 0 b) (BPi h) Nothing (f b) |
510 | Pi h a b -> shLam (usedVar 0 b) (BPi h) (f a) (f b) | 510 | Pi h a b -> shLam (usedVar 0 b) (BPi h) (f a) (f b) |
511 | ENat n -> pShow n | 511 | ENat n -> pShow n |
512 | (getTTup -> Just xs) -> shTuple $ f <$> xs | 512 | ConN FHCons [_, _, x, xs] -> foldl DApp (text "HCons") (f <$> [x, xs]) |
513 | (getTup -> Just xs) -> shTuple $ f <$> xs | ||
514 | Con s _ xs -> foldl DApp (pShow s) (f <$> xs) | 513 | Con s _ xs -> foldl DApp (pShow s) (f <$> xs) |
515 | TyConN s xs -> foldl DApp (pShow s) (f <$> xs) | 514 | TyConN s xs -> foldl DApp (pShow s) (f <$> xs) |
516 | TType -> text "Type" | 515 | TType -> text "Type" |
@@ -533,17 +532,6 @@ instance MkDoc Neutral where | |||
533 | TyCaseFun_ s [m, t, f] n -> foldl DApp (pShow s) (g <$> [m, t, Neut n, f]) | 532 | TyCaseFun_ s [m, t, f] n -> foldl DApp (pShow s) (g <$> [m, t, Neut n, f]) |
534 | TyCaseFun_ s _ n -> error $ "mkDoc TyCaseFun" | 533 | TyCaseFun_ s _ n -> error $ "mkDoc TyCaseFun" |
535 | 534 | ||
536 | getTup (hnf -> ConN FHCons [_, _, x, xs]) = (x:) <$> getTup xs | ||
537 | getTup (hnf -> ConN FHNil []) = Just [] | ||
538 | getTup _ = Nothing | ||
539 | |||
540 | getTTup (hnf -> TyConN FHList [xs]) = getList xs | ||
541 | getTTup _ = Nothing | ||
542 | |||
543 | getList (hnf -> ConN FCons [x, xs]) = (x:) <$> getList xs | ||
544 | getList (hnf -> ConN FNil []) = Just [] | ||
545 | getList _ = Nothing | ||
546 | |||
547 | -------------------------------------------------------------------------------- reduction | 535 | -------------------------------------------------------------------------------- reduction |
548 | 536 | ||
549 | {- todo: generate | 537 | {- todo: generate |
@@ -686,7 +674,7 @@ cstr = f [] | |||
686 | 674 | ||
687 | f_ [] typ a@Neut{} a' = CstrT typ a a' | 675 | f_ [] typ a@Neut{} a' = CstrT typ a a' |
688 | f_ [] typ a a'@Neut{} = CstrT typ a a' | 676 | f_ [] typ a a'@Neut{} = CstrT typ a a' |
689 | f_ ns typ a a' = CEmpty $ unlines [ "can not unify", ppShow a, "with", ppShow a' ] | 677 | f_ ns typ a a' = CEmpty $ simpleShow $ nest 2 ("can not unify" <$$> DTypeNamespace True (pShow a)) <$$> nest 2 ("with" <$$> DTypeNamespace True (pShow a')) |
690 | 678 | ||
691 | ff _ _ [] = CUnit | 679 | ff _ _ [] = CUnit |
692 | ff ns tt@(Pi v t _) ((t1, t2'): ts) = t2 (f ns t t1 t2') $ ff ns (appTy tt t1) ts | 680 | ff ns tt@(Pi v t _) ((t1, t2'): ts) = t2 (f ns t t1 t2') $ ff ns (appTy tt t1) ts |
diff --git a/src/LambdaCube/Compiler/CoreToIR.hs b/src/LambdaCube/Compiler/CoreToIR.hs index 303f1156..f65b543d 100644 --- a/src/LambdaCube/Compiler/CoreToIR.hs +++ b/src/LambdaCube/Compiler/CoreToIR.hs | |||
@@ -865,7 +865,7 @@ mkLam _ = Nothing | |||
865 | 865 | ||
866 | mkCon (ExpTV (I.Con s n xs) et vs) = Just (untick $ show s, chain vs (I.conType et s) $ I.mkConPars n et ++ xs) | 866 | mkCon (ExpTV (I.Con s n xs) et vs) = Just (untick $ show s, chain vs (I.conType et s) $ I.mkConPars n et ++ xs) |
867 | mkCon (ExpTV (I.TyCon s xs) et vs) = Just (untick $ show s, chain vs (nType s) xs) | 867 | mkCon (ExpTV (I.TyCon s xs) et vs) = Just (untick $ show s, chain vs (nType s) xs) |
868 | mkCon (ExpTV (I.Neut (I.Fun s (reverse -> xs) def)) et vs) = Just (untick $ show s, chain vs (nType s) xs) | 868 | mkCon (ExpTV (I.Neut (I.Fun s@(I.FunName _ 0 _{-I.DeltaDef{}-} _) (reverse -> xs) def)) et vs) = Just (untick $ show s, chain vs (nType s) xs) |
869 | mkCon (ExpTV (I.CaseFun s xs n) et vs) = Just (untick $ show s, chain vs (nType s) $ makeCaseFunPars' (mkEnv vs) n ++ xs ++ [I.Neut n]) | 869 | mkCon (ExpTV (I.CaseFun s xs n) et vs) = Just (untick $ show s, chain vs (nType s) $ makeCaseFunPars' (mkEnv vs) n ++ xs ++ [I.Neut n]) |
870 | mkCon (ExpTV (I.TyCaseFun s [m, t, f] n) et vs) = Just (untick $ show s, chain vs (nType s) [m, t, I.Neut n, f]) | 870 | mkCon (ExpTV (I.TyCaseFun s [m, t, f] n) et vs) = Just (untick $ show s, chain vs (nType s) [m, t, I.Neut n, f]) |
871 | mkCon _ = Nothing | 871 | mkCon _ = Nothing |
@@ -874,7 +874,13 @@ mkApp (ExpTV (I.Neut (I.App_ a b)) et vs) = Just (ExpTV (I.Neut a) t vs, head $ | |||
874 | where t = neutType' (mkEnv vs) a | 874 | where t = neutType' (mkEnv vs) a |
875 | mkApp _ = Nothing | 875 | mkApp _ = Nothing |
876 | 876 | ||
877 | mkFunc r@(ExpTV (IFunc (show -> n) def nt xs) ty vs) | all (supType . tyOf) (r: xs') && n `notElem` ["typeAnn"] && all validChar n | 877 | removeRHS 0 (I.RHS x) = Just x |
878 | removeRHS n (I.Lam x) | n > 0 = I.Lam <$> removeRHS (n-1) x | ||
879 | removeRHS _ _ = Nothing | ||
880 | |||
881 | mkFunc r@(ExpTV (I.Neut (I.Fun (I.FunName (show -> n) 0 (I.ExpDef def_) nt) xs I.RHS{})) ty vs) | ||
882 | | Just def <- removeRHS (length xs) def_ | ||
883 | , all (supType . tyOf) (r: xs') && n `notElem` ["typeAnn"] && all validChar n | ||
878 | = Just (untick n +++ intercalate "_" (filter (/="TT") $ map (filter isAlphaNum . plainShow) hs), toExp $ I.ET (foldl I.app_ def hs) (foldl I.appTy nt hs), tyOf r, xs') | 884 | = Just (untick n +++ intercalate "_" (filter (/="TT") $ map (filter isAlphaNum . plainShow) hs), toExp $ I.ET (foldl I.app_ def hs) (foldl I.appTy nt hs), tyOf r, xs') |
879 | where | 885 | where |
880 | a +++ [] = a | 886 | a +++ [] = a |
@@ -897,21 +903,10 @@ unLab' (I.RHS x) = unLab' x -- TODO: remove | |||
897 | unLab' x = x | 903 | unLab' x = x |
898 | 904 | ||
899 | unFunc' (I.Reduced x) = unFunc' x -- todo: remove? | 905 | unFunc' (I.Reduced x) = unFunc' x -- todo: remove? |
900 | unFunc' (UFL x) = unFunc' x | 906 | unFunc' (I.Neut (I.Fun (I.FunName _ _ I.ExpDef{} _) _ y)) = unFunc' y |
901 | unFunc' (I.RHS x) = unFunc' x -- TODO: remove | 907 | unFunc' (I.RHS x) = unFunc' x -- TODO: remove |
902 | unFunc' x = x | 908 | unFunc' x = x |
903 | 909 | ||
904 | pattern UFL y <- I.Neut (I.Fun (I.FunName _ _ I.ExpDef{} _) _ y) | ||
905 | |||
906 | pattern IFunc n def ty xs <- (mkIFunc -> Just (n, def, ty, xs)) | ||
907 | |||
908 | mkIFunc (I.Neut (I.Fun (I.FunName n 0 (I.ExpDef def) ty) xs I.RHS{})) | Just def' <- removeRHS (length xs) def = Just (n, def', ty, xs) | ||
909 | mkIFunc _ = Nothing | ||
910 | |||
911 | removeRHS 0 (I.RHS x) = Just x | ||
912 | removeRHS n (I.Lam x) | n > 0 = I.Lam <$> removeRHS (n-1) x | ||
913 | removeRHS _ _ = Nothing | ||
914 | |||
915 | instance Subst I.Exp ExpTV where | 910 | instance Subst I.Exp ExpTV where |
916 | subst_ i0 dx x (ExpTV a at vs) = ExpTV (subst_ i0 dx x a) (subst_ i0 dx x at) (zipWith (\i -> subst_ (i0+i) (I.upDB i dx) $ up i x{-todo: review-}) [1..] vs) | 911 | subst_ i0 dx x (ExpTV a at vs) = ExpTV (subst_ i0 dx x a) (subst_ i0 dx x at) (zipWith (\i -> subst_ (i0+i) (I.upDB i dx) $ up i x{-todo: review-}) [1..] vs) |
917 | 912 | ||
diff --git a/src/LambdaCube/Compiler/DesugaredSource.hs b/src/LambdaCube/Compiler/DesugaredSource.hs index 271c678e..074e0299 100644 --- a/src/LambdaCube/Compiler/DesugaredSource.hs +++ b/src/LambdaCube/Compiler/DesugaredSource.hs | |||
@@ -235,7 +235,6 @@ instance PShow FName where | |||
235 | pShow (CFName _ (SData s)) = pShow s | 235 | pShow (CFName _ (SData s)) = pShow s |
236 | pShow s = maybe (error "show") text' $ lookup s $ map (\(a, b) -> (b, a)) fntable | 236 | pShow s = maybe (error "show") text' $ lookup s $ map (\(a, b) -> (b, a)) fntable |
237 | where | 237 | where |
238 | text' "Nil" = "[]" | ||
239 | text' ":" = pShow ConsName | 238 | text' ":" = pShow ConsName |
240 | text' s = text s | 239 | text' s = text s |
241 | 240 | ||
@@ -468,7 +467,10 @@ shApp Hidden a b = DApp a (DAt b) | |||
468 | 467 | ||
469 | shLam usedVar h a b = shLam_ usedVar h (Just a) b | 468 | shLam usedVar h a b = shLam_ usedVar h (Just a) b |
470 | 469 | ||
471 | shLam_ False (BPi Hidden) (Just (DText "'CW" `DApp` a)) b = DFreshName False $ showContext (DUp 0 a) b | 470 | simpleFo (DExpand x _) = x |
471 | simpleFo x = x | ||
472 | |||
473 | shLam_ False (BPi Hidden) (Just ((simpleFo -> DText "'CW") `DApp` a)) b = DFreshName False $ showContext (DUp 0 a) b | ||
472 | where | 474 | where |
473 | showContext x (DFreshName u d) = DFreshName u $ showContext (DUp 0 x) d | 475 | showContext x (DFreshName u d) = DFreshName u $ showContext (DUp 0 x) d |
474 | showContext x (DParContext xs y) = DParContext (DComma x xs) y | 476 | showContext x (DParContext xs y) = DParContext (DComma x xs) y |
@@ -500,18 +502,19 @@ shLam_ usedVar h a b = DFreshName usedVar $ lam (p $ DUp 0 <$> a) b | |||
500 | showForall s x (DForall s' xs y) | s == s' = DForall s (DSep (InfixR 11) x xs) y | 502 | showForall s x (DForall s' xs y) | s == s' = DForall s (DSep (InfixR 11) x xs) y |
501 | showForall s x y = DForall s x y | 503 | showForall s x y = DForall s x y |
502 | 504 | ||
503 | -- TODO: use other sign instead of (=>) | 505 | showContext x y = DContext' x y |
504 | showContext x (DFreshName u d) = DFreshName u $ showContext (DUp 0 x) d | ||
505 | showContext x (DParContext xs y) = DParContext (DComma x xs) y | ||
506 | showContext x (DContext xs y) = DParContext (DComma x xs) y | ||
507 | showContext x y = DContext x y | ||
508 | 506 | ||
509 | showLam x (DFreshName u d) = DFreshName u $ showLam (DUp 0 x) d | 507 | showLam x (DFreshName u d) = DFreshName u $ showLam (DUp 0 x) d |
510 | showLam x (DLam xs y) = DLam (DSep (InfixR 11) x xs) y | 508 | showLam x (DLam xs y) = DLam (DSep (InfixR 11) x xs) y |
511 | showLam x y = DLam x y | 509 | showLam x y = DLam x y |
512 | 510 | ||
513 | shLet i a b = DLet' (DLet "=" (blue $ shVar i) $ DUp i a) (DUp i b) | 511 | shLet i a b = DLet' (DLet "=" (blue $ shVar i) $ DUp i a) (DUp i b) |
514 | shLet_ a b = DFreshName True $ DLet' (DLet "=" (shVar 0) $ DUp 0 a) b | 512 | |
513 | showLet x (DFreshName u d) = DFreshName u $ showLet (DUp 0 x) d | ||
514 | showLet x (DLet' xs y) = DLet' (DSemi x xs) y | ||
515 | showLet x y = DLet' x y | ||
516 | |||
517 | shLet_ a b = DFreshName True $ showLet (DLet "=" (shVar 0) $ DUp 0 a) b | ||
515 | 518 | ||
516 | -------------------------------------------------------------------------------- statement | 519 | -------------------------------------------------------------------------------- statement |
517 | 520 | ||
diff --git a/src/LambdaCube/Compiler/Infer.hs b/src/LambdaCube/Compiler/Infer.hs index b511d9c0..1cb528ea 100644 --- a/src/LambdaCube/Compiler/Infer.hs +++ b/src/LambdaCube/Compiler/Infer.hs | |||
@@ -51,17 +51,21 @@ varType err n_ env = f n_ env where | |||
51 | 51 | ||
52 | mkELet n x xt env = {-(if null vs then id else trace_ $ "mkELet " ++ show (length vs) ++ " " ++ show n)-} term | 52 | mkELet n x xt env = {-(if null vs then id else trace_ $ "mkELet " ++ show (length vs) ++ " " ++ show n)-} term |
53 | where | 53 | where |
54 | vs = sort $ Set.toList $ join grow $ free x <> free xt | 54 | vs = sort $ Set.toList $ grow mempty $ free x <> free xt |
55 | nloc = length vs | 55 | nloc = length vs |
56 | fn = FunName (mkFName n) nloc (ExpDef $ addLams 0 vs x) (addPis 0 vs xt) | 56 | fn = FunName (mkFName n) nloc (ExpDef $ addLams vs x) (addPis vs xt) |
57 | 57 | ||
58 | term = mkFun fn (Var <$> reverse vs) $ getFix x 0 | 58 | term = mkFun fn (Var <$> reverse vs) $ getFix x 0 |
59 | 59 | ||
60 | addLams l [] x = x | 60 | getFix (Lam z) i = Lam $ getFix z (i+1) |
61 | addLams l (v: vs) x = Lam $ rMove v l $ addLams (l+1) vs x | 61 | getFix (DFun FprimFix _ [t, Lam f]) i = subst 0 (foldl app_ term (downTo 0 i)) f |
62 | getFix x _ = x | ||
62 | 63 | ||
63 | addPis l [] x = x | 64 | addLams [] x = x |
64 | addPis l (v: vs) x = Pi Visible (snd $ varType "mkELet" v env) $ rMove v l $ addPis (l+1) vs x | 65 | addLams (v: vs) x = Lam $ rMove v 0 $ addLams vs x |
66 | |||
67 | addPis [] x = x | ||
68 | addPis (v: vs) x = Pi Visible (snd $ varType "mkELet" v env) $ rMove v 0 $ addPis vs x | ||
65 | 69 | ||
66 | grow acc s | 70 | grow acc s |
67 | | Set.null s = acc | 71 | | Set.null s = acc |
@@ -69,12 +73,6 @@ mkELet n x xt env = {-(if null vs then id else trace_ $ "mkELet " ++ show (lengt | |||
69 | where | 73 | where |
70 | s' = mconcat (free . snd . flip (varType "mkELet2") env <$> Set.toList s) | 74 | s' = mconcat (free . snd . flip (varType "mkELet2") env <$> Set.toList s) |
71 | 75 | ||
72 | getFix (Lam z) i = Lam $ getFix z (i+1) | ||
73 | getFix (DFun FprimFix _ [t, Lam f]) i = subst 0 (foldl app_ term (downTo 0 i)) f | ||
74 | getFix x _ = x | ||
75 | |||
76 | |||
77 | |||
78 | instance PShow (CEnv Exp) where | 76 | instance PShow (CEnv Exp) where |
79 | pShow = mkDoc False | 77 | pShow = mkDoc False |
80 | 78 | ||
diff --git a/src/LambdaCube/Compiler/Pretty.hs b/src/LambdaCube/Compiler/Pretty.hs index f9702b94..db31ee2e 100644 --- a/src/LambdaCube/Compiler/Pretty.hs +++ b/src/LambdaCube/Compiler/Pretty.hs | |||
@@ -16,6 +16,7 @@ module LambdaCube.Compiler.Pretty | |||
16 | import Data.Maybe | 16 | import Data.Maybe |
17 | import Data.String | 17 | import Data.String |
18 | import Data.Char | 18 | import Data.Char |
19 | import Data.Monoid | ||
19 | --import qualified Data.Set as Set | 20 | --import qualified Data.Set as Set |
20 | --import qualified Data.Map as Map | 21 | --import qualified Data.Map as Map |
21 | import Control.Applicative | 22 | import Control.Applicative |
@@ -153,8 +154,22 @@ renderDoc | |||
153 | showVarA (SimpleAtom s) = pure $ SimpleAtom s | 154 | showVarA (SimpleAtom s) = pure $ SimpleAtom s |
154 | showVarA (ComplexAtom s i d a) = ComplexAtom s i <$> showVars d <*> showVarA a | 155 | showVarA (ComplexAtom s i d a) = ComplexAtom s i <$> showVars d <*> showVarA a |
155 | 156 | ||
157 | getTup (DText "HCons" `DApp` x `DApp` (getTup -> Just xs)) = Just $ x: xs | ||
158 | getTup (DText "HNil") = Just [] | ||
159 | getTup _ = Nothing | ||
160 | |||
161 | getList (DOp0 ":" _ `DApp` x `DApp` (getList -> Just xs)) = Just $ x: xs | ||
162 | getList (DText "Nil") = Just [] | ||
163 | getList _ = Nothing | ||
164 | |||
165 | shTick True = DPreOp 20 (SimpleAtom "'") | ||
166 | shTick False = id | ||
167 | |||
156 | namespace :: Bool -> Doc -> Doc | 168 | namespace :: Bool -> Doc -> Doc |
157 | namespace tn x = case x of | 169 | namespace tn x = case x of |
170 | (getTup -> Just xs) -> shTick tn $ namespace tn $ shTuple xs | ||
171 | (getList -> Just xs) -> shTick tn $ namespace tn $ shList xs | ||
172 | DText "'HList" `DApp` (getList -> Just xs) -> shTick (not tn) $ namespace tn $ shTuple xs | ||
158 | DAtom x -> DAtom $ namespaceA x | 173 | DAtom x -> DAtom $ namespaceA x |
159 | DText "'List" `DApp` x -> namespace tn $ DBracket x | 174 | DText "'List" `DApp` x -> namespace tn $ DBracket x |
160 | DInfix pr' x op y -> DInfix pr' (namespace tn x) (namespaceA op) (namespace tn y) | 175 | DInfix pr' x op y -> DInfix pr' (namespace tn x) (namespaceA op) (namespace tn y) |
@@ -198,25 +213,39 @@ renderDoc | |||
198 | getApps (DApp (getApps -> (n, xs)) x) = (n, x: xs) | 213 | getApps (DApp (getApps -> (n, xs)) x) = (n, x: xs) |
199 | getApps x = (x, []) | 214 | getApps x = (x, []) |
200 | 215 | ||
216 | getSemis (DSemi x (getSemis -> (xs, n))) = (x: xs, n) | ||
217 | getSemis x = ([], x) | ||
218 | |||
219 | getCommas (DComma x (getCommas -> xs)) = x: xs | ||
220 | getCommas x = [x] | ||
221 | |||
201 | render :: Doc -> P.Doc | 222 | render :: Doc -> P.Doc |
202 | render = snd . render' | 223 | render = snd . render' |
203 | where | 224 | where |
204 | render' = \case | 225 | render' = \case |
205 | DText "Nil" -> rtext "[]" | ||
206 | DText "'Nil" -> rtext "'[]" | ||
207 | DAtom x -> renderA x | 226 | DAtom x -> renderA x |
208 | DFormat c x -> second c $ render' x | 227 | DFormat c x -> second c $ render' x |
209 | DDocOp f d -> (('\0', '\0'), f $ render <$> d) | 228 | DDocOp f d -> (('\0', '\0'), f $ render <$> d) |
210 | DPreOp _ op y -> renderA op <++> render' y | 229 | DPreOp _ op y -> renderA' op <++> render' y |
211 | DSep (InfixR 11) a b -> gr $ render' a <+++> render' b | 230 | DSep (InfixR 11) a b -> gr $ render' a <+++> render' b |
212 | x@DApp{} -> case getApps x of | 231 | x@DApp{} -> case getApps x of |
213 | (n, reverse -> xs) -> ((\xs -> (fst $ head xs, snd $ last xs)) *** P.nest 2 . P.sep) (unzip $ render' n: (render' <$> xs)) | 232 | (n, reverse -> xs) -> ((\xs -> (fst $ head xs, snd $ last xs)) *** P.nest 2 . P.sep) (unzip $ render' n: (render' <$> xs)) |
233 | x@DComma{} -> case getCommas x of | ||
234 | x: xs -> ((\xs -> (fst $ head xs, snd $ last xs)) *** P.cat) (unzip $ render' x: (second ("," P.<+>) . render' <$> xs)) | ||
235 | x@DSemi{} -> case getSemis x of | ||
236 | (xs, n) -> ((\xs -> (fst $ head xs, snd $ last xs)) *** P.sep) (unzip $ (second (<> ";") . render' <$> xs) ++ [render' n]) | ||
214 | DInfix _ x op y -> gr $ render' x <+++> renderA op <++> render' y | 237 | DInfix _ x op y -> gr $ render' x <+++> renderA op <++> render' y |
215 | 238 | ||
239 | renderA' (SimpleAtom s) = rtext s | ||
240 | renderA' x = gr $ renderA'' x | ||
241 | |||
242 | renderA'' (SimpleAtom s) = rtext s | ||
243 | renderA'' (ComplexAtom s _ d a) = rtext s <+++> render' d <+++> renderA'' a | ||
244 | |||
216 | renderA (SimpleAtom s) = rtext s | 245 | renderA (SimpleAtom s) = rtext s |
217 | renderA (ComplexAtom s _ d a) = rtext s <++> render' d <++> renderA a | 246 | renderA (ComplexAtom s _ d a) = rtext s <++> render' d <++> renderA a |
218 | 247 | ||
219 | gr = second (P.nest 2. P.group) | 248 | gr = second (P.nest 2 . P.group) |
220 | 249 | ||
221 | rtext "" = (('\0', '\0'), mempty) | 250 | rtext "" = (('\0', '\0'), mempty) |
222 | rtext s@(h:_) = ((h, last s), P.text s) | 251 | rtext s@(h:_) = ((h, last s), P.text s) |
@@ -224,12 +253,12 @@ renderDoc | |||
224 | ((lx, rx), x) <++> ((ly, ry), y) = ((lx, ry), z) | 253 | ((lx, rx), x) <++> ((ly, ry), y) = ((lx, ry), z) |
225 | where | 254 | where |
226 | z | sep rx ly = x P.<+> y | 255 | z | sep rx ly = x P.<+> y |
227 | | otherwise = x P.<> y | 256 | | otherwise = x <> y |
228 | 257 | ||
229 | ((lx, rx), x) <+++> ((ly, ry), y) = ((lx, ry), z) | 258 | ((lx, rx), x) <+++> ((ly, ry), y) = ((lx, ry), z) |
230 | where | 259 | where |
231 | z | sep rx ly = x P.<> P.line P.<> y | 260 | z | sep rx ly = x <> P.line <> y |
232 | | otherwise = x P.<> y | 261 | | otherwise = x <> y |
233 | 262 | ||
234 | sep x y | 263 | sep x y |
235 | | x == '\0' || y == '\0' = False | 264 | | x == '\0' || y == '\0' = False |
@@ -291,6 +320,7 @@ infixl 4 `DApp` | |||
291 | 320 | ||
292 | pattern DAt x = DGlue (InfixR 20) (DText "@") x | 321 | pattern DAt x = DGlue (InfixR 20) (DText "@") x |
293 | pattern DApp x y = DSep (InfixL 10) x y | 322 | pattern DApp x y = DSep (InfixL 10) x y |
323 | pattern DSemi x y = DOp ";" (InfixR (-19)) x y | ||
294 | pattern DArr_ s x y = DOp s (InfixR (-1)) x y -- -> => . | 324 | pattern DArr_ s x y = DOp s (InfixR (-1)) x y -- -> => . |
295 | pattern DCstr x y = DOp "~" (Infix (-2)) x y | 325 | pattern DCstr x y = DOp "~" (Infix (-2)) x y |
296 | pattern DAnn x y = DOp "::" (Infix (-3)) x (DTypeNamespace True y) | 326 | pattern DAnn x y = DOp "::" (Infix (-3)) x (DTypeNamespace True y) |
@@ -317,12 +347,16 @@ shTuple [] = "()" | |||
317 | shTuple [x] = DParen $ DParen x | 347 | shTuple [x] = DParen $ DParen x |
318 | shTuple xs = DParen $ foldr1 DComma xs | 348 | shTuple xs = DParen $ foldr1 DComma xs |
319 | 349 | ||
350 | shList [] = "[]" | ||
351 | shList xs = DBracket $ foldr1 DComma xs | ||
352 | |||
320 | shAnn = DAnn | 353 | shAnn = DAnn |
321 | 354 | ||
322 | shArr = DArr | 355 | shArr = DArr |
323 | 356 | ||
324 | 357 | ||
325 | pattern DForall s vs e = DArr_ s (DPreOp 10 (SimpleAtom "forall") vs) e | 358 | pattern DForall s vs e = DArr_ s (DPreOp 10 (SimpleAtom "forall") vs) e |
359 | pattern DContext' vs e = DArr_ "->" (DAt vs) e | ||
326 | pattern DContext vs e = DArr_ "=>" vs e | 360 | pattern DContext vs e = DArr_ "=>" vs e |
327 | pattern DParContext vs e = DContext (DParen vs) e | 361 | pattern DParContext vs e = DContext (DParen vs) e |
328 | pattern DLam vs e = DPreOp (-10) (ComplexAtom "\\" 11 vs (SimpleAtom "->")) e | 362 | pattern DLam vs e = DPreOp (-10) (ComplexAtom "\\" 11 vs (SimpleAtom "->")) e |