Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data Parser i o where
- ParseAny :: Parser i i
- ParseExtra :: (o -> Parser u) -> Parser i o -> Parser i u
- ParseEq :: (Show o, Eq o) => o -> Text -> Parser i o -> Parser i o
- ParseNull :: Parser Value ()
- ParseMaybe :: Parser Value o -> Parser Value (Maybe o)
- ParseBool :: Maybe Text -> Parser Bool o -> Parser Value o
- ParseString :: Maybe Text -> Parser Text o -> Parser Value o
- ParseNumber :: Maybe Text -> Parser Scientific o -> Parser Value o
- ParseArray :: Maybe Text -> Parser Array o -> Parser Value o
- ParseObject :: Maybe Text -> Parser Object a -> Parser Value a
- ParseList :: Parser Value o -> Parser Array (Vector o)
- ParseMap :: Parser Value v -> Parser Object (HashMap Text v)
- ParseMapKeys :: Ord k => Parser Text k -> Parser Object (HashMap Text v) -> Parser Object (Map k v)
- ParseField :: Text -> FieldParser o -> Parser Object o
- ParsePure :: a -> Parser i a
- ParseFmap :: (a -> b) -> Parser i a -> Parser i b
- ParseAp :: Parser i (a -> b) -> Parser i a -> Parser i b
- ParseAlt :: [Parser i o] -> Parser i o
- ParseComment :: Text -> Parser i o -> Parser i o
- data FieldParser o where
- FieldParserRequired :: YamlParser o -> FieldParser o
- FieldParserOptional :: YamlParser o -> FieldParser (Maybe o)
- FieldParserOptionalWithDefault :: Show o => YamlParser o -> o -> FieldParser o
- type YamlParser a = Parser Value a
- type ObjectParser a = Parser Object a
- type KeyParser a = Parser Text a
- objectParser :: Text -> ObjectParser o -> YamlParser o
- unnamedObjectParser :: ObjectParser o -> YamlParser o
- viaRead :: Read a => YamlParser a
- literalString :: Text -> YamlParser Text
- literalShowValue :: Show a => a -> YamlParser a
- literalValue :: ToJSON a => a -> YamlParser a
- alternatives :: [Parser i o] -> Parser i o
- (<?>) :: Parser i a -> Text -> Parser i a
- (<??>) :: Parser i a -> [Text] -> Parser i a
- requiredFieldWith :: Text -> Text -> YamlParser a -> ObjectParser a
- requiredFieldWith' :: Text -> YamlParser a -> ObjectParser a
- optionalFieldWith :: Text -> Text -> YamlParser a -> ObjectParser (Maybe a)
- optionalFieldWith' :: Text -> YamlParser a -> ObjectParser (Maybe a)
- optionalFieldWithDefaultWith :: Show a => Text -> a -> Text -> YamlParser a -> ObjectParser a
- optionalFieldWithDefaultWith' :: Show a => Text -> a -> YamlParser a -> ObjectParser a
- maybeParser :: Show o => (o -> Maybe u) -> Parser i o -> Parser i u
- eitherParser :: Show o => (o -> Either String u) -> Parser i o -> Parser i u
- extraParser :: (o -> Parser u) -> Parser i o -> Parser i u
Documentation
data Parser i o where Source #
A parser that takes values of type i
as input and parses them into values of type o
Note that there is no Monad
instance.
ParseAny :: Parser i i | Return the input |
ParseExtra :: (o -> Parser u) -> Parser i o -> Parser i u | Parse via an extra parsing function |
ParseEq | Match an exact value |
ParseNull :: Parser Value () | Parse |
ParseMaybe :: Parser Value o -> Parser Value (Maybe o) | |
ParseBool :: Maybe Text -> Parser Bool o -> Parser Value o | Parse a boolean value |
ParseString | Parse a String value |
ParseNumber | Parse a numeric value |
ParseArray | Parse an array |
ParseObject | Parse an object |
ParseList :: Parser Value o -> Parser Array (Vector o) | Parse a list of elements all in the same way |
ParseMap :: Parser Value v -> Parser Object (HashMap Text v) | Parse a map where the keys are the yaml keys |
ParseMapKeys :: Ord k => Parser Text k -> Parser Object (HashMap Text v) -> Parser Object (Map k v) | Parse a map's keys via a given parser |
ParseField | Parse a field of an object |
| |
ParsePure :: a -> Parser i a | A pure value |
ParseFmap :: (a -> b) -> Parser i a -> Parser i b | To implement Functor |
ParseAp :: Parser i (a -> b) -> Parser i a -> Parser i b | To implement Applicative |
ParseAlt :: [Parser i o] -> Parser i o | To implement Alternative |
ParseComment :: Text -> Parser i o -> Parser i o | Add comments to the parser. This info will be used in the schema for documentation. |
data FieldParser o where Source #
FieldParserRequired :: YamlParser o -> FieldParser o | |
FieldParserOptional :: YamlParser o -> FieldParser (Maybe o) | |
FieldParserOptionalWithDefault :: Show o => YamlParser o -> o -> FieldParser o |
type YamlParser a = Parser Value a Source #
type ObjectParser a = Parser Object a Source #
objectParser :: Text -> ObjectParser o -> YamlParser o Source #
Declare a parser of a named object
unnamedObjectParser :: ObjectParser o -> YamlParser o Source #
Declare a parser of an unnamed object
Prefer objectParser
if you can.
viaRead :: Read a => YamlParser a Source #
literalString :: Text -> YamlParser Text Source #
Declare a parser for an exact string.
You can use this to parse a constructor in an enum for example:
data Fruit = Apple | Banana instance YamlSchema Fruit where yamlSchema = Apple <$ literalString "Apple" <|> Banana <$ literalString "Banana"
literalShowValue :: Show a => a -> YamlParser a Source #
Declare a parser for a value using its show instance
Note that no value is read. The parsed string is just compared to the shown given value.
You can use this to parse a constructor in an enum when it has a Show
instance.
For example:
data Fruit = Apple | Banana | Melon deriving (Show, Eq) instance YamlSchema Fruit where yamlSchema = alternatives [ literalShowString Apple , literalShowString Banana , literalShowString Melon ]
literalValue :: ToJSON a => a -> YamlParser a Source #
Declare a parser for a value using its show instance
Note that no value is read. The parsed string is just compared to the shown given value.
You can use this to parse a constructor in an enum when it has a ToJSON
instance.
For example
data Fruit = Apple | Banana | Melon deriving (Eq, Generic) instance ToJSON Fruit instance YamlSchema Fruit where yamlSchema = alternatives [ literalValue Apple , literalValue Banana , literalValue Melon ]
alternatives :: [Parser i o] -> Parser i o Source #
Use the first parser of the given list that succeeds
You can use this to parse a constructor in an enum.
For example:
data Fruit = Apple | Banana | Melon instance YamlSchema Fruit where yamlSchema = alternatives [ Apple <$ literalString "Apple" , Banana <$ literalString "Banana" , Melon <$ literalString "Melon" ]
(<?>) :: Parser i a -> Text -> Parser i a Source #
Add a comment to a parser
This info will be used in the schema for documentation.
For example:
data Result = Error | Ok instance YamlSchema Result where yamlSchema = alternatives [ Error <$ literalString "Error" <?> "An error" , Ok <$ literalString "Ok" <?> "Oll Klear" ]
(<??>) :: Parser i a -> [Text] -> Parser i a Source #
Add a list of lines of comments to a parser
This info will be used in the schema for documentation.
For example:
data Result = Error | Ok instance YamlSchema Result where yamlSchema = alternatives [ Error <$ literalString "Error" <??> ["Just an error", "but I've got a lot to say about this"] , Ok <$ literalString "Ok" <??> ["Oll Klear", "I really don't know where 'OK' comes from?!"] ]
requiredFieldWith :: Text -> Text -> YamlParser a -> ObjectParser a Source #
A parser for a required field at a given key with a parser for what is found at that key
requiredFieldWith' :: Text -> YamlParser a -> ObjectParser a Source #
A parser for a required field at a given key with a parser for what is found at that key without a help text
optionalFieldWith :: Text -> Text -> YamlParser a -> ObjectParser (Maybe a) Source #
A parser for an optional field at a given key with a parser for what is found at that key
optionalFieldWith' :: Text -> YamlParser a -> ObjectParser (Maybe a) Source #
A parser for an optional field at a given key with a parser for what is found at that key without a help text
optionalFieldWithDefaultWith :: Show a => Text -> a -> Text -> YamlParser a -> ObjectParser a Source #
A parser for an optional field at a given key with a default value and a parser for what is found at that key
For the sake of documentation, the default value needs to be showable.
optionalFieldWithDefaultWith' :: Show a => Text -> a -> YamlParser a -> ObjectParser a Source #
A parser for an optional field at a given key with a default value and a parser for what is found at that key without a help text
For the sake of documentation, the default value needs to be showable.
maybeParser :: Show o => (o -> Maybe u) -> Parser i o -> Parser i u Source #
Make a parser that parses a value using the given extra parsing function
You can use this to make a parser for a type with a smart constructor.
Prefer eitherParser
if you can so you get better error messages.
Example:
parseUsername :: Text -> Maybe Username instance YamlSchema Username where yamlSchema = maybeParser parseUsername yamlSchema
eitherParser :: Show o => (o -> Either String u) -> Parser i o -> Parser i u Source #
Make a parser that parses a value using the given extra parsing function
You can use this to make a parser for a type with a smart constructor.
If you don't have a Show
instance for your o
, then you can use extraParser
instead.
Example:
parseUsername :: Text -> Either String Username instance YamlSchema Username where yamlSchema = eitherParser parseUsername yamlSchema
extraParser :: (o -> Parser u) -> Parser i o -> Parser i u Source #
Make a parser that parses a value using the given extra parsing function
You can use this to make a parser for a type with a smart constructor.
Prefer eitherParser
if you can, use this if you don't have a Show
instance for your o
.