module RDF.Parse where
import Common.Parsec
import Common.Lexer
import Common.AnnoParser (newlineOrEof)
import Common.Token (criticalKeywords)
import Common.IRI
import qualified Common.GlobalAnnotations as GA (PrefixMap)
import OWL2.AS
import OWL2.Parse hiding (stringLiteral, literal, skips, uriP)
import RDF.AS
import RDF.Symbols
import Data.Either
import qualified Data.Map as Map
import Text.ParserCombinators.Parsec
uriP :: CharParser st IRI
uriP :: CharParser st IRI
uriP =
CharParser st IRI -> CharParser st IRI
forall st a. CharParser st a -> CharParser st a
skips (CharParser st IRI -> CharParser st IRI)
-> CharParser st IRI -> CharParser st IRI
forall a b. (a -> b) -> a -> b
$ CharParser st IRI -> CharParser st IRI
forall tok st a. GenParser tok st a -> GenParser tok st a
try (CharParser st IRI -> CharParser st IRI)
-> CharParser st IRI -> CharParser st IRI
forall a b. (a -> b) -> a -> b
$ (IRI -> String)
-> CharParser st IRI -> (IRI -> Bool) -> CharParser st IRI
forall a tok st.
(a -> String)
-> GenParser tok st a -> (a -> Bool) -> GenParser tok st a
checkWithUsing IRI -> String
showIRI CharParser st IRI
forall st. CharParser st IRI
uriQ ((IRI -> Bool) -> CharParser st IRI)
-> (IRI -> Bool) -> CharParser st IRI
forall a b. (a -> b) -> a -> b
$ \ q :: IRI
q ->
Bool -> Bool
not (String -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (String -> Bool) -> String -> Bool
forall a b. (a -> b) -> a -> b
$ IRI -> String
prefixName IRI
q) Bool -> Bool -> Bool
|| String -> [String] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
notElem (Id -> String
forall a. Show a => a -> String
show (Id -> String) -> Id -> String
forall a b. (a -> b) -> a -> b
$ IRI -> Id
iriPath IRI
q) [String]
criticalKeywords
rdfEntityType :: CharParser st RDFEntityType
rdfEntityType :: CharParser st RDFEntityType
rdfEntityType = [CharParser st RDFEntityType] -> CharParser st RDFEntityType
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice ([CharParser st RDFEntityType] -> CharParser st RDFEntityType)
-> [CharParser st RDFEntityType] -> CharParser st RDFEntityType
forall a b. (a -> b) -> a -> b
$ (RDFEntityType -> CharParser st RDFEntityType)
-> [RDFEntityType] -> [CharParser st RDFEntityType]
forall a b. (a -> b) -> [a] -> [b]
map (\ f :: RDFEntityType
f -> String -> CharParser st String
forall st. String -> CharParser st String
keyword (RDFEntityType -> String
forall a. Show a => a -> String
show RDFEntityType
f) CharParser st String
-> CharParser st RDFEntityType -> CharParser st RDFEntityType
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> RDFEntityType -> CharParser st RDFEntityType
forall (m :: * -> *) a. Monad m => a -> m a
return RDFEntityType
f)
[RDFEntityType]
rdfEntityTypes
rdfSymbItems :: GenParser Char st SymbItems
rdfSymbItems :: GenParser Char st SymbItems
rdfSymbItems = do
Maybe RDFEntityType
ext <- ParsecT String st Identity RDFEntityType
-> ParsecT String st Identity (Maybe RDFEntityType)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe ParsecT String st Identity RDFEntityType
forall st. CharParser st RDFEntityType
rdfEntityType
[IRI]
iris <- GenParser Char st [IRI]
forall st. GenParser Char st [IRI]
rdfSymbs
SymbItems -> GenParser Char st SymbItems
forall (m :: * -> *) a. Monad m => a -> m a
return (SymbItems -> GenParser Char st SymbItems)
-> SymbItems -> GenParser Char st SymbItems
forall a b. (a -> b) -> a -> b
$ Maybe RDFEntityType -> [IRI] -> SymbItems
SymbItems Maybe RDFEntityType
ext [IRI]
iris
rdfSymbs :: GenParser Char st [IRI]
rdfSymbs :: GenParser Char st [IRI]
rdfSymbs = CharParser st IRI
forall st. CharParser st IRI
uriP CharParser st IRI
-> (IRI -> GenParser Char st [IRI]) -> GenParser Char st [IRI]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \ u :: IRI
u -> do
CharParser st ()
forall st. CharParser st ()
commaP CharParser st () -> CharParser st IRI -> CharParser st ()
forall tok st a b.
GenParser tok st a -> GenParser tok st b -> GenParser tok st a
`followedWith` CharParser st IRI
forall st. CharParser st IRI
uriP
[IRI]
us <- GenParser Char st [IRI]
forall st. GenParser Char st [IRI]
rdfSymbs
[IRI] -> GenParser Char st [IRI]
forall (m :: * -> *) a. Monad m => a -> m a
return ([IRI] -> GenParser Char st [IRI])
-> [IRI] -> GenParser Char st [IRI]
forall a b. (a -> b) -> a -> b
$ IRI
u IRI -> [IRI] -> [IRI]
forall a. a -> [a] -> [a]
: [IRI]
us
GenParser Char st [IRI]
-> GenParser Char st [IRI] -> GenParser Char st [IRI]
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> [IRI] -> GenParser Char st [IRI]
forall (m :: * -> *) a. Monad m => a -> m a
return [IRI
u]
rdfSymbMapItems :: GenParser Char st SymbMapItems
rdfSymbMapItems :: GenParser Char st SymbMapItems
rdfSymbMapItems = do
Maybe RDFEntityType
ext <- ParsecT String st Identity RDFEntityType
-> ParsecT String st Identity (Maybe RDFEntityType)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe ParsecT String st Identity RDFEntityType
forall st. CharParser st RDFEntityType
rdfEntityType
[(IRI, Maybe IRI)]
iris <- GenParser Char st [(IRI, Maybe IRI)]
forall st. GenParser Char st [(IRI, Maybe IRI)]
rdfSymbPairs
SymbMapItems -> GenParser Char st SymbMapItems
forall (m :: * -> *) a. Monad m => a -> m a
return (SymbMapItems -> GenParser Char st SymbMapItems)
-> SymbMapItems -> GenParser Char st SymbMapItems
forall a b. (a -> b) -> a -> b
$ Maybe RDFEntityType -> [(IRI, Maybe IRI)] -> SymbMapItems
SymbMapItems Maybe RDFEntityType
ext [(IRI, Maybe IRI)]
iris
rdfSymbPairs :: GenParser Char st [(IRI, Maybe IRI)]
rdfSymbPairs :: GenParser Char st [(IRI, Maybe IRI)]
rdfSymbPairs = GenParser Char st (IRI, Maybe IRI)
forall st. GenParser Char st (IRI, Maybe IRI)
uriPair GenParser Char st (IRI, Maybe IRI)
-> ((IRI, Maybe IRI) -> GenParser Char st [(IRI, Maybe IRI)])
-> GenParser Char st [(IRI, Maybe IRI)]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \ u :: (IRI, Maybe IRI)
u -> do
CharParser st ()
forall st. CharParser st ()
commaP CharParser st () -> GenParser Char st IRI -> CharParser st ()
forall tok st a b.
GenParser tok st a -> GenParser tok st b -> GenParser tok st a
`followedWith` GenParser Char st IRI
forall st. CharParser st IRI
uriP
[(IRI, Maybe IRI)]
us <- GenParser Char st [(IRI, Maybe IRI)]
forall st. GenParser Char st [(IRI, Maybe IRI)]
rdfSymbPairs
[(IRI, Maybe IRI)] -> GenParser Char st [(IRI, Maybe IRI)]
forall (m :: * -> *) a. Monad m => a -> m a
return ([(IRI, Maybe IRI)] -> GenParser Char st [(IRI, Maybe IRI)])
-> [(IRI, Maybe IRI)] -> GenParser Char st [(IRI, Maybe IRI)]
forall a b. (a -> b) -> a -> b
$ (IRI, Maybe IRI)
u (IRI, Maybe IRI) -> [(IRI, Maybe IRI)] -> [(IRI, Maybe IRI)]
forall a. a -> [a] -> [a]
: [(IRI, Maybe IRI)]
us
GenParser Char st [(IRI, Maybe IRI)]
-> GenParser Char st [(IRI, Maybe IRI)]
-> GenParser Char st [(IRI, Maybe IRI)]
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> [(IRI, Maybe IRI)] -> GenParser Char st [(IRI, Maybe IRI)]
forall (m :: * -> *) a. Monad m => a -> m a
return [(IRI, Maybe IRI)
u]
skips :: CharParser st a -> CharParser st a
skips :: CharParser st a -> CharParser st a
skips = (CharParser st a -> ParsecT String st Identity () -> CharParser st a
forall (m :: * -> *) a b. Monad m => m a -> m b -> m a
<< ParsecT String st Identity () -> ParsecT String st Identity ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany
(ParsecT String st Identity Char -> ParsecT String st Identity ()
forall (m :: * -> *) a. Monad m => m a -> m ()
forget ParsecT String st Identity Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
space ParsecT String st Identity ()
-> ParsecT String st Identity () -> ParsecT String st Identity ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String st Identity ()
forall st. CharParser st ()
parseComment ParsecT String st Identity ()
-> ParsecT String st Identity () -> ParsecT String st Identity ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String st Identity ()
forall st. CharParser st ()
nestCommentOut ParsecT String st Identity ()
-> String -> ParsecT String st Identity ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> String -> ParsecT s u m a
<?> ""))
charOrQuoteEscape :: CharParser st String
charOrQuoteEscape :: CharParser st String
charOrQuoteEscape = CharParser st String -> CharParser st String
forall tok st a. GenParser tok st a -> GenParser tok st a
try (String -> CharParser st String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string "\\\"") CharParser st String
-> CharParser st String -> CharParser st String
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Char -> String)
-> ParsecT String st Identity Char -> CharParser st String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Char -> String
forall (m :: * -> *) a. Monad m => a -> m a
return ParsecT String st Identity Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
anyChar
longLiteral :: CharParser st (String, Bool)
longLiteral :: CharParser st (String, Bool)
longLiteral = do
String -> ParsecT String st Identity String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string "\"\"\""
String
ls <- ParsecT String st Identity [String]
-> ParsecT String st Identity String
forall (m :: * -> *) a. Monad m => m [[a]] -> m [a]
flat (ParsecT String st Identity [String]
-> ParsecT String st Identity String)
-> ParsecT String st Identity [String]
-> ParsecT String st Identity String
forall a b. (a -> b) -> a -> b
$ ParsecT String st Identity String
-> ParsecT String st Identity String
-> ParsecT String st Identity [String]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill ParsecT String st Identity String
forall st. CharParser st String
charOrQuoteEscape (ParsecT String st Identity String
-> ParsecT String st Identity [String])
-> ParsecT String st Identity String
-> ParsecT String st Identity [String]
forall a b. (a -> b) -> a -> b
$ ParsecT String st Identity String
-> ParsecT String st Identity String
forall tok st a. GenParser tok st a -> GenParser tok st a
try (ParsecT String st Identity String
-> ParsecT String st Identity String)
-> ParsecT String st Identity String
-> ParsecT String st Identity String
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String st Identity String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string "\"\"\""
(String, Bool) -> CharParser st (String, Bool)
forall (m :: * -> *) a. Monad m => a -> m a
return (String
ls, Bool
True)
shortLiteral :: CharParser st (String, Bool)
shortLiteral :: CharParser st (String, Bool)
shortLiteral = do
Char -> ParsecT String st Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '"'
String
ls <- ParsecT String st Identity [String]
-> ParsecT String st Identity String
forall (m :: * -> *) a. Monad m => m [[a]] -> m [a]
flat (ParsecT String st Identity [String]
-> ParsecT String st Identity String)
-> ParsecT String st Identity [String]
-> ParsecT String st Identity String
forall a b. (a -> b) -> a -> b
$ ParsecT String st Identity String
-> ParsecT String st Identity String
-> ParsecT String st Identity [String]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill ParsecT String st Identity String
forall st. CharParser st String
charOrQuoteEscape (ParsecT String st Identity String
-> ParsecT String st Identity [String])
-> ParsecT String st Identity String
-> ParsecT String st Identity [String]
forall a b. (a -> b) -> a -> b
$ ParsecT String st Identity String
-> ParsecT String st Identity String
forall tok st a. GenParser tok st a -> GenParser tok st a
try (ParsecT String st Identity String
-> ParsecT String st Identity String)
-> ParsecT String st Identity String
-> ParsecT String st Identity String
forall a b. (a -> b) -> a -> b
$ String -> ParsecT String st Identity String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string "\""
(String, Bool) -> CharParser st (String, Bool)
forall (m :: * -> *) a. Monad m => a -> m a
return (String
ls, Bool
False)
stringLiteral :: CharParser st RDFLiteral
stringLiteral :: CharParser st RDFLiteral
stringLiteral = do
(s :: String
s, b :: Bool
b) <- GenParser Char st (String, Bool)
-> GenParser Char st (String, Bool)
forall tok st a. GenParser tok st a -> GenParser tok st a
try GenParser Char st (String, Bool)
forall st. CharParser st (String, Bool)
longLiteral GenParser Char st (String, Bool)
-> GenParser Char st (String, Bool)
-> GenParser Char st (String, Bool)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> GenParser Char st (String, Bool)
forall st. CharParser st (String, Bool)
shortLiteral
do
String -> ParsecT String st Identity String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string String
cTypeS
IRI
d <- CharParser st IRI
forall st. CharParser st IRI
datatypeUri
RDFLiteral -> CharParser st RDFLiteral
forall (m :: * -> *) a. Monad m => a -> m a
return (RDFLiteral -> CharParser st RDFLiteral)
-> RDFLiteral -> CharParser st RDFLiteral
forall a b. (a -> b) -> a -> b
$ Bool -> String -> TypedOrUntyped -> RDFLiteral
RDFLiteral Bool
b String
s (TypedOrUntyped -> RDFLiteral) -> TypedOrUntyped -> RDFLiteral
forall a b. (a -> b) -> a -> b
$ IRI -> TypedOrUntyped
Typed IRI
d
CharParser st RDFLiteral
-> CharParser st RDFLiteral -> CharParser st RDFLiteral
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> do
String -> ParsecT String st Identity String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string "@"
Maybe String
t <- CharParser st (Maybe String) -> CharParser st (Maybe String)
forall st a. CharParser st a -> CharParser st a
skips (CharParser st (Maybe String) -> CharParser st (Maybe String))
-> CharParser st (Maybe String) -> CharParser st (Maybe String)
forall a b. (a -> b) -> a -> b
$ ParsecT String st Identity String -> CharParser st (Maybe String)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe ParsecT String st Identity String
forall st. CharParser st String
languageTag
RDFLiteral -> CharParser st RDFLiteral
forall (m :: * -> *) a. Monad m => a -> m a
return (RDFLiteral -> CharParser st RDFLiteral)
-> RDFLiteral -> CharParser st RDFLiteral
forall a b. (a -> b) -> a -> b
$ Bool -> String -> TypedOrUntyped -> RDFLiteral
RDFLiteral Bool
b String
s (TypedOrUntyped -> RDFLiteral) -> TypedOrUntyped -> RDFLiteral
forall a b. (a -> b) -> a -> b
$ Maybe String -> TypedOrUntyped
Untyped Maybe String
t
CharParser st RDFLiteral
-> CharParser st RDFLiteral -> CharParser st RDFLiteral
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> CharParser st RDFLiteral -> CharParser st RDFLiteral
forall st a. CharParser st a -> CharParser st a
skips (RDFLiteral -> CharParser st RDFLiteral
forall (m :: * -> *) a. Monad m => a -> m a
return (RDFLiteral -> CharParser st RDFLiteral)
-> RDFLiteral -> CharParser st RDFLiteral
forall a b. (a -> b) -> a -> b
$ Bool -> String -> TypedOrUntyped -> RDFLiteral
RDFLiteral Bool
b String
s (TypedOrUntyped -> RDFLiteral) -> TypedOrUntyped -> RDFLiteral
forall a b. (a -> b) -> a -> b
$ IRI -> TypedOrUntyped
Typed (IRI -> TypedOrUntyped) -> IRI -> TypedOrUntyped
forall a b. (a -> b) -> a -> b
$ String -> IRI
mkIRI "string")
literal :: CharParser st RDFLiteral
literal :: CharParser st RDFLiteral
literal = do
FloatLit
f <- CharParser st FloatLit -> CharParser st FloatLit
forall st a. CharParser st a -> CharParser st a
skips (CharParser st FloatLit -> CharParser st FloatLit)
-> CharParser st FloatLit -> CharParser st FloatLit
forall a b. (a -> b) -> a -> b
$ CharParser st FloatLit -> CharParser st FloatLit
forall tok st a. GenParser tok st a -> GenParser tok st a
try CharParser st FloatLit
forall st. CharParser st FloatLit
floatingPointLit
CharParser st FloatLit
-> CharParser st FloatLit -> CharParser st FloatLit
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (DecLit -> FloatLit)
-> ParsecT String st Identity DecLit -> CharParser st FloatLit
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap DecLit -> FloatLit
decToFloat ParsecT String st Identity DecLit
forall st. CharParser st DecLit
decimalLit
RDFLiteral -> CharParser st RDFLiteral
forall (m :: * -> *) a. Monad m => a -> m a
return (RDFLiteral -> CharParser st RDFLiteral)
-> RDFLiteral -> CharParser st RDFLiteral
forall a b. (a -> b) -> a -> b
$ FloatLit -> RDFLiteral
RDFNumberLit FloatLit
f
CharParser st RDFLiteral
-> CharParser st RDFLiteral -> CharParser st RDFLiteral
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> CharParser st RDFLiteral
forall st. CharParser st RDFLiteral
stringLiteral
parseBase :: CharParser st Base
parseBase :: CharParser st Base
parseBase = do
String -> CharParser st ()
forall st. String -> CharParser st ()
pkeyword "@base"
IRI
base <- CharParser st IRI -> CharParser st IRI
forall st a. CharParser st a -> CharParser st a
skips CharParser st IRI
forall st. CharParser st IRI
uriP
CharParser st Char -> CharParser st Char
forall st a. CharParser st a -> CharParser st a
skips (CharParser st Char -> CharParser st Char)
-> CharParser st Char -> CharParser st Char
forall a b. (a -> b) -> a -> b
$ Char -> CharParser st Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '.'
Base -> CharParser st Base
forall (m :: * -> *) a. Monad m => a -> m a
return (Base -> CharParser st Base) -> Base -> CharParser st Base
forall a b. (a -> b) -> a -> b
$ IRI -> Base
Base IRI
base
parsePrefix :: CharParser st Prefix
parsePrefix :: CharParser st Prefix
parsePrefix = do
String -> CharParser st ()
forall st. String -> CharParser st ()
pkeyword "@prefix"
String
p <- CharParser st String -> CharParser st String
forall st a. CharParser st a -> CharParser st a
skips (String -> CharParser st String -> CharParser st String
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option "" CharParser st String
forall st. CharParser st String
prefix CharParser st String
-> ParsecT String st Identity Char -> CharParser st String
forall (m :: * -> *) a b. Monad m => m a -> m b -> m a
<< Char -> ParsecT String st Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char ':')
IRI
i <- CharParser st IRI -> CharParser st IRI
forall st a. CharParser st a -> CharParser st a
skips CharParser st IRI
forall st. CharParser st IRI
uriP
ParsecT String st Identity Char -> ParsecT String st Identity Char
forall st a. CharParser st a -> CharParser st a
skips (ParsecT String st Identity Char
-> ParsecT String st Identity Char)
-> ParsecT String st Identity Char
-> ParsecT String st Identity Char
forall a b. (a -> b) -> a -> b
$ Char -> ParsecT String st Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '.'
Prefix -> CharParser st Prefix
forall (m :: * -> *) a. Monad m => a -> m a
return (Prefix -> CharParser st Prefix) -> Prefix -> CharParser st Prefix
forall a b. (a -> b) -> a -> b
$ String -> IRI -> Prefix
PrefixR String
p IRI
i
parsePredicate :: CharParser st Predicate
parsePredicate :: CharParser st Predicate
parsePredicate = (IRI -> Predicate)
-> ParsecT String st Identity IRI -> CharParser st Predicate
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap IRI -> Predicate
Predicate (ParsecT String st Identity IRI -> CharParser st Predicate)
-> ParsecT String st Identity IRI -> CharParser st Predicate
forall a b. (a -> b) -> a -> b
$ ParsecT String st Identity IRI -> ParsecT String st Identity IRI
forall st a. CharParser st a -> CharParser st a
skips ParsecT String st Identity IRI
forall st. CharParser st IRI
uriP
parseSubject :: CharParser st Subject
parseSubject :: CharParser st Subject
parseSubject =
(IRI -> Subject)
-> ParsecT String st Identity IRI -> CharParser st Subject
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap IRI -> Subject
Subject (ParsecT String st Identity IRI -> ParsecT String st Identity IRI
forall st a. CharParser st a -> CharParser st a
skips ParsecT String st Identity IRI
forall st. CharParser st IRI
uriP)
CharParser st Subject
-> CharParser st Subject -> CharParser st Subject
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ([PredicateObjectList] -> Subject)
-> ParsecT String st Identity [PredicateObjectList]
-> CharParser st Subject
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [PredicateObjectList] -> Subject
SubjectList
(ParsecT String st Identity Char
-> ParsecT String st Identity Char
-> ParsecT String st Identity [PredicateObjectList]
-> ParsecT String st Identity [PredicateObjectList]
forall s (m :: * -> *) t u open close a.
Stream s m t =>
ParsecT s u m open
-> ParsecT s u m close -> ParsecT s u m a -> ParsecT s u m a
between (ParsecT String st Identity Char -> ParsecT String st Identity Char
forall st a. CharParser st a -> CharParser st a
skips (ParsecT String st Identity Char
-> ParsecT String st Identity Char)
-> ParsecT String st Identity Char
-> ParsecT String st Identity Char
forall a b. (a -> b) -> a -> b
$ Char -> ParsecT String st Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '[') (ParsecT String st Identity Char -> ParsecT String st Identity Char
forall st a. CharParser st a -> CharParser st a
skips (ParsecT String st Identity Char
-> ParsecT String st Identity Char)
-> ParsecT String st Identity Char
-> ParsecT String st Identity Char
forall a b. (a -> b) -> a -> b
$ Char -> ParsecT String st Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char ']') (ParsecT String st Identity [PredicateObjectList]
-> ParsecT String st Identity [PredicateObjectList])
-> ParsecT String st Identity [PredicateObjectList]
-> ParsecT String st Identity [PredicateObjectList]
forall a b. (a -> b) -> a -> b
$ ParsecT String st Identity [PredicateObjectList]
-> ParsecT String st Identity [PredicateObjectList]
forall st a. CharParser st a -> CharParser st a
skips ParsecT String st Identity [PredicateObjectList]
forall st. CharParser st [PredicateObjectList]
parsePredObjList)
CharParser st Subject
-> CharParser st Subject -> CharParser st Subject
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ([Object] -> Subject)
-> ParsecT String st Identity [Object] -> CharParser st Subject
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Object] -> Subject
SubjectCollection
(ParsecT String st Identity Char
-> ParsecT String st Identity Char
-> ParsecT String st Identity [Object]
-> ParsecT String st Identity [Object]
forall s (m :: * -> *) t u open close a.
Stream s m t =>
ParsecT s u m open
-> ParsecT s u m close -> ParsecT s u m a -> ParsecT s u m a
between (ParsecT String st Identity Char -> ParsecT String st Identity Char
forall st a. CharParser st a -> CharParser st a
skips (ParsecT String st Identity Char
-> ParsecT String st Identity Char)
-> ParsecT String st Identity Char
-> ParsecT String st Identity Char
forall a b. (a -> b) -> a -> b
$ Char -> ParsecT String st Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '(') (ParsecT String st Identity Char -> ParsecT String st Identity Char
forall st a. CharParser st a -> CharParser st a
skips (ParsecT String st Identity Char
-> ParsecT String st Identity Char)
-> ParsecT String st Identity Char
-> ParsecT String st Identity Char
forall a b. (a -> b) -> a -> b
$ Char -> ParsecT String st Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char ')') (ParsecT String st Identity [Object]
-> ParsecT String st Identity [Object])
-> ParsecT String st Identity [Object]
-> ParsecT String st Identity [Object]
forall a b. (a -> b) -> a -> b
$ ParsecT String st Identity Object
-> ParsecT String st Identity [Object]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT String st Identity Object
forall st. CharParser st Object
parseObject)
parseObject :: CharParser st Object
parseObject :: CharParser st Object
parseObject = (RDFLiteral -> Object)
-> ParsecT String st Identity RDFLiteral -> CharParser st Object
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap RDFLiteral -> Object
ObjectLiteral ParsecT String st Identity RDFLiteral
forall st. CharParser st RDFLiteral
literal CharParser st Object
-> CharParser st Object -> CharParser st Object
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Subject -> Object)
-> ParsecT String st Identity Subject -> CharParser st Object
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Subject -> Object
Object ParsecT String st Identity Subject
forall st. CharParser st Subject
parseSubject
parsePredObjects :: CharParser st PredicateObjectList
parsePredObjects :: CharParser st PredicateObjectList
parsePredObjects = do
Predicate
pr <- CharParser st Predicate
forall st. CharParser st Predicate
parsePredicate
[Object]
objs <- ParsecT String st Identity Object
-> ParsecT String st Identity Char
-> ParsecT String st Identity [Object]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
sepBy ParsecT String st Identity Object
forall st. CharParser st Object
parseObject (ParsecT String st Identity Char
-> ParsecT String st Identity [Object])
-> ParsecT String st Identity Char
-> ParsecT String st Identity [Object]
forall a b. (a -> b) -> a -> b
$ ParsecT String st Identity Char -> ParsecT String st Identity Char
forall st a. CharParser st a -> CharParser st a
skips (ParsecT String st Identity Char
-> ParsecT String st Identity Char)
-> ParsecT String st Identity Char
-> ParsecT String st Identity Char
forall a b. (a -> b) -> a -> b
$ Char -> ParsecT String st Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char ','
PredicateObjectList -> CharParser st PredicateObjectList
forall (m :: * -> *) a. Monad m => a -> m a
return (PredicateObjectList -> CharParser st PredicateObjectList)
-> PredicateObjectList -> CharParser st PredicateObjectList
forall a b. (a -> b) -> a -> b
$ Predicate -> [Object] -> PredicateObjectList
PredicateObjectList Predicate
pr [Object]
objs
parsePredObjList :: CharParser st [PredicateObjectList]
parsePredObjList :: CharParser st [PredicateObjectList]
parsePredObjList = ParsecT String st Identity PredicateObjectList
-> ParsecT String st Identity Char
-> CharParser st [PredicateObjectList]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
sepEndBy ParsecT String st Identity PredicateObjectList
forall st. CharParser st PredicateObjectList
parsePredObjects (ParsecT String st Identity Char
-> CharParser st [PredicateObjectList])
-> ParsecT String st Identity Char
-> CharParser st [PredicateObjectList]
forall a b. (a -> b) -> a -> b
$ ParsecT String st Identity Char -> ParsecT String st Identity Char
forall st a. CharParser st a -> CharParser st a
skips (ParsecT String st Identity Char
-> ParsecT String st Identity Char)
-> ParsecT String st Identity Char
-> ParsecT String st Identity Char
forall a b. (a -> b) -> a -> b
$ Char -> ParsecT String st Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char ';'
parseTriples :: CharParser st Triples
parseTriples :: CharParser st Triples
parseTriples = do
Subject
s <- CharParser st Subject
forall st. CharParser st Subject
parseSubject
[PredicateObjectList]
ls <- CharParser st [PredicateObjectList]
forall st. CharParser st [PredicateObjectList]
parsePredObjList
CharParser st Char -> CharParser st Char
forall st a. CharParser st a -> CharParser st a
skips (CharParser st Char -> CharParser st Char)
-> CharParser st Char -> CharParser st Char
forall a b. (a -> b) -> a -> b
$ Char -> CharParser st Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '.'
Triples -> CharParser st Triples
forall (m :: * -> *) a. Monad m => a -> m a
return (Triples -> CharParser st Triples)
-> Triples -> CharParser st Triples
forall a b. (a -> b) -> a -> b
$ Subject -> [PredicateObjectList] -> Triples
Triples Subject
s [PredicateObjectList]
ls
parseComment :: CharParser st ()
= do
String -> CharParser st String
forall st. String -> CharParser st String
tryString "#"
CharParser st String -> CharParser st ()
forall (m :: * -> *) a. Monad m => m a -> m ()
forget (CharParser st String -> CharParser st ())
-> CharParser st String -> CharParser st ()
forall a b. (a -> b) -> a -> b
$ CharParser st String -> CharParser st String
forall st a. CharParser st a -> CharParser st a
skips (CharParser st String -> CharParser st String)
-> CharParser st String -> CharParser st String
forall a b. (a -> b) -> a -> b
$ ParsecT String st Identity Char
-> CharParser st () -> CharParser st String
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill ParsecT String st Identity Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
anyChar CharParser st ()
forall st. CharParser st ()
newlineOrEof
parseStatement :: CharParser st Statement
parseStatement :: CharParser st Statement
parseStatement = (Base -> Statement)
-> ParsecT String st Identity Base -> CharParser st Statement
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Base -> Statement
BaseStatement ParsecT String st Identity Base
forall st. CharParser st Base
parseBase
CharParser st Statement
-> CharParser st Statement -> CharParser st Statement
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Prefix -> Statement)
-> ParsecT String st Identity Prefix -> CharParser st Statement
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Prefix -> Statement
PrefixStatement ParsecT String st Identity Prefix
forall st. CharParser st Prefix
parsePrefix CharParser st Statement
-> CharParser st Statement -> CharParser st Statement
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Triples -> Statement)
-> ParsecT String st Identity Triples -> CharParser st Statement
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Triples -> Statement
Statement ParsecT String st Identity Triples
forall st. CharParser st Triples
parseTriples
basicSpec :: GA.PrefixMap -> CharParser st TurtleDocument
basicSpec :: PrefixMap -> CharParser st TurtleDocument
basicSpec pm :: PrefixMap
pm = do
ParsecT String st Identity () -> ParsecT String st Identity [()]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT String st Identity ()
forall st. CharParser st ()
parseComment
[Statement]
ls <- ParsecT String st Identity Statement
-> ParsecT String st Identity [Statement]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT String st Identity Statement
forall st. CharParser st Statement
parseStatement
let td :: TurtleDocument
td = IRI -> PrefixMap -> [Statement] -> TurtleDocument
TurtleDocument
IRI
dummyIRI ((String -> IRI) -> Map String String -> PrefixMap
forall a b k. (a -> b) -> Map k a -> Map k b
Map.map String -> IRI
mkIRI (Map String String -> PrefixMap) -> Map String String -> PrefixMap
forall a b. (a -> b) -> a -> b
$ PrefixMap -> Map String String
convertPrefixMap PrefixMap
pm) [Statement]
ls
TurtleDocument -> CharParser st TurtleDocument
forall (m :: * -> *) a. Monad m => a -> m a
return TurtleDocument
td
predefinedPrefixes :: RDFPrefixMap
predefinedPrefixes :: PrefixMap
predefinedPrefixes = [(String, IRI)] -> PrefixMap
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList ([(String, IRI)] -> PrefixMap) -> [(String, IRI)] -> PrefixMap
forall a b. (a -> b) -> a -> b
$ [String] -> [IRI] -> [(String, IRI)]
forall a b. [a] -> [b] -> [(a, b)]
zip
["rdf", "rdfs", "dc", "owl", "ex", "xsd"]
([IRI] -> [(String, IRI)]) -> [IRI] -> [(String, IRI)]
forall a b. (a -> b) -> a -> b
$ [Either ParseError IRI] -> [IRI]
forall a b. [Either a b] -> [b]
rights ([Either ParseError IRI] -> [IRI])
-> [Either ParseError IRI] -> [IRI]
forall a b. (a -> b) -> a -> b
$ (String -> Either ParseError IRI)
-> [String] -> [Either ParseError IRI]
forall a b. (a -> b) -> [a] -> [b]
map (Parsec String () IRI -> String -> String -> Either ParseError IRI
forall s t a.
Stream s Identity t =>
Parsec s () a -> String -> s -> Either ParseError a
parse Parsec String () IRI
forall st. CharParser st IRI
uriQ "")
[ "<http://www.w3.org/1999/02/22-rdf-syntax-ns#>"
, "<http://www.w3.org/2000/01/rdf-schema#>"
, "<http://purl.org/dc/elements/1.1/>"
, "<http://www.w3.org/2002/07/owl#>"
, "<http://www.example.org/>"
, "<http://www.w3.org/2001/XMLSchema#>" ]