spiros-0.4.0: Spiros Boosalis's Custom Prelude

Safe HaskellNone
LanguageHaskell2010

Prelude.Spiros.Pretty

Description

TODO separate packages?

simple-print-parse re-exports these packages:

  • simple-print;
  • simple-parse, which has more dependencies (like on the exceptions package).

## Description

Provides utilities (and aliases) for defining simple ad-hoc parsers and (pretty-)printers for types (especially sum types).

## Motivation

Useful when:

  • you want your program to print out a human-friendly representations of haskell types, or to be able to consume them in either a consistent format or a versatile format;
  • but, you don't want to be burdened by a dependency on some parser package.

(i.e. by "human-friendly", I mean "more pleasantly readable and writable than with Show / Read").

uses of Print include:

  • error messages.

uses of Parse include:

  • command-line options.

## Features

Such "formats" include:

i.e. the user can define custom capitalization (via WordCasing) or a custom separator (via WordSeparator).

by default, each format's utility functions assume that:

  • constructors are written in (the conventional) class-case (i.e. ClassCase); and
  • the types are finite (satisfying Enum or GEnum).

but, each format's module also provides (more general) versions, which can be given:

  • some list of values; or,
  • even manually tokenized strings.

## Examples

to print out a constructor, the default toPrinter function does the following:

  • show it;
  • break up the string shown in its words and/or subwords;
  • merge that list of strings (back into a single string) via some TokenStyle (by default, HyphenCase).

HyphenCase being the most readable, imo. it's most common token style for: command line options, URLs, and so on.

## Naming

NOTE In this package, the word "print" means "convert to a human-friendly string", not "write to stdout".

Synopsis

Documentation

type Print a = a -> String Source #

Simple printer.

Usage:

Here is an example printer,

printVerbosity :: Parse Verbosity
printVerbosity = case

  Concise -> "concise"
  Verbose -> "verbose"

for this type

data Verbosity = Concise | Verbose

type Parse a = forall m. MonadThrow m => ParseM m a Source #

Simple parser.

Expansions.

                  Parse a

≡

(MonadThrow m) => ParseM m a

≡

(MonadThrow m) => (String -> m a)

Specializations.

Specializations include:

Parse a  ≡  (String -> Maybe                a)
Parse a  ≡  (String ->                      [a])
Parse a  ≡  (String -> Either SomeException a)
Parse a  ≡  (String -> IO                   a)

Usage:

Here is an example parser,

parseVerbosity :: Parse Verbosity
parseVerbosity s = go s

  where
  go = case
  
    "concise" -> return Concise
    "verbose" -> return Verbose
  
    "Concise" -> return Concise
    "Verbose" -> return Verbose
  
    "default" -> return def
  
    _         -> throwString s

parseVerbosity_Maybe :: ParseM Maybe Verbosity
parseVerbosity_Maybe = parseVerbosity

given

data Verbosity = Concise | Verbose

instance Default Verbosity where def = Concise

Also see ParseM.

type ParseM m a = String -> m a Source #

Simple parser.

Usage:

Here is an example parser,

parseVerbosity :: (MonadThrow m) => Parse m Verbosity
parseVerbosity s = go s

  where
  go = case
  
    "concise" -> return Concise
    "verbose" -> return Verbose
  
    "Concise" -> return Concise
    "Verbose" -> return Verbose
  
    "default" -> return def
  
    _         -> throwString s

parseVerbosity_Maybe :: Parse Maybe Verbosity
parseVerbosity_Maybe = parseVerbosity

given

data Verbosity = Concise | Verbose

instance Default Verbosity where def = Concise

newtype SimpleParserM (m :: * -> *) (a :: *) Source #

 

Constructors

SimpleParserM 

Fields

Instances
Functor m => Functor (SimpleParserM m) Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Methods

fmap :: (a -> b) -> SimpleParserM m a -> SimpleParserM m b #

(<$) :: a -> SimpleParserM m b -> SimpleParserM m a #

Generic (SimpleParserM m a) Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Associated Types

type Rep (SimpleParserM m a) :: Type -> Type #

Methods

from :: SimpleParserM m a -> Rep (SimpleParserM m a) x #

to :: Rep (SimpleParserM m a) x -> SimpleParserM m a #

type Rep (SimpleParserM m a) Source # 
Instance details

Defined in Prelude.Spiros.Pretty

