Skip to content

Commit 98bdf39

Browse files
committed
New create-bp-index command
1 parent 5fcdd97 commit 98bdf39

File tree

5 files changed

+63
-5
lines changed

5 files changed

+63
-5
lines changed

app/App/Commands.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module App.Commands where
22

33
import App.Commands.Count
4+
import App.Commands.CreateBpIndex
45
import App.Commands.CreateIbIndex
56
import App.Commands.CreateIndex
67
import App.Commands.Demo
@@ -16,4 +17,5 @@ commandsGeneral = subparser $ mempty
1617
<> cmdCount
1718
<> cmdCreateIndex
1819
<> cmdCreateIbIndex
20+
<> cmdCreateBpIndex
1921
<> cmdDemo

app/App/Commands/CreateBpIndex.hs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{-# LANGUAGE DataKinds #-}
2+
{-# LANGUAGE DeriveGeneric #-}
3+
{-# LANGUAGE FlexibleInstances #-}
4+
{-# LANGUAGE OverloadedStrings #-}
5+
{-# LANGUAGE ScopedTypeVariables #-}
6+
{-# LANGUAGE TypeApplications #-}
7+
{-# LANGUAGE TypeSynonymInstances #-}
8+
9+
module App.Commands.CreateBpIndex
10+
( cmdCreateBpIndex
11+
) where
12+
13+
import Control.Lens
14+
import Data.Generics.Product.Any
15+
import Data.Semigroup ((<>))
16+
import HaskellWorks.Data.Xml.Internal.ToIbBp64
17+
import HaskellWorks.Data.Xml.Succinct.Cursor.BlankedXml
18+
import Options.Applicative hiding (columns)
19+
20+
import qualified App.Commands.Types as Z
21+
import qualified Data.ByteString.Lazy as LBS
22+
23+
runCreateBpIndex :: Z.CreateBpIndexOptions -> IO ()
24+
runCreateBpIndex opt = do
25+
let input = opt ^. the @"input"
26+
let output = opt ^. the @"output"
27+
28+
lbs <- LBS.readFile input
29+
let blankedXml = lbsToBlankedXml lbs
30+
let ib = toBalancedParens64' blankedXml
31+
LBS.writeFile output (LBS.fromChunks ib)
32+
33+
return ()
34+
35+
optsCreateBpIndex :: Parser Z.CreateBpIndexOptions
36+
optsCreateBpIndex = Z.CreateBpIndexOptions
37+
<$> strOption
38+
( long "input"
39+
<> help "Input file"
40+
<> metavar "FILE"
41+
)
42+
<*> strOption
43+
( long "output"
44+
<> help "Balanced parens output"
45+
<> metavar "FILE"
46+
)
47+
48+
cmdCreateBpIndex :: Mod CommandFields (IO ())
49+
cmdCreateBpIndex = command "create-bp-index" $ flip info idm $ runCreateBpIndex <$> optsCreateBpIndex

app/App/Commands/CreateIbIndex.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ import qualified Data.ByteString.Lazy as LBS
2323
runCreateIbIndex :: Z.CreateIbIndexOptions -> IO ()
2424
runCreateIbIndex opt = do
2525
let input = opt ^. the @"input"
26-
let ibOutput = opt ^. the @"ibOutput"
26+
let output = opt ^. the @"output"
2727

2828
lbs <- LBS.readFile input
2929
let blankedXml = lbsToBlankedXml lbs
3030
let ib = toInterestBits64' blankedXml
31-
LBS.writeFile ibOutput (LBS.fromChunks ib)
31+
LBS.writeFile output (LBS.fromChunks ib)
3232

3333
return ()
3434

@@ -40,7 +40,7 @@ optsCreateIbIndex = Z.CreateIbIndexOptions
4040
<> metavar "FILE"
4141
)
4242
<*> strOption
43-
( long "ib-output"
43+
( long "output"
4444
<> help "Interest Bits output"
4545
<> metavar "FILE"
4646
)

app/App/Commands/Types.hs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module App.Commands.Types
55
( CountOptions(..)
66
, CreateIndexOptions(..)
77
, CreateIbIndexOptions(..)
8+
, CreateBpIndexOptions(..)
89
, DemoOptions(..)
910
) where
1011

@@ -27,6 +28,11 @@ data CreateIndexOptions = CreateIndexOptions
2728
} deriving (Eq, Show, Generic)
2829

2930
data CreateIbIndexOptions = CreateIbIndexOptions
30-
{ input :: FilePath
31-
, ibOutput :: FilePath
31+
{ input :: FilePath
32+
, output :: FilePath
33+
} deriving (Eq, Show, Generic)
34+
35+
data CreateBpIndexOptions = CreateBpIndexOptions
36+
{ input :: FilePath
37+
, output :: FilePath
3238
} deriving (Eq, Show, Generic)

hw-xml.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ executable hw-xml
141141
App.Commands.Count
142142
App.Commands.CreateIbIndex
143143
App.Commands.CreateIndex
144+
App.Commands.CreateBpIndex
144145
App.Commands.Demo
145146
App.Commands.Types
146147
App.Options

0 commit comments

Comments
 (0)