Skip to content

Commit f5706f0

Browse files
committed
Generate stack and cabal hie.yamls
1 parent 48fda59 commit f5706f0

File tree

6 files changed

+58
-6
lines changed

6 files changed

+58
-6
lines changed

app/Main.hs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ module Main where
22

33
import Data.Attoparsec.Text
44
import qualified Data.Text.IO as T
5-
import Lib
5+
import Hie.Cabal.Parser
6+
import Hie.Yaml
67
import System.Environment
78

89
main :: IO ()
910
main = do
1011
args <- getArgs
1112
file <- T.readFile $ head args
1213
case parseOnly parseSec file of
13-
Right r -> print r
14+
Right r -> do
15+
T.putStr $ cabalHieYaml r
16+
T.putStr $ stackHieYaml r
1417
_ -> error "Could not parse *.cabal file"

implicit-hie.cabal

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ cabal-version: 1.12
44
--
55
-- see: https://github.com/sol/hpack
66
--
7-
-- hash: 43f070b60e4bc798c52d79691e2dcdd543171eeee553cd2f28579bf9e3b6e10a
7+
-- hash: bc348cef928e75313b689d7626632633e11398ad278358aea4933e83a9564985
88

99
name: implicit-hie
1010
version: 0.1.0.0
@@ -27,7 +27,8 @@ source-repository head
2727

2828
library
2929
exposed-modules:
30-
Lib
30+
Hie.Cabal.Parser
31+
Hie.Yaml
3132
other-modules:
3233
Paths_implicit_hie
3334
hs-source-dirs:
@@ -37,6 +38,7 @@ library
3738
attoparsec
3839
, base >=4.7 && <5
3940
, text
41+
, yaml
4042
default-language: Haskell2010
4143

4244
executable implicit-hie-exe
@@ -51,6 +53,7 @@ executable implicit-hie-exe
5153
, base >=4.7 && <5
5254
, implicit-hie
5355
, text
56+
, yaml
5457
default-language: Haskell2010
5558

5659
test-suite implicit-hie-test
@@ -68,4 +71,5 @@ test-suite implicit-hie-test
6871
, hspec-attoparsec
6972
, implicit-hie
7073
, text
74+
, yaml
7175
default-language: Haskell2010

package.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ dependencies:
2323
- base >= 4.7 && < 5
2424
- text
2525
- attoparsec
26+
- yaml
2627

2728
ghc-options:
2829
# - -O2

src/Lib.hs renamed to src/Hie/Cabal/Parser.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{-# LANGUAGE OverloadedStrings #-}
22

3-
module Lib where
3+
module Hie.Cabal.Parser where
44

55
import Control.Applicative
66
import Control.Monad

src/Hie/Yaml.hs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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` '"'

test/Spec.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import qualified Data.Text as T
44
import Data.Text (Text)
5-
import Lib
5+
import Hie.Cabal.Parser
66
import Test.Hspec
77
import Test.Hspec.Attoparsec
88

0 commit comments

Comments
 (0)