{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeFamilies #-}
module Data.XML.Parser.High.NameParser
( NameParser(..)
, anyName
, anyNameExcept
) where
import Control.Applicative
import Control.Arrow
import Control.Monad
import Data.String
import Data.XML.Parser.Low
newtype NameParser a = NameParser { runNameParser :: QName -> Maybe a }
deriving instance Functor NameParser
deriving via (WrappedArrow (Kleisli Maybe) QName) instance Applicative NameParser
deriving via (WrappedArrow (Kleisli Maybe) QName) instance Alternative NameParser
instance (a ~ ()) => IsString (NameParser a) where
fromString s = NameParser $ \(QName _ name) ->
unless (fromString s == name) mempty
anyName :: NameParser QName
anyName = NameParser Just
anyNameExcept :: QName -> NameParser QName
anyNameExcept name = NameParser $ \name' -> do
guard $ name /= name'
return name'