toml-parser-2.0.0.0: TOML 1.0.0 parser
Copyright(c) Eric Mertens 2023
LicenseISC
Maintaineremertens@gmail.com
Safe HaskellSafe-Inferred
LanguageHaskell2010

Toml.Schema.Matcher

Description

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

Types

data Matcher l a Source #

Computations that result in a Result and which track a list of nested contexts to assist in generating warnings and error messages.

Use withScope to run a Matcher in a new, nested scope.

Instances

Instances details
MonadFail (Matcher a) Source #

Fail with an error message without an annotation.

Instance details

Defined in Toml.Schema.Matcher

Methods

fail :: String -> Matcher a a0 #

Alternative (Matcher a) Source # 
Instance details

Defined in Toml.Schema.Matcher

Methods

empty :: Matcher a a0 #

(<|>) :: Matcher a a0 -> Matcher a a0 -> Matcher a a0 #

some :: Matcher a a0 -> Matcher a [a0] #

many :: Matcher a a0 -> Matcher a [a0] #

Applicative (Matcher a) Source # 
Instance details

Defined in Toml.Schema.Matcher

Methods

pure :: a0 -> Matcher a a0 #

(<*>) :: Matcher a (a0 -> b) -> Matcher a a0 -> Matcher a b #

liftA2 :: (a0 -> b -> c) -> Matcher a a0 -> Matcher a b -> Matcher a c #

(*>) :: Matcher a a0 -> Matcher a b -> Matcher a b #

(<*) :: Matcher a a0 -> Matcher a b -> Matcher a a0 #

Functor (Matcher a) Source # 
Instance details

Defined in Toml.Schema.Matcher

Methods

fmap :: (a0 -> b) -> Matcher a a0 -> Matcher a b #

(<$) :: a0 -> Matcher a b -> Matcher a a0 #

Monad (Matcher a) Source # 
Instance details

Defined in Toml.Schema.Matcher

Methods

(>>=) :: Matcher a a0 -> (a0 -> Matcher a b) -> Matcher a b #

(>>) :: Matcher a a0 -> Matcher a b -> Matcher a b #

return :: a0 -> Matcher a a0 #

MonadPlus (Matcher a) Source # 
Instance details

Defined in Toml.Schema.Matcher

Methods

mzero :: Matcher a a0 #

mplus :: Matcher a a0 -> Matcher a a0 -> Matcher a a0 #

data Result e a Source #

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.

Constructors

Failure [e]

error messages

Success [e] a

warning messages and result

Instances

Instances details
(Read e, Read a) => Read (Result e a) Source #

Default instance

Instance details

Defined in Toml.Schema.Matcher

(Show e, Show a) => Show (Result e a) Source #

Default instance

Instance details

Defined in Toml.Schema.Matcher

Methods

showsPrec :: Int -> Result e a -> ShowS #

show :: Result e a -> String #

showList :: [Result e a] -> ShowS #

(Eq e, Eq a) => Eq (Result e a) Source #

Default instance

Instance details

Defined in Toml.Schema.Matcher

Methods

(==) :: Result e a -> Result e a -> Bool #

(/=) :: Result e a -> Result e a -> Bool #

(Ord e, Ord a) => Ord (Result e a) Source #

Default instance

Instance details

Defined in Toml.Schema.Matcher

Methods

compare :: Result e a -> Result e a -> Ordering #

(<) :: Result e a -> Result e a -> Bool #

(<=) :: Result e a -> Result e a -> Bool #

(>) :: Result e a -> Result e a -> Bool #

(>=) :: Result e a -> Result e a -> Bool #

max :: Result e a -> Result e a -> Result e a #

min :: Result e a -> Result e a -> Result e a #

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.

Constructors

MatchMessage 

Fields

Instances

Instances details
Foldable MatchMessage Source # 
Instance details

Defined in Toml.Schema.Matcher

Methods

