{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TupleSections #-}
module Language.Alloy.Parser (
parseInstance,
) where
import qualified Data.ByteString.Char8 as BS (putStrLn)
import qualified Data.Set as S (fromList)
import qualified Data.Map as M
(alter, empty, insert, singleton)
import Control.Applicative ((<|>))
import Control.Monad (void)
import Control.Monad.IO.Class (MonadIO (liftIO))
import Control.Monad.Except (MonadError, throwError)
import Data.ByteString (ByteString)
import Data.Functor (($>))
import Data.List (intercalate)
import Data.List.Extra (unsnoc)
import Data.Maybe (fromJust)
import Data.Set (Set)
import Text.Trifecta
import Language.Alloy.Types (
AlloyInstance,
Annotation (..),
Entries,
Entry (..),
Object (..),
Relation (..),
Signature (..),
)
parseInstance
:: (MonadIO m, MonadError ErrInfo m)
=> ByteString
-> m AlloyInstance
parseInstance :: forall (m :: * -> *).
(MonadIO m, MonadError ErrInfo m) =>
ByteString -> m AlloyInstance
parseInstance ByteString
inst = case Parser [Entries (,)] -> Delta -> ByteString -> Result [Entries (,)]
forall a. Parser a -> Delta -> ByteString -> Result a
parseByteString Parser [Entries (,)]
alloyInstance Delta
forall a. Monoid a => a
mempty ByteString
inst of
Failure ErrInfo
l -> do
IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ ByteString -> IO ()
BS.putStrLn ByteString
"Failed parsing Alloys response as AlloyInstance:"
IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ ByteString -> IO ()
BS.putStrLn ByteString
inst
ErrInfo -> m AlloyInstance
forall a. ErrInfo -> m a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError ErrInfo
l
Success [Entries (,)]
r -> AlloyInstance -> m AlloyInstance
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (AlloyInstance -> m AlloyInstance)
-> AlloyInstance -> m AlloyInstance
forall a b. (a -> b) -> a -> b
$ [Entries (,)] -> AlloyInstance
combineEntries [Entries (,)]
r
combineEntries :: [Entries (,)] -> AlloyInstance
combineEntries :: [Entries (,)] -> AlloyInstance
combineEntries = (Entries (,) -> AlloyInstance -> AlloyInstance)
-> AlloyInstance -> [Entries (,)] -> AlloyInstance
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Entries (,) -> AlloyInstance -> AlloyInstance
forall {k} {b :: * -> *}.
Ord k =>
(k, Entry (,) b) -> Map k (Entry Map b) -> Map k (Entry Map b)
createOrInsert AlloyInstance
forall k a. Map k a
M.empty
where
createOrInsert :: (k, Entry (,) b) -> Map k (Entry Map b) -> Map k (Entry Map b)
createOrInsert (k
s, Entry (,) b
e) Map k (Entry Map b)
ys = (Maybe (Entry Map b) -> Maybe (Entry Map b))
-> k -> Map k (Entry Map b) -> Map k (Entry Map b)
forall k a.
Ord k =>
(Maybe a -> Maybe a) -> k -> Map k a -> Map k a
M.alter (Entry Map b -> Maybe (Entry Map b)
forall a. a -> Maybe a
Just (Entry Map b -> Maybe (Entry Map b))
-> (Maybe (Entry Map b) -> Entry Map b)
-> Maybe (Entry Map b)
-> Maybe (Entry Map b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Entry (,) b -> Maybe (Entry Map b) -> Entry Map b
forall {b :: * -> *}.
Entry (,) b -> Maybe (Entry Map b) -> Entry Map b
alterSig Entry (,) b
e) k
s Map k (Entry Map b)
ys
alterSig :: Entry (,) b -> Maybe (Entry Map b) -> Entry Map b
alterSig Entry (,) b
e Maybe (Entry Map b)
Nothing = Entry (,) b
e { relation :: Map [Char] (Relation b)
relation = ([Char] -> Relation b -> Map [Char] (Relation b))
-> ([Char], Relation b) -> Map [Char] (Relation b)
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry [Char] -> Relation b -> Map [Char] (Relation b)
forall k a. k -> a -> Map k a
M.singleton (([Char], Relation b) -> Map [Char] (Relation b))
-> ([Char], Relation b) -> Map [Char] (Relation b)
forall a b. (a -> b) -> a -> b
$ Entry (,) b -> ([Char], Relation b)
forall (a :: * -> * -> *) (b :: * -> *).
Entry a b -> a [Char] (Relation b)
relation Entry (,) b
e}
alterSig Entry (,) b
e (Just Entry Map b
y) = Entry Map b
y { relation :: Map [Char] (Relation b)
relation = ([Char]
-> Relation b
-> Map [Char] (Relation b)
-> Map [Char] (Relation b))
-> ([Char], Relation b)
-> Map [Char] (Relation b)
-> Map [Char] (Relation b)
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry [Char]
-> Relation b -> Map [Char] (Relation b) -> Map [Char] (Relation b)
forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert (Entry (,) b -> ([Char], Relation b)
forall (a :: * -> * -> *) (b :: * -> *).
Entry a b -> a [Char] (Relation b)
relation Entry (,) b
e) (Entry Map b -> Map [Char] (Relation b)
forall (a :: * -> * -> *) (b :: * -> *).
Entry a b -> a [Char] (Relation b)
relation Entry Map b
y) }
crlf :: Parser Char
crlf :: Parser Char
crlf = Char -> Parser Char
forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'\r' Parser Char -> Parser Char -> Parser Char
forall a b. Parser a -> Parser b -> Parser b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Char -> Parser Char
forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'\n'
endOfLine :: Parser Char
endOfLine :: Parser Char
endOfLine = Parser Char
forall (m :: * -> *). CharParsing m => m Char
newline Parser Char -> Parser Char -> Parser Char
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser Char
crlf
alloyInstance :: Parser [Entries (,)]
alloyInstance :: Parser [Entries (,)]
alloyInstance = [Entries (,)] -> [Entries (,)] -> [Entries (,)]
forall a. [a] -> [a] -> [a]
(++)
([Entries (,)] -> [Entries (,)] -> [Entries (,)])
-> Parser [Entries (,)] -> Parser ([Entries (,)] -> [Entries (,)])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Char] -> Parser [Entries (,)]
entrySection [Char]
"---INSTANCE---"
Parser ([Entries (,)] -> [Entries (,)])
-> Parser [Entries (,)] -> Parser [Entries (,)]
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [Char] -> Parser [Entries (,)]
entrySection [Char]
"------State 0-------"
where
entrySection :: [Char] -> Parser [Entries (,)]
entrySection [Char]
x = (Parser () -> Parser ()
forall a. Parser a -> Parser a
forall (m :: * -> *) a. Parsing m => m a -> m a
try (Parser Char -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Parser Char -> Parser ()) -> Parser Char -> Parser ()
forall a b. (a -> b) -> a -> b
$ [Char] -> Parser [Char]
forall (m :: * -> *). CharParsing m => [Char] -> m [Char]
string [Char]
x Parser [Char] -> Parser Char -> Parser Char
forall a b. Parser a -> Parser b -> Parser b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Char
endOfLine) Parser () -> Parser () -> Parser ()
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> () -> Parser ()
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return ())
Parser () -> Parser [Entries (,)] -> Parser [Entries (,)]
forall a b. Parser a -> Parser b -> Parser b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser (Entries (,)) -> Parser [Entries (,)]
forall a. Parser a -> Parser [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many Parser (Entries (,))
entry
entry :: Parser (Entries (,))
entry :: Parser (Entries (,))
entry = do
Maybe Annotation
entryAnnotation <- Parser (Maybe Annotation) -> Parser (Maybe Annotation)
forall a. Parser a -> Parser a
forall (m :: * -> *) a. Parsing m => m a -> m a
try ([Char] -> Parser [Char]
forall (m :: * -> *). CharParsing m => [Char] -> m [Char]
string [Char]
"skolem " Parser [Char] -> Maybe Annotation -> Parser (Maybe Annotation)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Annotation -> Maybe Annotation
forall a. a -> Maybe a
Just Annotation
Skolem) Parser (Maybe Annotation)
-> Parser (Maybe Annotation) -> Parser (Maybe Annotation)
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe Annotation -> Parser (Maybe Annotation)
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe Annotation
forall a. Maybe a
Nothing
Signature
entrySignature <- Parser Signature
sig
(Signature
entrySignature,)
(Entry (,) Set -> Entries (,))
-> Parser (Entry (,) Set) -> Parser (Entries (,))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Maybe Annotation -> ([Char], Relation Set) -> Entry (,) Set
forall (a :: * -> * -> *) (b :: * -> *).
Maybe Annotation -> a [Char] (Relation b) -> Entry a b
Entry Maybe Annotation
entryAnnotation
(([Char], Relation Set) -> Entry (,) Set)
-> Parser ([Char], Relation Set) -> Parser (Entry (,) Set)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((,)
([Char] -> Relation Set -> ([Char], Relation Set))
-> Parser [Char] -> Parser (Relation Set -> ([Char], Relation Set))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (([Char] -> Parser [Char]
forall (m :: * -> *). CharParsing m => [Char] -> m [Char]
string [Char]
"<:" Parser [Char] -> Parser [Char] -> Parser [Char]
forall a b. Parser a -> Parser b -> Parser b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser [Char]
word) Parser [Char] -> Parser [Char] -> Parser [Char]
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Parser [Char]
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure [Char]
"")
Parser (Relation Set -> ([Char], Relation Set))
-> Parser (Relation Set) -> Parser ([Char], Relation Set)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser (Relation Set)
parseRelations Parser ([Char], Relation Set)
-> Parser () -> Parser ([Char], Relation Set)
forall a b. Parser a -> Parser b -> Parser a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* (Parser Char -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Parser Char
endOfLine Parser () -> Parser () -> Parser ()
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser ()
forall (m :: * -> *). Parsing m => m ()
eof)))
sig :: Parser Signature
sig :: Parser Signature
sig = do
[[Char]]
xs' <- Parser [[Char]]
slashedWord
Signature -> Parser Signature
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return (Signature -> Parser Signature) -> Signature -> Parser Signature
forall a b. (a -> b) -> a -> b
$ case Maybe ([[Char]], [Char]) -> ([[Char]], [Char])
forall a. HasCallStack => Maybe a -> a
fromJust (Maybe ([[Char]], [Char]) -> ([[Char]], [Char]))
-> Maybe ([[Char]], [Char]) -> ([[Char]], [Char])
forall a b. (a -> b) -> a -> b
$ [[Char]] -> Maybe ([[Char]], [Char])
forall a. [a] -> Maybe ([a], a)
unsnoc [[Char]]
xs' of
([], [Char]
x) -> Maybe [Char] -> [Char] -> Signature
Signature Maybe [Char]
forall a. Maybe a
Nothing [Char]
x
([[Char]]
xs, [Char]
x) -> Maybe [Char] -> [Char] -> Signature
Signature ([Char] -> Maybe [Char]
forall a. a -> Maybe a
Just ([Char] -> Maybe [Char]) -> [Char] -> Maybe [Char]
forall a b. (a -> b) -> a -> b
$ [Char] -> [[Char]] -> [Char]
forall a. [a] -> [[a]] -> [a]
intercalate [Char]
"/" ([[Char]] -> [Char]) -> [[Char]] -> [Char]
forall a b. (a -> b) -> a -> b
$ Int -> [[Char]] -> [[Char]]
forall a. Int -> [a] -> [a]
take ([[Char]] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [[Char]]
xs') [[Char]]
xs) [Char]
x
parseRelations :: Parser (Relation Set)
parseRelations :: Parser (Relation Set)
parseRelations = Char -> Parser Char
forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'='
Parser Char -> Parser (Relation Set) -> Parser (Relation Set)
forall a b. Parser a -> Parser b -> Parser b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (Parser (Relation Set) -> Parser (Relation Set)
forall a. Parser a -> Parser a
forall (m :: * -> *) a. Parsing m => m a -> m a
try ([Char] -> Parser [Char]
forall (m :: * -> *). CharParsing m => [Char] -> m [Char]
string [Char]
"{}" Parser [Char] -> Relation Set -> Parser (Relation Set)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Relation Set
forall (a :: * -> *). Relation a
EmptyRelation)
Parser (Relation Set)
-> Parser (Relation Set) -> Parser (Relation Set)
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Object -> Relation Set
forall (a :: * -> *). Object -> Relation a
Id (Object -> Relation Set) -> Parser Object -> Parser (Relation Set)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Object -> Parser Object
forall a. Parser a -> Parser a
forall (m :: * -> *) a. Parsing m => m a -> m a
try Parser Object
object)
Parser (Relation Set)
-> Parser (Relation Set) -> Parser (Relation Set)
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Set (Object, Object, Object) -> Relation Set)
-> Parser (Set (Object, Object, Object)) -> Parser (Relation Set)
forall a b. (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Set (Object, Object, Object) -> Relation Set
forall (a :: * -> *). a (Object, Object, Object) -> Relation a
Triple (Parser (Set (Object, Object, Object))
-> Parser (Set (Object, Object, Object))
forall a. Parser a -> Parser a
forall (m :: * -> *) a. Parsing m => m a -> m a
try (Parser (Set (Object, Object, Object))
-> Parser (Set (Object, Object, Object)))
-> Parser (Set (Object, Object, Object))
-> Parser (Set (Object, Object, Object))
forall a b. (a -> b) -> a -> b
$ Parser (Object, Object, Object)
-> Parser (Set (Object, Object, Object))
forall {f :: * -> *} {a}.
(Ord a, CharParsing f) =>
f a -> f (Set a)
sep Parser (Object, Object, Object)
tripleRel)
Parser (Relation Set)
-> Parser (Relation Set) -> Parser (Relation Set)
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Set (Object, Object) -> Relation Set)
-> Parser (Set (Object, Object)) -> Parser (Relation Set)
forall a b. (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Set (Object, Object) -> Relation Set
forall (a :: * -> *). a (Object, Object) -> Relation a
Double (Parser (Set (Object, Object)) -> Parser (Set (Object, Object))
forall a. Parser a -> Parser a
forall (m :: * -> *) a. Parsing m => m a -> m a
try (Parser (Set (Object, Object)) -> Parser (Set (Object, Object)))
-> Parser (Set (Object, Object)) -> Parser (Set (Object, Object))
forall a b. (a -> b) -> a -> b
$ Parser (Object, Object) -> Parser (Set (Object, Object))
forall {f :: * -> *} {a}.
(Ord a, CharParsing f) =>
f a -> f (Set a)
sep Parser (Object, Object)
doubleRel)
Parser (Relation Set)
-> Parser (Relation Set) -> Parser (Relation Set)
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Set Object -> Relation Set)
-> Parser (Set Object) -> Parser (Relation Set)
forall a b. (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Set Object -> Relation Set
forall (a :: * -> *). a Object -> Relation a
Single (Parser Object -> Parser (Set Object)
forall {f :: * -> *} {a}.
(Ord a, CharParsing f) =>
f a -> f (Set a)
sep Parser Object
singleRel))
where
sep :: f a -> f (Set a)
sep f a
rel = [a] -> Set a
forall a. Ord a => [a] -> Set a
S.fromList
([a] -> Set a) -> f [a] -> f (Set a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f Char -> f Char -> f [a] -> f [a]
forall (m :: * -> *) bra ket a.
Applicative m =>
m bra -> m ket -> m a -> m a
between (Char -> f Char
forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'{') (Char -> f Char
forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'}') (f a
rel f a -> f [Char] -> f [a]
forall (m :: * -> *) a sep. Alternative m => m a -> m sep -> m [a]
`sepBy` [Char] -> f [Char]
forall (m :: * -> *). CharParsing m => [Char] -> m [Char]
string [Char]
", ")
tripleRel :: Parser (Object, Object, Object)
tripleRel = (,,) (Object -> Object -> Object -> (Object, Object, Object))
-> Parser Object
-> Parser (Object -> Object -> (Object, Object, Object))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Object
nextObject Parser (Object -> Object -> (Object, Object, Object))
-> Parser Object -> Parser (Object -> (Object, Object, Object))
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Object
nextObject Parser (Object -> (Object, Object, Object))
-> Parser Object -> Parser (Object, Object, Object)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Object
object
doubleRel :: Parser (Object, Object)
doubleRel = (,) (Object -> Object -> (Object, Object))
-> Parser Object -> Parser (Object -> (Object, Object))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Object
nextObject Parser (Object -> (Object, Object))
-> Parser Object -> Parser (Object, Object)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Object
object
singleRel :: Parser Object
singleRel = Parser Object
object
nextObject :: Parser Object
nextObject = Parser Object
object Parser Object -> Parser [Char] -> Parser Object
forall a b. Parser a -> Parser b -> Parser a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* [Char] -> Parser [Char]
forall (m :: * -> *). CharParsing m => [Char] -> m [Char]
string [Char]
"->"
object :: Parser Object
object :: Parser Object
object =
Parser Object -> Parser Object
forall a. Parser a -> Parser a
forall (m :: * -> *) a. Parsing m => m a -> m a
try ([Char] -> Int -> Object
Object ([Char] -> Int -> Object)
-> ([[Char]] -> [Char]) -> [[Char]] -> Int -> Object
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> [[Char]] -> [Char]
forall a. [a] -> [[a]] -> [a]
intercalate [Char]
"/" ([[Char]] -> Int -> Object)
-> Parser [[Char]] -> Parser (Int -> Object)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [[Char]]
slashedWord Parser (Int -> Object) -> Parser Char -> Parser (Int -> Object)
forall a b. Parser a -> Parser b -> Parser a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Char -> Parser Char
forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'$' Parser (Int -> Object) -> Parser Int -> Parser Object
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ([Char] -> Int
forall a. Read a => [Char] -> a
read ([Char] -> Int) -> Parser [Char] -> Parser Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Char -> Parser [Char]
forall a. Parser a -> Parser [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
some Parser Char
forall (m :: * -> *). CharParsing m => m Char
digit))
Parser Object -> Parser Object -> Parser Object
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser Object -> Parser Object
forall a. Parser a -> Parser a
forall (m :: * -> *) a. Parsing m => m a -> m a
try (Int -> Object
NumberObject (Int -> Object) -> Parser Int -> Parser Object
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Int
int)
Parser Object -> Parser Object -> Parser Object
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Object
NamedObject ([Char] -> Object) -> Parser [Char] -> Parser Object
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [Char]
word
int :: Parser Int
int :: Parser Int
int = ([Char] -> Int) -> Parser [Char] -> Parser Int
forall a b. (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Char] -> Int
forall a. Read a => [Char] -> a
read (Parser [Char] -> Parser Int) -> Parser [Char] -> Parser Int
forall a b. (a -> b) -> a -> b
$ [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
(++)
([Char] -> [Char] -> [Char])
-> Parser [Char] -> Parser ([Char] -> [Char])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Parser [Char] -> Parser [Char]
forall a. Parser a -> Parser a
forall (m :: * -> *) a. Parsing m => m a -> m a
try ([Char] -> Parser [Char]
forall (m :: * -> *). CharParsing m => [Char] -> m [Char]
string [Char]
"-") Parser [Char] -> Parser [Char] -> Parser [Char]
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Parser [Char]
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure [Char]
"")
Parser ([Char] -> [Char]) -> Parser [Char] -> Parser [Char]
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Char -> Parser [Char]
forall a. Parser a -> Parser [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
some Parser Char
forall (m :: * -> *). CharParsing m => m Char
digit
slashedWord :: Parser [String]
slashedWord :: Parser [[Char]]
slashedWord = Parser [Char]
word Parser [Char] -> Parser Char -> Parser [[Char]]
forall (m :: * -> *) a sep. Alternative m => m a -> m sep -> m [a]
`sepBy1` Char -> Parser Char
forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'/'
word :: Parser String
word :: Parser [Char]
word = (:)
(Char -> [Char] -> [Char])
-> Parser Char -> Parser ([Char] -> [Char])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Parser Char
forall (m :: * -> *). CharParsing m => m Char
letter Parser Char -> Parser Char -> Parser Char
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Char -> Parser Char
forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'$')
Parser ([Char] -> [Char]) -> Parser [Char] -> Parser [Char]
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Char -> Parser [Char]
forall a. Parser a -> Parser [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (Parser Char
forall (m :: * -> *). CharParsing m => m Char
letter Parser Char -> Parser Char -> Parser Char
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser Char
forall (m :: * -> *). CharParsing m => m Char
digit Parser Char -> Parser Char -> Parser Char
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Char -> Parser Char
forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'_' Parser Char -> Parser Char -> Parser Char
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Char -> Parser Char
forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'\'')