type Rep (SimpleParserM m a) = D1 (MetaData "SimpleParserM" "Prelude.Spiros.Pretty" "spiros-0.4.0-7yNYhuNqI1YgajQL6GSlo" True) (C1 (MetaCons "SimpleParserM" PrefixI True) (S1 (MetaSel (Just "getSimpleParserM") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (String -> m a))))

data TokenStyle Source #

 

Constructors

TokenStyle 
Instances
Eq TokenStyle Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Ord TokenStyle Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Read TokenStyle Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Show TokenStyle Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Generic TokenStyle Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Associated Types

type Rep TokenStyle :: Type -> Type #

Lift TokenStyle Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Methods

lift :: TokenStyle -> Q Exp #

NFData TokenStyle Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Methods

rnf :: TokenStyle -> () #

Hashable TokenStyle Source # 
Instance details

Defined in Prelude.Spiros.Pretty

type Rep TokenStyle Source # 
Instance details

Defined in Prelude.Spiros.Pretty

type Rep TokenStyle = D1 (MetaData "TokenStyle" "Prelude.Spiros.Pretty" "spiros-0.4.0-7yNYhuNqI1YgajQL6GSlo" False) (C1 (MetaCons "TokenStyle" PrefixI True) (S1 (MetaSel (Just "separator") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 WordSeparator) :*: S1 (MetaSel (Just "casing") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 WordCasing)))

newtype WordSeparator Source #

 

Constructors

WordSeparator (Maybe Char) 
Instances
Eq WordSeparator Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Ord WordSeparator Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Read WordSeparator Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Show WordSeparator Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Generic WordSeparator Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Associated Types

type Rep WordSeparator :: Type -> Type #

Lift WordSeparator Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Methods

lift :: WordSeparator -> Q Exp #

NFData WordSeparator Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Methods

rnf :: WordSeparator -> () #

Hashable WordSeparator Source # 
Instance details

Defined in Prelude.Spiros.Pretty

type Rep WordSeparator Source # 
Instance details

Defined in Prelude.Spiros.Pretty

type Rep WordSeparator = D1 (MetaData "WordSeparator" "Prelude.Spiros.Pretty" "spiros-0.4.0-7yNYhuNqI1YgajQL6GSlo" True) (C1 (MetaCons "WordSeparator" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Maybe Char))))

data WordCasing Source #

 
Instances
Eq WordCasing Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Ord WordCasing Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Read WordCasing Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Show WordCasing Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Generic WordCasing Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Associated Types

type Rep WordCasing :: Type -> Type #

Lift WordCasing Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Methods

lift :: WordCasing -> Q Exp #

NFData WordCasing Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Methods

rnf :: WordCasing -> () #

Hashable WordCasing Source # 
Instance details

Defined in Prelude.Spiros.Pretty

type Rep WordCasing Source # 
Instance details

Defined in Prelude.Spiros.Pretty

type Rep WordCasing = D1 (MetaData "WordCasing" "Prelude.Spiros.Pretty" "spiros-0.4.0-7yNYhuNqI1YgajQL6GSlo" False) (C1 (MetaCons "WordCasing" PrefixI True) (S1 (MetaSel (Just "firstWord") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 SubwordCasing) :*: S1 (MetaSel (Just "laterWords") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 SubwordCasing)))

data SubwordCasing Source #

 

Constructors

LowerCased

e.g. "lower"

TitleCased

e.g. Title

UpperCased

e.g. UPPER

Instances
Bounded SubwordCasing Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Enum SubwordCasing Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Eq SubwordCasing Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Ord SubwordCasing Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Read SubwordCasing Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Show SubwordCasing Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Ix SubwordCasing Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Generic SubwordCasing Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Associated Types

type Rep SubwordCasing :: Type -> Type #

Lift SubwordCasing Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Methods

lift :: SubwordCasing -> Q Exp #

NFData SubwordCasing Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Methods

rnf :: SubwordCasing -> () #

GEnum SubwordCasing Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Methods

genum :: [SubwordCasing] #

Hashable SubwordCasing Source # 
Instance details

Defined in Prelude.Spiros.Pretty

type Rep SubwordCasing Source # 
Instance details

Defined in Prelude.Spiros.Pretty

type Rep SubwordCasing = D1 (MetaData "SubwordCasing" "Prelude.Spiros.Pretty" "spiros-0.4.0-7yNYhuNqI1YgajQL6GSlo" False) (C1 (MetaCons "LowerCased" PrefixI False) (U1 :: Type -> Type) :+: (C1 (MetaCons "TitleCased" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "UpperCased" PrefixI False) (U1 :: Type -> Type)))

