Copyright | (c) Eric Mertens 2023 |
---|---|
License | ISC |
Maintainer | emertens@gmail.com |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
This type helps to build up computations that can validate a TOML value and compute some application-specific representation.
It supports warning messages which can be used to deprecate old configuration options and to detect unused table keys.
It supports tracking multiple error messages when you have more than one decoding option and all of them have failed.
Use prettyMatchMessage
for an easy way to make human
readable strings from matcher outputs.
Synopsis
- data Matcher l a
- data Result e a
- data MatchMessage a = MatchMessage {}
- runMatcher :: Matcher l a -> Result (MatchMessage l) a
- withScope :: Scope -> Matcher l a -> Matcher l a
- getScope :: Matcher a [Scope]
- warn :: String -> Matcher a ()
- warnAt :: l -> String -> Matcher l ()
- failAt :: l -> String -> Matcher l a
- runMatcherIgnoreWarn :: Matcher l a -> Either [MatchMessage l] a
- runMatcherFatalWarn :: Matcher l a -> Either [MatchMessage l] a
- data Scope
- inKey :: Text -> Matcher l a -> Matcher l a
- inIndex :: Int -> Matcher l a -> Matcher l a
Types
Computations that result in a Result
and which track a list
of nested contexts to assist in generating warnings and error
messages.
Computation outcome with error and warning messages. Multiple error messages can occur when multiple alternatives all fail. Resolving any one of the error messages could allow the computation to succeed.
Instances
(Read e, Read a) => Read (Result e a) Source # | Default instance |
(Show e, Show a) => Show (Result e a) Source # | Default instance |
(Eq e, Eq a) => Eq (Result e a) Source # | Default instance |
(Ord e, Ord a) => Ord (Result e a) Source # | Default instance |
data MatchMessage a Source #
A message emitted while matching a TOML value. The message is paired with the path to the value that was in focus when the message was generated. These message get used for both warnings and errors.
For a convenient way to render these to a string, see prettyMatchMessage
.
Instances
Operations
runMatcher :: Matcher l a -> Result (MatchMessage l) a Source #
Run a Matcher
with an empty scope.
withScope :: Scope -> Matcher l a -> Matcher l a Source #
Run a Matcher
with a locally extended scope.
failAt :: l -> String -> Matcher l a Source #
Terminate the match with an error mentioning the given annotation.
Run helpers
runMatcherIgnoreWarn :: Matcher l a -> Either [MatchMessage l] a Source #
Run Matcher
and ignore warnings.
runMatcherFatalWarn :: Matcher l a -> Either [MatchMessage l] a Source #
Run Matcher
and treat warnings as errors.
Scope helpers
Scopes for TOML message.
ScopeIndex Int | zero-based array index |
ScopeKey Text | key in a table |