Skip to content

Commit

Permalink
Code cleanup and more haddock twiddles
Browse files Browse the repository at this point in the history
  • Loading branch information
robstewart57 committed Apr 16, 2016
1 parent c8208f1 commit a08040b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
12 changes: 3 additions & 9 deletions src/Data/RDF/Types.hs
Expand Up @@ -9,7 +9,7 @@ module Data.RDF.Types (

-- * Constructor functions
plainL,plainLL,typedL,
unode,bnode,lnode,triple,unodeValidate,uriValidate,
unode,bnode,lnode,triple,unodeValidate,uriValidate,uriValidateString,

-- * Node query function
isUNode,isLNode,isBNode,
Expand Down Expand Up @@ -186,17 +186,11 @@ uEscapedToXEscaped ss =
-- |Validate a Text URI and return it in a @Just Text@ if it is
-- valid, otherwise @Nothing@ is returned. See 'unodeValidate'.
uriValidate :: T.Text -> Maybe T.Text
uriValidate t = case isRdfURI of
uriValidate t = case isRdfURI t of
Left _err -> Nothing
Right uri -> Just uri
where
isRdfURI = parse (isRdfURIParser <* eof) ("Invalid URI: " ++ T.unpack t) t
-- [18] IRIREF from Turtle spec
isRdfURIParser = T.concat <$> many (T.singleton <$> noneOf (['\x00'..'\x20'] ++ [' ','<','>','"','{','}','|','^','`','\\']) <|> nt_uchar)
nt_uchar =
(try (char '\\' >> char 'u' >> count 4 hexDigit >>= \cs -> return $ T.pack (uEscapedToXEscaped cs)) <|>
try (char '\\' >> char 'U' >> count 8 hexDigit >>= \cs -> return $ T.pack (uEscapedToXEscaped cs)))

-- |Same as 'uriValidate', but on 'String' rather than 'T.Text'
uriValidateString :: String -> Maybe String
uriValidateString t = case isRdfURIString of
Left _err -> Nothing
Expand Down
9 changes: 4 additions & 5 deletions src/Text/RDF/RDF4H/NTriplesParser.hs
Expand Up @@ -10,15 +10,11 @@ import Data.RDF.Types
import Text.RDF.RDF4H.ParserUtils
import Data.Char (isLetter, isDigit,isAlphaNum)
import Data.Map as Map (empty)
import qualified Data.IntMap as M
import qualified Data.IntSet as S
import Data.Hashable (hash)
import Data.Maybe (catMaybes)
import Text.Parsec
import Text.Parsec.Text
import qualified Data.Text as T
import qualified Data.Text.IO as TIO
import Control.Monad (liftM,void,unless, guard)
import Control.Monad (liftM,void,guard)

-- |NTriplesParser is an 'RdfParser' implementation for parsing RDF in the
-- NTriples format. It requires no configuration options. To use this parser,
Expand Down Expand Up @@ -192,11 +188,14 @@ nt_blank_node_label = do
return (T.pack ("_:" ++ [s1] ++ s2))

-- [157s] PN_CHARS_BASE
-- Not used. It used to be. What's happened?
{-
nt_pn_chars_base :: GenParser () Char
nt_pn_chars_base = try $ do
c <- anyChar
guard $ isBaseChar c
return c
-}

isBaseChar :: Char -> Bool
isBaseChar c
Expand Down

0 comments on commit a08040b

Please sign in to comment.