{-# LANGUAGE CPP #-}
{-# LANGUAGE OverloadedStrings #-}
#if (__GLASGOW_HASKELL__ >= 802)
{-# LANGUAGE DerivingStrategies #-}
#endif
module Swish.RDF.Parser.Turtle
( ParseResult
, parseTurtle
, parseTurtlefromText
)
where
import Swish.GraphClass (arc)
import Swish.Namespace (Namespace, ScopedName)
import Swish.Namespace (makeNamespace, getNamespaceTuple
, getScopeNamespace, getScopedNameURI
, getScopeNamespace, makeURIScopedName, makeNSScopedName)
import Swish.QName (newLName, emptyLName)
import Swish.RDF.Graph
( RDFGraph, RDFLabel(..)
, NamespaceMap
, addArc
, setNamespaces
, emptyRDFGraph
)
import Swish.RDF.Vocabulary
( LanguageTag
, toLangTag
, rdfType
, rdfFirst, rdfRest, rdfNil
, xsdBoolean, xsdInteger, xsdDecimal, xsdDouble
, defaultBase
)
import Swish.RDF.Datatype (makeDatatypedLiteral)
import Swish.RDF.Parser.Utils
( ParseResult
, runParserWithError
, ignore
, noneOf
, char
, ichar
, string
, stringT
, sepEndBy1
, isymbol
, lexeme
, whiteSpace
, hex4
, hex8
, appendURIs
)
import Control.Applicative
import Control.Monad (foldM)
import Data.Char (chr, isAsciiLower, isAsciiUpper, isDigit, isHexDigit, ord, toLower)
#if MIN_VERSION_base(4, 7, 0)
import Data.Functor (($>))
#endif
import Data.Maybe (fromMaybe)
import Data.Word (Word32)
import Network.URI (URI(..), parseURIReference)
import Text.ParserCombinators.Poly.StateText
import qualified Data.Map as M
import qualified Data.Text as T
import qualified Data.Text.Lazy as L
#if !MIN_VERSION_base(4, 7, 0)
($>) :: Functor f => f a -> b -> f b
($>) = flip (<$)
#endif
data TurtleState = TurtleState
{ TurtleState -> RDFGraph
graphState :: RDFGraph
, TurtleState -> NamespaceMap
prefixUris :: NamespaceMap
, TurtleState -> URI
baseUri :: URI
, TurtleState -> Word32
nodeGen :: Word32
} deriving
#if (__GLASGOW_HASKELL__ >= 802)
stock
#endif
Int -> TurtleState -> ShowS
[TurtleState] -> ShowS
TurtleState -> [Char]
(Int -> TurtleState -> ShowS)
-> (TurtleState -> [Char])
-> ([TurtleState] -> ShowS)
-> Show TurtleState
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TurtleState -> ShowS
showsPrec :: Int -> TurtleState -> ShowS
$cshow :: TurtleState -> [Char]
show :: TurtleState -> [Char]
$cshowList :: [TurtleState] -> ShowS
showList :: [TurtleState] -> ShowS
Show
setPrefix :: Maybe T.Text -> URI -> TurtleState -> TurtleState
setPrefix :: Maybe Text -> URI -> TurtleState -> TurtleState
setPrefix Maybe Text
pre URI
uri TurtleState
st = TurtleState
st { prefixUris=p' }
where
p' :: NamespaceMap
p' = Maybe Text -> URI -> NamespaceMap -> NamespaceMap
forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert Maybe Text
pre URI
uri (TurtleState -> NamespaceMap
prefixUris TurtleState
st)
setBase :: URI -> TurtleState -> TurtleState
setBase :: URI -> TurtleState -> TurtleState
setBase URI
buri TurtleState
st = TurtleState
st { baseUri = buri }
getDefaultPrefix :: TurtleParser Namespace
getDefaultPrefix :: TurtleParser Namespace
getDefaultPrefix = do
TurtleState
s <- Parser TurtleState TurtleState
forall s. Parser s s
stGet
case TurtleState -> Maybe Text -> Maybe URI
getPrefixURI TurtleState
s Maybe Text
forall a. Maybe a
Nothing of
Just URI
uri -> Namespace -> TurtleParser Namespace
forall a. a -> Parser TurtleState a
forall (m :: * -> *) a. Monad m => a -> m a
return (Namespace -> TurtleParser Namespace)
-> Namespace -> TurtleParser Namespace
forall a b. (a -> b) -> a -> b
$ Maybe Text -> URI -> Namespace
makeNamespace Maybe Text
forall a. Maybe a
Nothing URI
uri
Maybe URI
_ -> [Char] -> TurtleParser Namespace
forall (p :: * -> *) a. PolyParse p => [Char] -> p a
failBad [Char]
"No default prefix defined; how unexpected (probably a programming error)!"
getPrefixURI :: TurtleState -> Maybe T.Text -> Maybe URI
getPrefixURI :: TurtleState -> Maybe Text -> Maybe URI
getPrefixURI TurtleState
st Maybe Text
pre = Maybe Text -> NamespaceMap -> Maybe URI
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Maybe Text
pre (TurtleState -> NamespaceMap
prefixUris TurtleState
st)
findPrefixNamespace :: Maybe L.Text -> TurtleParser Namespace
findPrefixNamespace :: Maybe Text -> TurtleParser Namespace
findPrefixNamespace (Just Text
p) = Text -> TurtleParser Namespace
findPrefix (Text -> Text
L.toStrict Text
p)
findPrefixNamespace Maybe Text
Nothing = TurtleParser Namespace
getDefaultPrefix
updateGraph :: (RDFGraph -> RDFGraph) -> TurtleState -> TurtleState
updateGraph :: (RDFGraph -> RDFGraph) -> TurtleState -> TurtleState
updateGraph RDFGraph -> RDFGraph
f TurtleState
s = TurtleState
s { graphState = f (graphState s) }
type TurtleParser a = Parser TurtleState a
parseTurtlefromText ::
L.Text
-> ParseResult
parseTurtlefromText :: Text -> ParseResult
parseTurtlefromText = (Text -> Maybe URI -> ParseResult)
-> Maybe URI -> Text -> ParseResult
forall a b c. (a -> b -> c) -> b -> a -> c
flip Text -> Maybe URI -> ParseResult
parseTurtle Maybe URI
forall a. Maybe a
Nothing
parseTurtle ::
L.Text
-> Maybe URI
-> ParseResult
parseTurtle :: Text -> Maybe URI -> ParseResult
parseTurtle Text
txt Maybe URI
mbase = TurtleParser RDFGraph -> Maybe URI -> Text -> ParseResult
forall a. TurtleParser a -> Maybe URI -> Text -> Either [Char] a
parseAnyfromText TurtleParser RDFGraph
turtleDoc Maybe URI
mbase Text
txt
emptyState ::
Maybe URI
-> TurtleState
emptyState :: Maybe URI -> TurtleState
emptyState Maybe URI
mbase =
let pmap :: Map k a
pmap = Map k a
forall k a. Map k a
M.empty
buri :: URI
buri = URI -> Maybe URI -> URI
forall a. a -> Maybe a -> a
fromMaybe (ScopedName -> URI
getScopedNameURI ScopedName
defaultBase) Maybe URI
mbase
in TurtleState
{ graphState :: RDFGraph
graphState = RDFGraph
emptyRDFGraph
, prefixUris :: NamespaceMap
prefixUris = NamespaceMap
forall k a. Map k a
pmap
, baseUri :: URI
baseUri = URI
buri
, nodeGen :: Word32
nodeGen = Word32
0
}
parseAnyfromText ::
TurtleParser a
-> Maybe URI
-> L.Text
-> Either String a
parseAnyfromText :: forall a. TurtleParser a -> Maybe URI -> Text -> Either [Char] a
parseAnyfromText TurtleParser a
parser Maybe URI
mbase = TurtleParser a -> TurtleState -> Text -> Either [Char] a
forall a b. Parser a b -> a -> Text -> Either [Char] b
runParserWithError TurtleParser a
parser (Maybe URI -> TurtleState
emptyState Maybe URI
mbase)
newBlankNode :: TurtleParser RDFLabel
newBlankNode :: TurtleParser RDFLabel
newBlankNode = do
Word32
n <- (TurtleState -> Word32) -> Parser TurtleState Word32
forall s a. (s -> a) -> Parser s a
stQuery (Word32 -> Word32
forall a. Enum a => a -> a
succ (Word32 -> Word32)
-> (TurtleState -> Word32) -> TurtleState -> Word32
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TurtleState -> Word32
nodeGen)
(TurtleState -> TurtleState) -> Parser TurtleState ()
forall s. (s -> s) -> Parser s ()
stUpdate ((TurtleState -> TurtleState) -> Parser TurtleState ())
-> (TurtleState -> TurtleState) -> Parser TurtleState ()
forall a b. (a -> b) -> a -> b
$ \TurtleState
s -> TurtleState
s { nodeGen = n }
RDFLabel -> TurtleParser RDFLabel
forall a. a -> Parser TurtleState a
forall (m :: * -> *) a. Monad m => a -> m a
return (RDFLabel -> TurtleParser RDFLabel)
-> RDFLabel -> TurtleParser RDFLabel
forall a b. (a -> b) -> a -> b
$ [Char] -> RDFLabel
Blank (Word32 -> [Char]
forall a. Show a => a -> [Char]
show Word32
n)
comma, semiColon , fullStop :: TurtleParser ()
comma :: Parser TurtleState ()
comma = [Char] -> Parser TurtleState ()
forall s. [Char] -> Parser s ()
isymbol [Char]
","
semiColon :: Parser TurtleState ()
semiColon = [Char] -> Parser TurtleState ()
forall s. [Char] -> Parser s ()
isymbol [Char]
";"
fullStop :: Parser TurtleState ()
fullStop = [Char] -> Parser TurtleState ()
forall s. [Char] -> Parser s ()
isymbol [Char]
"."
sQuot, dQuot, sQuot3, dQuot3 :: TurtleParser ()
sQuot :: Parser TurtleState ()
sQuot = Char -> Parser TurtleState ()
forall s. Char -> Parser s ()
ichar Char
'\''
dQuot :: Parser TurtleState ()
dQuot = Char -> Parser TurtleState ()
forall s. Char -> Parser s ()
ichar Char
'"'
sQuot3 :: Parser TurtleState ()
sQuot3 = Parser TurtleState [Char] -> Parser TurtleState ()
forall (f :: * -> *) a. Applicative f => f a -> f ()
ignore (Parser TurtleState [Char] -> Parser TurtleState ())
-> Parser TurtleState [Char] -> Parser TurtleState ()
forall a b. (a -> b) -> a -> b
$ [Char] -> Parser TurtleState [Char]
forall s. [Char] -> Parser s [Char]
string [Char]
"'''"
dQuot3 :: Parser TurtleState ()
dQuot3 = Parser TurtleState [Char] -> Parser TurtleState ()
forall (f :: * -> *) a. Applicative f => f a -> f ()
ignore (Parser TurtleState [Char] -> Parser TurtleState ())
-> Parser TurtleState [Char] -> Parser TurtleState ()
forall a b. (a -> b) -> a -> b
$ [Char] -> Parser TurtleState [Char]
forall s. [Char] -> Parser s [Char]
string [Char]
"\"\"\""
match :: (Ord a) => a -> [(a,a)] -> Bool
match :: forall a. Ord a => a -> [(a, a)] -> Bool
match a
v = ((a, a) -> Bool) -> [(a, a)] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (\(a
l,a
h) -> a
v a -> a -> Bool
forall a. Ord a => a -> a -> Bool
>= a
l Bool -> Bool -> Bool
&& a
v a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
h)
br :: Char -> Char -> TurtleParser a -> TurtleParser a
br :: forall a. Char -> Char -> TurtleParser a -> TurtleParser a
br Char
lsym Char
rsym =
let f :: Char -> Parser s Char
f = Parser s Char -> Parser s Char
forall s a. Parser s a -> Parser s a
lexeme (Parser s Char -> Parser s Char)
-> (Char -> Parser s Char) -> Char -> Parser s Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Parser s Char
forall s. Char -> Parser s Char
char
in Parser TurtleState Char
-> Parser TurtleState Char
-> Parser TurtleState a
-> Parser TurtleState a
forall (p :: * -> *) bra ket a.
PolyParse p =>
p bra -> p ket -> p a -> p a
bracket (Char -> Parser TurtleState Char
forall s. Char -> Parser s Char
f Char
lsym) (Char -> Parser TurtleState Char
forall s. Char -> Parser s Char
f Char
rsym)
atWord :: T.Text -> TurtleParser ()
atWord :: Text -> Parser TurtleState ()
atWord Text
s = (Char -> Parser TurtleState Char
forall s. Char -> Parser s Char
char Char
'@' Parser TurtleState Char
-> Parser TurtleState Text -> Parser TurtleState Text
forall a b.
Parser TurtleState a
-> Parser TurtleState b -> Parser TurtleState b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser TurtleState Text -> Parser TurtleState Text
forall s a. Parser s a -> Parser s a
lexeme (Text -> Parser TurtleState Text
forall s. Text -> Parser s Text
stringT Text
s)) Parser TurtleState Text -> () -> Parser TurtleState ()
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> ()
charI ::
Char
-> TurtleParser Char
charI :: Char -> Parser TurtleState Char
charI Char
c = (Char -> Bool) -> Parser TurtleState Char
forall s. (Char -> Bool) -> Parser s Char
satisfy (Char -> [Char] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` Char
c Char -> ShowS
forall a. a -> [a] -> [a]
: [ Char -> Char
toLower Char
c ])
stringI ::
String
-> TurtleParser String
stringI :: [Char] -> Parser TurtleState [Char]
stringI = (Char -> Parser TurtleState Char)
-> [Char] -> Parser TurtleState [Char]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM Char -> Parser TurtleState Char
charI
addStatement :: RDFLabel -> RDFLabel -> RDFLabel -> TurtleParser ()
addStatement :: RDFLabel -> RDFLabel -> RDFLabel -> Parser TurtleState ()
addStatement RDFLabel
s RDFLabel
p o :: RDFLabel
o@(TypedLit Text
_ ScopedName
dtype) | ScopedName
dtype ScopedName -> [ScopedName] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [ScopedName
xsdBoolean, ScopedName
xsdInteger, ScopedName
xsdDecimal, ScopedName
xsdDouble] = do
TurtleState
ost <- Parser TurtleState TurtleState
forall s. Parser s s
stGet
let stmt :: Arc RDFLabel
stmt = RDFLabel -> RDFLabel -> RDFLabel -> Arc RDFLabel
forall lb. lb -> lb -> lb -> Arc lb
arc RDFLabel
s RDFLabel
p RDFLabel
o
oldp :: NamespaceMap
oldp = TurtleState -> NamespaceMap
prefixUris TurtleState
ost
ogs :: RDFGraph
ogs = TurtleState -> RDFGraph
graphState TurtleState
ost
(Maybe Text
nspre, URI
nsuri) = Namespace -> (Maybe Text, URI)
getNamespaceTuple (Namespace -> (Maybe Text, URI)) -> Namespace -> (Maybe Text, URI)
forall a b. (a -> b) -> a -> b
$ ScopedName -> Namespace
getScopeNamespace ScopedName
dtype
newp :: NamespaceMap
newp = Maybe Text -> URI -> NamespaceMap -> NamespaceMap
forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert Maybe Text
nspre URI
nsuri NamespaceMap
oldp
(TurtleState -> TurtleState) -> Parser TurtleState ()
forall s. (s -> s) -> Parser s ()
stUpdate ((TurtleState -> TurtleState) -> Parser TurtleState ())
-> (TurtleState -> TurtleState) -> Parser TurtleState ()
forall a b. (a -> b) -> a -> b
$ \TurtleState
st -> TurtleState
st { prefixUris = newp, graphState = addArc stmt ogs }
addStatement RDFLabel
s RDFLabel
p RDFLabel
o = (TurtleState -> TurtleState) -> Parser TurtleState ()
forall s. (s -> s) -> Parser s ()
stUpdate ((RDFGraph -> RDFGraph) -> TurtleState -> TurtleState
updateGraph (Arc RDFLabel -> RDFGraph -> RDFGraph
forall lb. Label lb => Arc lb -> NSGraph lb -> NSGraph lb
addArc (RDFLabel -> RDFLabel -> RDFLabel -> Arc RDFLabel
forall lb. lb -> lb -> lb -> Arc lb
arc RDFLabel
s RDFLabel
p RDFLabel
o) ))
isaz, isAZ, isaZ, is09, isaZ09 :: Char -> Bool
isaz :: Char -> Bool
isaz = Char -> Bool
isAsciiLower
isAZ :: Char -> Bool
isAZ = Char -> Bool
isAsciiUpper
isaZ :: Char -> Bool
isaZ Char
c = Char -> Bool
isaz Char
c Bool -> Bool -> Bool
|| Char -> Bool
isAZ Char
c
is09 :: Char -> Bool
is09 = Char -> Bool
isDigit
isaZ09 :: Char -> Bool
isaZ09 Char
c = Char -> Bool
isaZ Char
c Bool -> Bool -> Bool
|| Char -> Bool
is09 Char
c
operatorLabel :: ScopedName -> TurtleParser RDFLabel
operatorLabel :: ScopedName -> TurtleParser RDFLabel
operatorLabel ScopedName
snam = do
TurtleState
st <- Parser TurtleState TurtleState
forall s. Parser s s
stGet
let (Maybe Text
pkey, URI
pval) = Namespace -> (Maybe Text, URI)
getNamespaceTuple (Namespace -> (Maybe Text, URI)) -> Namespace -> (Maybe Text, URI)
forall a b. (a -> b) -> a -> b
$ ScopedName -> Namespace
getScopeNamespace ScopedName
snam
opmap :: NamespaceMap
opmap = TurtleState -> NamespaceMap
prefixUris TurtleState
st
rval :: RDFLabel
rval = ScopedName -> RDFLabel
Res ScopedName
snam
case Maybe Text -> NamespaceMap -> Maybe URI
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Maybe Text
pkey NamespaceMap
opmap of
Just URI
val | URI
val URI -> URI -> Bool
forall a. Eq a => a -> a -> Bool
== URI
pval -> RDFLabel -> TurtleParser RDFLabel
forall a. a -> Parser TurtleState a
forall (m :: * -> *) a. Monad m => a -> m a
return RDFLabel
rval
| Bool
otherwise -> do
(TurtleState -> TurtleState) -> Parser TurtleState ()
forall s. (s -> s) -> Parser s ()
stUpdate ((TurtleState -> TurtleState) -> Parser TurtleState ())
-> (TurtleState -> TurtleState) -> Parser TurtleState ()
forall a b. (a -> b) -> a -> b
$ \TurtleState
s -> TurtleState
s { prefixUris = M.insert pkey pval opmap }
RDFLabel -> TurtleParser RDFLabel
forall a. a -> Parser TurtleState a
forall (m :: * -> *) a. Monad m => a -> m a
return RDFLabel
rval
Maybe URI
_ -> do
(TurtleState -> TurtleState) -> Parser TurtleState ()
forall s. (s -> s) -> Parser s ()
stUpdate ((TurtleState -> TurtleState) -> Parser TurtleState ())
-> (TurtleState -> TurtleState) -> Parser TurtleState ()
forall a b. (a -> b) -> a -> b
$ \TurtleState
s -> TurtleState
s { prefixUris = M.insert pkey pval opmap }
RDFLabel -> TurtleParser RDFLabel
forall a. a -> Parser TurtleState a
forall (m :: * -> *) a. Monad m => a -> m a
return RDFLabel
rval
findPrefix :: T.Text -> TurtleParser Namespace
findPrefix :: Text -> TurtleParser Namespace
findPrefix Text
pre = do
TurtleState
st <- Parser TurtleState TurtleState
forall s. Parser s s
stGet
case Maybe Text -> NamespaceMap -> Maybe URI
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
pre) (TurtleState -> NamespaceMap
prefixUris TurtleState
st) of
Just URI
uri -> Namespace -> TurtleParser Namespace
forall a. a -> Parser TurtleState a
forall (m :: * -> *) a. Monad m => a -> m a
return (Namespace -> TurtleParser Namespace)
-> Namespace -> TurtleParser Namespace
forall a b. (a -> b) -> a -> b
$ Maybe Text -> URI -> Namespace
makeNamespace (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
pre) URI
uri
Maybe URI
Nothing -> [Char] -> TurtleParser Namespace
forall (p :: * -> *) a. PolyParse p => [Char] -> p a
failBad ([Char] -> TurtleParser Namespace)
-> [Char] -> TurtleParser Namespace
forall a b. (a -> b) -> a -> b
$ [Char]
"Undefined prefix '" [Char] -> ShowS
forall a. [a] -> [a] -> [a]
++ Text -> [Char]
T.unpack Text
pre [Char] -> ShowS
forall a. [a] -> [a] -> [a]
++ [Char]
":'."
(<?) ::
Parser s a
-> String
-> Parser s a
<? :: forall s a. Parser s a -> [Char] -> Parser s a
(<?) Parser s a
p [Char]
m = Parser s a -> ShowS -> Parser s a
forall a. Parser s a -> ShowS -> Parser s a
forall (p :: * -> *) a. Commitment p => p a -> ShowS -> p a
adjustErr Parser s a
p (([Char]
m [Char] -> ShowS
forall a. [a] -> [a] -> [a]
++ [Char]
"\n") [Char] -> ShowS
forall a. [a] -> [a] -> [a]
++)
infixl 4 <?
turtleDoc :: TurtleParser RDFGraph
turtleDoc :: TurtleParser RDFGraph
turtleDoc = TurtleState -> RDFGraph
mkGr (TurtleState -> RDFGraph)
-> Parser TurtleState TurtleState -> TurtleParser RDFGraph
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Parser TurtleState ()
forall s. Parser s ()
whiteSpace Parser TurtleState ()
-> Parser TurtleState [()] -> Parser TurtleState [()]
forall a b.
Parser TurtleState a
-> Parser TurtleState b -> Parser TurtleState b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser TurtleState () -> Parser TurtleState [()]
forall a. Parser TurtleState a -> Parser TurtleState [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many Parser TurtleState ()
statement Parser TurtleState [()]
-> Parser TurtleState () -> Parser TurtleState ()
forall a b.
Parser TurtleState a
-> Parser TurtleState b -> Parser TurtleState b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser TurtleState ()
forall s. Parser s ()
eof Parser TurtleState ()
-> Parser TurtleState TurtleState -> Parser TurtleState TurtleState
forall a b.
Parser TurtleState a
-> Parser TurtleState b -> Parser TurtleState b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser TurtleState TurtleState
forall s. Parser s s
stGet)
where
mkGr :: TurtleState -> RDFGraph
mkGr TurtleState
s = NamespaceMap -> RDFGraph -> RDFGraph
forall lb. NamespaceMap -> NSGraph lb -> NSGraph lb
setNamespaces (TurtleState -> NamespaceMap
prefixUris TurtleState
s) (TurtleState -> RDFGraph
graphState TurtleState
s)
statement :: TurtleParser ()
statement :: Parser TurtleState ()
statement = Parser TurtleState ()
directive Parser TurtleState ()
-> Parser TurtleState () -> Parser TurtleState ()
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Parser TurtleState ()
triples Parser TurtleState ()
-> Parser TurtleState () -> Parser TurtleState ()
forall a b.
Parser TurtleState a
-> Parser TurtleState b -> Parser TurtleState b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser TurtleState () -> Parser TurtleState ()
forall a. Parser TurtleState a -> Parser TurtleState a
forall (p :: * -> *) a. Commitment p => p a -> p a
commit Parser TurtleState ()
fullStop Parser TurtleState () -> [Char] -> Parser TurtleState ()
forall s a. Parser s a -> [Char] -> Parser s a
<? [Char]
"Missing '.' after a statement.")
directive :: TurtleParser ()
directive :: Parser TurtleState ()
directive =
Parser TurtleState () -> Parser TurtleState ()
forall s a. Parser s a -> Parser s a
lexeme
(Parser TurtleState ()
prefixID Parser TurtleState () -> [Char] -> Parser TurtleState ()
forall s a. Parser s a -> [Char] -> Parser s a
<? [Char]
"Unable to parse @prefix statement."
Parser TurtleState ()
-> Parser TurtleState () -> Parser TurtleState ()
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser TurtleState ()
base Parser TurtleState () -> [Char] -> Parser TurtleState ()
forall s a. Parser s a -> [Char] -> Parser s a
<? [Char]
"Unable to parse @base statement."
Parser TurtleState ()
-> Parser TurtleState () -> Parser TurtleState ()
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser TurtleState ()
sparqlPrefix Parser TurtleState () -> [Char] -> Parser TurtleState ()
forall s a. Parser s a -> [Char] -> Parser s a
<? [Char]
"Unable to parse Sparql PREFIX statement."
Parser TurtleState ()
-> Parser TurtleState () -> Parser TurtleState ()
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser TurtleState ()
sparqlBase Parser TurtleState () -> [Char] -> Parser TurtleState ()
forall s a. Parser s a -> [Char] -> Parser s a
<? [Char]
"Unable to parse Sparql BASE statement.")
prefixID :: TurtleParser ()
prefixID :: Parser TurtleState ()
prefixID = do
Text -> Parser TurtleState ()
atWord Text
"prefix"
Maybe Text
p <- Parser TurtleState (Maybe Text) -> Parser TurtleState (Maybe Text)
forall a. Parser TurtleState a -> Parser TurtleState a
forall (p :: * -> *) a. Commitment p => p a -> p a
commit (Parser TurtleState (Maybe Text)
-> Parser TurtleState (Maybe Text))
-> Parser TurtleState (Maybe Text)
-> Parser TurtleState (Maybe Text)
forall a b. (a -> b) -> a -> b
$ Parser TurtleState (Maybe Text) -> Parser TurtleState (Maybe Text)
forall s a. Parser s a -> Parser s a
lexeme Parser TurtleState (Maybe Text)
_pnameNS
URI
u <- Parser TurtleState URI -> Parser TurtleState URI
forall s a. Parser s a -> Parser s a
lexeme Parser TurtleState URI
_iriRef
Parser TurtleState ()
fullStop
(TurtleState -> TurtleState) -> Parser TurtleState ()
forall s. (s -> s) -> Parser s ()
stUpdate ((TurtleState -> TurtleState) -> Parser TurtleState ())
-> (TurtleState -> TurtleState) -> Parser TurtleState ()
forall a b. (a -> b) -> a -> b
$ Maybe Text -> URI -> TurtleState -> TurtleState
setPrefix ((Text -> Text) -> Maybe Text -> Maybe Text
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Text -> Text
L.toStrict Maybe Text
p) URI
u
base :: TurtleParser ()
base :: Parser TurtleState ()
base = do
Text -> Parser TurtleState ()
atWord Text
"base"
URI
b <- Parser TurtleState URI -> Parser TurtleState URI
forall a. Parser TurtleState a -> Parser TurtleState a
forall (p :: * -> *) a. Commitment p => p a -> p a
commit (Parser TurtleState URI -> Parser TurtleState URI)
-> Parser TurtleState URI -> Parser TurtleState URI
forall a b. (a -> b) -> a -> b
$ Parser TurtleState URI -> Parser TurtleState URI
forall s a. Parser s a -> Parser s a
lexeme Parser TurtleState URI
_iriRef
Parser TurtleState ()
fullStop
(TurtleState -> TurtleState) -> Parser TurtleState ()
forall s. (s -> s) -> Parser s ()
stUpdate ((TurtleState -> TurtleState) -> Parser TurtleState ())
-> (TurtleState -> TurtleState) -> Parser TurtleState ()
forall a b. (a -> b) -> a -> b
$ URI -> TurtleState -> TurtleState
setBase URI
b
sparqlBase :: TurtleParser ()
sparqlBase :: Parser TurtleState ()
sparqlBase = Parser TurtleState [Char] -> Parser TurtleState [Char]
forall s a. Parser s a -> Parser s a
lexeme ([Char] -> Parser TurtleState [Char]
stringI [Char]
"BASE") Parser TurtleState [Char]
-> Parser TurtleState URI -> Parser TurtleState URI
forall a b.
Parser TurtleState a
-> Parser TurtleState b -> Parser TurtleState b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser TurtleState URI -> Parser TurtleState URI
forall a. Parser TurtleState a -> Parser TurtleState a
forall (p :: * -> *) a. Commitment p => p a -> p a
commit Parser TurtleState URI
_iriRef Parser TurtleState URI
-> (URI -> Parser TurtleState ()) -> Parser TurtleState ()
forall a b.
Parser TurtleState a
-> (a -> Parser TurtleState b) -> Parser TurtleState b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (TurtleState -> TurtleState) -> Parser TurtleState ()
forall s. (s -> s) -> Parser s ()
stUpdate ((TurtleState -> TurtleState) -> Parser TurtleState ())
-> (URI -> TurtleState -> TurtleState)
-> URI
-> Parser TurtleState ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. URI -> TurtleState -> TurtleState
setBase
sparqlPrefix :: TurtleParser ()
sparqlPrefix :: Parser TurtleState ()
sparqlPrefix = do
Parser TurtleState [Char] -> Parser TurtleState ()
forall (f :: * -> *) a. Applicative f => f a -> f ()
ignore (Parser TurtleState [Char] -> Parser TurtleState ())
-> Parser TurtleState [Char] -> Parser TurtleState ()
forall a b. (a -> b) -> a -> b
$ Parser TurtleState [Char] -> Parser TurtleState [Char]
forall s a. Parser s a -> Parser s a
lexeme (Parser TurtleState [Char] -> Parser TurtleState [Char])
-> Parser TurtleState [Char] -> Parser TurtleState [Char]
forall a b. (a -> b) -> a -> b
$ [Char] -> Parser TurtleState [Char]
stringI [Char]
"PREFIX"
Maybe Text
p <- Parser TurtleState (Maybe Text) -> Parser TurtleState (Maybe Text)
forall a. Parser TurtleState a -> Parser TurtleState a
forall (p :: * -> *) a. Commitment p => p a -> p a
commit (Parser TurtleState (Maybe Text)
-> Parser TurtleState (Maybe Text))
-> Parser TurtleState (Maybe Text)
-> Parser TurtleState (Maybe Text)
forall a b. (a -> b) -> a -> b
$ Parser TurtleState (Maybe Text) -> Parser TurtleState (Maybe Text)
forall s a. Parser s a -> Parser s a
lexeme Parser TurtleState (Maybe Text)
_pnameNS
URI
u <- Parser TurtleState URI -> Parser TurtleState URI
forall s a. Parser s a -> Parser s a
lexeme Parser TurtleState URI
_iriRef
(TurtleState -> TurtleState) -> Parser TurtleState ()
forall s. (s -> s) -> Parser s ()
stUpdate ((TurtleState -> TurtleState) -> Parser TurtleState ())
-> (TurtleState -> TurtleState) -> Parser TurtleState ()
forall a b. (a -> b) -> a -> b
$ Maybe Text -> URI -> TurtleState -> TurtleState
setPrefix ((Text -> Text) -> Maybe Text -> Maybe Text
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Text -> Text
L.toStrict Maybe Text
p) URI
u
triples :: TurtleParser ()
triples :: Parser TurtleState ()
triples =
(TurtleParser RDFLabel
subject TurtleParser RDFLabel
-> (RDFLabel -> Parser TurtleState ()) -> Parser TurtleState ()
forall a b.
Parser TurtleState a
-> (a -> Parser TurtleState b) -> Parser TurtleState b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= RDFLabel -> Parser TurtleState ()
predicateObjectList)
Parser TurtleState ()
-> Parser TurtleState () -> Parser TurtleState ()
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
(TurtleParser RDFLabel
blankNodePropertyList TurtleParser RDFLabel
-> (RDFLabel -> Parser TurtleState ()) -> Parser TurtleState ()
forall a b.
Parser TurtleState a
-> (a -> Parser TurtleState b) -> Parser TurtleState b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Parser TurtleState (Maybe ()) -> Parser TurtleState ()
forall (f :: * -> *) a. Applicative f => f a -> f ()
ignore (Parser TurtleState (Maybe ()) -> Parser TurtleState ())
-> (RDFLabel -> Parser TurtleState (Maybe ()))
-> RDFLabel
-> Parser TurtleState ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Parser TurtleState () -> Parser TurtleState (Maybe ())
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Parser TurtleState () -> Parser TurtleState (Maybe ()))
-> (RDFLabel -> Parser TurtleState ())
-> RDFLabel
-> Parser TurtleState (Maybe ())
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RDFLabel -> Parser TurtleState ()
predicateObjectList)
predicateObjectList :: RDFLabel -> TurtleParser ()
predicateObjectList :: RDFLabel -> Parser TurtleState ()
predicateObjectList RDFLabel
subj =
let term :: Parser TurtleState ()
term = TurtleParser RDFLabel
verb TurtleParser RDFLabel
-> (RDFLabel -> Parser TurtleState ()) -> Parser TurtleState ()
forall a b.
Parser TurtleState a
-> (a -> Parser TurtleState b) -> Parser TurtleState b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= RDFLabel -> RDFLabel -> Parser TurtleState ()
objectList RDFLabel
subj
in Parser TurtleState [()] -> Parser TurtleState ()
forall (f :: * -> *) a. Applicative f => f a -> f ()
ignore (Parser TurtleState [()] -> Parser TurtleState ())
-> Parser TurtleState [()] -> Parser TurtleState ()
forall a b. (a -> b) -> a -> b
$ Parser TurtleState ()
-> Parser TurtleState [()] -> Parser TurtleState [()]
forall s a b. Parser s a -> Parser s b -> Parser s [a]
sepEndBy1 Parser TurtleState ()
term (Parser TurtleState () -> Parser TurtleState [()]
forall (p :: * -> *) a. PolyParse p => p a -> p [a]
many1 Parser TurtleState ()
semiColon)
objectList :: RDFLabel -> RDFLabel -> TurtleParser ()
objectList :: RDFLabel -> RDFLabel -> Parser TurtleState ()
objectList RDFLabel
subj RDFLabel
prd = TurtleParser RDFLabel
-> Parser TurtleState () -> Parser TurtleState [RDFLabel]
forall (p :: * -> *) a sep. PolyParse p => p a -> p sep -> p [a]
sepBy1 TurtleParser RDFLabel
object Parser TurtleState ()
comma Parser TurtleState [RDFLabel]
-> ([RDFLabel] -> Parser TurtleState ()) -> Parser TurtleState ()
forall a b.
Parser TurtleState a
-> (a -> Parser TurtleState b) -> Parser TurtleState b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (RDFLabel -> Parser TurtleState ())
-> [RDFLabel] -> Parser TurtleState ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (RDFLabel -> RDFLabel -> RDFLabel -> Parser TurtleState ()
addStatement RDFLabel
subj RDFLabel
prd)
verb :: TurtleParser RDFLabel
verb :: TurtleParser RDFLabel
verb = TurtleParser RDFLabel
predicate TurtleParser RDFLabel
-> TurtleParser RDFLabel -> TurtleParser RDFLabel
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Parser TurtleState Char -> Parser TurtleState Char
forall s a. Parser s a -> Parser s a
lexeme (Char -> Parser TurtleState Char
forall s. Char -> Parser s Char
char Char
'a') Parser TurtleState Char
-> TurtleParser RDFLabel -> TurtleParser RDFLabel
forall a b.
Parser TurtleState a
-> Parser TurtleState b -> Parser TurtleState b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ScopedName -> TurtleParser RDFLabel
operatorLabel ScopedName
rdfType)
subject :: TurtleParser RDFLabel
subject :: TurtleParser RDFLabel
subject = (ScopedName -> RDFLabel
Res (ScopedName -> RDFLabel)
-> Parser TurtleState ScopedName -> TurtleParser RDFLabel
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser TurtleState ScopedName
iri) TurtleParser RDFLabel
-> TurtleParser RDFLabel -> TurtleParser RDFLabel
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> TurtleParser RDFLabel
blankNode TurtleParser RDFLabel
-> TurtleParser RDFLabel -> TurtleParser RDFLabel
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> TurtleParser RDFLabel
collection
predicate :: TurtleParser RDFLabel
predicate :: TurtleParser RDFLabel
predicate = ScopedName -> RDFLabel
Res (ScopedName -> RDFLabel)
-> Parser TurtleState ScopedName -> TurtleParser RDFLabel
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser TurtleState ScopedName
iri
object :: TurtleParser RDFLabel
object :: TurtleParser RDFLabel
object = (ScopedName -> RDFLabel
Res (ScopedName -> RDFLabel)
-> Parser TurtleState ScopedName -> TurtleParser RDFLabel
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser TurtleState ScopedName
iri) TurtleParser RDFLabel
-> TurtleParser RDFLabel -> TurtleParser RDFLabel
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> TurtleParser RDFLabel
blankNode TurtleParser RDFLabel
-> TurtleParser RDFLabel -> TurtleParser RDFLabel
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> TurtleParser RDFLabel
collection TurtleParser RDFLabel
-> TurtleParser RDFLabel -> TurtleParser RDFLabel
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
TurtleParser RDFLabel
blankNodePropertyList TurtleParser RDFLabel
-> TurtleParser RDFLabel -> TurtleParser RDFLabel
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> TurtleParser RDFLabel
literal
literal :: TurtleParser RDFLabel
literal :: TurtleParser RDFLabel
literal = TurtleParser RDFLabel -> TurtleParser RDFLabel
forall s a. Parser s a -> Parser s a
lexeme (TurtleParser RDFLabel -> TurtleParser RDFLabel)
-> TurtleParser RDFLabel -> TurtleParser RDFLabel
forall a b. (a -> b) -> a -> b
$ TurtleParser RDFLabel
rdfLiteral TurtleParser RDFLabel
-> TurtleParser RDFLabel -> TurtleParser RDFLabel
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> TurtleParser RDFLabel
numericLiteral TurtleParser RDFLabel
-> TurtleParser RDFLabel -> TurtleParser RDFLabel
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> TurtleParser RDFLabel
booleanLiteral
blankNodePropertyList :: TurtleParser RDFLabel
blankNodePropertyList :: TurtleParser RDFLabel
blankNodePropertyList = do
RDFLabel
bNode <- TurtleParser RDFLabel
newBlankNode
Char -> Char -> Parser TurtleState () -> Parser TurtleState ()
forall a. Char -> Char -> TurtleParser a -> TurtleParser a
br Char
'[' Char
']' (Parser TurtleState () -> Parser TurtleState ())
-> Parser TurtleState () -> Parser TurtleState ()
forall a b. (a -> b) -> a -> b
$ Parser TurtleState () -> Parser TurtleState ()
forall s a. Parser s a -> Parser s a
lexeme (RDFLabel -> Parser TurtleState ()
predicateObjectList RDFLabel
bNode)
RDFLabel -> TurtleParser RDFLabel
forall a. a -> Parser TurtleState a
forall (m :: * -> *) a. Monad m => a -> m a
return RDFLabel
bNode
collection :: TurtleParser RDFLabel
collection :: TurtleParser RDFLabel
collection = do
[RDFLabel]
os <- Char
-> Char
-> Parser TurtleState [RDFLabel]
-> Parser TurtleState [RDFLabel]
forall a. Char -> Char -> TurtleParser a -> TurtleParser a
br Char
'(' Char
')' (Parser TurtleState [RDFLabel] -> Parser TurtleState [RDFLabel])
-> Parser TurtleState [RDFLabel] -> Parser TurtleState [RDFLabel]
forall a b. (a -> b) -> a -> b
$ TurtleParser RDFLabel -> Parser TurtleState [RDFLabel]
forall a. Parser TurtleState a -> Parser TurtleState [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many TurtleParser RDFLabel
object
RDFLabel
eNode <- ScopedName -> TurtleParser RDFLabel
operatorLabel ScopedName
rdfNil
case [RDFLabel]
os of
[] -> RDFLabel -> TurtleParser RDFLabel
forall a. a -> Parser TurtleState a
forall (m :: * -> *) a. Monad m => a -> m a
return RDFLabel
eNode
(RDFLabel
x:[RDFLabel]
xs) -> do
RDFLabel
sNode <- TurtleParser RDFLabel
newBlankNode
RDFLabel
first <- ScopedName -> TurtleParser RDFLabel
operatorLabel ScopedName
rdfFirst
RDFLabel -> RDFLabel -> RDFLabel -> Parser TurtleState ()
addStatement RDFLabel
sNode RDFLabel
first RDFLabel
x
RDFLabel
lNode <- (RDFLabel -> RDFLabel -> TurtleParser RDFLabel)
-> RDFLabel -> [RDFLabel] -> TurtleParser RDFLabel
forall (t :: * -> *) (m :: * -> *) b a.
(Foldable t, Monad m) =>
(b -> a -> m b) -> b -> t a -> m b
foldM RDFLabel -> RDFLabel -> TurtleParser RDFLabel
addElem RDFLabel
sNode [RDFLabel]
xs
RDFLabel
rest <- ScopedName -> TurtleParser RDFLabel
operatorLabel ScopedName
rdfRest
RDFLabel -> RDFLabel -> RDFLabel -> Parser TurtleState ()
addStatement RDFLabel
lNode RDFLabel
rest RDFLabel
eNode
RDFLabel -> TurtleParser RDFLabel
forall a. a -> Parser TurtleState a
forall (m :: * -> *) a. Monad m => a -> m a
return RDFLabel
sNode
where
addElem :: RDFLabel -> RDFLabel -> TurtleParser RDFLabel
addElem RDFLabel
prevNode RDFLabel
curElem = do
RDFLabel
bNode <- TurtleParser RDFLabel
newBlankNode
RDFLabel
first <- ScopedName -> TurtleParser RDFLabel
operatorLabel ScopedName
rdfFirst
RDFLabel
rest <- ScopedName -> TurtleParser RDFLabel
operatorLabel ScopedName
rdfRest
RDFLabel -> RDFLabel -> RDFLabel -> Parser TurtleState ()
addStatement RDFLabel
prevNode RDFLabel
rest RDFLabel
bNode
RDFLabel -> RDFLabel -> RDFLabel -> Parser TurtleState ()
addStatement RDFLabel
bNode RDFLabel
first RDFLabel
curElem
RDFLabel -> TurtleParser RDFLabel
forall a. a -> Parser TurtleState a
forall (m :: * -> *) a. Monad m => a -> m a
return RDFLabel
bNode
numericLiteral :: TurtleParser RDFLabel
numericLiteral :: TurtleParser RDFLabel
numericLiteral =
let f :: ScopedName -> Text -> RDFLabel
f ScopedName
t Text
v = ScopedName -> Text -> RDFLabel
makeDatatypedLiteral ScopedName
t (Text -> Text
L.toStrict Text
v)
in (ScopedName -> Text -> RDFLabel
f ScopedName
xsdDouble (Text -> RDFLabel)
-> Parser TurtleState Text -> TurtleParser RDFLabel
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser TurtleState Text
_double)
TurtleParser RDFLabel
-> TurtleParser RDFLabel -> TurtleParser RDFLabel
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
(ScopedName -> Text -> RDFLabel
f ScopedName
xsdDecimal (Text -> RDFLabel)
-> Parser TurtleState Text -> TurtleParser RDFLabel
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser TurtleState Text
_decimal)
TurtleParser RDFLabel
-> TurtleParser RDFLabel -> TurtleParser RDFLabel
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
(ScopedName -> Text -> RDFLabel
f ScopedName
xsdInteger (Text -> RDFLabel)
-> Parser TurtleState Text -> TurtleParser RDFLabel
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser TurtleState Text
_integer)
rdfLiteral :: TurtleParser RDFLabel
rdfLiteral :: TurtleParser RDFLabel
rdfLiteral = do
Text
lbl <- Text -> Text
L.toStrict (Text -> Text)
-> Parser TurtleState Text -> Parser TurtleState Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser TurtleState Text
turtleString
Maybe (Either LanguageTag ScopedName)
opt <- Parser TurtleState (Either LanguageTag ScopedName)
-> Parser TurtleState (Maybe (Either LanguageTag ScopedName))
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional ((LanguageTag -> Either LanguageTag ScopedName
forall a b. a -> Either a b
Left (LanguageTag -> Either LanguageTag ScopedName)
-> Parser TurtleState LanguageTag
-> Parser TurtleState (Either LanguageTag ScopedName)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Parser TurtleState LanguageTag
_langTag Parser TurtleState LanguageTag
-> [Char] -> Parser TurtleState LanguageTag
forall s a. Parser s a -> [Char] -> Parser s a
<? [Char]
"Unable to parse the language tag"))
Parser TurtleState (Either LanguageTag ScopedName)
-> Parser TurtleState (Either LanguageTag ScopedName)
-> Parser TurtleState (Either LanguageTag ScopedName)
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
([Char] -> Parser TurtleState [Char]
forall s. [Char] -> Parser s [Char]
string [Char]
"^^" Parser TurtleState [Char]
-> Parser TurtleState (Either LanguageTag ScopedName)
-> Parser TurtleState (Either LanguageTag ScopedName)
forall a b.
Parser TurtleState a
-> Parser TurtleState b -> Parser TurtleState b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (ScopedName -> Either LanguageTag ScopedName
forall a b. b -> Either a b
Right (ScopedName -> Either LanguageTag ScopedName)
-> Parser TurtleState ScopedName
-> Parser TurtleState (Either LanguageTag ScopedName)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Parser TurtleState ScopedName -> Parser TurtleState ScopedName
forall a. Parser TurtleState a -> Parser TurtleState a
forall (p :: * -> *) a. Commitment p => p a -> p a
commit Parser TurtleState ScopedName
iri Parser TurtleState ScopedName
-> [Char] -> Parser TurtleState ScopedName
forall s a. Parser s a -> [Char] -> Parser s a
<? [Char]
"Unable to parse the datatype of the literal"))))
Parser TurtleState (Maybe ()) -> Parser TurtleState ()
forall (f :: * -> *) a. Applicative f => f a -> f ()
ignore (Parser TurtleState (Maybe ()) -> Parser TurtleState ())
-> Parser TurtleState (Maybe ()) -> Parser TurtleState ()
forall a b. (a -> b) -> a -> b
$ Parser TurtleState () -> Parser TurtleState (Maybe ())
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional Parser TurtleState ()
forall s. Parser s ()
whiteSpace
RDFLabel -> TurtleParser RDFLabel
forall a. a -> Parser TurtleState a
forall (m :: * -> *) a. Monad m => a -> m a
return (RDFLabel -> TurtleParser RDFLabel)
-> RDFLabel -> TurtleParser RDFLabel
forall a b. (a -> b) -> a -> b
$ case Maybe (Either LanguageTag ScopedName)
opt of
Just (Left LanguageTag
lcode) -> Text -> LanguageTag -> RDFLabel
LangLit Text
lbl LanguageTag
lcode
Just (Right ScopedName
dtype) -> Text -> ScopedName -> RDFLabel
TypedLit Text
lbl ScopedName
dtype
Maybe (Either LanguageTag ScopedName)
_ -> Text -> RDFLabel
Lit Text
lbl
booleanLiteral :: TurtleParser RDFLabel
booleanLiteral :: TurtleParser RDFLabel
booleanLiteral = ScopedName -> Text -> RDFLabel
makeDatatypedLiteral ScopedName
xsdBoolean (Text -> RDFLabel) -> ([Char] -> Text) -> [Char] -> RDFLabel
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> Text
T.pack ([Char] -> RDFLabel)
-> Parser TurtleState [Char] -> TurtleParser RDFLabel
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser TurtleState [Char] -> Parser TurtleState [Char]
forall s a. Parser s a -> Parser s a
lexeme ([Char] -> Parser TurtleState [Char]
forall s. [Char] -> Parser s [Char]
string [Char]
"true" Parser TurtleState [Char]
-> Parser TurtleState [Char] -> Parser TurtleState [Char]
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Parser TurtleState [Char]
forall s. [Char] -> Parser s [Char]
string [Char]
"false")
turtleString :: TurtleParser L.Text
turtleString :: Parser TurtleState Text
turtleString =
Parser TurtleState Text -> Parser TurtleState Text
forall s a. Parser s a -> Parser s a
lexeme (
Parser TurtleState Text
_stringLiteralLongQuote Parser TurtleState Text
-> Parser TurtleState Text -> Parser TurtleState Text
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser TurtleState Text
_stringLiteralQuote Parser TurtleState Text
-> Parser TurtleState Text -> Parser TurtleState Text
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
Parser TurtleState Text
_stringLiteralLongSingleQuote Parser TurtleState Text
-> Parser TurtleState Text -> Parser TurtleState Text
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser TurtleState Text
_stringLiteralSingleQuote
) Parser TurtleState Text -> [Char] -> Parser TurtleState Text
forall s a. Parser s a -> [Char] -> Parser s a
<? [Char]
"Unable to parse a string literal"
iri :: TurtleParser ScopedName
iri :: Parser TurtleState ScopedName
iri = Parser TurtleState ScopedName -> Parser TurtleState ScopedName
forall s a. Parser s a -> Parser s a
lexeme (
(URI -> ScopedName
makeURIScopedName (URI -> ScopedName)
-> Parser TurtleState URI -> Parser TurtleState ScopedName
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser TurtleState URI
_iriRef)
Parser TurtleState ScopedName
-> Parser TurtleState ScopedName -> Parser TurtleState ScopedName
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
Parser TurtleState ScopedName
prefixedName)
prefixedName :: TurtleParser ScopedName
prefixedName :: Parser TurtleState ScopedName
prefixedName =
Parser TurtleState ScopedName
_pnameLN Parser TurtleState ScopedName
-> Parser TurtleState ScopedName -> Parser TurtleState ScopedName
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
(Namespace -> LName -> ScopedName)
-> LName -> Namespace -> ScopedName
forall a b c. (a -> b -> c) -> b -> a -> c
flip Namespace -> LName -> ScopedName
makeNSScopedName LName
emptyLName (Namespace -> ScopedName)
-> TurtleParser Namespace -> Parser TurtleState ScopedName
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Parser TurtleState (Maybe Text)
_pnameNS Parser TurtleState (Maybe Text)
-> (Maybe Text -> TurtleParser Namespace) -> TurtleParser Namespace
forall a b.
Parser TurtleState a
-> (a -> Parser TurtleState b) -> Parser TurtleState b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Maybe Text -> TurtleParser Namespace
findPrefixNamespace)
blankNode :: TurtleParser RDFLabel
blankNode :: TurtleParser RDFLabel
blankNode = TurtleParser RDFLabel -> TurtleParser RDFLabel
forall s a. Parser s a -> Parser s a
lexeme (TurtleParser RDFLabel
_blankNodeLabel TurtleParser RDFLabel
-> TurtleParser RDFLabel -> TurtleParser RDFLabel
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> TurtleParser RDFLabel
_anon)
_iriRef :: TurtleParser URI
_iriRef :: Parser TurtleState URI
_iriRef = do
[Char]
ustr <- Parser TurtleState Char
-> Parser TurtleState Char
-> Parser TurtleState [Char]
-> Parser TurtleState [Char]
forall (p :: * -> *) bra ket a.
PolyParse p =>
p bra -> p ket -> p a -> p a
bracket (Char -> Parser TurtleState Char
forall s. Char -> Parser s Char
char Char
'<') (Parser TurtleState Char -> Parser TurtleState Char
forall a. Parser TurtleState a -> Parser TurtleState a
forall (p :: * -> *) a. Commitment p => p a -> p a
commit (Char -> Parser TurtleState Char
forall s. Char -> Parser s Char
char Char
'>')) (Parser TurtleState Char -> Parser TurtleState [Char]
forall a. Parser TurtleState a -> Parser TurtleState [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many Parser TurtleState Char
iriRefChar)
case [Char] -> Maybe URI
parseURIReference [Char]
ustr of
Maybe URI
Nothing -> [Char] -> Parser TurtleState URI
forall (p :: * -> *) a. PolyParse p => [Char] -> p a
failBad ([Char] -> Parser TurtleState URI)
-> [Char] -> Parser TurtleState URI
forall a b. (a -> b) -> a -> b
$ [Char]
"Invalid URI: <" [Char] -> ShowS
forall a. [a] -> [a] -> [a]
++ [Char]
ustr [Char] -> ShowS
forall a. [a] -> [a] -> [a]
++ [Char]
">"
Just URI
uref -> do
TurtleState
s <- Parser TurtleState TurtleState
forall s. Parser s s
stGet
([Char] -> Parser TurtleState URI)
-> (URI -> Parser TurtleState URI)
-> Either [Char] URI
-> Parser TurtleState URI
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either [Char] -> Parser TurtleState URI
forall a. [Char] -> Parser TurtleState a
forall (m :: * -> *) a. MonadFail m => [Char] -> m a
fail URI -> Parser TurtleState URI
forall a. a -> Parser TurtleState a
forall (m :: * -> *) a. Monad m => a -> m a
return (Either [Char] URI -> Parser TurtleState URI)
-> Either [Char] URI -> Parser TurtleState URI
forall a b. (a -> b) -> a -> b
$ URI -> URI -> Either [Char] URI
appendURIs (TurtleState -> URI
baseUri TurtleState
s) URI
uref
iriRefChar :: TurtleParser Char
iriRefChar :: Parser TurtleState Char
iriRefChar = (Char -> Bool) -> Parser TurtleState Char
forall s. (Char -> Bool) -> Parser s Char
satisfy Char -> Bool
isIRIChar Parser TurtleState Char
-> Parser TurtleState Char -> Parser TurtleState Char
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser TurtleState Char
_uchar
isIRIChar :: Char -> Bool
isIRIChar :: Char -> Bool
isIRIChar Char
c =
Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
> Int -> Char
chr Int
0x20
Bool -> Bool -> Bool
&&
Char
c Char -> [Char] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` ([Char]
"<>\"{}|^`\\"::String)
_pnameNS :: TurtleParser (Maybe L.Text)
_pnameNS :: Parser TurtleState (Maybe Text)
_pnameNS = Parser TurtleState Text -> Parser TurtleState (Maybe Text)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional Parser TurtleState Text
_pnPrefix Parser TurtleState (Maybe Text)
-> Parser TurtleState Char -> Parser TurtleState (Maybe Text)
forall a b.
Parser TurtleState a
-> Parser TurtleState b -> Parser TurtleState a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Char -> Parser TurtleState Char
forall s. Char -> Parser s Char
char Char
':'
_pnameLN :: TurtleParser ScopedName
_pnameLN :: Parser TurtleState ScopedName
_pnameLN = do
Namespace
ns <- Parser TurtleState (Maybe Text)
_pnameNS Parser TurtleState (Maybe Text)
-> (Maybe Text -> TurtleParser Namespace) -> TurtleParser Namespace
forall a b.
Parser TurtleState a
-> (a -> Parser TurtleState b) -> Parser TurtleState b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Maybe Text -> TurtleParser Namespace
findPrefixNamespace
Text
l <- (Text -> Text)
-> Parser TurtleState Text -> Parser TurtleState Text
forall a b.
(a -> b) -> Parser TurtleState a -> Parser TurtleState b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Text -> Text
L.toStrict Parser TurtleState Text
_pnLocal
case Text -> Maybe LName
newLName Text
l of
Just LName
lname -> ScopedName -> Parser TurtleState ScopedName
forall a. a -> Parser TurtleState a
forall (m :: * -> *) a. Monad m => a -> m a
return (ScopedName -> Parser TurtleState ScopedName)
-> ScopedName -> Parser TurtleState ScopedName
forall a b. (a -> b) -> a -> b
$ Namespace -> LName -> ScopedName
makeNSScopedName Namespace
ns LName
lname
Maybe LName
_ -> [Char] -> Parser TurtleState ScopedName
forall a. [Char] -> Parser TurtleState a
forall (m :: * -> *) a. MonadFail m => [Char] -> m a
fail ([Char] -> Parser TurtleState ScopedName)
-> [Char] -> Parser TurtleState ScopedName
forall a b. (a -> b) -> a -> b
$ [Char]
"Invalid local name: '" [Char] -> ShowS
forall a. [a] -> [a] -> [a]
++ Text -> [Char]
T.unpack Text
l [Char] -> ShowS
forall a. [a] -> [a] -> [a]
++ [Char]
"'"
_blankNodeLabel :: TurtleParser RDFLabel
_blankNodeLabel :: TurtleParser RDFLabel
_blankNodeLabel = do
Parser TurtleState [Char] -> Parser TurtleState ()
forall (f :: * -> *) a. Applicative f => f a -> f ()
ignore (Parser TurtleState [Char] -> Parser TurtleState ())
-> Parser TurtleState [Char] -> Parser TurtleState ()
forall a b. (a -> b) -> a -> b
$ [Char] -> Parser TurtleState [Char]
forall s. [Char] -> Parser s [Char]
string [Char]
"_:"
Char
fChar <- Parser TurtleState Char
_pnCharsU Parser TurtleState Char
-> Parser TurtleState Char -> Parser TurtleState Char
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Char -> Bool) -> Parser TurtleState Char
forall s. (Char -> Bool) -> Parser s Char
satisfy Char -> Bool
is09
Text
rest <- Parser TurtleState Text
_pnRest
RDFLabel -> TurtleParser RDFLabel
forall a. a -> Parser TurtleState a
forall (m :: * -> *) a. Monad m => a -> m a
return (RDFLabel -> TurtleParser RDFLabel)
-> RDFLabel -> TurtleParser RDFLabel
forall a b. (a -> b) -> a -> b
$ [Char] -> RDFLabel
Blank ([Char] -> RDFLabel) -> [Char] -> RDFLabel
forall a b. (a -> b) -> a -> b
$ Char
fChar Char -> ShowS
forall a. a -> [a] -> [a]
: Text -> [Char]
L.unpack Text
rest
_pnRest :: TurtleParser L.Text
_pnRest :: Parser TurtleState Text
_pnRest = Parser TurtleState Char -> Parser TurtleState Text
noTrailingDot Parser TurtleState Char
_pnChars
noTrailing ::
TurtleParser a
-> ([a] -> String)
-> TurtleParser a
-> TurtleParser L.Text
noTrailing :: forall a.
TurtleParser a
-> ([a] -> [Char]) -> TurtleParser a -> Parser TurtleState Text
noTrailing TurtleParser a
dotParser [a] -> [Char]
conv TurtleParser a
parser = do
[a]
lbl <- TurtleParser a -> Parser TurtleState [a]
forall a. Parser TurtleState a -> Parser TurtleState [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (TurtleParser a
parser TurtleParser a -> TurtleParser a -> TurtleParser a
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> TurtleParser a
dotParser)
let (Int
nret, [Char]
lclean) = [Char] -> (Int, [Char])
clean ([Char] -> (Int, [Char])) -> [Char] -> (Int, [Char])
forall a b. (a -> b) -> a -> b
$ [a] -> [Char]
conv [a]
lbl
edl :: a -> a
edl = a -> a
forall a. a -> a
id
snocdl :: a -> ([a] -> c) -> [a] -> c
snocdl a
x [a] -> c
xs = [a] -> c
xs ([a] -> c) -> ([a] -> [a]) -> [a] -> c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a
xa -> [a] -> [a]
forall a. a -> [a] -> [a]
:)
appenddl :: (b -> c) -> (a -> b) -> a -> c
appenddl = (b -> c) -> (a -> b) -> a -> c
forall b c a. (b -> c) -> (a -> b) -> a -> c
(.)
replicatedl :: Int -> a -> [a] -> [a]
replicatedl Int
n a
x = (Int -> a -> [a]
forall a. Int -> a -> [a]
replicate Int
n a
x [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
++)
clean :: String -> (Int, String)
clean :: [Char] -> (Int, [Char])
clean = Int -> ShowS -> [Char] -> (Int, [Char])
forall {b}. Int -> ([Char] -> b) -> [Char] -> (Int, b)
go Int
0 ShowS
forall a. a -> a
edl
where
go :: Int -> ([Char] -> b) -> [Char] -> (Int, b)
go Int
n [Char] -> b
acc [] = (Int
n, [Char] -> b
acc [])
go Int
n [Char] -> b
acc (Char
'.':[Char]
xs) = Int -> ([Char] -> b) -> [Char] -> (Int, b)
go (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) [Char] -> b
acc [Char]
xs
go Int
0 [Char] -> b
acc (Char
x:[Char]
xs) = Int -> ([Char] -> b) -> [Char] -> (Int, b)
go Int
0 (Char -> ([Char] -> b) -> [Char] -> b
forall {a} {c}. a -> ([a] -> c) -> [a] -> c
snocdl Char
x [Char] -> b
acc) [Char]
xs
go Int
n [Char] -> b
acc (Char
x:[Char]
xs) = Int -> ([Char] -> b) -> [Char] -> (Int, b)
go Int
0 (([Char] -> b) -> ShowS -> [Char] -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
appenddl [Char] -> b
acc (Char -> ShowS -> ShowS
forall {a} {c}. a -> ([a] -> c) -> [a] -> c
snocdl Char
x (Int -> Char -> ShowS
forall {a}. Int -> a -> [a] -> [a]
replicatedl Int
n Char
'.'))) [Char]
xs
Text -> Parser TurtleState ()
forall s. Text -> Parser s ()
reparse (Text -> Parser TurtleState ()) -> Text -> Parser TurtleState ()
forall a b. (a -> b) -> a -> b
$ Int64 -> Text -> Text
L.replicate (Int -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
nret) Text
"."
Text -> Parser TurtleState Text
forall a. a -> Parser TurtleState a
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> Parser TurtleState Text)
-> Text -> Parser TurtleState Text
forall a b. (a -> b) -> a -> b
$ [Char] -> Text
L.pack [Char]
lclean
noTrailingDot ::
TurtleParser Char
-> TurtleParser L.Text
noTrailingDot :: Parser TurtleState Char -> Parser TurtleState Text
noTrailingDot = Parser TurtleState Char
-> ShowS -> Parser TurtleState Char -> Parser TurtleState Text
forall a.
TurtleParser a
-> ([a] -> [Char]) -> TurtleParser a -> Parser TurtleState Text
noTrailing (Char -> Parser TurtleState Char
forall s. Char -> Parser s Char
char Char
'.') ShowS
forall a. a -> a
id
noTrailingDotM ::
TurtleParser L.Text
-> TurtleParser L.Text
noTrailingDotM :: Parser TurtleState Text -> Parser TurtleState Text
noTrailingDotM = Parser TurtleState Text
-> ([Text] -> [Char])
-> Parser TurtleState Text
-> Parser TurtleState Text
forall a.
TurtleParser a
-> ([a] -> [Char]) -> TurtleParser a -> Parser TurtleState Text
noTrailing (Char -> Parser TurtleState Char
forall s. Char -> Parser s Char
char Char
'.' Parser TurtleState Char -> Text -> Parser TurtleState Text
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Text
".") (Text -> [Char]
L.unpack (Text -> [Char]) -> ([Text] -> Text) -> [Text] -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Text] -> Text
L.concat)
_langTag :: TurtleParser LanguageTag
_langTag :: Parser TurtleState LanguageTag
_langTag = do
Char -> Parser TurtleState ()
forall s. Char -> Parser s ()
ichar Char
'@'
Text
h <- Parser TurtleState Text -> Parser TurtleState Text
forall a. Parser TurtleState a -> Parser TurtleState a
forall (p :: * -> *) a. Commitment p => p a -> p a
commit (Parser TurtleState Text -> Parser TurtleState Text)
-> Parser TurtleState Text -> Parser TurtleState Text
forall a b. (a -> b) -> a -> b
$ (Char -> Bool) -> Parser TurtleState Text
forall s. (Char -> Bool) -> Parser s Text
many1Satisfy Char -> Bool
isaZ
Maybe Text
mt <- Parser TurtleState Text -> Parser TurtleState (Maybe Text)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Char -> Text -> Text
L.cons (Char -> Text -> Text)
-> Parser TurtleState Char -> Parser TurtleState (Text -> Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Char -> Parser TurtleState Char
forall s. Char -> Parser s Char
char Char
'-' Parser TurtleState (Text -> Text)
-> Parser TurtleState Text -> Parser TurtleState Text
forall a b.
Parser TurtleState (a -> b)
-> Parser TurtleState a -> Parser TurtleState b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Char -> Bool) -> Parser TurtleState Text
forall s. (Char -> Bool) -> Parser s Text
many1Satisfy Char -> Bool
isaZ09)
let lbl :: Text
lbl = Text -> Text
L.toStrict (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ Text -> Text -> Text
L.append Text
h (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
fromMaybe Text
L.empty Maybe Text
mt
case Text -> Maybe LanguageTag
toLangTag Text
lbl of
Just LanguageTag
lt -> LanguageTag -> Parser TurtleState LanguageTag
forall a. a -> Parser TurtleState a
forall (m :: * -> *) a. Monad m => a -> m a
return LanguageTag
lt
Maybe LanguageTag
_ -> [Char] -> Parser TurtleState LanguageTag
forall a. [Char] -> Parser TurtleState a
forall (m :: * -> *) a. MonadFail m => [Char] -> m a
fail ([Char]
"Invalid language tag: " [Char] -> ShowS
forall a. [a] -> [a] -> [a]
++ Text -> [Char]
T.unpack Text
lbl)
_leadingSign :: TurtleParser (Maybe Bool)
_leadingSign :: TurtleParser (Maybe Bool)
_leadingSign = do
Maybe Char
ms <- Parser TurtleState Char -> Parser TurtleState (Maybe Char)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional ((Char -> Bool) -> Parser TurtleState Char
forall s. (Char -> Bool) -> Parser s Char
satisfy (Char -> [Char] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` ([Char]
"+-"::String)))
Maybe Bool -> TurtleParser (Maybe Bool)
forall a. a -> Parser TurtleState a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe Bool -> TurtleParser (Maybe Bool))
-> Maybe Bool -> TurtleParser (Maybe Bool)
forall a b. (a -> b) -> a -> b
$ (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'+') (Char -> Bool) -> Maybe Char -> Maybe Bool
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` Maybe Char
ms
addSign :: Maybe Bool -> L.Text -> L.Text
addSign :: Maybe Bool -> Text -> Text
addSign (Just Bool
True) Text
t = Char -> Text -> Text
L.cons Char
'+' Text
t
addSign (Just Bool
_) Text
t = Char -> Text -> Text
L.cons Char
'-' Text
t
addSign Maybe Bool
_ Text
t = Text
t
_integer :: TurtleParser L.Text
_integer :: Parser TurtleState Text
_integer = do
Maybe Bool
ms <- TurtleParser (Maybe Bool)
_leadingSign
Text
rest <- (Char -> Bool) -> Parser TurtleState Text
forall s. (Char -> Bool) -> Parser s Text
many1Satisfy Char -> Bool
is09
Text -> Parser TurtleState Text
forall a. a -> Parser TurtleState a
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> Parser TurtleState Text)
-> Text -> Parser TurtleState Text
forall a b. (a -> b) -> a -> b
$ Maybe Bool -> Text -> Text
addSign Maybe Bool
ms Text
rest
_decimal :: TurtleParser L.Text
_decimal :: Parser TurtleState Text
_decimal = do
Maybe Bool
ms <- TurtleParser (Maybe Bool)
_leadingSign
Text
leading <- (Char -> Bool) -> Parser TurtleState Text
forall s. (Char -> Bool) -> Parser s Text
manySatisfy Char -> Bool
is09
Char -> Parser TurtleState ()
forall s. Char -> Parser s ()
ichar Char
'.'
Text
trailing <- (Char -> Bool) -> Parser TurtleState Text
forall s. (Char -> Bool) -> Parser s Text
many1Satisfy Char -> Bool
is09
let ans2 :: Text
ans2 = Char -> Text -> Text
L.cons Char
'.' Text
trailing
ans :: Text
ans = if Text -> Bool
L.null Text
leading
then Text
ans2
else Text -> Text -> Text
L.append Text
leading Text
ans2
Text -> Parser TurtleState Text
forall a. a -> Parser TurtleState a
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> Parser TurtleState Text)
-> Text -> Parser TurtleState Text
forall a b. (a -> b) -> a -> b
$ Maybe Bool -> Text -> Text
addSign Maybe Bool
ms Text
ans
_d1 :: TurtleParser L.Text
_d1 :: Parser TurtleState Text
_d1 = do
Text
a <- (Char -> Bool) -> Parser TurtleState Text
forall s. (Char -> Bool) -> Parser s Text
many1Satisfy Char -> Bool
is09
Char -> Parser TurtleState ()
forall s. Char -> Parser s ()
ichar Char
'.'
Text
b <- (Char -> Bool) -> Parser TurtleState Text
forall s. (Char -> Bool) -> Parser s Text
manySatisfy Char -> Bool
is09
Text -> Parser TurtleState Text
forall a. a -> Parser TurtleState a
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> Parser TurtleState Text)
-> Text -> Parser TurtleState Text
forall a b. (a -> b) -> a -> b
$ Text
a Text -> Text -> Text
`L.append` (Char
'.' Char -> Text -> Text
`L.cons` Text
b)
_d2 :: TurtleParser L.Text
_d2 :: Parser TurtleState Text
_d2 = do
Char -> Parser TurtleState ()
forall s. Char -> Parser s ()
ichar Char
'.'
Text
b <- (Char -> Bool) -> Parser TurtleState Text
forall s. (Char -> Bool) -> Parser s Text
many1Satisfy Char -> Bool
is09
Text -> Parser TurtleState Text
forall a. a -> Parser TurtleState a
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> Parser TurtleState Text)
-> Text -> Parser TurtleState Text
forall a b. (a -> b) -> a -> b
$ Char
'.' Char -> Text -> Text
`L.cons` Text
b
_d3 :: TurtleParser L.Text
_d3 :: Parser TurtleState Text
_d3 = (Char -> Bool) -> Parser TurtleState Text
forall s. (Char -> Bool) -> Parser s Text
many1Satisfy Char -> Bool
is09
_double :: TurtleParser L.Text
_double :: Parser TurtleState Text
_double = do
Maybe Bool
ms <- TurtleParser (Maybe Bool)
_leadingSign
Text
leading <- Parser TurtleState Text
_d1 Parser TurtleState Text
-> Parser TurtleState Text -> Parser TurtleState Text
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser TurtleState Text
_d2 Parser TurtleState Text
-> Parser TurtleState Text -> Parser TurtleState Text
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser TurtleState Text
_d3
Text
e <- Parser TurtleState Text
_exponent
Text -> Parser TurtleState Text
forall a. a -> Parser TurtleState a
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> Parser TurtleState Text)
-> Text -> Parser TurtleState Text
forall a b. (a -> b) -> a -> b
$ Maybe Bool -> Text -> Text
addSign Maybe Bool
ms (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ Text
leading Text -> Text -> Text
`L.append` Text
e
_exponent :: TurtleParser L.Text
_exponent :: Parser TurtleState Text
_exponent = do
Char
e <- Char -> Parser TurtleState Char
forall s. Char -> Parser s Char
char Char
'e' Parser TurtleState Char
-> Parser TurtleState Char -> Parser TurtleState Char
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Char -> Parser TurtleState Char
forall s. Char -> Parser s Char
char Char
'E'
Maybe Bool
ms <- TurtleParser (Maybe Bool)
_leadingSign
Char -> Text -> Text
L.cons Char
e (Text -> Text) -> (Text -> Text) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe Bool -> Text -> Text
addSign Maybe Bool
ms (Text -> Text)
-> Parser TurtleState Text -> Parser TurtleState Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser TurtleState Text
_integer
_protChar :: TurtleParser Char
_protChar :: Parser TurtleState Char
_protChar = Char -> Parser TurtleState Char
forall s. Char -> Parser s Char
char Char
'\\' Parser TurtleState Char
-> Parser TurtleState Char -> Parser TurtleState Char
forall a b.
Parser TurtleState a
-> Parser TurtleState b -> Parser TurtleState b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (Parser TurtleState Char
_echar' Parser TurtleState Char
-> Parser TurtleState Char -> Parser TurtleState Char
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser TurtleState Char
_uchar')
_exclSLQ, _exclSLSQ :: String
_exclSLQ :: [Char]
_exclSLQ = (Int -> Char) -> [Int] -> [Char]
forall a b. (a -> b) -> [a] -> [b]
map Int -> Char
chr [Int
0x22, Int
0x5c, Int
0x0a, Int
0x0d]
_exclSLSQ :: [Char]
_exclSLSQ = (Int -> Char) -> [Int] -> [Char]
forall a b. (a -> b) -> [a] -> [b]
map Int -> Char
chr [Int
0x27, Int
0x5c, Int
0x0a, Int
0x0d]
_stringLiteralQuote, _stringLiteralSingleQuote :: TurtleParser L.Text
_stringLiteralQuote :: Parser TurtleState Text
_stringLiteralQuote = Parser TurtleState ()
-> Parser TurtleState Char -> Parser TurtleState Text
forall a.
TurtleParser a
-> Parser TurtleState Char -> Parser TurtleState Text
_stringIt Parser TurtleState ()
dQuot ([Char] -> Parser TurtleState Char
_tChars [Char]
_exclSLQ)
_stringLiteralSingleQuote :: Parser TurtleState Text
_stringLiteralSingleQuote = Parser TurtleState ()
-> Parser TurtleState Char -> Parser TurtleState Text
forall a.
TurtleParser a
-> Parser TurtleState Char -> Parser TurtleState Text
_stringIt Parser TurtleState ()
sQuot ([Char] -> Parser TurtleState Char
_tChars [Char]
_exclSLSQ)
_stringLiteralLongQuote, _stringLiteralLongSingleQuote :: TurtleParser L.Text
_stringLiteralLongQuote :: Parser TurtleState Text
_stringLiteralLongQuote = Parser TurtleState ()
-> Parser TurtleState Text -> Parser TurtleState Text
forall a.
TurtleParser a
-> Parser TurtleState Text -> Parser TurtleState Text
_stringItLong Parser TurtleState ()
dQuot3 (Char -> Parser TurtleState Text
_tCharsLong Char
'"')
_stringLiteralLongSingleQuote :: Parser TurtleState Text
_stringLiteralLongSingleQuote = Parser TurtleState ()
-> Parser TurtleState Text -> Parser TurtleState Text
forall a.
TurtleParser a
-> Parser TurtleState Text -> Parser TurtleState Text
_stringItLong Parser TurtleState ()
sQuot3 (Char -> Parser TurtleState Text
_tCharsLong Char
'\'')
_stringIt :: TurtleParser a -> TurtleParser Char -> TurtleParser L.Text
_stringIt :: forall a.
TurtleParser a
-> Parser TurtleState Char -> Parser TurtleState Text
_stringIt TurtleParser a
sep Parser TurtleState Char
chars = [Char] -> Text
L.pack ([Char] -> Text)
-> Parser TurtleState [Char] -> Parser TurtleState Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TurtleParser a
-> TurtleParser a
-> Parser TurtleState [Char]
-> Parser TurtleState [Char]
forall (p :: * -> *) bra ket a.
PolyParse p =>
p bra -> p ket -> p a -> p a
bracket TurtleParser a
sep TurtleParser a
sep (Parser TurtleState Char -> Parser TurtleState [Char]
forall a. Parser TurtleState a -> Parser TurtleState [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many Parser TurtleState Char
chars)
_stringItLong :: TurtleParser a -> TurtleParser L.Text -> TurtleParser L.Text
_stringItLong :: forall a.
TurtleParser a
-> Parser TurtleState Text -> Parser TurtleState Text
_stringItLong TurtleParser a
sep Parser TurtleState Text
chars = [Text] -> Text
L.concat ([Text] -> Text)
-> Parser TurtleState [Text] -> Parser TurtleState Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TurtleParser a
-> TurtleParser a
-> Parser TurtleState [Text]
-> Parser TurtleState [Text]
forall (p :: * -> *) bra ket a.
PolyParse p =>
p bra -> p ket -> p a -> p a
bracket TurtleParser a
sep TurtleParser a
sep (Parser TurtleState Text -> Parser TurtleState [Text]
forall a. Parser TurtleState a -> Parser TurtleState [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many Parser TurtleState Text
chars)
_tChars :: String -> TurtleParser Char
_tChars :: [Char] -> Parser TurtleState Char
_tChars [Char]
excl = Parser TurtleState Char
_protChar Parser TurtleState Char
-> Parser TurtleState Char -> Parser TurtleState Char
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Parser TurtleState Char
forall s. [Char] -> Parser s Char
noneOf [Char]
excl
oneOrTwo :: Char -> TurtleParser L.Text
oneOrTwo :: Char -> Parser TurtleState Text
oneOrTwo Char
c = do
Parser TurtleState Char -> Parser TurtleState ()
forall (f :: * -> *) a. Applicative f => f a -> f ()
ignore (Parser TurtleState Char -> Parser TurtleState ())
-> Parser TurtleState Char -> Parser TurtleState ()
forall a b. (a -> b) -> a -> b
$ Char -> Parser TurtleState Char
forall s. Char -> Parser s Char
char Char
c
Maybe Char
mb <- Parser TurtleState Char -> Parser TurtleState (Maybe Char)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Char -> Parser TurtleState Char
forall s. Char -> Parser s Char
char Char
c)
case Maybe Char
mb of
Just Char
_ -> Text -> Parser TurtleState Text
forall a. a -> Parser TurtleState a
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> Parser TurtleState Text)
-> Text -> Parser TurtleState Text
forall a b. (a -> b) -> a -> b
$ [Char] -> Text
L.pack [Char
c,Char
c]
Maybe Char
_ -> Text -> Parser TurtleState Text
forall a. a -> Parser TurtleState a
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> Parser TurtleState Text)
-> Text -> Parser TurtleState Text
forall a b. (a -> b) -> a -> b
$ Char -> Text
L.singleton Char
c
_multiQuote :: Char -> TurtleParser L.Text
_multiQuote :: Char -> Parser TurtleState Text
_multiQuote Char
c = do
Maybe Text
mq <- Parser TurtleState Text -> Parser TurtleState (Maybe Text)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Char -> Parser TurtleState Text
oneOrTwo Char
c)
Char
r <- [Char] -> Parser TurtleState Char
forall s. [Char] -> Parser s Char
noneOf (Char
c Char -> ShowS
forall a. a -> [a] -> [a]
: [Char]
"\\")
Text -> Parser TurtleState Text
forall a. a -> Parser TurtleState a
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> Parser TurtleState Text)
-> Text -> Parser TurtleState Text
forall a b. (a -> b) -> a -> b
$ Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
fromMaybe Text
L.empty Maybe Text
mq Text -> Char -> Text
`L.snoc` Char
r
_tCharsLong :: Char -> TurtleParser L.Text
_tCharsLong :: Char -> Parser TurtleState Text
_tCharsLong Char
c =
Char -> Text
L.singleton (Char -> Text)
-> Parser TurtleState Char -> Parser TurtleState Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser TurtleState Char
_protChar
Parser TurtleState Text
-> Parser TurtleState Text -> Parser TurtleState Text
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Char -> Parser TurtleState Text
_multiQuote Char
c
_uchar :: TurtleParser Char
_uchar :: Parser TurtleState Char
_uchar = Char -> Parser TurtleState Char
forall s. Char -> Parser s Char
char Char
'\\' Parser TurtleState Char
-> Parser TurtleState Char -> Parser TurtleState Char
forall a b.
Parser TurtleState a
-> Parser TurtleState b -> Parser TurtleState b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser TurtleState Char
_uchar'
_uchar' :: TurtleParser Char
_uchar' :: Parser TurtleState Char
_uchar' =
(Char -> Parser TurtleState Char
forall s. Char -> Parser s Char
char Char
'u' Parser TurtleState Char
-> Parser TurtleState Char -> Parser TurtleState Char
forall a b.
Parser TurtleState a
-> Parser TurtleState b -> Parser TurtleState b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (Parser TurtleState Char -> Parser TurtleState Char
forall a. Parser TurtleState a -> Parser TurtleState a
forall (p :: * -> *) a. Commitment p => p a -> p a
commit Parser TurtleState Char
forall a. Parser a Char
hex4 Parser TurtleState Char -> [Char] -> Parser TurtleState Char
forall s a. Parser s a -> [Char] -> Parser s a
<? [Char]
"Expected 4 hex characters after \\u"))
Parser TurtleState Char
-> Parser TurtleState Char -> Parser TurtleState Char
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
(Char -> Parser TurtleState Char
forall s. Char -> Parser s Char
char Char
'U' Parser TurtleState Char
-> Parser TurtleState Char -> Parser TurtleState Char
forall a b.
Parser TurtleState a
-> Parser TurtleState b -> Parser TurtleState b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (Parser TurtleState Char -> Parser TurtleState Char
forall a. Parser TurtleState a -> Parser TurtleState a
forall (p :: * -> *) a. Commitment p => p a -> p a
commit Parser TurtleState Char
forall a. Parser a Char
hex8 Parser TurtleState Char -> [Char] -> Parser TurtleState Char
forall s a. Parser s a -> [Char] -> Parser s a
<? [Char]
"Expected 8 hex characters after \\U"))
_echar' :: TurtleParser Char
_echar' :: Parser TurtleState Char
_echar' =
(Char -> Parser TurtleState Char
forall s. Char -> Parser s Char
char Char
't' Parser TurtleState Char -> Char -> Parser TurtleState Char
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Char
'\t') Parser TurtleState Char
-> Parser TurtleState Char -> Parser TurtleState Char
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
(Char -> Parser TurtleState Char
forall s. Char -> Parser s Char
char Char
'b' Parser TurtleState Char -> Char -> Parser TurtleState Char
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Char
'\b') Parser TurtleState Char
-> Parser TurtleState Char -> Parser TurtleState Char
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
(Char -> Parser TurtleState Char
forall s. Char -> Parser s Char
char Char
'n' Parser TurtleState Char -> Char -> Parser TurtleState Char
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Char
'\n') Parser TurtleState Char
-> Parser TurtleState Char -> Parser TurtleState Char
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
(Char -> Parser TurtleState Char
forall s. Char -> Parser s Char
char Char
'r' Parser TurtleState Char -> Char -> Parser TurtleState Char
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Char
'\r') Parser TurtleState Char
-> Parser TurtleState Char -> Parser TurtleState Char
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
(Char -> Parser TurtleState Char
forall s. Char -> Parser s Char
char Char
'f' Parser TurtleState Char -> Char -> Parser TurtleState Char
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Char
'\f') Parser TurtleState Char
-> Parser TurtleState Char -> Parser TurtleState Char
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
(Char -> Parser TurtleState Char
forall s. Char -> Parser s Char
char Char
'\\' Parser TurtleState Char -> Char -> Parser TurtleState Char
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Char
'\\') Parser TurtleState Char
-> Parser TurtleState Char -> Parser TurtleState Char
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
(Char -> Parser TurtleState Char
forall s. Char -> Parser s Char
char Char
'"' Parser TurtleState Char -> Char -> Parser TurtleState Char
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Char
'"') Parser TurtleState Char
-> Parser TurtleState Char -> Parser TurtleState Char
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
(Char -> Parser TurtleState Char
forall s. Char -> Parser s Char
char Char
'\'' Parser TurtleState Char -> Char -> Parser TurtleState Char
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Char
'\'')
_ws :: TurtleParser ()
_ws :: Parser TurtleState ()
_ws = Parser TurtleState Char -> Parser TurtleState ()
forall (f :: * -> *) a. Applicative f => f a -> f ()
ignore (Parser TurtleState Char -> Parser TurtleState ())
-> Parser TurtleState Char -> Parser TurtleState ()
forall a b. (a -> b) -> a -> b
$ (Char -> Bool) -> Parser TurtleState Char
forall s. (Char -> Bool) -> Parser s Char
satisfy (Char -> [Char] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Char]
_wsChars)
_wsChars :: String
_wsChars :: [Char]
_wsChars = (Int -> Char) -> [Int] -> [Char]
forall a b. (a -> b) -> [a] -> [b]
map Int -> Char
chr [Int
0x20, Int
0x09, Int
0x0d, Int
0x0a]
_anon :: TurtleParser RDFLabel
_anon :: TurtleParser RDFLabel
_anon =
Char -> Char -> Parser TurtleState [()] -> Parser TurtleState [()]
forall a. Char -> Char -> TurtleParser a -> TurtleParser a
br Char
'[' Char
']' (Parser TurtleState () -> Parser TurtleState [()]
forall a. Parser TurtleState a -> Parser TurtleState [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many Parser TurtleState ()
_ws) Parser TurtleState [()]
-> TurtleParser RDFLabel -> TurtleParser RDFLabel
forall a b.
Parser TurtleState a
-> Parser TurtleState b -> Parser TurtleState b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> TurtleParser RDFLabel
newBlankNode
_pnCharsBase :: TurtleParser Char
_pnCharsBase :: Parser TurtleState Char
_pnCharsBase =
let f :: Char -> Bool
f Char
c = let i :: Int
i = Char -> Int
ord Char
c
in Char -> Bool
isaZ Char
c Bool -> Bool -> Bool
||
Int -> [(Int, Int)] -> Bool
forall a. Ord a => a -> [(a, a)] -> Bool
match Int
i [(Int
0xc0, Int
0xd6), (Int
0xd8, Int
0xf6), (Int
0xf8, Int
0x2ff),
(Int
0x370, Int
0x37d), (Int
0x37f, Int
0x1fff), (Int
0x200c, Int
0x200d),
(Int
0x2070, Int
0x218f), (Int
0x2c00, Int
0x2fef), (Int
0x3001, Int
0xd7ff),
(Int
0xf900, Int
0xfdcf), (Int
0xfdf0, Int
0xfffd), (Int
0x10000, Int
0xeffff)]
in (Char -> Bool) -> Parser TurtleState Char
forall s. (Char -> Bool) -> Parser s Char
satisfy Char -> Bool
f
_pnCharsU, _pnChars :: TurtleParser Char
_pnCharsU :: Parser TurtleState Char
_pnCharsU = Parser TurtleState Char
_pnCharsBase Parser TurtleState Char
-> Parser TurtleState Char -> Parser TurtleState Char
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Char -> Parser TurtleState Char
forall s. Char -> Parser s Char
char Char
'_'
_pnChars :: Parser TurtleState Char
_pnChars =
let f :: Char -> Bool
f Char
c = let i :: Int
i = Char -> Int
ord Char
c
in Int -> [(Int, Int)] -> Bool
forall a. Ord a => a -> [(a, a)] -> Bool
match Int
i [(Int
0x300, Int
0x36f), (Int
0x203f, Int
0x2040)]
in Parser TurtleState Char
_pnCharsU Parser TurtleState Char
-> Parser TurtleState Char -> Parser TurtleState Char
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Char -> Parser TurtleState Char
forall s. Char -> Parser s Char
char Char
'-' Parser TurtleState Char
-> Parser TurtleState Char -> Parser TurtleState Char
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Char -> Bool) -> Parser TurtleState Char
forall s. (Char -> Bool) -> Parser s Char
satisfy Char -> Bool
is09 Parser TurtleState Char
-> Parser TurtleState Char -> Parser TurtleState Char
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
Char -> Parser TurtleState Char
forall s. Char -> Parser s Char
char (Int -> Char
chr Int
0xb7) Parser TurtleState Char
-> Parser TurtleState Char -> Parser TurtleState Char
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Char -> Bool) -> Parser TurtleState Char
forall s. (Char -> Bool) -> Parser s Char
satisfy Char -> Bool
f
_pnPrefix :: TurtleParser L.Text
_pnPrefix :: Parser TurtleState Text
_pnPrefix = Char -> Text -> Text
L.cons (Char -> Text -> Text)
-> Parser TurtleState Char -> Parser TurtleState (Text -> Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser TurtleState Char
_pnCharsBase Parser TurtleState (Text -> Text)
-> Parser TurtleState Text -> Parser TurtleState Text
forall a b.
Parser TurtleState (a -> b)
-> Parser TurtleState a -> Parser TurtleState b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser TurtleState Text
_pnRest
_pnLocal :: TurtleParser L.Text
_pnLocal :: Parser TurtleState Text
_pnLocal = do
Text
s <- Char -> Text
L.singleton (Char -> Text)
-> Parser TurtleState Char -> Parser TurtleState Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Parser TurtleState Char
_pnCharsU Parser TurtleState Char
-> Parser TurtleState Char -> Parser TurtleState Char
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Char -> Parser TurtleState Char
forall s. Char -> Parser s Char
char Char
':' Parser TurtleState Char
-> Parser TurtleState Char -> Parser TurtleState Char
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Char -> Bool) -> Parser TurtleState Char
forall s. (Char -> Bool) -> Parser s Char
satisfy Char -> Bool
is09)
Parser TurtleState Text
-> Parser TurtleState Text -> Parser TurtleState Text
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser TurtleState Text
_plx
Text
e <- Parser TurtleState Text -> Parser TurtleState Text
noTrailingDotM (Char -> Text
L.singleton (Char -> Text)
-> Parser TurtleState Char -> Parser TurtleState Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Parser TurtleState Char
_pnChars Parser TurtleState Char
-> Parser TurtleState Char -> Parser TurtleState Char
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Char -> Parser TurtleState Char
forall s. Char -> Parser s Char
char Char
':') Parser TurtleState Text
-> Parser TurtleState Text -> Parser TurtleState Text
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser TurtleState Text
_plx)
Text -> Parser TurtleState Text
forall a. a -> Parser TurtleState a
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> Parser TurtleState Text)
-> Text -> Parser TurtleState Text
forall a b. (a -> b) -> a -> b
$ Text
s Text -> Text -> Text
`L.append` Text
e
_plx, _percent :: TurtleParser L.Text
_plx :: Parser TurtleState Text
_plx = Parser TurtleState Text
_percent Parser TurtleState Text
-> Parser TurtleState Text -> Parser TurtleState Text
forall a.
Parser TurtleState a
-> Parser TurtleState a -> Parser TurtleState a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Char -> Text
L.singleton (Char -> Text)
-> Parser TurtleState Char -> Parser TurtleState Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser TurtleState Char
_pnLocalEsc)
_percent :: Parser TurtleState Text
_percent = do
Char -> Parser TurtleState ()
forall s. Char -> Parser s ()
ichar Char
'%'
Char
a <- Parser TurtleState Char
_hex
Char -> Text -> Text
L.cons Char
'%' (Text -> Text) -> (Char -> Text) -> Char -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Text -> Text
L.cons Char
a (Text -> Text) -> (Char -> Text) -> Char -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Text
L.singleton (Char -> Text)
-> Parser TurtleState Char -> Parser TurtleState Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser TurtleState Char
_hex
_hex, _pnLocalEsc :: TurtleParser Char
_hex :: Parser TurtleState Char
_hex = (Char -> Bool) -> Parser TurtleState Char
forall s. (Char -> Bool) -> Parser s Char
satisfy Char -> Bool
isHexDigit
_pnLocalEsc :: Parser TurtleState Char
_pnLocalEsc = Char -> Parser TurtleState Char
forall s. Char -> Parser s Char
char Char
'\\' Parser TurtleState Char
-> Parser TurtleState Char -> Parser TurtleState Char
forall a b.
Parser TurtleState a
-> Parser TurtleState b -> Parser TurtleState b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (Char -> Bool) -> Parser TurtleState Char
forall s. (Char -> Bool) -> Parser s Char
satisfy (Char -> [Char] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Char]
_pnLocalEscChars)
_pnLocalEscChars :: String
_pnLocalEscChars :: [Char]
_pnLocalEscChars = [Char]
"_~.-!$&'()*+,;=/?#@%"