diff options
author | Péter Diviánszky <divipp@gmail.com> | 2016-05-01 16:51:22 +0200 |
---|---|---|
committer | Péter Diviánszky <divipp@gmail.com> | 2016-05-01 16:51:22 +0200 |
commit | 1a7544763729938e7009ead1e375e9bbf413afb0 (patch) | |
tree | 62af78c28cd91597fe40391d4020cb47f697334a /src/LambdaCube/Compiler/DesugaredSource.hs | |
parent | 11b4a98c3fc7014cdef123fea4081d58e8edbaa2 (diff) |
better namespace handling in pretty print
Diffstat (limited to 'src/LambdaCube/Compiler/DesugaredSource.hs')
-rw-r--r-- | src/LambdaCube/Compiler/DesugaredSource.hs | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/src/LambdaCube/Compiler/DesugaredSource.hs b/src/LambdaCube/Compiler/DesugaredSource.hs index 8f92f18a..75244d14 100644 --- a/src/LambdaCube/Compiler/DesugaredSource.hs +++ b/src/LambdaCube/Compiler/DesugaredSource.hs | |||
@@ -242,7 +242,7 @@ infixl 2 `SAppV`, `SAppH` | |||
242 | pattern SBuiltin s <- SGlobal (SIName _ s) | 242 | pattern SBuiltin s <- SGlobal (SIName _ s) |
243 | where SBuiltin s = SGlobal (SIName (debugSI $ "builtin " ++ s) s) | 243 | where SBuiltin s = SGlobal (SIName (debugSI $ "builtin " ++ s) s) |
244 | 244 | ||
245 | pattern SRHS a = SBuiltin "^rhs" `SAppV` a | 245 | pattern SRHS a = SBuiltin "_rhs" `SAppV` a |
246 | pattern Section e = SBuiltin "^section" `SAppV` e | 246 | pattern Section e = SBuiltin "^section" `SAppV` e |
247 | pattern SType = SBuiltin "'Type" | 247 | pattern SType = SBuiltin "'Type" |
248 | pattern Parens e = SBuiltin "parens" `SAppV` e | 248 | pattern Parens e = SBuiltin "parens" `SAppV` e |
@@ -381,11 +381,13 @@ instance (Up a, PShow a) => PShow (SExp' a) where | |||
381 | pShow = \case | 381 | pShow = \case |
382 | SGlobal op | Just p <- getFixity op -> DOp0 (sName op) p | 382 | SGlobal op | Just p <- getFixity op -> DOp0 (sName op) p |
383 | SGlobal ns -> pShow ns | 383 | SGlobal ns -> pShow ns |
384 | SAnn a b -> shAnn False (pShow a) (pShow b) | 384 | SAnn a b -> shAnn (pShow a) (pShow b) |
385 | TyType a -> text "tyType" `dApp` pShow a | 385 | TyType a -> text "tyType" `dApp` pShow a |
386 | SAppV a b -> pShow a `dApp` pShow b | 386 | SAppV a b -> pShow a `dApp` pShow b |
387 | SApp h a b -> shApp h (pShow a) (pShow b) | 387 | SApp h a b -> shApp h (pShow a) (pShow b) |
388 | Wildcard t -> shAnn True (text "_") (pShow t) | 388 | Wildcard SType -> text "_" |
389 | Wildcard t -> shAnn (text "_") (pShow t) | ||
390 | SBind_ _ h _ SType b -> shLam_ (usedVar 0 b) h Nothing (pShow b) | ||
389 | SBind_ _ h _ a b -> shLam (usedVar 0 b) h (pShow a) (pShow b) | 391 | SBind_ _ h _ a b -> shLam (usedVar 0 b) h (pShow a) (pShow b) |
390 | SLet _ a b -> shLet_ (pShow a) (pShow b) | 392 | SLet _ a b -> shLet_ (pShow a) (pShow b) |
391 | STyped a -> pShow a | 393 | STyped a -> pShow a |
@@ -395,7 +397,9 @@ instance (Up a, PShow a) => PShow (SExp' a) where | |||
395 | shApp Visible a b = DApp a b | 397 | shApp Visible a b = DApp a b |
396 | shApp Hidden a b = DApp a (DAt b) | 398 | shApp Hidden a b = DApp a (DAt b) |
397 | 399 | ||
398 | shLam usedVar h a b = DFreshName usedVar $ lam (p $ DUp 0 a) b | 400 | shLam usedVar h a b = shLam_ usedVar h (Just a) b |
401 | |||
402 | shLam_ usedVar h a b = DFreshName usedVar $ lam (p $ DUp 0 <$> a) b | ||
399 | where | 403 | where |
400 | lam = case h of | 404 | lam = case h of |
401 | BPi Visible | 405 | BPi Visible |
@@ -406,13 +410,15 @@ shLam usedVar h a b = DFreshName usedVar $ lam (p $ DUp 0 a) b | |||
406 | | otherwise -> showContext | 410 | | otherwise -> showContext |
407 | _ -> showLam | 411 | _ -> showLam |
408 | 412 | ||
413 | shAnn' a = maybe a (shAnn a) | ||
414 | |||
409 | p = case h of | 415 | p = case h of |
410 | BMeta -> shAnn True (blue $ DVar 0) | 416 | BMeta -> shAnn' (blue $ DVar 0) |
411 | BLam Hidden -> DAt . ann | 417 | BLam Hidden -> DAt . ann |
412 | _ -> ann | 418 | _ -> ann |
413 | 419 | ||
414 | ann | usedVar = shAnn True (DVar 0) | 420 | ann | usedVar = shAnn' (DVar 0) |
415 | | otherwise = id | 421 | | otherwise = fromMaybe (text "Type") |
416 | 422 | ||
417 | showForall s x (DFreshName u d) = DFreshName u $ showForall s (DUp 0 x) d | 423 | showForall s x (DFreshName u d) = DFreshName u $ showForall s (DUp 0 x) d |
418 | showForall s x (DForall s' xs y) | s == s' = DForall s (DSep (InfixR 11) x xs) y | 424 | showForall s x (DForall s' xs y) | s == s' = DForall s (DSep (InfixR 11) x xs) y |
@@ -441,9 +447,9 @@ pattern Primitive n t = Let n (Just t) (SBuiltin "undefined") | |||
441 | 447 | ||
442 | instance PShow Stmt where | 448 | instance PShow Stmt where |
443 | pShow = \case | 449 | pShow = \case |
444 | Primitive n t -> shAnn False (pShow n) (pShow t) | 450 | Primitive n t -> shAnn (pShow n) (pShow t) |
445 | Let n ty e -> DLet "=" (pShow n) $ maybe (pShow e) (\ty -> shAnn False (pShow e) (pShow ty)) ty | 451 | Let n ty e -> DLet "=" (pShow n) $ maybe (pShow e) (\ty -> shAnn (pShow e) (pShow ty)) ty |
446 | Data n ps ty cs -> "data" <+> text (sName n) | 452 | Data n ps ty cs -> "data" <+> shAnn (foldl dApp (pShow n) [shAnn (text "_") (pShow t) | (v, t) <- ps]) (pShow ty) <+> "where" |
447 | PrecDef n i -> pShow i <+> DOp0 (sName n) i | 453 | PrecDef n i -> pShow i <+> DOp0 (sName n) i |
448 | 454 | ||
449 | instance DeBruijnify SIName Stmt where | 455 | instance DeBruijnify SIName Stmt where |