data KnownTokenStyle Source #

 

Constructors

CamelCase

e.g. "camelCase"

ClassCase

e.g. ClassCase

ConstCase

e.g. CONST_CASE

PascalCase

e.g. Pascal_Case

SqueezeCase

e.g. "squeezecase"

UnderscoreCase

e.g. "underscore_case"

HyphenCase

e.g. "hyphen-case"

SlashCase

e.g. "slash/case"

DotCase

e.g. "dot.case"

Instances
Bounded KnownTokenStyle Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Enum KnownTokenStyle Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Eq KnownTokenStyle Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Ord KnownTokenStyle Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Read KnownTokenStyle Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Show KnownTokenStyle Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Ix KnownTokenStyle Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Generic KnownTokenStyle Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Associated Types

type Rep KnownTokenStyle :: Type -> Type #

Lift KnownTokenStyle Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Methods

lift :: KnownTokenStyle -> Q Exp #

NFData KnownTokenStyle Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Methods

rnf :: KnownTokenStyle -> () #

GEnum KnownTokenStyle Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Methods

genum :: [KnownTokenStyle] #

Hashable KnownTokenStyle Source # 
Instance details

Defined in Prelude.Spiros.Pretty

type Rep KnownTokenStyle Source # 
Instance details

Defined in Prelude.Spiros.Pretty

type Rep KnownTokenStyle = D1 (MetaData "KnownTokenStyle" "Prelude.Spiros.Pretty" "spiros-0.4.0-7yNYhuNqI1YgajQL6GSlo" False) (((C1 (MetaCons "CamelCase" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "ClassCase" PrefixI False) (U1 :: Type -> Type)) :+: (C1 (MetaCons "ConstCase" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "PascalCase" PrefixI False) (U1 :: Type -> Type))) :+: ((C1 (MetaCons "SqueezeCase" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "UnderscoreCase" PrefixI False) (U1 :: Type -> Type)) :+: (C1 (MetaCons "HyphenCase" PrefixI False) (U1 :: Type -> Type) :+: (C1 (MetaCons "SlashCase" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "DotCase" PrefixI False) (U1 :: Type -> Type)))))

type ShowPrinter t a = (Enum a, Show a, IsString t) Source #

 

type ReadParser t a = (Read a, String ~ t) Source #

 

data PrintConfig t a Source #

 

Constructors

PrintConfig 

Fields

  • style :: TokenStyle

    The style a constructor is printed as.

  • showHaskell :: a -> t

    How to show a value as a Haskell identifier/constructor (often show). , values :: [a] --

Instances
Generic (PrintConfig t a) Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Associated Types

type Rep (PrintConfig t a) :: Type -> Type #

Methods

from :: PrintConfig t a -> Rep (PrintConfig t a) x #

to :: Rep (PrintConfig t a) x -> PrintConfig t a #

ShowPrinter t a => Default (PrintConfig t a) Source #
= defaultPrintConfig
Instance details

Defined in Prelude.Spiros.Pretty

Methods

def :: PrintConfig t a #

NFData (PrintConfig t a) Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Methods

rnf :: PrintConfig t a -> () #

type Rep (PrintConfig t a) Source # 
Instance details

Defined in Prelude.Spiros.Pretty

type Rep (PrintConfig t a) = D1 (MetaData "PrintConfig" "Prelude.Spiros.Pretty" "spiros-0.4.0-7yNYhuNqI1YgajQL6GSlo" False) (C1 (MetaCons "PrintConfig" PrefixI True) (S1 (MetaSel (Just "style") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 TokenStyle) :*: S1 (MetaSel (Just "showHaskell") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (a -> t))))

data ParseConfig t a Source #

 

Constructors

ParseConfig 

Fields

Instances
Generic (ParseConfig t a) Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Associated Types

type Rep (ParseConfig t a) :: Type -> Type #

Methods

from :: ParseConfig t a -> Rep (ParseConfig t a) x #

to :: Rep (ParseConfig t a) x -> ParseConfig t a #

ReadParser t a => Default (ParseConfig t a) Source #
= defaultParseConfig
Instance details

Defined in Prelude.Spiros.Pretty

Methods

def :: ParseConfig t a #

NFData (ParseConfig t a) Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Methods

rnf :: ParseConfig t a -> () #

type Rep (ParseConfig t a) Source # 
Instance details

Defined in Prelude.Spiros.Pretty

