Skip to content

Commit

Permalink
refactor(lib): Make haddock easier to read
Browse files Browse the repository at this point in the history
  • Loading branch information
sgillespie committed Mar 18, 2024
1 parent 5890f8c commit 1985ef0
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 43 deletions.
2 changes: 0 additions & 2 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module Main (main) where
import Data.Gibberish
import Data.Gibberish.Formatting qualified as Fmt

import Control.Monad.IO.Class (MonadIO (..))
import Data.Text (Text ())
import Data.Text qualified as Text
import Data.Text.IO qualified as Text
Expand All @@ -12,7 +11,6 @@ import Options.Applicative hiding (columns)
import Options.Applicative.Help.Pretty
import PackageInfo_gibberish (name, version)
import System.Environment (getArgs)
import System.Random (RandomGen (..), getStdGen)
import Prelude hiding (Word ())

termLen :: Int
Expand Down
49 changes: 27 additions & 22 deletions src/Data/Gibberish.hs
Original file line number Diff line number Diff line change
@@ -1,48 +1,53 @@
module Data.Gibberish
( -- * Core types
GenPasswordOpts (..),
GenPassphraseOpts (..),
Unigram (..),
Digram (..),
Trigram (..),
Frequency (..),
Frequencies (..),
Trigraph (..),
Word (..),

-- * Password/phrase generation
( -- * Generating Passwords
genPassword,
genPasswords,
genPasswords',

-- * Generating Passphrases
genPassphrase,
genPassphrase',

-- * Trigraph generation
Language (..),
TrigraphConfig (..),
genTrigraph,
loadTrigraph,

-- * Password/phrase generation monad
-- * The Pass Monad
Pass (),
PassT (..),
MonadRandom (..),
runPass,
evalPass,
usingPass,

-- * The PassT Monad Transformer
PassT (..),
runPassT,
evalPassT,
usingPassT,
module Control.Monad.Random,

-- * Error handling
-- * Core Types
GenPasswordOpts (..),
GenPassphraseOpts (..),
Language (..),
TrigraphConfig (..),
Trigraph (..),
Word (..),
Unigram (..),
Digram (..),
Trigram (..),
Frequency (..),
Frequencies (..),

-- * Error Handling
GibberishErr (..),
isTrigraphNotFound,
isImpossibleError,

-- * Working with Trigraphs
genTrigraph,
loadTrigraph,
) where

import Data.Gibberish.Errors
import Data.Gibberish.Gen
import Data.Gibberish.Monad.Pass
import Data.Gibberish.Types

import Control.Monad.Random
import Prelude hiding (Word ())
16 changes: 2 additions & 14 deletions src/Data/Gibberish/Gen/Trigraph.hs
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
{-# LANGUAGE OverloadedLists #-}

module Data.Gibberish.Gen.Trigraph
( Language (..),
TrigraphConfig (..),
genTrigraph,
( genTrigraph,
loadTrigraph,
) where

import Data.Gibberish.Errors (GibberishErr (..))
import Data.Gibberish.Types
import Data.Gibberish.Utils (toQwertyKey)
import Paths_gibberish (getDataFileName)

import Control.Exception (throwIO)
import Control.Monad (unless)
import Data.Aeson qualified as Aeson
import Data.Char (isPunctuation, toLower)
import Data.Gibberish.Types
import Data.Map.Strict (Map ())
import Data.Map.Strict qualified as Map
import Data.Maybe (fromJust)
Expand All @@ -24,16 +22,6 @@ import Data.Text qualified as Text
import System.Directory (doesFileExist)
import System.FilePath ((</>))

data Language
= English
| Spanish
| CustomTrigraph TrigraphConfig
deriving stock (Eq, Show)

newtype TrigraphConfig = TrigraphConfig
{unTrigraphConfig :: FilePath}
deriving stock (Eq, Show)

-- | Generate trigraphs from a list of words
genTrigraph :: [Text] -> Trigraph
genTrigraph = Trigraph . foldr (foldWord . normalizeWord) Map.empty
Expand Down
6 changes: 2 additions & 4 deletions src/Data/Gibberish/Monad/Pass.hs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
module Data.Gibberish.Monad.Pass
( Pass (),
PassT (..),
MonadRandom (..),
runPass,
evalPass,
usingPass,
runPassT,
evalPassT,
usingPassT,
module Control.Monad.Random,
) where

import Control.Monad.IO.Class (MonadIO ())
import Control.Monad.Random (MonadRandom (..))
import Control.Monad.Trans.Random (RandT (), evalRandT, runRandT)
import Control.Monad.Random
import Data.Functor.Identity (Identity (..))

-- | Password/Passphrase generation monad parameterized by the type @gen@ of the generator
Expand Down
14 changes: 14 additions & 0 deletions src/Data/Gibberish/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module Data.Gibberish.Types
( GenPasswordOpts (..),
GenPassphraseOpts (..),
Language (..),
TrigraphConfig (..),
Unigram (..),
Digram (..),
Trigram (..),
Expand Down Expand Up @@ -54,6 +56,18 @@ data GenPassphraseOpts = GenPassphraseOpts
}
deriving stock (Eq, Show)

-- | A language indicating the dictionary that generated a trigraph
data Language
= English
| Spanish
| CustomTrigraph TrigraphConfig
deriving stock (Eq, Show)

-- | A path to a trigraph json config file
newtype TrigraphConfig = TrigraphConfig
{unTrigraphConfig :: FilePath}
deriving stock (Eq, Show)

-- | A unigram is a single letter
newtype Unigram = Unigram {unUnigram :: Char}
deriving stock (Eq, Ord, Show)
Expand Down
2 changes: 1 addition & 1 deletion test/Data/Gibberish/Gen/PassSpec.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Data.Gibberish.Gen.PassSpec (spec) where

import Data.Gibberish.Gen.Pass
import Data.Gibberish.Gen.Trigraph (Language (..), loadTrigraph)
import Data.Gibberish.Gen.Trigraph (loadTrigraph)
import Data.Gibberish.Monad.Pass (usingPass, usingPassT)
import Data.Gibberish.Types
import Data.Gibberish.Utils (numeralConversions, symbolConversions)
Expand Down

0 comments on commit 1985ef0

Please sign in to comment.