summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2019-03-22 17:40:54 -0400
committerJoe Crayne <joe@jerkface.net>2019-03-22 17:40:54 -0400
commita7ef7551b3bc078c6992619e3fe847324b074d24 (patch)
treead63ea9890ba75bfc8d6c51f6a288e46e164b2cf
parentb511cbf06b5ad30a555c5bf99598b7257d628eea (diff)
Apply do-syntax.
-rw-r--r--Sweeten.hs21
-rw-r--r--monkeypatch.cabal2
-rw-r--r--monkeypatch.hs3
3 files changed, 24 insertions, 2 deletions
diff --git a/Sweeten.hs b/Sweeten.hs
new file mode 100644
index 0000000..929f9f8
--- /dev/null
+++ b/Sweeten.hs
@@ -0,0 +1,21 @@
1{-# LANGUAGE ScopedTypeVariables #-}
2module Sweeten where
3
4import Data.Data
5import Data.Generics.Aliases
6import Data.Generics.Schemes
7import Language.Haskell.Exts.Syntax as HS
8
9applyDoSyntax :: forall l. (Typeable l, Data l) => Exp l -> Exp l
10applyDoSyntax = everywhere (mkT (applyDoSyntax1 :: Exp l -> Exp l))
11
12applyDoSyntax1 :: Exp l -> Exp l
13applyDoSyntax1 exp@(InfixApp la x (QVarOp lb (UnQual lc (Symbol ld ">>="))) (Lambda le [pat] y)) =
14 case y of
15 Do lf ss -> Do la (Generator lb pat x : ss)
16 _ -> Do la [Generator lb pat x, Qualifier le y]
17applyDoSyntax1 exp@(InfixApp la x (QVarOp lb (UnQual lc (Symbol ld ">>"))) y) =
18 case y of
19 Do lf ss -> Do la (Qualifier lb x : ss)
20 _ -> Do la [Qualifier lb x, Qualifier lc y]
21applyDoSyntax1 exp = exp
diff --git a/monkeypatch.cabal b/monkeypatch.cabal
index 23bc405..2b06032 100644
--- a/monkeypatch.cabal
+++ b/monkeypatch.cabal
@@ -52,7 +52,7 @@ extra-source-files: CHANGELOG.md
52 52
53executable monkeypatch 53executable monkeypatch
54 main-is: monkeypatch.hs 54 main-is: monkeypatch.hs
55 other-modules: GrepNested 55 other-modules: GrepNested, Sweeten
56 -- other-extensions: 56 -- other-extensions:
57 build-depends: base >=4.10.1.0 && <=4.12 57 build-depends: base >=4.10.1.0 && <=4.12
58 , containers ^>=0.5.10.2 58 , containers ^>=0.5.10.2
diff --git a/monkeypatch.hs b/monkeypatch.hs
index b72e346..37e52a6 100644
--- a/monkeypatch.hs
+++ b/monkeypatch.hs
@@ -49,6 +49,7 @@ import Text.PrettyPrint (Doc, doubleQuotes, empty, text, vcat, ($$),
49 (<+>)) 49 (<+>))
50import Text.Show.Pretty 50import Text.Show.Pretty
51 51
52import Sweeten
52import GrepNested 53import GrepNested
53 54
54trace :: p -> a -> a 55trace :: p -> a -> a
@@ -631,7 +632,7 @@ transpile o fname incs (CTranslUnit edecls _) = do
631 return $ foldr applyComputation (Computation Map.empty Map.empty retUnit) xs 632 return $ foldr applyComputation (Computation Map.empty Map.empty retUnit) xs
632 case mhask of 633 case mhask of
633 Just hask -> do printHeader 634 Just hask -> do printHeader
634 mapM_ (putStrLn . (" "++)) $ lines $ HS.prettyPrint $ comp hask 635 mapM_ (putStrLn . (" "++)) $ lines $ HS.prettyPrint $ applyDoSyntax $ comp hask
635 Nothing -> forM_ (oSelectFunction o) $ \_ -> do 636 Nothing -> forM_ (oSelectFunction o) $ \_ -> do
636 printHeader 637 printHeader
637 forM_ bdy $ \d -> do 638 forM_ bdy $ \d -> do