| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
YamlParse.Applicative.Parser
Synopsis
- data Parser i o where
- ParseAny :: Parser i i
- ParseMaybe :: (o -> Maybe u) -> Parser i o -> Parser i u
- ParseEq :: (Show o, Eq o) => o -> Text -> Parser i o -> Parser i 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)
- 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
- object :: Text -> ObjectParser o -> YamlParser o
- unnamedObject :: ObjectParser o -> YamlParser o
- 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
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.
Constructors
| ParseAny :: Parser i i | Return the input |
| ParseMaybe :: (o -> Maybe u) -> Parser i o -> Parser i u | Parse via a parser function |
| ParseEq | Match an exact value |
| 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 |
| ParseField | Parse a field of an object |
Fields
| |
| 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 #
Constructors
| 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 #
object :: Text -> ObjectParser o -> YamlParser o Source #
Declare a parser of a named object
unnamedObject :: ObjectParser o -> YamlParser o Source #
Declare a parser of an unnamed object
Prefer object if you can.
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.