Copyright | (c) Tony Zorman 2020 2021 2022 |
---|---|
License | AGPL |
Maintainer | Tony Zorman <soliditsallgood@mailbox.org> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
This module contains utility functions for working with the 'optparse-applicative' library.
Much of the module revolves around easily building options that can take "multiple arguments" in the form of separated inputs (e.g. program --option one,two,three,four). This still honours the POSIX standard for options only taking a single argument (by not using spaces to separate the different inputs), while also being very convenient to enter (as opposed to, say, wrapping everything inside quotes).
Another focus involves connecting the attoparsec
library with
'optparse-applicative' (this is often useful when options involve more
complex parsing patterns).
Synopsis
- type AttoParser = Parser
- attoReadM :: AttoParser a -> ReadM a
- optionA :: AttoParser a -> Mod OptionFields a -> Parser a
- splitWith :: AttoParser p -> String -> AttoParser [p]
- splitOn :: String -> AttoParser [Text]
- anyOf :: [(a, [Text])] -> AttoParser a
- anyOfSkip :: (Char -> Bool) -> [(a, [Text])] -> AttoParser a
- anyOfRM :: [(a, [Text])] -> ReadM a
- aliases :: Foldable t => t Text -> AttoParser Text
- showSepChars :: Foldable t => t Char -> String
Types
type AttoParser = Parser Source #
Less confusion as to which Parser
one is referring to.
Interfacing with parsing libraries
optionA :: AttoParser a -> Mod OptionFields a -> Parser a Source #
Like option
, but takes an AttoParser
instead of a ReadM
.
Parsing a list of things
:: AttoParser p | Parser for a single entry |
-> String | Characters that may be used to separate different entries |
-> AttoParser [p] |
Parse a collection of things, separated by some specific characters.
splitOn :: String -> AttoParser [Text] Source #
Like splitWith
, but the parser is just taking everything it can until the
next separation character.
Parsing one thing out of a list of things
anyOf :: [(a, [Text])] -> AttoParser a Source #
Create a parser that matches any of the given a
, with the given aliases.
anyOfSkip :: (Char -> Bool) -> [(a, [Text])] -> AttoParser a Source #
Like anyOf
but, after having found a match, skip all remaining
text as long as the given predicate is true.
anyOfRM :: [(a, [Text])] -> ReadM a Source #
Like anyOf
, but return a 'ReadM a' instead of an 'AttoParser a'.
Easier parsing for a thing
aliases :: Foldable t => t Text -> AttoParser Text Source #
Create a parser that matches case-insensitively for all elements of a given list.