fold :: Monoid m => MatchMessage m -> m #

foldMap :: Monoid m => (a -> m) -> MatchMessage a -> m #

foldMap' :: Monoid m => (a -> m) -> MatchMessage a -> m #

foldr :: (a -> b -> b) -> b -> MatchMessage a -> b #

foldr' :: (a -> b -> b) -> b -> MatchMessage a -> b #

foldl :: (b -> a -> b) -> b -> MatchMessage a -> b #

foldl' :: (b -> a -> b) -> b -> MatchMessage a -> b #

foldr1 :: (a -> a -> a) -> MatchMessage a -> a #

foldl1 :: (a -> a -> a) -> MatchMessage a -> a #

toList :: MatchMessage a -> [a] #

null :: MatchMessage a -> Bool #

length :: MatchMessage a -> Int #

elem :: Eq a => a -> MatchMessage a -> Bool #

maximum :: Ord a => MatchMessage a -> a #

minimum :: Ord a => MatchMessage a -> a #

sum :: Num a => MatchMessage a -> a #

product :: Num a => MatchMessage a -> a #

Traversable MatchMessage Source # 
Instance details

Defined in Toml.Schema.Matcher

Methods

traverse :: Applicative f => (a -> f b) -> MatchMessage a -> f (MatchMessage b) #

sequenceA :: Applicative f => MatchMessage (f a) -> f (MatchMessage a) #

mapM :: Monad m => (a -> m b) -> MatchMessage a -> m (MatchMessage b) #

sequence :: Monad m => MatchMessage (m a) -> m (MatchMessage a) #

Functor MatchMessage Source # 
Instance details

Defined in Toml.Schema.Matcher

Methods

fmap :: (a -> b) -> MatchMessage a -> MatchMessage b #

(<$) :: a -> MatchMessage b -> MatchMessage a #

Read a => Read (MatchMessage a) Source #

Default instance

Instance details

Defined in Toml.Schema.Matcher

Show a => Show (MatchMessage a) Source #

Default instance

Instance details

Defined in Toml.Schema.Matcher

Eq a => Eq (MatchMessage a) Source #

Default instance

Instance details

Defined in Toml.Schema.Matcher

Ord a => Ord (MatchMessage a) Source #

Default instance

Instance details

Defined in Toml.Schema.Matcher

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.

getScope :: Matcher a [Scope] Source #

Get the current list of scopes.

warn :: String -> Matcher a () Source #

Emit a warning without an annotation.

warnAt :: l -> String -> Matcher l () Source #

Emit a warning mentioning the given annotation.

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

data Scope Source #

Scopes for TOML message.

Constructors

ScopeIndex Int

zero-based array index

ScopeKey Text

key in a table

Instances

Instances details
Read Scope Source #

Default instance

Instance details

Defined in Toml.Schema.Matcher

Show Scope Source #

Default instance

Instance details

Defined in Toml.Schema.Matcher

Methods

showsPrec :: Int -> Scope -> ShowS #

show :: Scope -> String #

showList :: [Scope] -> ShowS #

Eq Scope Source #

Default instance

Instance details

Defined in Toml.Schema.Matcher

Methods

(==) :: Scope -> Scope -> Bool #

(/=) :: Scope -> Scope -> Bool #

Ord Scope Source #

Default instance

Instance details

Defined in Toml.Schema.Matcher

Methods

compare :: Scope -> Scope -> Ordering #

(<) :: Scope -> Scope -> Bool #

(<=) :: Scope -> Scope -> Bool #

(>) :: Scope -> Scope -> Bool #

(>=) :: Scope -> Scope -> Bool #

max :: Scope -> Scope -> Scope #

min :: Scope -> Scope -> Scope #

inKey :: Text -> Matcher l a -> Matcher l a Source #

Update the scope with the message corresponding to a table key

inIndex :: Int -> Matcher l a -> Matcher l a Source #

Update the scope with the message corresponding to an array index