type Rep (ParseConfig t a) = D1 (MetaData "ParseConfig" "Prelude.Spiros.Pretty" "spiros-0.4.0-7yNYhuNqI1YgajQL6GSlo" False) (C1 (MetaCons "ParseConfig" PrefixI True) (S1 (MetaSel (Just "styles") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [TokenStyle]) :*: S1 (MetaSel (Just "readHaskell") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (t -> Maybe a))))

newtype Tokens Source #

Under tokenization (i.e. parsing into tokens), some information about capitalization must be preserved.

For example, this "word":

GHCVersion

is represented as (and should be parsed into):

[ toAcronymToken "GHC"
, toSubwordToken "Version"
] :: Tokens

which is equivalent to (i.e. lower-cased and without the smart-constructors):

[ AcronymToken "ghc"
, SubwordToken "version"
] :: Tokens

Constructors

Tokens (NonEmpty Token) 
Instances
IsList Tokens Source #

newtype wrapping/unwrapping only.

NOTE fromList is partial, crashing on an empty list literal (see unsafeTokensFromList).

Instance details

Defined in Prelude.Spiros.Pretty

Associated Types

type Item Tokens :: Type #

Eq Tokens Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Methods

(==) :: Tokens -> Tokens -> Bool #

(/=) :: Tokens -> Tokens -> Bool #

Ord Tokens Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Read Tokens Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Show Tokens Source # 
Instance details

Defined in Prelude.Spiros.Pretty

IsString Tokens Source #
≡ (:| [])

(i.e. a singleton token.)

Instance details

Defined in Prelude.Spiros.Pretty

Methods

fromString :: String -> Tokens #

Generic Tokens Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Associated Types

type Rep Tokens :: Type -> Type #

Methods

from :: Tokens -> Rep Tokens x #

to :: Rep Tokens x -> Tokens #

Semigroup Tokens Source # 
Instance details

Defined in Prelude.Spiros.Pretty

NFData Tokens Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Methods

rnf :: Tokens -> () #

Hashable Tokens Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Methods

hashWithSalt :: Int -> Tokens -> Int #

hash :: Tokens -> Int #

type Rep Tokens Source # 
Instance details

Defined in Prelude.Spiros.Pretty

type Rep Tokens = D1 (MetaData "Tokens" "Prelude.Spiros.Pretty" "spiros-0.4.0-7yNYhuNqI1YgajQL6GSlo" True) (C1 (MetaCons "Tokens" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (NonEmpty Token))))
type Item Tokens Source # 
Instance details

Defined in Prelude.Spiros.Pretty

unsafeTokensFromList :: [Token] -> Tokens Source #

Dumb constructor.

NOTE fromList is partial, crashing on an empty list literal.

data Token Source #

A valid Token MUST be:

  • case-insensitive (i.e. foldCase);
  • non-empty (i.e. not "" and/or []).
Instances
Eq Token Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Methods

(==) :: Token -> Token -> Bool #

(/=) :: Token -> Token -> Bool #

Ord Token Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Methods

compare :: Token -> Token -> Ordering #

(<) :: Token -> Token -> Bool #

(<=) :: Token -> Token -> Bool #

(>) :: Token -> Token -> Bool #

(>=) :: Token -> Token -> Bool #

max :: Token -> Token -> Token #

min :: Token -> Token -> Token #

Read Token Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Show Token Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Methods

showsPrec :: Int -> Token -> ShowS #

show :: Token -> String #

showList :: [Token] -> ShowS #

IsString Token Source #
= toSubwordToken

With case-folding via foldCase.

Instance details

Defined in Prelude.Spiros.Pretty

Methods

fromString :: String -> Token #

Generic Token Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Associated Types

type Rep Token :: Type -> Type #

Methods

from :: Token -> Rep Token x #

to :: Rep Token x -> Token #

FoldCase Token Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Methods

foldCase :: Token -> Token #

foldCaseList :: [Token] -> [Token]

NFData Token Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Methods

rnf :: Token -> () #

Hashable Token Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Methods

hashWithSalt :: Int -> Token -> Int #

hash :: Token -> Int #

type Rep Token Source # 
Instance details

Defined in Prelude.Spiros.Pretty

type Rep Token = D1 (MetaData "Token" "Prelude.Spiros.Pretty" "spiros-0.4.0-7yNYhuNqI1YgajQL6GSlo" False) (C1 (MetaCons "SubwordToken" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Subword)) :+: (C1 (MetaCons "AcronymToken" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Char])) :+: C1 (MetaCons "EmptyToken" PrefixI False) (U1 :: Type -> Type)))

