-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Self-describing consumers/parsers; forms, cmd-line args, JSON, etc. -- -- Self-describing consumers/parsers. See the README.md for more -- information. It is currently EXPERIMENTAL. @package descriptive @version 0.0.0 -- | Descriptive parsers. module Descriptive -- | Description of a consumable thing. data Description a Unit :: !a -> Description a Bounded :: !Integer -> !Bound -> !(Description a) -> Description a And :: !(Description a) -> !(Description a) -> Description a Or :: !(Description a) -> !(Description a) -> Description a Sequence :: [Description a] -> Description a Wrap :: a -> (Description a) -> Description a None :: Description a -- | The bounds of a many-consumable thing. data Bound NaturalBound :: !Integer -> Bound UnlimitedBound :: Bound -- | A consumer. data Consumer s d a Consumer :: (s -> (Description d, s)) -> (s -> (Either (Description d) a, s)) -> Consumer s d a consumerDesc :: Consumer s d a -> s -> (Description d, s) consumerParse :: Consumer s d a -> s -> (Either (Description d) a, s) -- | Make a consumer. consumer :: (s -> (Description d, s)) -> (s -> (Either (Description d) a, s)) -> Consumer s d a -- | Wrap a consumer with another consumer. wrap :: (s -> (t -> (Description d, t)) -> (Description d, s)) -> (s -> (t -> (Description d, t)) -> (t -> (Either (Description d) a, t)) -> (Either (Description d) b, s)) -> Consumer t d a -> Consumer s d b -- | Compose contiguous items into one sequence. sequencing :: [Consumer d s a] -> Consumer d s [a] -- | Run a consumer. consume :: Consumer s d a -> s -> (Either (Description d) a, s) -- | Describe a consumer. describe :: Consumer s d a -> s -> (Description d, s) instance Show Bound instance Show a => Show (Description a) instance Monoid a => Monoid (Consumer s d a) instance Monoid a => Monoid (Either (Description d) a) instance Alternative (Consumer s d) instance Applicative (Consumer s d) instance Functor (Consumer s d) instance Monoid (Description d) -- | Consuming form a list of characters. -- -- Examples: -- -- λ> describe (zeroOrMore (char k) <> string "abc") [] -- (And (Bounded 0 UnlimitedBound (Unit "k")) (And (Unit "a") (And (Unit -- "b") (And (Unit "c") None))),"") -- -- λ> consumer (zeroOrMore (char k) <> string "abc") -- "kkkabc" (Right "kkkabc","") -- -- λ> consumer (zeroOrMore (char k) <> string "abc") -- "kkkabq" (Left (Unit "c"),"") -- -- λ> consumer (zeroOrMore (char k) <> string "abc") -- "kkkab" (Left (Unit "a character"),"") module Descriptive.Char -- | Consume any character. anyChar :: Consumer [Char] Text Char -- | A character consumer. char :: Char -> Consumer [Char] Text Char -- | A string consumer. string :: [Char] -> Consumer [Char] Text [Char] -- | Validating form with named inputs. module Descriptive.Form -- | Form descriptor. data Form Input :: !Text -> Form Constraint :: !Text -> Form -- | Consume any character. input :: Text -> Consumer (Map Text Text) Form Text -- | Validate a form input with a description of what's required. validate :: Text -> (a -> Maybe b) -> Consumer (Map Text Text) Form a -> Consumer (Map Text Text) Form b instance Show Form -- | Validating indexed formlet with auto-generated input names. module Descriptive.Formlet data Formlet Index :: !Integer -> Formlet Constrained :: !Text -> Formlet data FormletState FormletState :: (Map Integer Text) -> !Integer -> FormletState formletMap :: FormletState -> (Map Integer Text) formletIndex :: FormletState -> !Integer -- | Consume any character. indexed :: Consumer FormletState Formlet Text instance Show Formlet instance Show FormletState -- | Command-line options parser. module Descriptive.Options -- | Description of a commandline option. data Option AnyString :: !Text -> Option Constant :: !Text -> Option Flag :: !Text -> !Text -> Option Arg :: !Text -> !Text -> Option Prefix :: !Text -> !Text -> Option -- | Make a text description of the command line options. textDescription :: Description Option -> Text -- | Make a text description of an option. textOpt :: Option -> Text -- | Consume one argument from the argument list. anyString :: Text -> Consumer [Text] Option Text -- | Consume one argument from the argument list. constant :: Text -> Consumer [Text] Option Text -- | Find a short boolean flag. flag :: Text -> Text -> Consumer [Text] Option Bool -- | Find an argument prefixed by -X. prefix :: Text -> Text -> Consumer [Text] Option Text -- | Find a named argument. arg :: Text -> Text -> Consumer [Text] Option Text instance Show Option -- | A JSON API which describes itself. module Descriptive.JSON -- | Description of parseable things. data Doc Integer :: !Text -> Doc Text :: !Text -> Doc Struct :: !Text -> Doc Key :: !Text -> Doc -- | Consume an object. obj :: Text -> Consumer Object Doc a -> Consumer Value Doc a -- | Consume from object at the given key. key :: Text -> Consumer Value Doc a -> Consumer Object Doc a -- | Consume a string. string :: Text -> Consumer Value Doc Text -- | Consume an integer. integer :: Text -> Consumer Value Doc Integer instance Show Doc