{-# LANGUAGE OverloadedStrings #-} module SimpleParser.Examples.Sexp ( Sexp (..) , SexpF (..) , Atom (..) , SexpLabel (..) , SexpParserC , SexpParserM , sexpParser , recSexpParser ) where import Control.Applicative (empty) import Control.Monad (void) import Data.Char (isDigit, isSpace) import Data.Scientific (Scientific) import Data.Sequence (Seq) import Data.Text (Text) import qualified Data.Text as T import Data.Void (Void) import SimpleParser (Chunked (..), EmbedTextLabel (..), ExplainLabel (..), MatchBlock (..), MatchCase (..), Parser, TextLabel, TextualStream, anyToken, applySign, betweenParser, escapedStringParser, lexemeParser, lookAheadMatch, matchToken, numParser, packChunk, popChunk, satisfyToken, sepByParser, signParser, signedNumStartPred, spaceParser, takeTokensWhile) data Atom = AtomIdent !Text | AtomString !Text | AtomInt !Integer | AtomSci !Scientific deriving (Atom -> Atom -> Bool (Atom -> Atom -> Bool) -> (Atom -> Atom -> Bool) -> Eq Atom forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a /= :: Atom -> Atom -> Bool $c/= :: Atom -> Atom -> Bool == :: Atom -> Atom -> Bool $c== :: Atom -> Atom -> Bool Eq, Int -> Atom -> ShowS [Atom] -> ShowS Atom -> String (Int -> Atom -> ShowS) -> (Atom -> String) -> ([Atom] -> ShowS) -> Show Atom forall a. (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a showList :: [Atom] -> ShowS $cshowList :: [Atom] -> ShowS show :: Atom -> String $cshow :: Atom -> String showsPrec :: Int -> Atom -> ShowS $cshowsPrec :: Int -> Atom -> ShowS Show) data SexpF a = SexpAtom !Atom | SexpList !(Seq a) deriving (SexpF a -> SexpF a -> Bool (SexpF a -> SexpF a -> Bool) -> (SexpF a -> SexpF a -> Bool) -> Eq (SexpF a) forall a. Eq a => SexpF a -> SexpF a -> Bool forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a /= :: SexpF a -> SexpF a -> Bool $c/= :: forall a. Eq a => SexpF a -> SexpF a -> Bool == :: SexpF a -> SexpF a -> Bool $c== :: forall a. Eq a => SexpF a -> SexpF a -> Bool Eq, Int -> SexpF a -> ShowS [SexpF a] -> ShowS SexpF a -> String (Int -> SexpF a -> ShowS) -> (SexpF a -> String) -> ([SexpF a] -> ShowS) -> Show (SexpF a) forall a. Show a => Int -> SexpF a -> ShowS forall a. Show a => [SexpF a] -> ShowS forall a. Show a => SexpF a -> String forall a. (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a showList :: [SexpF a] -> ShowS $cshowList :: forall a. Show a => [SexpF a] -> ShowS show :: SexpF a -> String $cshow :: forall a. Show a => SexpF a -> String showsPrec :: Int -> SexpF a -> ShowS $cshowsPrec :: forall a. Show a => Int -> SexpF a -> ShowS Show, a -> SexpF b -> SexpF a (a -> b) -> SexpF a -> SexpF b (forall a b. (a -> b) -> SexpF a -> SexpF b) -> (forall a b. a -> SexpF b -> SexpF a) -> Functor SexpF forall a b. a -> SexpF b -> SexpF a forall a b. (a -> b) -> SexpF a -> SexpF b forall (f :: * -> *). (forall a b. (a -> b) -> f a -> f b) -> (forall a b. a -> f b -> f a) -> Functor f <$ :: a -> SexpF b -> SexpF a $c<$ :: forall a b. a -> SexpF b -> SexpF a fmap :: (a -> b) -> SexpF a -> SexpF b $cfmap :: forall a b. (a -> b) -> SexpF a -> SexpF b Functor, SexpF a -> Bool (a -> m) -> SexpF a -> m (a -> b -> b) -> b -> SexpF a -> b (forall m. Monoid m => SexpF m -> m) -> (forall m a. Monoid m => (a -> m) -> SexpF a -> m) -> (forall m a. Monoid m => (a -> m) -> SexpF a -> m) -> (forall a b. (a -> b -> b) -> b -> SexpF a -> b) -> (forall a b. (a -> b -> b) -> b -> SexpF a -> b) -> (forall b a. (b -> a -> b) -> b -> SexpF a -> b) -> (forall b a. (b -> a -> b) -> b -> SexpF a -> b) -> (forall a. (a -> a -> a) -> SexpF a -> a) -> (forall a. (a -> a -> a) -> SexpF a -> a) -> (forall a. SexpF a -> [a]) -> (forall a. SexpF a -> Bool) -> (forall a. SexpF a -> Int) -> (forall a. Eq a => a -> SexpF a -> Bool) -> (forall a. Ord a => SexpF a -> a) -> (forall a. Ord a => SexpF a -> a) -> (forall a. Num a => SexpF a -> a) -> (forall a. Num a => SexpF a -> a) -> Foldable SexpF forall a. Eq a => a -> SexpF a -> Bool forall a. Num a => SexpF a -> a forall a. Ord a => SexpF a -> a forall m. Monoid m => SexpF m -> m forall a. SexpF a -> Bool forall a. SexpF a -> Int forall a. SexpF a -> [a] forall a. (a -> a -> a) -> SexpF a -> a forall m a. Monoid m => (a -> m) -> SexpF a -> m forall b a. (b -> a -> b) -> b -> SexpF a -> b forall a b. (a -> b -> b) -> b -> SexpF a -> b forall (t :: * -> *). (forall m. Monoid m => t m -> m) -> (forall m a. Monoid m => (a -> m) -> t a -> m) -> (forall m a. Monoid m => (a -> m) -> t a -> m) -> (forall a b. (a -> b -> b) -> b -> t a -> b) -> (forall a b. (a -> b -> b) -> b -> t a -> b) -> (forall b a. (b -> a -> b) -> b -> t a -> b) -> (forall b a. (b -> a -> b) -> b -> t a -> b) -> (forall a. (a -> a -> a) -> t a -> a) -> (forall a. (a -> a -> a) -> t a -> a) -> (forall a. t a -> [a]) -> (forall a. t a -> Bool) -> (forall a. t a -> Int) -> (forall a. Eq a => a -> t a -> Bool) -> (forall a. Ord a => t a -> a) -> (forall a. Ord a => t a -> a) -> (forall a. Num a => t a -> a) -> (forall a. Num a => t a -> a) -> Foldable t product :: SexpF a -> a $cproduct :: forall a. Num a => SexpF a -> a sum :: SexpF a -> a $csum :: forall a. Num a => SexpF a -> a minimum :: SexpF a -> a $cminimum :: forall a. Ord a => SexpF a -> a maximum :: SexpF a -> a $cmaximum :: forall a. Ord a => SexpF a -> a elem :: a -> SexpF a -> Bool $celem :: forall a. Eq a => a -> SexpF a -> Bool length :: SexpF a -> Int $clength :: forall a. SexpF a -> Int null :: SexpF a -> Bool $cnull :: forall a. SexpF a -> Bool toList :: SexpF a -> [a] $ctoList :: forall a. SexpF a -> [a] foldl1 :: (a -> a -> a) -> SexpF a -> a $cfoldl1 :: forall a. (a -> a -> a) -> SexpF a -> a foldr1 :: (a -> a -> a) -> SexpF a -> a $cfoldr1 :: forall a. (a -> a -> a) -> SexpF a -> a foldl' :: (b -> a -> b) -> b -> SexpF a -> b $cfoldl' :: forall b a. (b -> a -> b) -> b -> SexpF a -> b foldl :: (b -> a -> b) -> b -> SexpF a -> b $cfoldl :: forall b a. (b -> a -> b) -> b -> SexpF a -> b foldr' :: (a -> b -> b) -> b -> SexpF a -> b $cfoldr' :: forall a b. (a -> b -> b) -> b -> SexpF a -> b foldr :: (a -> b -> b) -> b -> SexpF a -> b $cfoldr :: forall a b. (a -> b -> b) -> b -> SexpF a -> b foldMap' :: (a -> m) -> SexpF a -> m $cfoldMap' :: forall m a. Monoid m => (a -> m) -> SexpF a -> m foldMap :: (a -> m) -> SexpF a -> m $cfoldMap :: forall m a. Monoid m => (a -> m) -> SexpF a -> m fold :: SexpF m -> m $cfold :: forall m. Monoid m => SexpF m -> m Foldable, Functor SexpF Foldable SexpF Functor SexpF -> Foldable SexpF -> (forall (f :: * -> *) a b. Applicative f => (a -> f b) -> SexpF a -> f (SexpF b)) -> (forall (f :: * -> *) a. Applicative f => SexpF (f a) -> f (SexpF a)) -> (forall (m :: * -> *) a b. Monad m => (a -> m b) -> SexpF a -> m (SexpF b)) -> (forall (m :: * -> *) a. Monad m => SexpF (m a) -> m (SexpF a)) -> Traversable SexpF (a -> f b) -> SexpF a -> f (SexpF b) forall (t :: * -> *). Functor t -> Foldable t -> (forall (f :: * -> *) a b. Applicative f => (a -> f b) -> t a -> f (t b)) -> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a)) -> (forall (m :: * -> *) a b. Monad m => (a -> m b) -> t a -> m (t b)) -> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a)) -> Traversable t forall (m :: * -> *) a. Monad m => SexpF (m a) -> m (SexpF a) forall (f :: * -> *) a. Applicative f => SexpF (f a) -> f (SexpF a) forall (m :: * -> *) a b. Monad m => (a -> m b) -> SexpF a -> m (SexpF b) forall (f :: * -> *) a b. Applicative f => (a -> f b) -> SexpF a -> f (SexpF b) sequence :: SexpF (m a) -> m (SexpF a) $csequence :: forall (m :: * -> *) a. Monad m => SexpF (m a) -> m (SexpF a) mapM :: (a -> m b) -> SexpF a -> m (SexpF b) $cmapM :: forall (m :: * -> *) a b. Monad m => (a -> m b) -> SexpF a -> m (SexpF b) sequenceA :: SexpF (f a) -> f (SexpF a) $csequenceA :: forall (f :: * -> *) a. Applicative f => SexpF (f a) -> f (SexpF a) traverse :: (a -> f b) -> SexpF a -> f (SexpF b) $ctraverse :: forall (f :: * -> *) a b. Applicative f => (a -> f b) -> SexpF a -> f (SexpF b) $cp2Traversable :: Foldable SexpF $cp1Traversable :: Functor SexpF Traversable) data SexpLabel = SexpLabelIdentStart | SexpLabelEmbedText !TextLabel | SexpLabelCustom !Text deriving (SexpLabel -> SexpLabel -> Bool (SexpLabel -> SexpLabel -> Bool) -> (SexpLabel -> SexpLabel -> Bool) -> Eq SexpLabel forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a /= :: SexpLabel -> SexpLabel -> Bool $c/= :: SexpLabel -> SexpLabel -> Bool == :: SexpLabel -> SexpLabel -> Bool $c== :: SexpLabel -> SexpLabel -> Bool Eq, Int -> SexpLabel -> ShowS [SexpLabel] -> ShowS SexpLabel -> String (Int -> SexpLabel -> ShowS) -> (SexpLabel -> String) -> ([SexpLabel] -> ShowS) -> Show SexpLabel forall a. (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a showList :: [SexpLabel] -> ShowS $cshowList :: [SexpLabel] -> ShowS show :: SexpLabel -> String $cshow :: SexpLabel -> String showsPrec :: Int -> SexpLabel -> ShowS $cshowsPrec :: Int -> SexpLabel -> ShowS Show) instance ExplainLabel SexpLabel where explainLabel :: SexpLabel -> Builder explainLabel SexpLabel sl = case SexpLabel sl of SexpLabel SexpLabelIdentStart -> Builder "start of identifier" SexpLabelEmbedText TextLabel tl -> TextLabel -> Builder forall l. ExplainLabel l => l -> Builder explainLabel TextLabel tl SexpLabel _ -> Builder forall a. HasCallStack => a undefined instance EmbedTextLabel SexpLabel where embedTextLabel :: TextLabel -> SexpLabel embedTextLabel = TextLabel -> SexpLabel SexpLabelEmbedText newtype Sexp = Sexp { Sexp -> SexpF Sexp unSexp :: SexpF Sexp } deriving (Sexp -> Sexp -> Bool (Sexp -> Sexp -> Bool) -> (Sexp -> Sexp -> Bool) -> Eq Sexp forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a /= :: Sexp -> Sexp -> Bool $c/= :: Sexp -> Sexp -> Bool == :: Sexp -> Sexp -> Bool $c== :: Sexp -> Sexp -> Bool Eq, Int -> Sexp -> ShowS [Sexp] -> ShowS Sexp -> String (Int -> Sexp -> ShowS) -> (Sexp -> String) -> ([Sexp] -> ShowS) -> Show Sexp forall a. (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a showList :: [Sexp] -> ShowS $cshowList :: [Sexp] -> ShowS show :: Sexp -> String $cshow :: Sexp -> String showsPrec :: Int -> Sexp -> ShowS $cshowsPrec :: Int -> Sexp -> ShowS Show) type SexpParserC s = TextualStream s type SexpParserM s a = Parser SexpLabel s Void a sexpParser :: SexpParserC s => SexpParserM s Sexp sexpParser :: SexpParserM s Sexp sexpParser = let p :: SexpParserM s Sexp p = (SexpF Sexp -> Sexp) -> ParserT SexpLabel s Void Identity (SexpF Sexp) -> SexpParserM s Sexp forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap SexpF Sexp -> Sexp Sexp (SexpParserM s Sexp -> ParserT SexpLabel s Void Identity (SexpF Sexp) forall s a. SexpParserC s => SexpParserM s a -> SexpParserM s (SexpF a) recSexpParser SexpParserM s Sexp p) in SexpParserM s Sexp p recSexpParser :: SexpParserC s => SexpParserM s a -> SexpParserM s (SexpF a) recSexpParser :: SexpParserM s a -> SexpParserM s (SexpF a) recSexpParser SexpParserM s a root = MatchBlock SexpLabel s Void Identity Char (SexpF a) -> SexpParserM s (SexpF a) forall (m :: * -> *) l s e a b. Monad m => MatchBlock l s e m a b -> ParserT l s e m b lookAheadMatch MatchBlock SexpLabel s Void Identity Char (SexpF a) block where block :: MatchBlock SexpLabel s Void Identity Char (SexpF a) block = ParserT SexpLabel s Void Identity Char -> SexpParserM s (SexpF a) -> [MatchCase SexpLabel s Void Identity Char (SexpF a)] -> MatchBlock SexpLabel s Void Identity Char (SexpF a) forall l s e (m :: * -> *) a b. ParserT l s e m a -> ParserT l s e m b -> [MatchCase l s e m a b] -> MatchBlock l s e m a b MatchBlock ParserT SexpLabel s Void Identity Char forall s (m :: * -> *) l e. (Stream s, Monad m) => ParserT l s e m (Token s) anyToken ((Atom -> SexpF a) -> ParserT SexpLabel s Void Identity Atom -> SexpParserM s (SexpF a) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap Atom -> SexpF a forall a. Atom -> SexpF a SexpAtom ParserT SexpLabel s Void Identity Atom forall s. SexpParserC s => SexpParserM s Atom atomP) [ Maybe SexpLabel -> (Char -> Bool) -> SexpParserM s (SexpF a) -> MatchCase SexpLabel s Void Identity Char (SexpF a) forall l s e (m :: * -> *) a b. Maybe l -> (a -> Bool) -> ParserT l s e m b -> MatchCase l s e m a b MatchCase Maybe SexpLabel forall a. Maybe a Nothing (Char -> Char -> Bool forall a. Eq a => a -> a -> Bool == Char '(') ((Seq a -> SexpF a) -> ParserT SexpLabel s Void Identity (Seq a) -> SexpParserM s (SexpF a) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap Seq a -> SexpF a forall a. Seq a -> SexpF a SexpList (SexpParserM s a -> ParserT SexpLabel s Void Identity (Seq a) forall s a. SexpParserC s => SexpParserM s a -> SexpParserM s (Seq a) listP SexpParserM s a root)) ] nonDelimPred :: Char -> Bool nonDelimPred :: Char -> Bool nonDelimPred Char c = Char c Char -> Char -> Bool forall a. Eq a => a -> a -> Bool /= Char '(' Bool -> Bool -> Bool && Char c Char -> Char -> Bool forall a. Eq a => a -> a -> Bool /= Char ')' Bool -> Bool -> Bool && Bool -> Bool not (Char -> Bool isSpace Char c) identStartPred :: Char -> Bool identStartPred :: Char -> Bool identStartPred Char c = Bool -> Bool not (Char -> Bool isDigit Char c) Bool -> Bool -> Bool && Char -> Bool identContPred Char c identContPred :: Char -> Bool identContPred :: Char -> Bool identContPred Char c = Char c Char -> Char -> Bool forall a. Eq a => a -> a -> Bool /= Char '"' Bool -> Bool -> Bool && Char -> Bool nonDelimPred Char c stringP :: SexpParserC s => SexpParserM s Text stringP :: SexpParserM s Text stringP = (Chunk s -> Text) -> ParserT SexpLabel s Void Identity (Chunk s) -> SexpParserM s Text forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap Chunk s -> Text forall chunk. TextualChunked chunk => chunk -> Text packChunk (Char -> ParserT SexpLabel s Void Identity (Chunk s) forall s (m :: * -> *) l e. (Stream s, Token s ~ Char, Monad m) => Char -> ParserT l s e m (Chunk s) escapedStringParser Char '"') identifierP :: SexpParserC s => SexpParserM s Text identifierP :: SexpParserM s Text identifierP = do Char x <- Maybe SexpLabel -> (Token s -> Bool) -> ParserT SexpLabel s Void Identity (Token s) forall s (m :: * -> *) l e. (Stream s, Monad m) => Maybe l -> (Token s -> Bool) -> ParserT l s e m (Token s) satisfyToken (SexpLabel -> Maybe SexpLabel forall a. a -> Maybe a Just SexpLabel SexpLabelIdentStart) Char -> Bool Token s -> Bool identStartPred Chunk s xs <- (Token s -> Bool) -> ParserT SexpLabel s Void Identity (Chunk s) forall s (m :: * -> *) l e. (Stream s, Monad m) => (Token s -> Bool) -> ParserT l s e m (Chunk s) takeTokensWhile Char -> Bool Token s -> Bool identContPred Text -> SexpParserM s Text forall (f :: * -> *) a. Applicative f => a -> f a pure (Chunk s -> Text forall chunk. TextualChunked chunk => chunk -> Text packChunk (Char -> Chunk s -> Chunk s forall chunk token. Chunked chunk token => token -> chunk -> chunk consChunk Char x Chunk s xs)) spaceP :: SexpParserC s => SexpParserM s () spaceP :: SexpParserM s () spaceP = SexpParserM s () forall s (m :: * -> *) l e. (Stream s, Token s ~ Char, Monad m) => ParserT l s e m () spaceParser lexP :: SexpParserC s => SexpParserM s a -> SexpParserM s a lexP :: SexpParserM s a -> SexpParserM s a lexP = ParserT SexpLabel s Void Identity () -> SexpParserM s a -> SexpParserM s a forall (m :: * -> *) l s e a. Monad m => ParserT l s e m () -> ParserT l s e m a -> ParserT l s e m a lexemeParser ParserT SexpLabel s Void Identity () forall s. SexpParserC s => SexpParserM s () spaceP openParenP :: SexpParserC s => SexpParserM s () openParenP :: SexpParserM s () openParenP = SexpParserM s () -> SexpParserM s () forall s a. SexpParserC s => SexpParserM s a -> SexpParserM s a lexP (ParserT SexpLabel s Void Identity Char -> SexpParserM s () forall (f :: * -> *) a. Functor f => f a -> f () void (Token s -> ParserT SexpLabel s Void Identity (Token s) forall s (m :: * -> *) l e. (Stream s, Monad m, Eq (Token s)) => Token s -> ParserT l s e m (Token s) matchToken Char Token s '(')) closeParenP :: SexpParserC s => SexpParserM s () closeParenP :: SexpParserM s () closeParenP = SexpParserM s () -> SexpParserM s () forall s a. SexpParserC s => SexpParserM s a -> SexpParserM s a lexP (ParserT SexpLabel s Void Identity Char -> SexpParserM s () forall (f :: * -> *) a. Functor f => f a -> f () void (Token s -> ParserT SexpLabel s Void Identity (Token s) forall s (m :: * -> *) l e. (Stream s, Monad m, Eq (Token s)) => Token s -> ParserT l s e m (Token s) matchToken Char Token s ')')) numAtomP :: SexpParserC s => SexpParserM s Atom numAtomP :: SexpParserM s Atom numAtomP = do Maybe Sign ms <- ParserT SexpLabel s Void Identity (Maybe Sign) forall s (m :: * -> *) l e. (Stream s, Token s ~ Char, Monad m) => ParserT l s e m (Maybe Sign) signParser Either Integer Scientific n <- ParserT SexpLabel s Void Identity (Either Integer Scientific) forall l s (m :: * -> *) e. (EmbedTextLabel l, Stream s, Token s ~ Char, Monad m) => ParserT l s e m (Either Integer Scientific) numParser case Either Integer Scientific n of Left Integer i -> Atom -> SexpParserM s Atom forall (f :: * -> *) a. Applicative f => a -> f a pure (Integer -> Atom AtomInt (Maybe Sign -> Integer -> Integer forall a. Num a => Maybe Sign -> a -> a applySign Maybe Sign ms Integer i)) Right Scientific s -> Atom -> SexpParserM s Atom forall (f :: * -> *) a. Applicative f => a -> f a pure (Scientific -> Atom AtomSci (Maybe Sign -> Scientific -> Scientific forall a. Num a => Maybe Sign -> a -> a applySign Maybe Sign ms Scientific s)) chunk1 :: SexpParserC s => SexpParserM s Text chunk1 :: SexpParserM s Text chunk1 = do Maybe (Chunk s) mc <- Int -> ParserT SexpLabel s Void Identity (Maybe (Chunk s)) forall s (m :: * -> *) l e. (Stream s, Monad m) => Int -> ParserT l s e m (Maybe (Chunk s)) popChunk Int 2 case Maybe (Chunk s) mc of Just Chunk s c | Bool -> Bool not (Chunk s -> Bool forall chunk token. Chunked chunk token => chunk -> Bool chunkEmpty Chunk s c) -> Text -> SexpParserM s Text forall (f :: * -> *) a. Applicative f => a -> f a pure (Chunk s -> Text forall chunk. TextualChunked chunk => chunk -> Text packChunk Chunk s c) Maybe (Chunk s) _ -> SexpParserM s Text forall (f :: * -> *) a. Alternative f => f a empty unaryIdentPred :: Char -> Text -> Bool unaryIdentPred :: Char -> Text -> Bool unaryIdentPred Char u Text t0 = case Text -> Maybe (Char, Text) T.uncons Text t0 of Just (Char c0, Text t1) | Char u Char -> Char -> Bool forall a. Eq a => a -> a -> Bool == Char c0 -> case Text -> Maybe (Char, Text) T.uncons Text t1 of Just (Char c1, Text _) -> Bool -> Bool not (Char -> Bool isDigit Char c1) Maybe (Char, Text) Nothing -> Bool True Maybe (Char, Text) _ -> Bool False identAtomP :: SexpParserC s => SexpParserM s Atom identAtomP :: SexpParserM s Atom identAtomP = (Text -> Atom) -> ParserT SexpLabel s Void Identity Text -> SexpParserM s Atom forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap Text -> Atom AtomIdent ParserT SexpLabel s Void Identity Text forall s. SexpParserC s => SexpParserM s Text identifierP atomP :: SexpParserC s => SexpParserM s Atom atomP :: SexpParserM s Atom atomP = SexpParserM s Atom -> SexpParserM s Atom forall s a. SexpParserC s => SexpParserM s a -> SexpParserM s a lexP (MatchBlock SexpLabel s Void Identity Text Atom -> SexpParserM s Atom forall (m :: * -> *) l s e a b. Monad m => MatchBlock l s e m a b -> ParserT l s e m b lookAheadMatch MatchBlock SexpLabel s Void Identity Text Atom block) where block :: MatchBlock SexpLabel s Void Identity Text Atom block = ParserT SexpLabel s Void Identity Text -> SexpParserM s Atom -> [MatchCase SexpLabel s Void Identity Text Atom] -> MatchBlock SexpLabel s Void Identity Text Atom forall l s e (m :: * -> *) a b. ParserT l s e m a -> ParserT l s e m b -> [MatchCase l s e m a b] -> MatchBlock l s e m a b MatchBlock ParserT SexpLabel s Void Identity Text forall s. SexpParserC s => SexpParserM s Text chunk1 (String -> SexpParserM s Atom forall (m :: * -> *) a. MonadFail m => String -> m a fail String "failed to parse sexp atom") [ Maybe SexpLabel -> (Text -> Bool) -> SexpParserM s Atom -> MatchCase SexpLabel s Void Identity Text Atom forall l s e (m :: * -> *) a b. Maybe l -> (a -> Bool) -> ParserT l s e m b -> MatchCase l s e m a b MatchCase Maybe SexpLabel forall a. Maybe a Nothing ((Char -> Char -> Bool forall a. Eq a => a -> a -> Bool == Char '"') (Char -> Bool) -> (Text -> Char) -> Text -> Bool forall b c a. (b -> c) -> (a -> b) -> a -> c . Text -> Char T.head) ((Text -> Atom) -> ParserT SexpLabel s Void Identity Text -> SexpParserM s Atom forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap Text -> Atom AtomString ParserT SexpLabel s Void Identity Text forall s. SexpParserC s => SexpParserM s Text stringP) , Maybe SexpLabel -> (Text -> Bool) -> SexpParserM s Atom -> MatchCase SexpLabel s Void Identity Text Atom forall l s e (m :: * -> *) a b. Maybe l -> (a -> Bool) -> ParserT l s e m b -> MatchCase l s e m a b MatchCase Maybe SexpLabel forall a. Maybe a Nothing (Char -> Text -> Bool unaryIdentPred Char '+') SexpParserM s Atom forall s. SexpParserC s => SexpParserM s Atom identAtomP , Maybe SexpLabel -> (Text -> Bool) -> SexpParserM s Atom -> MatchCase SexpLabel s Void Identity Text Atom forall l s e (m :: * -> *) a b. Maybe l -> (a -> Bool) -> ParserT l s e m b -> MatchCase l s e m a b MatchCase Maybe SexpLabel forall a. Maybe a Nothing (Char -> Text -> Bool unaryIdentPred Char '-') SexpParserM s Atom forall s. SexpParserC s => SexpParserM s Atom identAtomP , Maybe SexpLabel -> (Text -> Bool) -> SexpParserM s Atom -> MatchCase SexpLabel s Void Identity Text Atom forall l s e (m :: * -> *) a b. Maybe l -> (a -> Bool) -> ParserT l s e m b -> MatchCase l s e m a b MatchCase Maybe SexpLabel forall a. Maybe a Nothing (Char -> Bool signedNumStartPred (Char -> Bool) -> (Text -> Char) -> Text -> Bool forall b c a. (b -> c) -> (a -> b) -> a -> c . Text -> Char T.head) SexpParserM s Atom forall s. SexpParserC s => SexpParserM s Atom numAtomP , Maybe SexpLabel -> (Text -> Bool) -> SexpParserM s Atom -> MatchCase SexpLabel s Void Identity Text Atom forall l s e (m :: * -> *) a b. Maybe l -> (a -> Bool) -> ParserT l s e m b -> MatchCase l s e m a b MatchCase Maybe SexpLabel forall a. Maybe a Nothing (Char -> Bool identStartPred (Char -> Bool) -> (Text -> Char) -> Text -> Bool forall b c a. (b -> c) -> (a -> b) -> a -> c . Text -> Char T.head) SexpParserM s Atom forall s. SexpParserC s => SexpParserM s Atom identAtomP ] listP :: SexpParserC s => SexpParserM s a -> SexpParserM s (Seq a) listP :: SexpParserM s a -> SexpParserM s (Seq a) listP SexpParserM s a root = SexpParserM s (Seq a) -> SexpParserM s (Seq a) forall s a. SexpParserC s => SexpParserM s a -> SexpParserM s a lexP (ParserT SexpLabel s Void Identity () -> ParserT SexpLabel s Void Identity () -> SexpParserM s (Seq a) -> SexpParserM s (Seq a) forall (m :: * -> *) l s e a. Monad m => ParserT l s e m () -> ParserT l s e m () -> ParserT l s e m a -> ParserT l s e m a betweenParser ParserT SexpLabel s Void Identity () forall s. SexpParserC s => SexpParserM s () openParenP ParserT SexpLabel s Void Identity () forall s. SexpParserC s => SexpParserM s () closeParenP (SexpParserM s a -> ParserT SexpLabel s Void Identity () -> SexpParserM s (Seq a) forall seq elem (m :: * -> *) l s e. (Chunked seq elem, Monad m) => ParserT l s e m elem -> ParserT l s e m () -> ParserT l s e m seq sepByParser SexpParserM s a root ParserT SexpLabel s Void Identity () forall s. SexpParserC s => SexpParserM s () spaceP))