toSubwordToken :: String -> Token Source #

Smart constructor for SubwordToken.

Calls foldCase for case-insensitivity.

toAcronymToken :: String -> Token Source #

Smart constructor for AcronymToken.

Calls foldCase for case-insensitivity.

newtype Subword Source #

Represents one part of word being tokenized.

A valid Subword, like a valid Token, MUST be:

  • case-insensitive (i.e. foldCase);
  • non-empty (i.e. not "").

NOTE Subword is a Semigroup but not a Monoid.

Conceptually, it's one-or-more case-folded characters:

NonEmpty (CI Char)

Constructors

Subword String 
Instances
Eq Subword Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Methods

(==) :: Subword -> Subword -> Bool #

(/=) :: Subword -> Subword -> Bool #

Ord Subword Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Read Subword Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Show Subword Source # 
Instance details

Defined in Prelude.Spiros.Pretty

IsString Subword Source #
toSubword

NOTE fromString is partial, crashing on an empty string literal (see unsafeSubword'). While fromString may be called directly, it's (idiomatically) called "indirectly" by the compiler, when converting string literals under -XOverloadedStrings; thus, many error messages from its partiality should have a stack traces.

Instance details

Defined in Prelude.Spiros.Pretty

Methods

fromString :: String -> Subword #

Generic Subword Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Associated Types

type Rep Subword :: Type -> Type #

Methods

from :: Subword -> Rep Subword x #

to :: Rep Subword x -> Subword #

Semigroup Subword Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Lift Subword Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Methods

lift :: Subword -> Q Exp #

NFData Subword Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Methods

rnf :: Subword -> () #

Hashable Subword Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Methods

hashWithSalt :: Int -> Subword -> Int #

hash :: Subword -> Int #

type Rep Subword Source # 
Instance details

Defined in Prelude.Spiros.Pretty

type Rep Subword = D1 (MetaData "Subword" "Prelude.Spiros.Pretty" "spiros-0.4.0-7yNYhuNqI1YgajQL6GSlo" True) (C1 (MetaCons "Subword" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 String)))

safeSubword :: String -> Maybe Subword Source #

Smart constructor for Subword.

Besides the constructor itself, it calls:

unsafeSubword :: String -> Subword Source #

Dumb constructor, for Subword.

See safeSubword (which this wraps).

data AcronymStyle Source #

 
Instances
Bounded AcronymStyle Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Enum AcronymStyle Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Eq AcronymStyle Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Ord AcronymStyle Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Read AcronymStyle Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Show AcronymStyle Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Ix AcronymStyle Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Generic AcronymStyle Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Associated Types

type Rep AcronymStyle :: Type -> Type #

Lift AcronymStyle Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Methods

lift :: AcronymStyle -> Q Exp #

Default AcronymStyle Source #
= defaultAcronymStyle
Instance details

Defined in Prelude.Spiros.Pretty

Methods

def :: AcronymStyle #

NFData AcronymStyle Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Methods

rnf :: AcronymStyle -> () #

GEnum AcronymStyle Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Methods

genum :: [AcronymStyle] #

Hashable AcronymStyle Source # 
Instance details

Defined in Prelude.Spiros.Pretty

type Rep AcronymStyle Source # 
Instance details

Defined in Prelude.Spiros.Pretty

type Rep AcronymStyle = D1 (MetaData "AcronymStyle" "Prelude.Spiros.Pretty" "spiros-0.4.0-7yNYhuNqI1YgajQL6GSlo" False) (C1 (MetaCons "UpperCasedAcronym" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "TitleCasedAcronym" PrefixI False) (U1 :: Type -> Type))

data TokenizationConfig Source #

 
Instances
Eq TokenizationConfig Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Ord TokenizationConfig Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Read TokenizationConfig Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Show TokenizationConfig Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Generic TokenizationConfig Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Associated Types

type Rep TokenizationConfig :: Type -> Type #

Lift TokenizationConfig Source # 
Instance details

Defined in Prelude.Spiros.Pretty

NFData TokenizationConfig Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Methods

rnf :: TokenizationConfig -> () #

Hashable TokenizationConfig Source # 
Instance details

Defined in Prelude.Spiros.Pretty

type Rep TokenizationConfig Source # 
Instance details

Defined in Prelude.Spiros.Pretty

