module Text.Interpolation.Nyan.Core.Internal.Parser where
import Control.Applicative (many, optional)
import Control.Monad (guard, when, (<=<))
import Control.Monad.State (MonadState, execStateT, get, put)
import Data.Bifunctor (first)
import Data.Char (isAlphaNum, isSpace)
import Data.Foldable (asum)
import Data.Functor (($>))
import Data.Text (Text)
import qualified Data.Text as T
import Fmt (Builder, build, fmt)
import Text.Interpolation.Nyan.Core.Internal.Base
import Text.Megaparsec (Parsec, customFailure, eof, errorBundlePretty, label, lookAhead, parse,
single, takeWhile1P, takeWhileP)
import Text.Megaparsec.Error (ShowErrorComponent (..))
newtype OptionChanged = OptionChanged Bool
deriving stock (Int -> OptionChanged -> ShowS
[OptionChanged] -> ShowS
OptionChanged -> String
(Int -> OptionChanged -> ShowS)
-> (OptionChanged -> String)
-> ([OptionChanged] -> ShowS)
-> Show OptionChanged
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OptionChanged] -> ShowS
$cshowList :: [OptionChanged] -> ShowS
show :: OptionChanged -> String
$cshow :: OptionChanged -> String
showsPrec :: Int -> OptionChanged -> ShowS
$cshowsPrec :: Int -> OptionChanged -> ShowS
Show, OptionChanged -> OptionChanged -> Bool
(OptionChanged -> OptionChanged -> Bool)
-> (OptionChanged -> OptionChanged -> Bool) -> Eq OptionChanged
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OptionChanged -> OptionChanged -> Bool
$c/= :: OptionChanged -> OptionChanged -> Bool
== :: OptionChanged -> OptionChanged -> Bool
$c== :: OptionChanged -> OptionChanged -> Bool
Eq)
data SwitchesOptionsBuilder = SwitchesOptionsBuilder
{ SwitchesOptionsBuilder -> (OptionChanged, Maybe Bool)
spacesTrimmingB :: (OptionChanged, Maybe Bool)
, SwitchesOptionsBuilder -> (OptionChanged, Maybe Bool)
indentationStrippingB :: (OptionChanged, Maybe Bool)
, SwitchesOptionsBuilder -> (OptionChanged, Maybe Bool)
leadingNewlineStrippingB :: (OptionChanged, Maybe Bool)
, SwitchesOptionsBuilder -> (OptionChanged, Maybe Bool)
trailingSpacesStrippingB :: (OptionChanged, Maybe Bool)
, SwitchesOptionsBuilder -> (OptionChanged, Maybe ReturnType)
returnTypeB :: (OptionChanged, Maybe ReturnType)
, SwitchesOptionsBuilder -> (OptionChanged, Maybe Bool)
reducedNewlinesB :: (OptionChanged, Maybe Bool)
, SwitchesOptionsBuilder -> (OptionChanged, Maybe Bool)
monadicB :: (OptionChanged, Maybe Bool)
, SwitchesOptionsBuilder -> PreviewLevel
previewLevelB :: PreviewLevel
}
toSwitchesOptionsBuilder :: DefaultSwitchesOptions -> SwitchesOptionsBuilder
toSwitchesOptionsBuilder :: DefaultSwitchesOptions -> SwitchesOptionsBuilder
toSwitchesOptionsBuilder DefaultSwitchesOptions{Maybe Bool
Maybe ReturnType
defMonadic :: DefaultSwitchesOptions -> Maybe Bool
defReturnType :: DefaultSwitchesOptions -> Maybe ReturnType
defReducedNewlines :: DefaultSwitchesOptions -> Maybe Bool
defTrailingSpacesStripping :: DefaultSwitchesOptions -> Maybe Bool
defLeadingNewlineStripping :: DefaultSwitchesOptions -> Maybe Bool
defIndentationStripping :: DefaultSwitchesOptions -> Maybe Bool
defSpacesTrimming :: DefaultSwitchesOptions -> Maybe Bool
defMonadic :: Maybe Bool
defReturnType :: Maybe ReturnType
defReducedNewlines :: Maybe Bool
defTrailingSpacesStripping :: Maybe Bool
defLeadingNewlineStripping :: Maybe Bool
defIndentationStripping :: Maybe Bool
defSpacesTrimming :: Maybe Bool
..} =
SwitchesOptionsBuilder :: (OptionChanged, Maybe Bool)
-> (OptionChanged, Maybe Bool)
-> (OptionChanged, Maybe Bool)
-> (OptionChanged, Maybe Bool)
-> (OptionChanged, Maybe ReturnType)
-> (OptionChanged, Maybe Bool)
-> (OptionChanged, Maybe Bool)
-> PreviewLevel
-> SwitchesOptionsBuilder
SwitchesOptionsBuilder
{ spacesTrimmingB :: (OptionChanged, Maybe Bool)
spacesTrimmingB = (Bool -> OptionChanged
OptionChanged Bool
False, Maybe Bool
defSpacesTrimming)
, indentationStrippingB :: (OptionChanged, Maybe Bool)
indentationStrippingB = (Bool -> OptionChanged
OptionChanged Bool
False, Maybe Bool
defIndentationStripping)
, leadingNewlineStrippingB :: (OptionChanged, Maybe Bool)
leadingNewlineStrippingB = (Bool -> OptionChanged
OptionChanged Bool
False, Maybe Bool
defLeadingNewlineStripping)
, trailingSpacesStrippingB :: (OptionChanged, Maybe Bool)
trailingSpacesStrippingB = (Bool -> OptionChanged
OptionChanged Bool
False, Maybe Bool
defTrailingSpacesStripping)
, returnTypeB :: (OptionChanged, Maybe ReturnType)
returnTypeB = (Bool -> OptionChanged
OptionChanged Bool
False, Maybe ReturnType
defReturnType)
, reducedNewlinesB :: (OptionChanged, Maybe Bool)
reducedNewlinesB = (Bool -> OptionChanged
OptionChanged Bool
False, Maybe Bool
defMonadic)
, monadicB :: (OptionChanged, Maybe Bool)
monadicB = (Bool -> OptionChanged
OptionChanged Bool
False, Maybe Bool
defMonadic)
, previewLevelB :: PreviewLevel
previewLevelB = PreviewLevel
PreviewNone
}
finalizeSwitchesOptions :: MonadFail m => SwitchesOptionsBuilder -> m SwitchesOptions
finalizeSwitchesOptions :: SwitchesOptionsBuilder -> m SwitchesOptions
finalizeSwitchesOptions SwitchesOptionsBuilder{(OptionChanged, Maybe Bool)
(OptionChanged, Maybe ReturnType)
PreviewLevel
previewLevelB :: PreviewLevel
monadicB :: (OptionChanged, Maybe Bool)
reducedNewlinesB :: (OptionChanged, Maybe Bool)
returnTypeB :: (OptionChanged, Maybe ReturnType)
trailingSpacesStrippingB :: (OptionChanged, Maybe Bool)
leadingNewlineStrippingB :: (OptionChanged, Maybe Bool)
indentationStrippingB :: (OptionChanged, Maybe Bool)
spacesTrimmingB :: (OptionChanged, Maybe Bool)
previewLevelB :: SwitchesOptionsBuilder -> PreviewLevel
monadicB :: SwitchesOptionsBuilder -> (OptionChanged, Maybe Bool)
reducedNewlinesB :: SwitchesOptionsBuilder -> (OptionChanged, Maybe Bool)
returnTypeB :: SwitchesOptionsBuilder -> (OptionChanged, Maybe ReturnType)
trailingSpacesStrippingB :: SwitchesOptionsBuilder -> (OptionChanged, Maybe Bool)
leadingNewlineStrippingB :: SwitchesOptionsBuilder -> (OptionChanged, Maybe Bool)
indentationStrippingB :: SwitchesOptionsBuilder -> (OptionChanged, Maybe Bool)
spacesTrimmingB :: SwitchesOptionsBuilder -> (OptionChanged, Maybe Bool)
..} = do
Bool
spacesTrimming <- String -> (OptionChanged, Maybe Bool) -> m Bool
forall (m :: * -> *) a a.
MonadFail m =>
String -> (a, Maybe a) -> m a
fromOptional String
"spaces trimming" (OptionChanged, Maybe Bool)
spacesTrimmingB
Bool
indentationStripping <- String -> (OptionChanged, Maybe Bool) -> m Bool
forall (m :: * -> *) a a.
MonadFail m =>
String -> (a, Maybe a) -> m a
fromOptional String
"indentation stripping" (OptionChanged, Maybe Bool)
indentationStrippingB
Bool
leadingNewlineStripping <- String -> (OptionChanged, Maybe Bool) -> m Bool
forall (m :: * -> *) a a.
MonadFail m =>
String -> (a, Maybe a) -> m a
fromOptional String
"leading newline stripping" (OptionChanged, Maybe Bool)
leadingNewlineStrippingB
Bool
trailingSpacesStripping <- String -> (OptionChanged, Maybe Bool) -> m Bool
forall (m :: * -> *) a a.
MonadFail m =>
String -> (a, Maybe a) -> m a
fromOptional String
"trailing spaces stripping" (OptionChanged, Maybe Bool)
trailingSpacesStrippingB
ReturnType
returnType <- String -> (OptionChanged, Maybe ReturnType) -> m ReturnType
forall (m :: * -> *) a a.
MonadFail m =>
String -> (a, Maybe a) -> m a
fromOptional String
"return type" (OptionChanged, Maybe ReturnType)
returnTypeB
Bool
reducedNewlines <- String -> (OptionChanged, Maybe Bool) -> m Bool
forall (m :: * -> *) a a.
MonadFail m =>
String -> (a, Maybe a) -> m a
fromOptional String
"reduced newlines" (OptionChanged, Maybe Bool)
reducedNewlinesB
Bool
monadic <- String -> (OptionChanged, Maybe Bool) -> m Bool
forall (m :: * -> *) a a.
MonadFail m =>
String -> (a, Maybe a) -> m a
fromOptional String
"monadic" (OptionChanged, Maybe Bool)
monadicB
let previewLevel :: PreviewLevel
previewLevel = PreviewLevel
previewLevelB
SwitchesOptions -> m SwitchesOptions
forall (m :: * -> *) a. Monad m => a -> m a
return SwitchesOptions :: Bool
-> Bool
-> Bool
-> Bool
-> ReturnType
-> Bool
-> Bool
-> PreviewLevel
-> SwitchesOptions
SwitchesOptions{Bool
PreviewLevel
ReturnType
previewLevel :: PreviewLevel
monadic :: Bool
reducedNewlines :: Bool
returnType :: ReturnType
trailingSpacesStripping :: Bool
leadingNewlineStripping :: Bool
indentationStripping :: Bool
spacesTrimming :: Bool
previewLevel :: PreviewLevel
monadic :: Bool
reducedNewlines :: Bool
returnType :: ReturnType
trailingSpacesStripping :: Bool
leadingNewlineStripping :: Bool
indentationStripping :: Bool
spacesTrimming :: Bool
..}
where
fromOptional :: String -> (a, Maybe a) -> m a
fromOptional String
desc (a
_, Maybe a
mval) = case Maybe a
mval of
Maybe a
Nothing -> String -> m a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> m a) -> String -> m a
forall a b. (a -> b) -> a -> b
$ String
"Switch for " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
desc String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
" must be specified"
Just a
val -> a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
val
type SwitchesOptionsSetter m = (MonadState SwitchesOptionsBuilder m, MonadFail m)
setIfNew
:: (MonadFail m, Eq a)
=> String -> a -> (OptionChanged, Maybe a) -> m (OptionChanged, Maybe a)
setIfNew :: String
-> a -> (OptionChanged, Maybe a) -> m (OptionChanged, Maybe a)
setIfNew String
desc a
new (OptionChanged Bool
ch, Maybe a
old)
| Bool
ch = String -> m (OptionChanged, Maybe a)
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> m (OptionChanged, Maybe a))
-> String -> m (OptionChanged, Maybe a)
forall a b. (a -> b) -> a -> b
$ String
"Modifying `" String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
desc String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
"` option for the second time"
| Maybe a
old Maybe a -> Maybe a -> Bool
forall a. Eq a => a -> a -> Bool
== a -> Maybe a
forall a. a -> Maybe a
Just a
new = String -> m (OptionChanged, Maybe a)
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> m (OptionChanged, Maybe a))
-> String -> m (OptionChanged, Maybe a)
forall a b. (a -> b) -> a -> b
$ String
"Switch option `" String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
desc String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
"` is set redundantly"
| Bool
otherwise = (OptionChanged, Maybe a) -> m (OptionChanged, Maybe a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> OptionChanged
OptionChanged Bool
True, a -> Maybe a
forall a. a -> Maybe a
Just a
new)
setSpacesTrimming :: SwitchesOptionsSetter m => Bool -> m ()
setSpacesTrimming :: Bool -> m ()
setSpacesTrimming Bool
enable = do
SwitchesOptionsBuilder
opts <- m SwitchesOptionsBuilder
forall s (m :: * -> *). MonadState s m => m s
get
(OptionChanged, Maybe Bool)
res <- String
-> Bool
-> (OptionChanged, Maybe Bool)
-> m (OptionChanged, Maybe Bool)
forall (m :: * -> *) a.
(MonadFail m, Eq a) =>
String
-> a -> (OptionChanged, Maybe a) -> m (OptionChanged, Maybe a)
setIfNew String
"spaces trimming" Bool
enable (SwitchesOptionsBuilder -> (OptionChanged, Maybe Bool)
spacesTrimmingB SwitchesOptionsBuilder
opts)
SwitchesOptionsBuilder -> m ()
forall s (m :: * -> *). MonadState s m => s -> m ()
put SwitchesOptionsBuilder
opts{ spacesTrimmingB :: (OptionChanged, Maybe Bool)
spacesTrimmingB = (OptionChanged, Maybe Bool)
res }
setIndentationStripping :: SwitchesOptionsSetter m => Bool -> m ()
setIndentationStripping :: Bool -> m ()
setIndentationStripping Bool
enable = do
SwitchesOptionsBuilder
opts <- m SwitchesOptionsBuilder
forall s (m :: * -> *). MonadState s m => m s
get
(OptionChanged, Maybe Bool)
res <- String
-> Bool
-> (OptionChanged, Maybe Bool)
-> m (OptionChanged, Maybe Bool)
forall (m :: * -> *) a.
(MonadFail m, Eq a) =>
String
-> a -> (OptionChanged, Maybe a) -> m (OptionChanged, Maybe a)
setIfNew String
"indentation stripping" Bool
enable (SwitchesOptionsBuilder -> (OptionChanged, Maybe Bool)
indentationStrippingB SwitchesOptionsBuilder
opts)
SwitchesOptionsBuilder -> m ()
forall s (m :: * -> *). MonadState s m => s -> m ()
put SwitchesOptionsBuilder
opts{ indentationStrippingB :: (OptionChanged, Maybe Bool)
indentationStrippingB = (OptionChanged, Maybe Bool)
res }
setLeadingNewlineStripping :: SwitchesOptionsSetter m => Bool -> m ()
setLeadingNewlineStripping :: Bool -> m ()
setLeadingNewlineStripping Bool
enable = do
SwitchesOptionsBuilder
opts <- m SwitchesOptionsBuilder
forall s (m :: * -> *). MonadState s m => m s
get
(OptionChanged, Maybe Bool)
res <- String
-> Bool
-> (OptionChanged, Maybe Bool)
-> m (OptionChanged, Maybe Bool)
forall (m :: * -> *) a.
(MonadFail m, Eq a) =>
String
-> a -> (OptionChanged, Maybe a) -> m (OptionChanged, Maybe a)
setIfNew String
"leading newline stripping" Bool
enable (SwitchesOptionsBuilder -> (OptionChanged, Maybe Bool)
leadingNewlineStrippingB SwitchesOptionsBuilder
opts)
SwitchesOptionsBuilder -> m ()
forall s (m :: * -> *). MonadState s m => s -> m ()
put SwitchesOptionsBuilder
opts{ leadingNewlineStrippingB :: (OptionChanged, Maybe Bool)
leadingNewlineStrippingB = (OptionChanged, Maybe Bool)
res }
setTrailingSpacesStripping :: SwitchesOptionsSetter m => Bool -> m ()
setTrailingSpacesStripping :: Bool -> m ()
setTrailingSpacesStripping Bool
enable = do
SwitchesOptionsBuilder
opts <- m SwitchesOptionsBuilder
forall s (m :: * -> *). MonadState s m => m s
get
(OptionChanged, Maybe Bool)
res <- String
-> Bool
-> (OptionChanged, Maybe Bool)
-> m (OptionChanged, Maybe Bool)
forall (m :: * -> *) a.
(MonadFail m, Eq a) =>
String
-> a -> (OptionChanged, Maybe a) -> m (OptionChanged, Maybe a)
setIfNew String
"trailing spaces stripping" Bool
enable (SwitchesOptionsBuilder -> (OptionChanged, Maybe Bool)
trailingSpacesStrippingB SwitchesOptionsBuilder
opts)
SwitchesOptionsBuilder -> m ()
forall s (m :: * -> *). MonadState s m => s -> m ()
put SwitchesOptionsBuilder
opts{ trailingSpacesStrippingB :: (OptionChanged, Maybe Bool)
trailingSpacesStrippingB = (OptionChanged, Maybe Bool)
res }
setReducedNewlines :: SwitchesOptionsSetter m => Bool -> m ()
setReducedNewlines :: Bool -> m ()
setReducedNewlines Bool
enable = do
SwitchesOptionsBuilder
opts <- m SwitchesOptionsBuilder
forall s (m :: * -> *). MonadState s m => m s
get
(OptionChanged, Maybe Bool)
res <- String
-> Bool
-> (OptionChanged, Maybe Bool)
-> m (OptionChanged, Maybe Bool)
forall (m :: * -> *) a.
(MonadFail m, Eq a) =>
String
-> a -> (OptionChanged, Maybe a) -> m (OptionChanged, Maybe a)
setIfNew String
"reduced newlines" Bool
enable (SwitchesOptionsBuilder -> (OptionChanged, Maybe Bool)
reducedNewlinesB SwitchesOptionsBuilder
opts)
SwitchesOptionsBuilder -> m ()
forall s (m :: * -> *). MonadState s m => s -> m ()
put SwitchesOptionsBuilder
opts{ reducedNewlinesB :: (OptionChanged, Maybe Bool)
reducedNewlinesB = (OptionChanged, Maybe Bool)
res }
setMonadic :: SwitchesOptionsSetter m => Bool -> m ()
setMonadic :: Bool -> m ()
setMonadic Bool
enable = do
SwitchesOptionsBuilder
opts <- m SwitchesOptionsBuilder
forall s (m :: * -> *). MonadState s m => m s
get
(OptionChanged, Maybe Bool)
res <- String
-> Bool
-> (OptionChanged, Maybe Bool)
-> m (OptionChanged, Maybe Bool)
forall (m :: * -> *) a.
(MonadFail m, Eq a) =>
String
-> a -> (OptionChanged, Maybe a) -> m (OptionChanged, Maybe a)
setIfNew String
"monadic" Bool
enable (SwitchesOptionsBuilder -> (OptionChanged, Maybe Bool)
monadicB SwitchesOptionsBuilder
opts)
SwitchesOptionsBuilder -> m ()
forall s (m :: * -> *). MonadState s m => s -> m ()
put SwitchesOptionsBuilder
opts{ monadicB :: (OptionChanged, Maybe Bool)
monadicB = (OptionChanged, Maybe Bool)
res }
setReturnType :: SwitchesOptionsSetter m => ReturnType -> m ()
setReturnType :: ReturnType -> m ()
setReturnType ReturnType
ty = do
SwitchesOptionsBuilder
opts <- m SwitchesOptionsBuilder
forall s (m :: * -> *). MonadState s m => m s
get
(OptionChanged, Maybe ReturnType)
res <- String
-> ReturnType
-> (OptionChanged, Maybe ReturnType)
-> m (OptionChanged, Maybe ReturnType)
forall (m :: * -> *) a.
(MonadFail m, Eq a) =>
String
-> a -> (OptionChanged, Maybe a) -> m (OptionChanged, Maybe a)
setIfNew String
"return type" ReturnType
ty (SwitchesOptionsBuilder -> (OptionChanged, Maybe ReturnType)
returnTypeB SwitchesOptionsBuilder
opts)
SwitchesOptionsBuilder -> m ()
forall s (m :: * -> *). MonadState s m => s -> m ()
put SwitchesOptionsBuilder
opts{ returnTypeB :: (OptionChanged, Maybe ReturnType)
returnTypeB = (OptionChanged, Maybe ReturnType)
res }
accountPreview :: SwitchesOptionsSetter m => m ()
accountPreview :: m ()
accountPreview = do
SwitchesOptionsBuilder
opts <- m SwitchesOptionsBuilder
forall s (m :: * -> *). MonadState s m => m s
get
Bool -> m () -> m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (SwitchesOptionsBuilder -> PreviewLevel
previewLevelB SwitchesOptionsBuilder
opts PreviewLevel -> PreviewLevel -> Bool
forall a. Eq a => a -> a -> Bool
== PreviewLevel
forall a. Bounded a => a
maxBound) (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$
String -> m ()
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Too high preview level"
SwitchesOptionsBuilder -> m ()
forall s (m :: * -> *). MonadState s m => s -> m ()
put SwitchesOptionsBuilder
opts{ previewLevelB :: PreviewLevel
previewLevelB = Int -> PreviewLevel
forall a. Enum a => Int -> a
toEnum (Int -> PreviewLevel) -> Int -> PreviewLevel
forall a b. (a -> b) -> a -> b
$ PreviewLevel -> Int
forall a. Enum a => a -> Int
fromEnum (SwitchesOptionsBuilder -> PreviewLevel
previewLevelB SwitchesOptionsBuilder
opts) Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1 }
notAnyOf :: [Char -> Bool] -> Char -> Bool
notAnyOf :: [Char -> Bool] -> Char -> Bool
notAnyOf [Char -> Bool]
ps Char
c = Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ [Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
or ([Char -> Bool] -> Char -> [Bool]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [Char -> Bool]
ps Char
c)
one :: a -> [a]
one :: a -> [a]
one = (a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [])
data CustomParserFailure
= SwitchesHelpRequested DefaultSwitchesOptions
instance Eq CustomParserFailure where
CustomParserFailure
a == :: CustomParserFailure -> CustomParserFailure -> Bool
== CustomParserFailure
b = CustomParserFailure -> CustomParserFailure -> Ordering
forall a. Ord a => a -> a -> Ordering
compare CustomParserFailure
a CustomParserFailure
b Ordering -> Ordering -> Bool
forall a. Eq a => a -> a -> Bool
== Ordering
EQ
instance Ord CustomParserFailure where
SwitchesHelpRequested{} compare :: CustomParserFailure -> CustomParserFailure -> Ordering
`compare` SwitchesHelpRequested{} = Ordering
EQ
instance ShowErrorComponent CustomParserFailure where
showErrorComponent :: CustomParserFailure -> String
showErrorComponent = \case
SwitchesHelpRequested DefaultSwitchesOptions
defSOpts -> Builder -> String
forall b. FromBuilder b => Builder -> b
fmt (Builder -> String) -> Builder -> String
forall a b. (a -> b) -> a -> b
$ DefaultSwitchesOptions -> Builder
switchesHelpMessage DefaultSwitchesOptions
defSOpts
switchesSectionP :: DefaultSwitchesOptions -> Parsec CustomParserFailure Text SwitchesOptions
switchesSectionP :: DefaultSwitchesOptions
-> Parsec CustomParserFailure Text SwitchesOptions
switchesSectionP DefaultSwitchesOptions
defSOpts =
SwitchesOptionsBuilder
-> Parsec CustomParserFailure Text SwitchesOptions
forall (m :: * -> *).
MonadFail m =>
SwitchesOptionsBuilder -> m SwitchesOptions
finalizeSwitchesOptions (SwitchesOptionsBuilder
-> Parsec CustomParserFailure Text SwitchesOptions)
-> (StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
[()]
-> ParsecT
CustomParserFailure Text Identity SwitchesOptionsBuilder)
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
[()]
-> Parsec CustomParserFailure Text SwitchesOptions
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=<
(StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
[()]
-> SwitchesOptionsBuilder
-> ParsecT
CustomParserFailure Text Identity SwitchesOptionsBuilder)
-> SwitchesOptionsBuilder
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
[()]
-> ParsecT CustomParserFailure Text Identity SwitchesOptionsBuilder
forall a b c. (a -> b -> c) -> b -> a -> c
flip StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
[()]
-> SwitchesOptionsBuilder
-> ParsecT CustomParserFailure Text Identity SwitchesOptionsBuilder
forall (m :: * -> *) s a. Monad m => StateT s m a -> s -> m s
execStateT (DefaultSwitchesOptions -> SwitchesOptionsBuilder
toSwitchesOptionsBuilder DefaultSwitchesOptions
defSOpts) (StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
[()]
-> Parsec CustomParserFailure Text SwitchesOptions)
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
[()]
-> Parsec CustomParserFailure Text SwitchesOptions
forall a b. (a -> b) -> a -> b
$ StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
()
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
[()]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
()
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
[()])
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
()
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
[()]
forall a b. (a -> b) -> a -> b
$ String
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
()
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
()
forall e s (m :: * -> *) a.
MonadParsec e s m =>
String -> m a -> m a
label String
switchLabel (StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
()
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
())
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
()
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
()
forall a b. (a -> b) -> a -> b
$ [StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
()]
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
()
forall (t :: * -> *) (f :: * -> *) a.
(Foldable t, Alternative f) =>
t (f a) -> f a
asum
[ [StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Bool]
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Bool
forall (t :: * -> *) (f :: * -> *) a.
(Foldable t, Alternative f) =>
t (f a) -> f a
asum
[ Token Text
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
(Token Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Token s -> m (Token s)
single Char
Token Text
's' StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Char
-> Bool
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Bool
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Bool
True
, Token Text
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
(Token Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Token s -> m (Token s)
single Char
Token Text
'S' StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Char
-> Bool
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Bool
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Bool
False
] StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Bool
-> (Bool
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
())
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Bool
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
()
forall (m :: * -> *). SwitchesOptionsSetter m => Bool -> m ()
setSpacesTrimming
, [StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Bool]
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Bool
forall (t :: * -> *) (f :: * -> *) a.
(Foldable t, Alternative f) =>
t (f a) -> f a
asum
[ Token Text
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
(Token Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Token s -> m (Token s)
single Char
Token Text
'd' StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Char
-> Bool
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Bool
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Bool
True
, Token Text
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
(Token Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Token s -> m (Token s)
single Char
Token Text
'D' StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Char
-> Bool
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Bool
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Bool
False
] StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Bool
-> (Bool
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
())
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Bool
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
()
forall (m :: * -> *). SwitchesOptionsSetter m => Bool -> m ()
setIndentationStripping
, [StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Bool]
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Bool
forall (t :: * -> *) (f :: * -> *) a.
(Foldable t, Alternative f) =>
t (f a) -> f a
asum
[ Token Text
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
(Token Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Token s -> m (Token s)
single Char
Token Text
'a' StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Char
-> Bool
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Bool
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Bool
True
, Token Text
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
(Token Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Token s -> m (Token s)
single Char
Token Text
'A' StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Char
-> Bool
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Bool
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Bool
False
] StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Bool
-> (Bool
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
())
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Bool
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
()
forall (m :: * -> *). SwitchesOptionsSetter m => Bool -> m ()
setLeadingNewlineStripping
, [StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Bool]
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Bool
forall (t :: * -> *) (f :: * -> *) a.
(Foldable t, Alternative f) =>
t (f a) -> f a
asum
[ Token Text
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
(Token Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Token s -> m (Token s)
single Char
Token Text
'z' StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Char
-> Bool
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Bool
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Bool
True
, Token Text
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
(Token Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Token s -> m (Token s)
single Char
Token Text
'Z' StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Char
-> Bool
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Bool
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Bool
False
] StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Bool
-> (Bool
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
())
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Bool
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
()
forall (m :: * -> *). SwitchesOptionsSetter m => Bool -> m ()
setTrailingSpacesStripping
, [StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Bool]
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Bool
forall (t :: * -> *) (f :: * -> *) a.
(Foldable t, Alternative f) =>
t (f a) -> f a
asum
[ Token Text
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
(Token Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Token s -> m (Token s)
single Char
Token Text
'n' StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Char
-> Bool
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Bool
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Bool
True
, Token Text
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
(Token Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Token s -> m (Token s)
single Char
Token Text
'N' StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Char
-> Bool
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Bool
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Bool
False
] StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Bool
-> (Bool
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
())
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Bool
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
()
forall (m :: * -> *). SwitchesOptionsSetter m => Bool -> m ()
setReducedNewlines
, [StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Bool]
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Bool
forall (t :: * -> *) (f :: * -> *) a.
(Foldable t, Alternative f) =>
t (f a) -> f a
asum
[ Token Text
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
(Token Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Token s -> m (Token s)
single Char
Token Text
'm' StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Char
-> Bool
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Bool
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Bool
True
, Token Text
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
(Token Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Token s -> m (Token s)
single Char
Token Text
'M' StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Char
-> Bool
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Bool
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Bool
False
] StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Bool
-> (Bool
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
())
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Bool
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
()
forall (m :: * -> *). SwitchesOptionsSetter m => Bool -> m ()
setMonadic
, [StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
ReturnType]
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
ReturnType
forall (t :: * -> *) (f :: * -> *) a.
(Foldable t, Alternative f) =>
t (f a) -> f a
asum
[ Token Text
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
(Token Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Token s -> m (Token s)
single Char
Token Text
'B' StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Char
-> ReturnType
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
ReturnType
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> ReturnType
AnyFromBuilder
, Token Text
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
(Token Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Token s -> m (Token s)
single Char
Token Text
'b' StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Char
-> ReturnType
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
ReturnType
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> ReturnType
ConcreteBuilder
, Token Text
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
(Token Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Token s -> m (Token s)
single Char
Token Text
't' StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Char
-> ReturnType
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
ReturnType
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> ReturnType
ConcreteText
, Token Text
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
(Token Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Token s -> m (Token s)
single Char
Token Text
'T' StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Char
-> ReturnType
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
ReturnType
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> ReturnType
ConcreteLText
] StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
ReturnType
-> (ReturnType
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
())
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ReturnType
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
()
forall (m :: * -> *). SwitchesOptionsSetter m => ReturnType -> m ()
setReturnType
, Token Text
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
(Token Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Token s -> m (Token s)
single Char
Token Text
'!' StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Char
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
()
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
()
forall (m :: * -> *). SwitchesOptionsSetter m => m ()
accountPreview
, Token Text
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
(Token Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Token s -> m (Token s)
single Char
Token Text
'?' StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
Char
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
()
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> CustomParserFailure
-> StateT
SwitchesOptionsBuilder
(ParsecT CustomParserFailure Text Identity)
()
forall e s (m :: * -> *) a. MonadParsec e s m => e -> m a
customFailure (DefaultSwitchesOptions -> CustomParserFailure
SwitchesHelpRequested DefaultSwitchesOptions
defSOpts)
]
where
switchLabel :: String
switchLabel = String
"switch option (type '?' here for help)"
switchesHelpMessage :: DefaultSwitchesOptions -> Builder
switchesHelpMessage :: DefaultSwitchesOptions -> Builder
switchesHelpMessage DefaultSwitchesOptions
sopts =
let SwitchesOptions
_exhaustivnessCheck :: SwitchesOptions = Bool
-> Bool
-> Bool
-> Bool
-> ReturnType
-> Bool
-> Bool
-> PreviewLevel
-> SwitchesOptions
SwitchesOptions
(String -> Bool
forall a. HasCallStack => String -> a
error String
"")
(String -> Bool
forall a. HasCallStack => String -> a
error String
"")
(String -> Bool
forall a. HasCallStack => String -> a
error String
"")
(String -> Bool
forall a. HasCallStack => String -> a
error String
"")
(String -> ReturnType
forall a. HasCallStack => String -> a
error String
"")
(String -> Bool
forall a. HasCallStack => String -> a
error String
"")
(String -> Bool
forall a. HasCallStack => String -> a
error String
"")
(String -> PreviewLevel
forall a. HasCallStack => String -> a
error String
"")
in [Builder] -> Builder
forall a. Monoid a => [a] -> a
mconcat
[ Builder
"\nHelp on switches:\n"
, Maybe Bool -> [(Text, Builder, Maybe Bool)] -> Builder
forall a. Eq a => a -> [(Text, Builder, a)] -> Builder
helpOnOptions (DefaultSwitchesOptions -> Maybe Bool
defSpacesTrimming DefaultSwitchesOptions
sopts)
[ (Text
"s", Builder
"enable spaces trimming", Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
True)
, (Text
"S", Builder
"disable spaces trimming", Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
False)
]
, Maybe Bool -> [(Text, Builder, Maybe Bool)] -> Builder
forall a. Eq a => a -> [(Text, Builder, a)] -> Builder
helpOnOptions (DefaultSwitchesOptions -> Maybe Bool
defIndentationStripping DefaultSwitchesOptions
sopts)
[ (Text
"d", Builder
"enable indentation stripping", Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
True)
, (Text
"D", Builder
"disable indentation stripping", Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
False)
]
, Maybe Bool -> [(Text, Builder, Maybe Bool)] -> Builder
forall a. Eq a => a -> [(Text, Builder, a)] -> Builder
helpOnOptions (DefaultSwitchesOptions -> Maybe Bool
defLeadingNewlineStripping DefaultSwitchesOptions
sopts)
[ (Text
"a", Builder
"enable leading newline stripping", Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
True)
, (Text
"A", Builder
"disable leading newline stripping", Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
False)
]
, Maybe Bool -> [(Text, Builder, Maybe Bool)] -> Builder
forall a. Eq a => a -> [(Text, Builder, a)] -> Builder
helpOnOptions (DefaultSwitchesOptions -> Maybe Bool
defTrailingSpacesStripping DefaultSwitchesOptions
sopts)
[ (Text
"z", Builder
"enable trailing spaces stripping", Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
True)
, (Text
"Z", Builder
"disable trailing spaces stripping", Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
False)
]
, Maybe Bool -> [(Text, Builder, Maybe Bool)] -> Builder
forall a. Eq a => a -> [(Text, Builder, a)] -> Builder
helpOnOptions (DefaultSwitchesOptions -> Maybe Bool
defReducedNewlines DefaultSwitchesOptions
sopts)
[ (Text
"n", Builder
"enable newlines reducing", Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
True)
, (Text
"N", Builder
"disable newlines reducing", Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
False)
]
, Maybe Bool -> [(Text, Builder, Maybe Bool)] -> Builder
forall a. Eq a => a -> [(Text, Builder, a)] -> Builder
helpOnOptions (DefaultSwitchesOptions -> Maybe Bool
defMonadic DefaultSwitchesOptions
sopts)
[ (Text
"m", Builder
"enable monadic interpolated values", Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
True)
, (Text
"M", Builder
"disable monadic interpolated values", Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
False)
]
, Maybe ReturnType -> [(Text, Builder, Maybe ReturnType)] -> Builder
forall a. Eq a => a -> [(Text, Builder, a)] -> Builder
helpOnOptions (DefaultSwitchesOptions -> Maybe ReturnType
defReturnType DefaultSwitchesOptions
sopts)
[ (Text
"t", Builder
"return `Text`", ReturnType -> Maybe ReturnType
forall a. a -> Maybe a
Just ReturnType
ConcreteText)
, (Text
"T", Builder
"return lazy `Text`", ReturnType -> Maybe ReturnType
forall a. a -> Maybe a
Just ReturnType
ConcreteLText)
, (Text
"b", Builder
"return `Builder`", ReturnType -> Maybe ReturnType
forall a. a -> Maybe a
Just ReturnType
ConcreteBuilder)
, (Text
"B", Builder
"return any text-like type (`FromBuilder a => a`)", ReturnType -> Maybe ReturnType
forall a. a -> Maybe a
Just ReturnType
AnyFromBuilder)
]
, PreviewLevel -> [(Text, Builder, PreviewLevel)] -> Builder
forall a. Eq a => a -> [(Text, Builder, a)] -> Builder
helpOnOptions PreviewLevel
PreviewNone
[ (Text
"!", Builder
"show rendered text (without substitutions) as a warning", PreviewLevel
PreviewExact)
, (Text
"!!", Builder
"like ! but also marks invisible characters like spaces", PreviewLevel
PreviewInvisible)
]
]
where
helpOnOptions :: a -> [(Text, Builder, a)] -> Builder
helpOnOptions a
defVal [(Text, Builder, a)]
available = [Builder] -> Builder
forall a. Monoid a => [a] -> a
mconcat
[ Builder
"· " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Text -> Builder
forall p. Buildable p => p -> Builder
build @Text Text
switch Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
" - " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
help Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
"\n"
| (Text
switch, Builder
help, a
val) <- [(Text, Builder, a)]
available
, a
val a -> a -> Bool
forall a. Eq a => a -> a -> Bool
/= a
defVal
]
intPieceP :: Ord e => Parsec e Text [ParsedIntPiece]
intPieceP :: Parsec e Text [ParsedIntPiece]
intPieceP = [Parsec e Text [ParsedIntPiece]] -> Parsec e Text [ParsedIntPiece]
forall (t :: * -> *) (f :: * -> *) a.
(Foldable t, Alternative f) =>
t (f a) -> f a
asum
[
ParsedIntPiece -> [ParsedIntPiece]
forall a. a -> [a]
one (ParsedIntPiece -> [ParsedIntPiece])
-> (Text -> ParsedIntPiece) -> Text -> [ParsedIntPiece]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ParsedIntPiece
PipString (Text -> [ParsedIntPiece])
-> ParsecT e Text Identity Text -> Parsec e Text [ParsedIntPiece]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe String
-> (Token Text -> Bool) -> ParsecT e Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Maybe String -> (Token s -> Bool) -> m (Tokens s)
takeWhile1P Maybe String
forall a. Maybe a
Nothing ([Char -> Bool] -> Char -> Bool
notAnyOf [(Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'\\'), (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'#'), Char -> Bool
isSpace])
, Token Text -> ParsecT e Text Identity (Token Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Token s -> m (Token s)
single Char
Token Text
'#' ParsecT e Text Identity Char
-> Parsec e Text [ParsedIntPiece] -> Parsec e Text [ParsedIntPiece]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> do
Text
mode <- Maybe String
-> (Token Text -> Bool) -> ParsecT e Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Maybe String -> (Token s -> Bool) -> m (Tokens s)
takeWhileP Maybe String
forall a. Maybe a
Nothing \Token Text
c ->
Char -> Bool
isAlphaNum Char
Token Text
c Bool -> Bool -> Bool
|| Char
Token Text
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'_'
[Parsec e Text [ParsedIntPiece]] -> Parsec e Text [ParsedIntPiece]
forall (t :: * -> *) (f :: * -> *) a.
(Foldable t, Alternative f) =>
t (f a) -> f a
asum
[ do
Char
_ <- Token Text -> ParsecT e Text Identity (Token Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Token s -> m (Token s)
single Char
Token Text
'{'
[Text]
intTxt <- ParsecT e Text Identity Text -> ParsecT e Text Identity [Text]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (ParsecT e Text Identity Text -> ParsecT e Text Identity [Text])
-> ParsecT e Text Identity Text -> ParsecT e Text Identity [Text]
forall a b. (a -> b) -> a -> b
$ [ParsecT e Text Identity Text] -> ParsecT e Text Identity Text
forall (t :: * -> *) (f :: * -> *) a.
(Foldable t, Alternative f) =>
t (f a) -> f a
asum
[ Maybe String
-> (Token Text -> Bool) -> ParsecT e Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Maybe String -> (Token s -> Bool) -> m (Tokens s)
takeWhile1P (String -> Maybe String
forall a. a -> Maybe a
Just String
"interpolated piece") ((Token Text -> Bool) -> ParsecT e Text Identity (Tokens Text))
-> (Token Text -> Bool) -> ParsecT e Text Identity (Tokens Text)
forall a b. (a -> b) -> a -> b
$ [Char -> Bool] -> Char -> Bool
notAnyOf [(Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'\\'), (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'}')]
, Token Text -> ParsecT e Text Identity (Token Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Token s -> m (Token s)
single Char
Token Text
'\\' ParsecT e Text Identity Char
-> ParsecT e Text Identity Text -> ParsecT e Text Identity Text
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Char -> Text
T.singleton (Char -> Text)
-> ParsecT e Text Identity Char -> ParsecT e Text Identity Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [ParsecT e Text Identity Char] -> ParsecT e Text Identity Char
forall (t :: * -> *) (f :: * -> *) a.
(Foldable t, Alternative f) =>
t (f a) -> f a
asum
[ Token Text -> ParsecT e Text Identity (Token Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Token s -> m (Token s)
single Char
Token Text
'\\'
, Token Text -> ParsecT e Text Identity (Token Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Token s -> m (Token s)
single Char
Token Text
'}'
]
]
Char
_ <- Token Text -> ParsecT e Text Identity (Token Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Token s -> m (Token s)
single Char
Token Text
'}'
[ParsedIntPiece] -> Parsec e Text [ParsedIntPiece]
forall (m :: * -> *) a. Monad m => a -> m a
return ([ParsedIntPiece] -> Parsec e Text [ParsedIntPiece])
-> (ParsedIntPiece -> [ParsedIntPiece])
-> ParsedIntPiece
-> Parsec e Text [ParsedIntPiece]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParsedIntPiece -> [ParsedIntPiece]
forall a. a -> [a]
one (ParsedIntPiece -> Parsec e Text [ParsedIntPiece])
-> ParsedIntPiece -> Parsec e Text [ParsedIntPiece]
forall a b. (a -> b) -> a -> b
$ IntData -> ParsedIntPiece
PipInt IntData :: Text -> Text -> IntData
IntData
{ idMode :: Text
idMode = Text
mode
, idCode :: Text
idCode = [Text] -> Text
forall a. Monoid a => [a] -> a
mconcat [Text]
intTxt
}
, [ParsedIntPiece] -> Parsec e Text [ParsedIntPiece]
forall (m :: * -> *) a. Monad m => a -> m a
return ([ParsedIntPiece] -> Parsec e Text [ParsedIntPiece])
-> [ParsedIntPiece] -> Parsec e Text [ParsedIntPiece]
forall a b. (a -> b) -> a -> b
$ ParsedIntPiece -> [ParsedIntPiece]
forall a. a -> [a]
one (ParsedIntPiece -> [ParsedIntPiece])
-> (Text -> ParsedIntPiece) -> Text -> [ParsedIntPiece]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ParsedIntPiece
PipString (Text -> [ParsedIntPiece]) -> Text -> [ParsedIntPiece]
forall a b. (a -> b) -> a -> b
$ Text
"#" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
mode
]
, Token Text -> ParsecT e Text Identity (Token Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Token s -> m (Token s)
single Char
Token Text
'\\' ParsecT e Text Identity Char
-> Parsec e Text [ParsedIntPiece] -> Parsec e Text [ParsedIntPiece]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> [Parsec e Text [ParsedIntPiece]] -> Parsec e Text [ParsedIntPiece]
forall (t :: * -> *) (f :: * -> *) a.
(Foldable t, Alternative f) =>
t (f a) -> f a
asum
[ ParsedIntPiece -> [ParsedIntPiece]
forall a. a -> [a]
one (ParsedIntPiece -> [ParsedIntPiece])
-> (Char -> ParsedIntPiece) -> Char -> [ParsedIntPiece]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ParsedIntPiece
PipString (Text -> ParsedIntPiece)
-> (Char -> Text) -> Char -> ParsedIntPiece
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Text
T.singleton (Char -> [ParsedIntPiece])
-> ParsecT e Text Identity Char -> Parsec e Text [ParsedIntPiece]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Token Text -> ParsecT e Text Identity (Token Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Token s -> m (Token s)
single Char
Token Text
'\\'
, ParsedIntPiece -> [ParsedIntPiece]
forall a. a -> [a]
one (ParsedIntPiece -> [ParsedIntPiece])
-> (Char -> ParsedIntPiece) -> Char -> [ParsedIntPiece]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ParsedIntPiece
PipString (Text -> ParsedIntPiece)
-> (Char -> Text) -> Char -> ParsedIntPiece
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Text
T.singleton (Char -> [ParsedIntPiece])
-> ParsecT e Text Identity Char -> Parsec e Text [ParsedIntPiece]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Token Text -> ParsecT e Text Identity (Token Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Token s -> m (Token s)
single Char
Token Text
'#'
, ParsecT e Text Identity ParsedIntPiece
newline ParsecT e Text Identity ParsedIntPiece
-> Parsec e Text [ParsedIntPiece] -> Parsec e Text [ParsedIntPiece]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parsec e Text [ParsedIntPiece]
lineStart
]
, (:) (ParsedIntPiece -> [ParsedIntPiece] -> [ParsedIntPiece])
-> ParsecT e Text Identity ParsedIntPiece
-> ParsecT e Text Identity ([ParsedIntPiece] -> [ParsedIntPiece])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT e Text Identity ParsedIntPiece
newline ParsecT e Text Identity ([ParsedIntPiece] -> [ParsedIntPiece])
-> Parsec e Text [ParsedIntPiece] -> Parsec e Text [ParsedIntPiece]
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parsec e Text [ParsedIntPiece]
lineStart
, ParsedIntPiece -> [ParsedIntPiece]
forall a. a -> [a]
one (ParsedIntPiece -> [ParsedIntPiece])
-> (Text -> ParsedIntPiece) -> Text -> [ParsedIntPiece]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ParsedIntPiece
PipString (Text -> [ParsedIntPiece])
-> ParsecT e Text Identity Text -> Parsec e Text [ParsedIntPiece]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe String
-> (Token Text -> Bool) -> ParsecT e Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Maybe String -> (Token s -> Bool) -> m (Tokens s)
takeWhile1P Maybe String
forall a. Maybe a
Nothing Char -> Bool
Token Text -> Bool
isNonNewlineSpace
, String -> Parsec e Text [ParsedIntPiece]
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Unexpected: failed to consume some input"
]
where
newline :: ParsecT e Text Identity ParsedIntPiece
newline = Text -> ParsedIntPiece
PipNewline (Text -> ParsedIntPiece)
-> ([Text] -> Text) -> [Text] -> ParsedIntPiece
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Text] -> Text
forall a. Monoid a => [a] -> a
mconcat ([Text] -> ParsedIntPiece)
-> ParsecT e Text Identity [Text]
-> ParsecT e Text Identity ParsedIntPiece
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [ParsecT e Text Identity Text] -> ParsecT e Text Identity [Text]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence
[ Text -> (Char -> Text) -> Maybe Char -> Text
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Text
"" Char -> Text
T.singleton (Maybe Char -> Text)
-> ParsecT e Text Identity (Maybe Char)
-> ParsecT e Text Identity Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT e Text Identity Char
-> ParsecT e Text Identity (Maybe Char)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Token Text -> ParsecT e Text Identity (Token Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Token s -> m (Token s)
single Char
Token Text
'\r')
, Char -> Text
T.singleton (Char -> Text)
-> ParsecT e Text Identity Char -> ParsecT e Text Identity Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Token Text -> ParsecT e Text Identity (Token Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Token s -> m (Token s)
single Char
Token Text
'\n'
]
isNonNewlineSpace :: Char -> Bool
isNonNewlineSpace Char
c = Char -> Bool
isSpace Char
c Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
'\n' Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
'\r'
lineStart :: Parsec e Text [ParsedIntPiece]
lineStart = [Parsec e Text [ParsedIntPiece]] -> Parsec e Text [ParsedIntPiece]
forall (t :: * -> *) (f :: * -> *) a.
(Foldable t, Alternative f) =>
t (f a) -> f a
asum
[ ParsecT e Text Identity ParsedIntPiece
-> ParsecT e Text Identity ParsedIntPiece
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
lookAhead ParsecT e Text Identity ParsedIntPiece
newline ParsecT e Text Identity ParsedIntPiece
-> [ParsedIntPiece] -> Parsec e Text [ParsedIntPiece]
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> [ParsedIntPiece
PipEmptyLine]
, do
Word
wss <- (Integral Int, Num Word) => Int -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral @Int @Word (Int -> Word) -> (Text -> Int) -> Text -> Word
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Int
T.length (Text -> Word)
-> ParsecT e Text Identity Text -> ParsecT e Text Identity Word
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
Maybe String
-> (Token Text -> Bool) -> ParsecT e Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Maybe String -> (Token s -> Bool) -> m (Tokens s)
takeWhileP Maybe String
forall a. Maybe a
Nothing Char -> Bool
Token Text -> Bool
isNonNewlineSpace
[ParsedIntPiece] -> Parsec e Text [ParsedIntPiece]
forall (m :: * -> *) a. Monad m => a -> m a
return ([ParsedIntPiece] -> Parsec e Text [ParsedIntPiece])
-> [ParsedIntPiece] -> Parsec e Text [ParsedIntPiece]
forall a b. (a -> b) -> a -> b
$ Bool -> [()]
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Word
wss Word -> Word -> Bool
forall a. Ord a => a -> a -> Bool
> Word
0) [()] -> ParsedIntPiece -> [ParsedIntPiece]
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Word -> ParsedIntPiece
PipLeadingWs Word
wss
]
glueParsedStrings :: ParsedInterpolatedString -> ParsedInterpolatedString
glueParsedStrings :: [ParsedIntPiece] -> [ParsedIntPiece]
glueParsedStrings = \case
[] -> []
PipString Text
s1 : PipString Text
s2 : [ParsedIntPiece]
ps -> [ParsedIntPiece] -> [ParsedIntPiece]
glueParsedStrings (Text -> ParsedIntPiece
PipString (Text
s1 Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
s2) ParsedIntPiece -> [ParsedIntPiece] -> [ParsedIntPiece]
forall a. a -> [a] -> [a]
: [ParsedIntPiece]
ps)
ParsedIntPiece
p : [ParsedIntPiece]
ps -> ParsedIntPiece
p ParsedIntPiece -> [ParsedIntPiece] -> [ParsedIntPiece]
forall a. a -> [a] -> [a]
: [ParsedIntPiece] -> [ParsedIntPiece]
glueParsedStrings [ParsedIntPiece]
ps
intStringP
:: DefaultSwitchesOptions
-> Parsec CustomParserFailure Text (SwitchesOptions, ParsedInterpolatedString)
intStringP :: DefaultSwitchesOptions
-> Parsec
CustomParserFailure Text (SwitchesOptions, [ParsedIntPiece])
intStringP DefaultSwitchesOptions
sopts = do
SwitchesOptions
switches <- DefaultSwitchesOptions
-> Parsec CustomParserFailure Text SwitchesOptions
switchesSectionP DefaultSwitchesOptions
sopts
Char
_ <- Token Text
-> ParsecT CustomParserFailure Text Identity (Token Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Token s -> m (Token s)
single Char
Token Text
'|'
[ParsedIntPiece]
pieces <- [ParsedIntPiece] -> [ParsedIntPiece]
glueParsedStrings ([ParsedIntPiece] -> [ParsedIntPiece])
-> ([[ParsedIntPiece]] -> [ParsedIntPiece])
-> [[ParsedIntPiece]]
-> [ParsedIntPiece]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [[ParsedIntPiece]] -> [ParsedIntPiece]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[ParsedIntPiece]] -> [ParsedIntPiece])
-> ParsecT CustomParserFailure Text Identity [[ParsedIntPiece]]
-> ParsecT CustomParserFailure Text Identity [ParsedIntPiece]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT CustomParserFailure Text Identity [ParsedIntPiece]
-> ParsecT CustomParserFailure Text Identity [[ParsedIntPiece]]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many ParsecT CustomParserFailure Text Identity [ParsedIntPiece]
forall e. Ord e => Parsec e Text [ParsedIntPiece]
intPieceP
ParsecT CustomParserFailure Text Identity ()
forall e s (m :: * -> *). MonadParsec e s m => m ()
eof
(SwitchesOptions, [ParsedIntPiece])
-> Parsec
CustomParserFailure Text (SwitchesOptions, [ParsedIntPiece])
forall (m :: * -> *) a. Monad m => a -> m a
return (SwitchesOptions
switches, [ParsedIntPiece]
pieces)
parseIntString
:: DefaultSwitchesOptions
-> Text
-> Either String (SwitchesOptions, ParsedInterpolatedString)
parseIntString :: DefaultSwitchesOptions
-> Text -> Either String (SwitchesOptions, [ParsedIntPiece])
parseIntString DefaultSwitchesOptions
defSOpts Text
txt =
(ParseErrorBundle Text CustomParserFailure -> String)
-> Either
(ParseErrorBundle Text CustomParserFailure)
(SwitchesOptions, [ParsedIntPiece])
-> Either String (SwitchesOptions, [ParsedIntPiece])
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first ParseErrorBundle Text CustomParserFailure -> String
forall s e.
(VisualStream s, TraversableStream s, ShowErrorComponent e) =>
ParseErrorBundle s e -> String
errorBundlePretty (Either
(ParseErrorBundle Text CustomParserFailure)
(SwitchesOptions, [ParsedIntPiece])
-> Either String (SwitchesOptions, [ParsedIntPiece]))
-> Either
(ParseErrorBundle Text CustomParserFailure)
(SwitchesOptions, [ParsedIntPiece])
-> Either String (SwitchesOptions, [ParsedIntPiece])
forall a b. (a -> b) -> a -> b
$
Parsec CustomParserFailure Text (SwitchesOptions, [ParsedIntPiece])
-> String
-> Text
-> Either
(ParseErrorBundle Text CustomParserFailure)
(SwitchesOptions, [ParsedIntPiece])
forall e s a.
Parsec e s a -> String -> s -> Either (ParseErrorBundle s e) a
parse (DefaultSwitchesOptions
-> Parsec
CustomParserFailure Text (SwitchesOptions, [ParsedIntPiece])
intStringP DefaultSwitchesOptions
defSOpts) String
"int QQ" Text
txt