File tree Expand file tree Collapse file tree 6 files changed +58
-6
lines changed Expand file tree Collapse file tree 6 files changed +58
-6
lines changed Original file line number Diff line number Diff line change @@ -2,13 +2,16 @@ module Main where
2
2
3
3
import Data.Attoparsec.Text
4
4
import qualified Data.Text.IO as T
5
- import Lib
5
+ import Hie.Cabal.Parser
6
+ import Hie.Yaml
6
7
import System.Environment
7
8
8
9
main :: IO ()
9
10
main = do
10
11
args <- getArgs
11
12
file <- T. readFile $ head args
12
13
case parseOnly parseSec file of
13
- Right r -> print r
14
+ Right r -> do
15
+ T. putStr $ cabalHieYaml r
16
+ T. putStr $ stackHieYaml r
14
17
_ -> error " Could not parse *.cabal file"
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ cabal-version: 1.12
4
4
--
5
5
-- see: https://github.com/sol/hpack
6
6
--
7
- -- hash: 43f070b60e4bc798c52d79691e2dcdd543171eeee553cd2f28579bf9e3b6e10a
7
+ -- hash: bc348cef928e75313b689d7626632633e11398ad278358aea4933e83a9564985
8
8
9
9
name : implicit-hie
10
10
version : 0.1.0.0
@@ -27,7 +27,8 @@ source-repository head
27
27
28
28
library
29
29
exposed-modules :
30
- Lib
30
+ Hie.Cabal.Parser
31
+ Hie.Yaml
31
32
other-modules :
32
33
Paths_implicit_hie
33
34
hs-source-dirs :
@@ -37,6 +38,7 @@ library
37
38
attoparsec
38
39
, base >= 4.7 && < 5
39
40
, text
41
+ , yaml
40
42
default-language : Haskell2010
41
43
42
44
executable implicit-hie-exe
@@ -51,6 +53,7 @@ executable implicit-hie-exe
51
53
, base >= 4.7 && < 5
52
54
, implicit-hie
53
55
, text
56
+ , yaml
54
57
default-language : Haskell2010
55
58
56
59
test-suite implicit-hie-test
@@ -68,4 +71,5 @@ test-suite implicit-hie-test
68
71
, hspec-attoparsec
69
72
, implicit-hie
70
73
, text
74
+ , yaml
71
75
default-language : Haskell2010
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ dependencies:
23
23
- base >= 4.7 && < 5
24
24
- text
25
25
- attoparsec
26
+ - yaml
26
27
27
28
ghc-options :
28
29
# - -O2
Original file line number Diff line number Diff line change 1
1
{-# LANGUAGE OverloadedStrings #-}
2
2
3
- module Lib where
3
+ module Hie.Cabal.Parser where
4
4
5
5
import Control.Applicative
6
6
import Control.Monad
Original file line number Diff line number Diff line change
1
+ {-# LANGUAGE OverloadedStrings #-}
2
+
3
+ module Hie.Yaml
4
+ ( cabalHieYaml ,
5
+ stackHieYaml ,
6
+ )
7
+ where
8
+
9
+ import qualified Data.Text as T
10
+ import Hie.Cabal.Parser
11
+
12
+ cabalHieYaml :: Package -> T. Text
13
+ cabalHieYaml (Package n cs) =
14
+ " cradle:\n "
15
+ <> indentT (" cabal:\n " <> indentT (T. unlines (map (cabalComponent n) cs)))
16
+
17
+ stackHieYaml :: Package -> T. Text
18
+ stackHieYaml (Package n cs) =
19
+ " cradle:\n "
20
+ <> indentT (" stack:\n " <> indentT (T. unlines (map (stackComponent n) cs)))
21
+
22
+ indentT :: T. Text -> T. Text
23
+ indentT = T. unlines . map (" " <> ) . T. lines
24
+
25
+ cabalComponent :: Name -> Component -> T. Text
26
+ cabalComponent n (Lib p) = component p $ " lib:" <> n
27
+ cabalComponent _ (Exe p cn) = component p $ " exe:" <> cn
28
+ cabalComponent _ (Test p cn) = component p $ " test:" <> cn
29
+
30
+ stackComponent :: Name -> Component -> T. Text
31
+ stackComponent n (Lib p) = component p $ n <> " :lib"
32
+ stackComponent n (Exe p cn) = component p $ n <> " :exe:" <> cn
33
+ stackComponent n (Test p cn) = component p $ n <> " :test:" <> cn
34
+
35
+ component :: T. Text -> T. Text -> T. Text
36
+ component p c =
37
+ " - path: "
38
+ <> dQuote p
39
+ <> " \n "
40
+ <> " component: "
41
+ <> dQuote c
42
+
43
+ dQuote :: T. Text -> T. Text
44
+ dQuote t = T. cons ' "' t `T.snoc` ' "'
Original file line number Diff line number Diff line change 2
2
3
3
import qualified Data.Text as T
4
4
import Data.Text (Text )
5
- import Lib
5
+ import Hie.Cabal.Parser
6
6
import Test.Hspec
7
7
import Test.Hspec.Attoparsec
8
8
You can’t perform that action at this time.
0 commit comments