type Rep TokenizationConfig = D1 (MetaData "TokenizationConfig" "Prelude.Spiros.Pretty" "spiros-0.4.0-7yNYhuNqI1YgajQL6GSlo" False) (C1 (MetaCons "TokenizationConfig" PrefixI True) (S1 (MetaSel (Just "acronymStyle") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 AcronymStyle) :*: (S1 (MetaSel (Just "inputStyle") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 TokenStyle) :*: S1 (MetaSel (Just "outputStyle") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 TokenStyle))))

data PrintTokenConfig Source #

 
Instances
Eq PrintTokenConfig Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Ord PrintTokenConfig Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Read PrintTokenConfig Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Show PrintTokenConfig Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Generic PrintTokenConfig Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Associated Types

type Rep PrintTokenConfig :: Type -> Type #

Lift PrintTokenConfig Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Methods

lift :: PrintTokenConfig -> Q Exp #

NFData PrintTokenConfig Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Methods

rnf :: PrintTokenConfig -> () #

Hashable PrintTokenConfig Source # 
Instance details

Defined in Prelude.Spiros.Pretty

type Rep PrintTokenConfig Source # 
Instance details

Defined in Prelude.Spiros.Pretty

type Rep PrintTokenConfig = D1 (MetaData "PrintTokenConfig" "Prelude.Spiros.Pretty" "spiros-0.4.0-7yNYhuNqI1YgajQL6GSlo" False) (C1 (MetaCons "PrintTokenConfig" PrefixI True) (S1 (MetaSel (Just "acronymStyle") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 AcronymStyle) :*: S1 (MetaSel (Just "tokenStyle") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 TokenStyle)))

data ParseTokenConfig Source #

 
Instances
Eq ParseTokenConfig Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Ord ParseTokenConfig Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Read ParseTokenConfig Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Show ParseTokenConfig Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Generic ParseTokenConfig Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Associated Types

type Rep ParseTokenConfig :: Type -> Type #

Lift ParseTokenConfig Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Methods

lift :: ParseTokenConfig -> Q Exp #

NFData ParseTokenConfig Source # 
Instance details

Defined in Prelude.Spiros.Pretty

Methods

rnf :: ParseTokenConfig -> () #

Hashable ParseTokenConfig Source # 
Instance details

Defined in Prelude.Spiros.Pretty

type Rep ParseTokenConfig Source # 
Instance details

Defined in Prelude.Spiros.Pretty

type Rep ParseTokenConfig = D1 (MetaData "ParseTokenConfig" "Prelude.Spiros.Pretty" "spiros-0.4.0-7yNYhuNqI1YgajQL6GSlo" False) (C1 (MetaCons "ParseTokenConfig" PrefixI True) (S1 (MetaSel (Just "acronymStyle") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 AcronymStyle) :*: S1 (MetaSel (Just "tokenStyle") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 TokenStyle)))

restyleString :: TokenizationConfig -> String -> String Source #

Example
  1. We have an Enum whose constructors' names:
  • are class-cased (the conventional styling);
  • are suffixed by the name of their type;
  • and may have acronyms (i.e. an alpha-numeric sequence, with all letters being upper-case).

e.g.:

data Query

  = WindowIdQuery
  | WMClassQuery

  deriving (Enum,Bounded,Show,Read)
  1. We want to render its constructors' names, as the valid values of a command-line option

i.e.:

printQueryForCmdLn :: Print Query
printQueryForCmdLn WindowIdQuery = "window-id
printQueryForCmdLn WMClassQuery  = "wm-class

NOTE the acronym WM is (correctly) grouped into a single Token; c.f. the (incorrectly) un-grouped "w-m-class", which is less legible.

  1. We can also print it as an idiomatic command-line option, by (type) name.

i.e.:

printQueryAsLongOptionAndShortOption :: (String, Char)
printQueryAsLongOptionAndShortOption = ("query", q)

e.g. (assuming an executable named ./example):

$ ./example --query=window-id
$ ./example -q wm-class

restyleClassCasedToHyphenated :: String -> String Source #

Specializes restyleString; with ClassCase, HyphenCase, and UpperCasedAcronym.

>>> restyleClassCasedToHyphenated "WMClass"
"wm-class"
>>> restyleClassCasedToHyphenated "WindowId"
"window-id"

intersperseBySeparator :: WordSeparator -> NonEmpty String -> NonEmpty String Source #

>>> :set -XOverloadedStrings
>>> :set -XOverloadedLists
>>> toList (intersperseBySeparator (WordSeparator (Just '-')) ["cabal","new","build"])
["cabal","-","new","-","build"]
>>> toList (intersperseBySeparator (WordSeparator Nothing) ["cabal","new","build"])
["cabal","new","build"]