{-# OPTIONS_GHC -Wno-orphans #-}
module IsString () where
import GHC.Exts (IsString (..))
import Text.Parsec (eof, parse)
import Parser (clause, term, vname)
import Syntax (Clause (..), Term (..), VariableName)
instance IsString Clause where
fromString :: String -> Clause
fromString String
s =
case Parsec String () ProgramClause
-> String -> String -> Either ParseError ProgramClause
forall s t a.
Stream s Identity t =>
Parsec s () a -> String -> s -> Either ParseError a
parse (Parsec String () ProgramClause
clause Parsec String () ProgramClause
-> ParsecT String () Identity () -> Parsec String () ProgramClause
forall a b.
ParsecT String () Identity a
-> ParsecT String () Identity b -> ParsecT String () Identity a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT String () Identity ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof) String
"(Clause literal)" String
s of
Left ParseError
e -> String -> Clause
forall a. HasCallStack => String -> a
error (ParseError -> String
forall a. Show a => a -> String
show ParseError
e)
Right (String
name, [Term]
args, [Term]
goals) -> String -> [Term] -> [Term] -> Clause
Clause String
name [Term]
args [Term]
goals
instance IsString Term where
fromString :: String -> Term
fromString String
s =
case Parsec String () Term -> String -> String -> Either ParseError Term
forall s t a.
Stream s Identity t =>
Parsec s () a -> String -> s -> Either ParseError a
parse (Parsec String () Term
term Parsec String () Term
-> ParsecT String () Identity () -> Parsec String () Term
forall a b.
ParsecT String () Identity a
-> ParsecT String () Identity b -> ParsecT String () Identity a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT String () Identity ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof) String
"(Term literal)" String
s of
Left ParseError
e -> String -> Term
forall a. HasCallStack => String -> a
error (ParseError -> String
forall a. Show a => a -> String
show ParseError
e)
Right Term
c -> Term
c
instance IsString VariableName where
fromString :: String -> VariableName
fromString String
s =
case Parsec String () VariableName
-> String -> String -> Either ParseError VariableName
forall s t a.
Stream s Identity t =>
Parsec s () a -> String -> s -> Either ParseError a
parse (Parsec String () VariableName
vname Parsec String () VariableName
-> ParsecT String () Identity () -> Parsec String () VariableName
forall a b.
ParsecT String () Identity a
-> ParsecT String () Identity b -> ParsecT String () Identity a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT String () Identity ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof) String
"(VariableName literal)" String
s of
Left ParseError
e -> String -> VariableName
forall a. HasCallStack => String -> a
error (ParseError -> String
forall a. Show a => a -> String
show ParseError
e)
Right VariableName
c -> VariableName
c